2023-02-03 10:33:56 +00:00
|
|
|
@using ImageBoardServerApp.Auth
|
2023-01-26 12:04:55 +00:00
|
|
|
@using ImageBoardServerApp.Data.Repository
|
2023-05-17 11:17:53 +00:00
|
|
|
@using ImageBoardServerApp.Util
|
2023-04-10 17:19:55 +00:00
|
|
|
@using System.Text.RegularExpressions
|
2023-03-17 23:52:30 +00:00
|
|
|
@using System.ComponentModel.DataAnnotations
|
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-13 17:45:14 +00:00
|
|
|
@if (@role != "User")
|
2023-02-07 20:21:38 +00:00
|
|
|
{
|
2023-02-13 17:45:14 +00:00
|
|
|
<span class="@role" >##@role</span>
|
2023-02-07 20:21:38 +00:00
|
|
|
}
|
2023-01-25 22:45:36 +00:00
|
|
|
<span class="date">@getTimeFromUnix(comment.CreatedAt)</span>
|
2023-03-11 01:50:07 +00:00
|
|
|
<span class="post-id">No.@comment.GET</span>
|
2023-01-25 22:45:36 +00:00
|
|
|
</div>
|
|
|
|
@if (opened)
|
|
|
|
{
|
|
|
|
<div class="threadContent">
|
|
|
|
<div class="threadImage">
|
2023-01-26 12:04:55 +00:00
|
|
|
@if (image != null)
|
2023-01-25 22:45:36 +00:00
|
|
|
{
|
2023-03-17 23:52:30 +00:00
|
|
|
string isActiveClass = isActive ? "active" : "";
|
|
|
|
<img @onclick="() => isActive = !isActive" class="@isActiveClass" src="@($"{@image.ImageLocation}?size=258x258")" alt="No Image found" />
|
2023-01-25 22:45:36 +00:00
|
|
|
}
|
|
|
|
</div>
|
|
|
|
<div class="threadTextContainer">
|
2023-03-17 23:52:30 +00:00
|
|
|
@for (var y = 0; y < comment.Content.Split("\n").Length; y++)
|
2023-01-25 22:45:36 +00:00
|
|
|
{
|
2023-03-17 23:52:30 +00:00
|
|
|
var s = comment.Content.Split("\n")[y];
|
2023-02-24 23:08:36 +00:00
|
|
|
var className = "";
|
2023-03-17 23:52:30 +00:00
|
|
|
|
2023-02-24 23:08:36 +00:00
|
|
|
@if (s.StartsWith(">") && !Regex.IsMatch(s, "^>{2,}"))
|
2023-01-26 12:04:55 +00:00
|
|
|
{
|
2023-02-24 23:08:36 +00:00
|
|
|
className = "greenText";
|
2023-01-26 12:04:55 +00:00
|
|
|
}
|
2023-02-24 23:08:36 +00:00
|
|
|
<span class='threadText @className'>
|
2023-03-17 23:52:30 +00:00
|
|
|
@for (var x = 0; x < s.Split(" ").Length; x++)
|
|
|
|
{
|
|
|
|
var line = s.Split(" ")[x];
|
2023-02-24 23:08:36 +00:00
|
|
|
@if (@Regex.IsMatch(line, ">>\\d+"))
|
|
|
|
{
|
2023-03-17 23:52:30 +00:00
|
|
|
var className2 = "";
|
|
|
|
var x1 = x;
|
|
|
|
var y1 = y;
|
|
|
|
var commentNumber = int.Parse(Regex.Match(s, ">>(\\d+)").Value.Substring(2));
|
2023-02-24 23:08:36 +00:00
|
|
|
className2 = "redText";
|
2023-03-17 23:52:30 +00:00
|
|
|
<span
|
|
|
|
@onmouseenter="() => onHover(x1, y1, commentNumber)"
|
|
|
|
@onmouseleave="() => onHover(x1, y1, -1)" class="threadMsg @className2"
|
|
|
|
>
|
2023-02-24 23:08:36 +00:00
|
|
|
@line
|
2023-03-17 23:52:30 +00:00
|
|
|
</span>
|
2023-04-10 17:19:55 +00:00
|
|
|
@if (hoveringOver.p != -1 && hoveringOver == (x, y, commentNumber) && (hoverComment.ContainsKey(commentNumber) || hoverPost.ContainsKey(commentNumber)))
|
2023-03-17 23:52:30 +00:00
|
|
|
{
|
|
|
|
@if (isComment[commentNumber])
|
|
|
|
{
|
|
|
|
<div>
|
|
|
|
<CommentHover comment="hoverComment[commentNumber]"/>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
<div>
|
|
|
|
<Post post="hoverPost[commentNumber]" showOpenThread="false"/>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
}
|
2023-02-24 23:08:36 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
<span class="threadMsg">
|
|
|
|
@line
|
|
|
|
</span>
|
|
|
|
}
|
|
|
|
<span> </span>
|
|
|
|
|
|
|
|
}
|
|
|
|
</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>
|
2023-04-10 17:19:55 +00:00
|
|
|
<!--
|
|
|
|
<button class="button-31" role="button">Button 31</button>
|
|
|
|
|
|
|
|
/* CSS */
|
|
|
|
.button-31 {
|
|
|
|
background-color: #222;
|
|
|
|
border-radius: 4px;
|
|
|
|
border-style: none;
|
|
|
|
box-sizing: border-box;
|
|
|
|
color: #fff;
|
|
|
|
cursor: pointer;
|
|
|
|
display: inline-block;
|
|
|
|
font-family: "Farfetch Basis","Helvetica Neue",Arial,sans-serif;
|
|
|
|
font-size: 16px;
|
|
|
|
font-weight: 700;
|
|
|
|
line-height: 1.5;
|
|
|
|
margin: 0;
|
|
|
|
max-width: none;
|
|
|
|
min-height: 44px;
|
|
|
|
min-width: 10px;
|
|
|
|
outline: none;
|
|
|
|
overflow: hidden;
|
|
|
|
padding: 9px 20px 8px;
|
|
|
|
position: relative;
|
|
|
|
text-align: center;
|
|
|
|
text-transform: none;
|
|
|
|
user-select: none;
|
|
|
|
-webkit-user-select: none;
|
|
|
|
touch-action: manipulation;
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
|
|
|
|
.button-31:hover,
|
|
|
|
.button-31:focus {
|
|
|
|
opacity: .75;
|
|
|
|
}
|
|
|
|
!-->
|
2023-02-03 10:33:56 +00:00
|
|
|
<span>]</span>
|
|
|
|
<span>[</span>
|
2023-02-12 16:01:46 +00:00
|
|
|
<a class="report" href="/sys/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
|
|
|
|
2023-03-17 23:52:30 +00:00
|
|
|
private bool isActive { get; set; } = false;
|
|
|
|
|
|
|
|
private (int x, int y, int p) hoveringOver { get; set; } = (-1, -1, -1);
|
|
|
|
private Dictionary<int, bool> isComment{ get; set; }
|
|
|
|
private Dictionary<int, CommentData> hoverComment { get; set; }
|
|
|
|
private Dictionary<int, PostData> hoverPost { get; set; }
|
|
|
|
private Dictionary<int, int> nrToGet { get; set; }
|
|
|
|
|
|
|
|
private void onHover(int x, int y, int p)
|
|
|
|
{
|
2023-04-10 17:19:55 +00:00
|
|
|
if (hoverComment.ContainsKey(p) || hoverPost.ContainsKey(p))
|
|
|
|
{
|
|
|
|
hoveringOver= (x, y, -1);
|
|
|
|
}
|
2023-03-17 23:52:30 +00:00
|
|
|
hoveringOver = (x, y, p);
|
|
|
|
}
|
|
|
|
|
2023-03-10 23:56:51 +00:00
|
|
|
public bool canDel { get; set; }
|
|
|
|
|
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);
|
2023-02-24 23:08:36 +00:00
|
|
|
if (foundusr.Role != "User" || comment.UserID == foundusr.UserID)
|
2023-02-03 10:33:56 +00:00
|
|
|
{
|
2023-02-13 17:45:14 +00:00
|
|
|
await TheManager.deleteComment(comment);
|
2023-02-03 10:33:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2023-01-26 12:04:55 +00:00
|
|
|
|
|
|
|
private ImageData image;
|
2023-02-13 17:45:14 +00:00
|
|
|
private string role;
|
2023-03-10 23:56:51 +00:00
|
|
|
|
2023-03-11 15:00:50 +00:00
|
|
|
protected override async Task OnParametersSetAsync()
|
2023-03-10 23:56:51 +00:00
|
|
|
{
|
2023-03-11 15:00:50 +00:00
|
|
|
await base.OnParametersSetAsync();
|
2023-03-10 23:56:51 +00:00
|
|
|
var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider;
|
|
|
|
var user = await cauthStateProvder.GetAuthenticationStateAsync();
|
|
|
|
var usr = user.User;
|
|
|
|
UserData foundusr = await UsersRepository.getUserByEmailAsync(usr.Identity.Name);
|
|
|
|
if (foundusr != null && (foundusr.Role != "User" || comment.UserID == foundusr.UserID))
|
|
|
|
{
|
|
|
|
canDel = true;
|
|
|
|
}
|
|
|
|
canDel = false;
|
2023-03-17 23:52:30 +00:00
|
|
|
|
|
|
|
hoverComment = new Dictionary<int, CommentData>();
|
|
|
|
hoverPost = new Dictionary<int, PostData>();
|
|
|
|
nrToGet = new Dictionary<int, int>();
|
|
|
|
isComment = new Dictionary<int, bool>();
|
|
|
|
|
|
|
|
foreach (string s in comment.Content.Split("\n"))
|
|
|
|
{
|
|
|
|
@foreach (string line in s.Split(" "))
|
|
|
|
{
|
|
|
|
@if (Regex.IsMatch(line, ">>\\d+"))
|
|
|
|
{
|
|
|
|
var commentNumber = int.Parse(Regex.Match(s, ">>(\\d+)").Value.Substring(2));
|
|
|
|
string board = comment.Board;
|
|
|
|
if (await TheManager.isGETComment(board, commentNumber))
|
|
|
|
{
|
|
|
|
CommentData c = await CommentsRepository.getCommentByGETAsync(board, commentNumber);
|
|
|
|
if (c == null)
|
|
|
|
continue;
|
|
|
|
hoverComment[commentNumber] = c;
|
|
|
|
nrToGet[commentNumber] = c.GET;
|
|
|
|
isComment[commentNumber] = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PostData p = await PostsRepository.getPostByGETAsync(board, commentNumber);
|
|
|
|
if (p == null)
|
|
|
|
continue;
|
|
|
|
hoverPost[commentNumber] = p;
|
|
|
|
nrToGet[commentNumber] = p.GET;
|
|
|
|
isComment[commentNumber] = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-03-10 23:56:51 +00:00
|
|
|
}
|
|
|
|
|
2023-01-26 12:04:55 +00:00
|
|
|
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-02-13 17:45:14 +00:00
|
|
|
|
|
|
|
var cmt = await CommentsRepository.getCommentByIdAsync(comment.CommentID);
|
|
|
|
role = cmt.User.Role;
|
2023-01-26 12:04:55 +00:00
|
|
|
}
|
2023-01-25 22:45:36 +00:00
|
|
|
|
|
|
|
private bool opened = true;
|
|
|
|
|
|
|
|
private string toggleText = "-";
|
|
|
|
|
|
|
|
private void ToggleOpened()
|
|
|
|
{
|
|
|
|
opened = !opened;
|
|
|
|
toggleText = opened ? "-" : "+";
|
|
|
|
}
|
|
|
|
|
2023-03-17 23:52:30 +00:00
|
|
|
private string toggleText2 = "-";
|
|
|
|
private bool showHover = false;
|
|
|
|
private void ToggleHovered(MouseEventArgs e, string id)
|
|
|
|
{
|
|
|
|
showHover = !showHover;
|
|
|
|
toggleText2 = showHover ? "-" : "+";
|
|
|
|
}
|
|
|
|
|
2023-01-25 22:45:36 +00:00
|
|
|
[Parameter]
|
|
|
|
[Required]
|
|
|
|
public CommentData comment { get; set; }
|
|
|
|
}
|