bulletboards/ImageBoardServerApp/Shared/Components/CommentHover.razor

100 lines
2.9 KiB
Text
Raw Permalink Normal View History

@using ImageBoardServerApp.Data.Repository
@using System.ComponentModel.DataAnnotations
@using System.Text.RegularExpressions
<div class="comment">
<span class="name">@comment.Username</span>
@if (@role != "User" && !comment.shouldAnon)
{
<span class="@role">##@role&nbsp;</span>
}
else
{
<span>&nbsp;</span>
}
<span class="date">@getTimeFromUnix(comment.CreatedAt)</span>
<span class="post-id">No.@comment.GET</span>
<div class="threadContent">
@if (image != null)
{
<div class="threadImage">
<img src="@($"{image.ImageLocation}?size=258x258")" alt="No Image found"/>
</div>
}
<div class="threadTextContainer">
@for (var y = 0; y < comment.Content.Split("\n").Length; y++)
{
var s = comment.Content.Split("\n")[y];
var className = "";
@if (s.StartsWith(">") && !Regex.IsMatch(s, "^>{2,}"))
{
className = "greenText";
}
<p class='threadText @className'>
@for (var x = 0; x < s.Split(" ").Length; x++)
{
var line = s.Split(" ")[x];
@if (@Regex.IsMatch(line, ">>\\d+"))
{
var className2 = "";
<a class="redText">
@line
</a>
}
else
{
@if (line.StartsWith("https://") || line.StartsWith("http://"))
{
<a href="@line">@line</a>
}
else
{
@line
}
@(" ")
}
}
</p>
}
</div>
</div>
</div>
@code {
private ImageData image;
private string role;
private static DateTime getTimeFromUnix(double javaTimeStamp)
{
var dateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
dateTime = dateTime.AddMilliseconds(javaTimeStamp).ToLocalTime();
return dateTime;
}
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
int i;
try
{
i = (int)comment.ImageID;
}
catch (InvalidOperationException ioe)
{
i = -1;
}
if (i != null)
{
image = await ImagesRepository.getImageByIdAsync(i);
}
var cmt = await CommentsRepository.getCommentByIdAsync(comment.CommentID);
role = cmt.User.Role;
}
[Parameter]
[Required]
public CommentData comment { get; set; }
}