108 lines
No EOL
3 KiB
Text
108 lines
No EOL
3 KiB
Text
@using System.ComponentModel.DataAnnotations
|
|
@using ImageBoardServerApp.Auth
|
|
@using ImageBoardServerApp.Data
|
|
@using ImageBoardServerApp.Data.Repository
|
|
@inject AuthenticationStateProvider authStateProvider
|
|
|
|
<div class="threadHeader">
|
|
<span>[</span>
|
|
<a class="toggleOpened" onclick="@ToggleOpened">@toggleText</a>
|
|
<span>]</span>
|
|
<span class="name">@comment.Username</span>
|
|
@if (@comment.User.Role != "User")
|
|
{
|
|
<span class="@comment.User.Role" >##@comment.User.Role</span>
|
|
}
|
|
<span class="date">@getTimeFromUnix(comment.CreatedAt)</span>
|
|
<span class="post-id">No.@comment.CommentID</span>
|
|
</div>
|
|
@if (opened)
|
|
{
|
|
<div class="threadContent">
|
|
<div class="threadImage">
|
|
@if (image != null)
|
|
{
|
|
<img src="@($"{image.ImageLocation}")" alt="No Image found" />
|
|
}
|
|
</div>
|
|
<div class="threadTextContainer">
|
|
@foreach (string s in @comment.Content.Split("\n"))
|
|
{
|
|
@if (s.StartsWith(">"))
|
|
{
|
|
<span class="threadText greenText">@s</span>
|
|
}
|
|
else
|
|
{
|
|
<span class='threadText'>@s</span>
|
|
}
|
|
}
|
|
</div>
|
|
</div>
|
|
<div class="threadFooter">
|
|
<span>[</span>
|
|
<a @onclick="@deletePost" href="javascript:void(0)">Delete</a>
|
|
<span>]</span>
|
|
<span>[</span>
|
|
<a class="report" href="/report/comment/@comment.Board/@comment.CommentID" target="_blank">Report</a>
|
|
<span>]</span>
|
|
</div>
|
|
}
|
|
|
|
|
|
|
|
@code {
|
|
|
|
private async Task deletePost()
|
|
{
|
|
var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider;
|
|
var user = await cauthStateProvder.GetAuthenticationStateAsync();
|
|
var usr = user.User;
|
|
UserData foundusr = await UsersRepository.getUserByEmailAsync(usr.Identity.Name);
|
|
if (foundusr.PermissionInteger >= 50 || comment.UserID == foundusr.UserID)
|
|
{
|
|
await CommentsRepository.deleteCommentAsync(comment.CommentID);
|
|
}
|
|
}
|
|
|
|
|
|
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;
|
|
}
|
|
|
|
private ImageData image;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
int i;
|
|
try
|
|
{
|
|
i = (int)comment.ImageID;
|
|
}
|
|
catch (InvalidOperationException ioe)
|
|
{
|
|
i = -1;
|
|
}
|
|
if (i != null)
|
|
{
|
|
image = await ImagesRepository.getImageByIdAsync(i);
|
|
}
|
|
}
|
|
|
|
private bool opened = true;
|
|
|
|
private string toggleText = "-";
|
|
|
|
private void ToggleOpened()
|
|
{
|
|
opened = !opened;
|
|
toggleText = opened ? "-" : "+";
|
|
}
|
|
|
|
[Parameter]
|
|
[Required]
|
|
public CommentData comment { get; set; }
|
|
} |