bulletboards/ImageBoardServerApp/Shared/Components/Comment.razor

108 lines
3 KiB
Text
Raw Normal View History

2023-01-25 22:45:36 +00:00
@using System.ComponentModel.DataAnnotations
2023-02-03 10:33:56 +00:00
@using ImageBoardServerApp.Auth
2023-01-25 22:45:36 +00:00
@using ImageBoardServerApp.Data
@using ImageBoardServerApp.Data.Repository
2023-02-03 10:33:56 +00:00
@inject AuthenticationStateProvider authStateProvider
2023-01-25 22:45:36 +00:00
<div class="threadHeader">
<span>[</span>
<a class="toggleOpened" onclick="@ToggleOpened">@toggleText</a>
<span>]</span>
<span class="name">@comment.Username</span>
2023-02-07 20:47:28 +00:00
@if (@comment.User.Role != "User")
2023-02-07 20:21:38 +00:00
{
<span class="@comment.User.Role" >##@comment.User.Role</span>
}
2023-01-25 22:45:36 +00:00
<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)
2023-01-25 22:45:36 +00:00
{
<img src="@($"{image.ImageLocation}")" alt="No Image found" />
2023-01-25 22:45:36 +00:00
}
</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>
}
2023-01-25 22:45:36 +00:00
}
</div>
</div>
<div class="threadFooter">
<span>[</span>
2023-02-03 10:33:56 +00:00
<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>
2023-01-25 22:45:36 +00:00
<span>]</span>
</div>
}
@code {
2023-02-03 10:33:56 +00:00
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);
}
}
2023-01-25 22:45:36 +00:00
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);
}
}
2023-01-25 22:45:36 +00:00
private bool opened = true;
private string toggleText = "-";
private void ToggleOpened()
{
opened = !opened;
toggleText = opened ? "-" : "+";
}
[Parameter]
[Required]
public CommentData comment { get; set; }
}