2023-04-10 17:19:55 +00:00
|
|
|
@using ImageBoardServerApp.Data.Repository
|
2023-05-17 11:17:53 +00:00
|
|
|
@using ImageBoardServerApp.Util
|
2023-03-17 23:49:50 +00:00
|
|
|
@using ImageBoardServerApp.Auth
|
|
|
|
@using System.ComponentModel.DataAnnotations
|
2023-04-10 17:19:55 +00:00
|
|
|
@using System.Text.RegularExpressions
|
2023-02-02 17:50:50 +00:00
|
|
|
@inject AuthenticationStateProvider authStateProvider
|
2023-02-13 17:45:14 +00:00
|
|
|
@inject NavigationManager navigationManager;
|
2023-01-18 12:56:24 +00:00
|
|
|
|
2023-02-24 23:08:36 +00:00
|
|
|
|
2023-06-07 12:46:39 +00:00
|
|
|
<div class="post">
|
|
|
|
<div class="threadHeader">
|
|
|
|
@if (showOpenThread)
|
2023-02-07 20:47:28 +00:00
|
|
|
{
|
2023-06-07 12:46:39 +00:00
|
|
|
<span>[</span>
|
|
|
|
<a class="toggleOpened" onclick="@ToggleOpened">@toggleText</a>
|
|
|
|
<span>] </span>
|
2023-02-07 20:47:28 +00:00
|
|
|
}
|
2023-06-07 12:46:39 +00:00
|
|
|
<span class="title">@post.Title</span>
|
|
|
|
<span class="name">@post.Username </span>
|
2023-06-13 06:51:53 +00:00
|
|
|
@if (post.User.Role != "User" && !post.shouldAnon)
|
2023-06-12 16:51:25 +00:00
|
|
|
{
|
2023-06-13 06:51:53 +00:00
|
|
|
<span class="@post.User.Role">##@post.User.Role </span>
|
2023-06-12 16:51:25 +00:00
|
|
|
}
|
2023-06-13 06:51:53 +00:00
|
|
|
<span> </span>
|
2023-06-07 12:46:39 +00:00
|
|
|
<span class="date"> @getTimeFromUnix(post.CreatedAt)</span>
|
|
|
|
<span class="post-id">No.@post.GET</span>
|
|
|
|
@if (post.IsSticky)
|
|
|
|
{
|
|
|
|
<img src="img/static/sys/sticky.png" alt="Stickied"/>
|
|
|
|
}
|
|
|
|
@if (post.IsLocked)
|
|
|
|
{
|
|
|
|
<img src="img/static/sys/locked.png" alt="Locked"/>
|
|
|
|
}
|
2023-01-18 12:56:24 +00:00
|
|
|
</div>
|
2023-06-12 16:51:25 +00:00
|
|
|
@if (opened)
|
2023-06-07 12:46:39 +00:00
|
|
|
{
|
|
|
|
<div class="threadContent">
|
|
|
|
<div class="threadImage">
|
|
|
|
@if (@post.Image != null)
|
2023-02-27 13:34:41 +00:00
|
|
|
{
|
2023-06-07 12:46:39 +00:00
|
|
|
string isActiveClass = isActive ? "active" : "";
|
2023-06-12 16:51:25 +00:00
|
|
|
<img @onclick="() => isActive = !isActive" class="@isActiveClass" src="@($"{@post.Image.ImageLocation}?size=258x258")" alt="No Image found"/>
|
2023-02-27 13:34:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-06-07 12:46:39 +00:00
|
|
|
<span>[No Image]</span>
|
2023-02-27 13:34:41 +00:00
|
|
|
}
|
2023-06-07 12:46:39 +00:00
|
|
|
</div>
|
|
|
|
<div class="threadTextContainer">
|
|
|
|
@if (showOpenThread)
|
2023-02-27 13:34:41 +00:00
|
|
|
{
|
2023-06-13 12:35:44 +00:00
|
|
|
@foreach (string s in post.Content.Split("\n").Take(6))
|
2023-06-07 12:46:39 +00:00
|
|
|
{
|
|
|
|
var className = "";
|
|
|
|
@if (s.StartsWith(">") && !Regex.IsMatch(s, "^>{2,}"))
|
|
|
|
{
|
|
|
|
className = "greenText";
|
|
|
|
}
|
2023-06-13 12:35:44 +00:00
|
|
|
<p class="@className">
|
|
|
|
@foreach (string s2 in s.Split(" "))
|
2023-06-12 20:29:32 +00:00
|
|
|
{
|
2023-06-13 12:35:44 +00:00
|
|
|
@if (s2.StartsWith("https://") || s2.StartsWith("http://"))
|
|
|
|
{
|
|
|
|
<a href="@s2">@s2</a>
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
@s2
|
|
|
|
}
|
|
|
|
@(" ")
|
2023-06-12 20:29:32 +00:00
|
|
|
}
|
2023-06-13 12:35:44 +00:00
|
|
|
</p>
|
|
|
|
<p/>
|
2023-06-07 12:46:39 +00:00
|
|
|
}
|
|
|
|
@if (post.Content.Split("\n").Length > 6)
|
|
|
|
{
|
2023-06-13 12:35:44 +00:00
|
|
|
<p class="greenText">[Open thread to read more...]</p>
|
2023-06-07 12:46:39 +00:00
|
|
|
}
|
2023-02-27 13:34:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-06-07 12:46:39 +00:00
|
|
|
@foreach (string s in post.Content.Split("\n"))
|
|
|
|
{
|
|
|
|
var className = "";
|
|
|
|
@if (s.StartsWith(">") && !Regex.IsMatch(s, "^>{2,}"))
|
|
|
|
{
|
|
|
|
className = "greenText";
|
|
|
|
}
|
2023-06-13 12:35:44 +00:00
|
|
|
<p class="@className">
|
|
|
|
@foreach (string s2 in s.Split(" "))
|
2023-06-12 20:29:32 +00:00
|
|
|
{
|
2023-06-13 12:35:44 +00:00
|
|
|
@if (s2.StartsWith("https://") || s2.StartsWith("http://"))
|
|
|
|
{
|
|
|
|
<a href="@s2">@s2</a>
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
@s2
|
|
|
|
}
|
|
|
|
@(" ")
|
2023-06-12 20:29:32 +00:00
|
|
|
}
|
2023-06-13 12:35:44 +00:00
|
|
|
</p>
|
|
|
|
<p/>
|
2023-06-12 16:51:25 +00:00
|
|
|
}
|
2023-02-27 13:34:41 +00:00
|
|
|
}
|
2023-06-07 12:46:39 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="threadFooter">
|
|
|
|
<AuthorizeView Roles="Admin, Mod">
|
|
|
|
<Authorized>
|
2023-06-07 12:49:04 +00:00
|
|
|
<span>[</span>
|
2023-06-07 12:46:39 +00:00
|
|
|
@if (post.IsSticky)
|
|
|
|
{
|
|
|
|
<button class="statButton" onclick="@stickyMe">Unsticky</button>
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
<button class="statButton" onclick="@stickyMe">Sticky</button>
|
|
|
|
}
|
|
|
|
@if (post.IsLocked)
|
|
|
|
{
|
|
|
|
<button class="statButton" onclick="@lockMe">Unlock</button>
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
<button class="statButton" onclick="@lockMe">Lock</button>
|
|
|
|
}
|
2023-06-07 12:49:04 +00:00
|
|
|
<span>]</span>
|
2023-06-07 12:46:39 +00:00
|
|
|
</Authorized>
|
|
|
|
</AuthorizeView>
|
2023-06-07 12:49:04 +00:00
|
|
|
<span>[</span>
|
2023-06-07 12:46:39 +00:00
|
|
|
<a class="repButton" href="@reportURL" target="_blank">Report</a>
|
|
|
|
@if (canDel)
|
|
|
|
{
|
|
|
|
<button class="delButton" onclick="@deletePost">Delete</button>
|
|
|
|
}
|
|
|
|
@if (showOpenThread)
|
|
|
|
{
|
|
|
|
<a class="opButton" href="@threadURL">@openThreadName</a>
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
<span class="openThread">@post.Comments.Count Comments</span>
|
|
|
|
}
|
2023-06-07 12:49:04 +00:00
|
|
|
<span>]</span>
|
2023-06-07 12:46:39 +00:00
|
|
|
</div>
|
|
|
|
}
|
|
|
|
</div>
|
2023-01-18 12:56:24 +00:00
|
|
|
|
|
|
|
@code {
|
2023-06-07 12:46:39 +00:00
|
|
|
private string reportURL { get; set; }
|
|
|
|
private string threadURL { get; set; }
|
|
|
|
private string openThreadName { get; set; }
|
|
|
|
|
2023-06-12 16:51:25 +00:00
|
|
|
public bool canDel { get; set; } = false;
|
2023-03-17 23:49:50 +00:00
|
|
|
public bool isActive { get; set; } = false;
|
2023-05-31 12:13:18 +00:00
|
|
|
|
|
|
|
private int linecnt = 0;
|
2023-06-12 16:51:25 +00:00
|
|
|
|
2023-02-27 13:34:41 +00:00
|
|
|
private async void lockMe()
|
2023-02-24 23:08:36 +00:00
|
|
|
{
|
|
|
|
post.IsLocked = !post.IsLocked;
|
|
|
|
await PostsRepository.updatePostAsync(post);
|
|
|
|
}
|
|
|
|
|
2023-02-27 13:34:41 +00:00
|
|
|
private async void stickyMe()
|
2023-02-24 23:08:36 +00:00
|
|
|
{
|
|
|
|
post.IsSticky = !post.IsSticky;
|
|
|
|
await PostsRepository.updatePostAsync(post);
|
|
|
|
}
|
2023-06-12 16:51:25 +00:00
|
|
|
|
2023-01-18 12:56:24 +00:00
|
|
|
private static DateTime getTimeFromUnix(double javaTimeStamp)
|
|
|
|
{
|
|
|
|
var dateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
|
2023-06-12 16:51:25 +00:00
|
|
|
dateTime = dateTime.AddMilliseconds(javaTimeStamp).ToLocalTime();
|
2023-01-18 12:56:24 +00:00
|
|
|
return dateTime;
|
|
|
|
}
|
2023-03-10 23:56:51 +00:00
|
|
|
|
2023-02-02 17:50:50 +00:00
|
|
|
private async Task deletePost()
|
|
|
|
{
|
2023-02-13 17:45:14 +00:00
|
|
|
string boardTag = post.Board;
|
2023-02-02 17:50:50 +00:00
|
|
|
var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider;
|
|
|
|
var user = await cauthStateProvder.GetAuthenticationStateAsync();
|
|
|
|
var usr = user.User;
|
2023-06-12 18:46:44 +00:00
|
|
|
UserData foundusr = await UsersRepository.getUserByEmailRawAsync(usr.Identity.Name);
|
2023-02-24 23:08:36 +00:00
|
|
|
if (foundusr.Role != "User" || post.UserID == foundusr.UserID)
|
2023-02-02 17:50:50 +00:00
|
|
|
{
|
2023-02-13 17:45:14 +00:00
|
|
|
await TheManager.deleteThread(post);
|
2023-06-13 15:08:44 +00:00
|
|
|
navigationManager.NavigateTo($"/sys/click/red/_{boardTag}");
|
2023-02-02 17:50:50 +00:00
|
|
|
}
|
|
|
|
}
|
2023-02-24 23:08:36 +00:00
|
|
|
|
|
|
|
|
2023-01-18 12:56:24 +00:00
|
|
|
private bool opened = true;
|
|
|
|
|
|
|
|
private string toggleText = "-";
|
|
|
|
|
2023-02-14 11:46:52 +00:00
|
|
|
private string value;
|
|
|
|
|
2023-01-18 12:56:24 +00:00
|
|
|
private void ToggleOpened()
|
|
|
|
{
|
|
|
|
opened = !opened;
|
|
|
|
toggleText = opened ? "-" : "+";
|
|
|
|
}
|
|
|
|
|
2023-06-12 16:51:25 +00:00
|
|
|
protected override async Task OnInitializedAsync()
|
2023-02-14 11:46:52 +00:00
|
|
|
{
|
|
|
|
value = TheManager.getBumpValue(post) + "v";
|
2023-06-07 12:46:39 +00:00
|
|
|
|
|
|
|
reportURL = $"/sys/report/op/{post.Board}/{post.PostID}";
|
|
|
|
threadURL = $"/{post.Board}/thread/{post.PostID}";
|
|
|
|
openThreadName = $"({post.Comments.Count}) View Thread";
|
2023-06-12 16:51:25 +00:00
|
|
|
|
2023-06-13 06:51:53 +00:00
|
|
|
var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider;
|
|
|
|
var user = await cauthStateProvder.GetAuthenticationStateAsync();
|
|
|
|
UserData foundusr = await UsersRepository.getUserByEmailRawAsync(user.User.Identity.Name);
|
2023-03-10 23:56:51 +00:00
|
|
|
if (foundusr != null && (foundusr.Role != "User" || post.UserID == foundusr.UserID))
|
|
|
|
{
|
|
|
|
canDel = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
canDel = false;
|
2023-06-13 06:51:53 +00:00
|
|
|
await base.OnInitializedAsync();
|
2023-02-14 11:46:52 +00:00
|
|
|
}
|
|
|
|
|
2023-06-12 16:51:25 +00:00
|
|
|
|
2023-01-18 12:56:24 +00:00
|
|
|
[Parameter]
|
|
|
|
[Required]
|
|
|
|
public PostData post { get; set; }
|
2023-06-12 16:51:25 +00:00
|
|
|
|
|
|
|
|
2023-01-25 22:45:36 +00:00
|
|
|
[Parameter]
|
|
|
|
[Required]
|
|
|
|
public bool showOpenThread { get; set; }
|
2023-06-12 16:51:25 +00:00
|
|
|
|
2023-01-18 12:56:24 +00:00
|
|
|
}
|