2021-07-17 20:42:55 +00:00
|
|
|
import autosize from "autosize";
|
2021-08-12 01:06:54 +00:00
|
|
|
import { Component, createRef, linkEvent, RefObject } from "inferno";
|
2020-09-06 16:15:25 +00:00
|
|
|
import {
|
2021-07-17 20:42:55 +00:00
|
|
|
AddAdminResponse,
|
|
|
|
AddModToCommunityResponse,
|
2020-09-06 16:15:25 +00:00
|
|
|
BanFromCommunityResponse,
|
2021-03-15 18:09:31 +00:00
|
|
|
BanPersonResponse,
|
2021-08-20 02:56:18 +00:00
|
|
|
BlockPersonResponse,
|
2022-07-30 13:28:08 +00:00
|
|
|
CommentNode as CommentNodeI,
|
2021-09-28 10:38:59 +00:00
|
|
|
CommentReportResponse,
|
2021-07-17 20:42:55 +00:00
|
|
|
CommentResponse,
|
2022-07-30 13:28:08 +00:00
|
|
|
CommentSortType,
|
2021-07-17 20:42:55 +00:00
|
|
|
CommunityResponse,
|
2022-07-30 13:28:08 +00:00
|
|
|
GetComments,
|
|
|
|
GetCommentsResponse,
|
2021-07-17 20:42:55 +00:00
|
|
|
GetCommunityResponse,
|
2020-12-24 01:58:27 +00:00
|
|
|
GetPost,
|
2021-07-17 20:42:55 +00:00
|
|
|
GetPostResponse,
|
2020-09-06 16:15:25 +00:00
|
|
|
GetSiteResponse,
|
2021-04-23 21:48:31 +00:00
|
|
|
ListingType,
|
2021-09-28 10:38:59 +00:00
|
|
|
PostReportResponse,
|
2021-07-17 20:42:55 +00:00
|
|
|
PostResponse,
|
|
|
|
PostView,
|
2022-06-23 19:44:05 +00:00
|
|
|
PurgeItemResponse,
|
2021-07-17 20:42:55 +00:00
|
|
|
Search,
|
|
|
|
SearchResponse,
|
|
|
|
SearchType,
|
|
|
|
SortType,
|
|
|
|
UserOperation,
|
2022-06-21 21:42:29 +00:00
|
|
|
wsJsonToRes,
|
|
|
|
wsUserOp,
|
2021-02-22 02:39:04 +00:00
|
|
|
} from "lemmy-js-client";
|
2021-07-17 20:42:55 +00:00
|
|
|
import { Subscription } from "rxjs";
|
|
|
|
import { i18n } from "../../i18next";
|
2022-07-30 13:28:08 +00:00
|
|
|
import { CommentViewType, InitialFetchRequest } from "../../interfaces";
|
2021-07-17 20:42:55 +00:00
|
|
|
import { UserService, WebSocketService } from "../../services";
|
2020-09-06 16:15:25 +00:00
|
|
|
import {
|
2021-07-17 20:42:55 +00:00
|
|
|
buildCommentsTree,
|
|
|
|
commentsToFlatNodes,
|
2022-07-30 13:28:08 +00:00
|
|
|
commentTreeMaxDepth,
|
2020-09-06 16:15:25 +00:00
|
|
|
createCommentLikeRes,
|
|
|
|
createPostLikeRes,
|
2021-11-16 14:46:12 +00:00
|
|
|
debounce,
|
2021-07-17 20:42:55 +00:00
|
|
|
editCommentRes,
|
2022-06-21 21:42:29 +00:00
|
|
|
enableDownvotes,
|
|
|
|
enableNsfw,
|
2020-09-09 00:48:17 +00:00
|
|
|
getCommentIdFromProps,
|
2022-07-30 13:28:08 +00:00
|
|
|
getCommentParentId,
|
|
|
|
getDepthFromComment,
|
2021-07-17 20:42:55 +00:00
|
|
|
getIdFromProps,
|
|
|
|
insertCommentIntoTree,
|
2020-09-09 00:48:17 +00:00
|
|
|
isBrowser,
|
2020-09-11 18:09:21 +00:00
|
|
|
isImage,
|
2023-01-04 16:56:24 +00:00
|
|
|
myAuth,
|
2021-02-02 18:36:59 +00:00
|
|
|
restoreScrollPosition,
|
2021-07-17 20:42:55 +00:00
|
|
|
saveCommentRes,
|
|
|
|
saveScrollPosition,
|
|
|
|
setIsoData,
|
|
|
|
setupTippy,
|
|
|
|
toast,
|
2022-06-21 21:42:29 +00:00
|
|
|
trendingFetchLimit,
|
2021-08-20 02:56:18 +00:00
|
|
|
updatePersonBlock,
|
2021-07-17 20:42:55 +00:00
|
|
|
wsClient,
|
|
|
|
wsSubscribe,
|
|
|
|
} from "../../utils";
|
|
|
|
import { CommentForm } from "../comment/comment-form";
|
|
|
|
import { CommentNodes } from "../comment/comment-nodes";
|
|
|
|
import { HtmlTags } from "../common/html-tags";
|
2021-07-18 03:56:33 +00:00
|
|
|
import { Icon, Spinner } from "../common/icon";
|
2021-07-17 20:42:55 +00:00
|
|
|
import { Sidebar } from "../community/sidebar";
|
2021-02-22 02:39:04 +00:00
|
|
|
import { PostListing } from "./post-listing";
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2021-11-16 14:46:12 +00:00
|
|
|
const commentsShownInterval = 15;
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
interface PostState {
|
2023-01-04 16:56:24 +00:00
|
|
|
postId?: number;
|
|
|
|
commentId?: number;
|
|
|
|
postRes?: GetPostResponse;
|
|
|
|
commentsRes?: GetCommentsResponse;
|
2021-02-08 04:23:31 +00:00
|
|
|
commentTree: CommentNodeI[];
|
2020-09-06 16:15:25 +00:00
|
|
|
commentSort: CommentSortType;
|
|
|
|
commentViewType: CommentViewType;
|
|
|
|
scrolled?: boolean;
|
|
|
|
loading: boolean;
|
2023-01-04 16:56:24 +00:00
|
|
|
crossPosts?: PostView[];
|
2020-09-06 16:15:25 +00:00
|
|
|
siteRes: GetSiteResponse;
|
2021-08-12 01:00:26 +00:00
|
|
|
commentSectionRef?: RefObject<HTMLDivElement>;
|
2021-07-18 03:56:33 +00:00
|
|
|
showSidebarMobile: boolean;
|
2021-11-16 14:46:12 +00:00
|
|
|
maxCommentsShown: number;
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export class Post extends Component<any, PostState> {
|
2023-01-04 16:56:24 +00:00
|
|
|
private subscription?: Subscription;
|
|
|
|
private isoData = setIsoData(this.context);
|
2021-11-16 15:37:40 +00:00
|
|
|
private commentScrollDebounced: () => void;
|
2023-01-04 16:56:24 +00:00
|
|
|
state: PostState = {
|
2020-09-09 00:48:17 +00:00
|
|
|
postId: getIdFromProps(this.props),
|
|
|
|
commentId: getCommentIdFromProps(this.props),
|
2022-07-30 13:28:08 +00:00
|
|
|
commentTree: [],
|
|
|
|
commentSort: CommentSortType[CommentSortType.Hot],
|
2020-09-06 16:15:25 +00:00
|
|
|
commentViewType: CommentViewType.Tree,
|
|
|
|
scrolled: false,
|
|
|
|
loading: true,
|
2020-12-24 01:58:27 +00:00
|
|
|
siteRes: this.isoData.site_res,
|
2021-07-18 03:56:33 +00:00
|
|
|
showSidebarMobile: false,
|
2021-11-16 14:46:12 +00:00
|
|
|
maxCommentsShown: commentsShownInterval,
|
2020-09-06 16:15:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
constructor(props: any, context: any) {
|
|
|
|
super(props, context);
|
|
|
|
|
2020-09-09 00:48:17 +00:00
|
|
|
this.parseMessage = this.parseMessage.bind(this);
|
|
|
|
this.subscription = wsSubscribe(this.parseMessage);
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2022-09-22 15:03:35 +00:00
|
|
|
this.state = { ...this.state, commentSectionRef: createRef() };
|
|
|
|
|
2020-09-09 00:48:17 +00:00
|
|
|
// Only fetch the data if coming from another route
|
|
|
|
if (this.isoData.path == this.context.router.route.match.url) {
|
2022-09-22 15:03:35 +00:00
|
|
|
this.state = {
|
|
|
|
...this.state,
|
2023-01-04 16:56:24 +00:00
|
|
|
postRes: this.isoData.routeData[0] as GetPostResponse,
|
|
|
|
commentsRes: this.isoData.routeData[1] as GetCommentsResponse,
|
2022-09-22 15:03:35 +00:00
|
|
|
};
|
|
|
|
|
2023-01-04 16:56:24 +00:00
|
|
|
if (this.state.commentsRes) {
|
2022-09-22 15:03:35 +00:00
|
|
|
this.state = {
|
|
|
|
...this.state,
|
|
|
|
commentTree: buildCommentsTree(
|
2023-01-04 16:56:24 +00:00
|
|
|
this.state.commentsRes.comments,
|
|
|
|
!!this.state.commentId
|
2022-09-22 15:03:35 +00:00
|
|
|
),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
this.state = { ...this.state, loading: false };
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2021-01-24 01:41:23 +00:00
|
|
|
if (isBrowser()) {
|
2023-01-04 16:56:24 +00:00
|
|
|
if (this.state.postRes) {
|
|
|
|
WebSocketService.Instance.send(
|
|
|
|
wsClient.communityJoin({
|
|
|
|
community_id: this.state.postRes.community_view.community.id,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
2022-07-30 13:28:08 +00:00
|
|
|
|
2023-01-04 16:56:24 +00:00
|
|
|
if (this.state.postId) {
|
|
|
|
WebSocketService.Instance.send(
|
|
|
|
wsClient.postJoin({ post_id: this.state.postId })
|
|
|
|
);
|
|
|
|
}
|
2022-06-21 21:42:29 +00:00
|
|
|
|
2021-01-24 01:41:23 +00:00
|
|
|
this.fetchCrossPosts();
|
2021-08-12 01:06:54 +00:00
|
|
|
|
|
|
|
if (this.checkScrollIntoCommentsParam) {
|
2021-08-12 01:00:26 +00:00
|
|
|
this.scrollIntoCommentSection();
|
2021-01-24 01:41:23 +00:00
|
|
|
}
|
2020-09-09 00:48:17 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.fetchPost();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fetchPost() {
|
2023-01-04 16:56:24 +00:00
|
|
|
this.setState({ commentsRes: undefined, postRes: undefined });
|
|
|
|
let auth = myAuth(false);
|
|
|
|
let postForm: GetPost = {
|
2020-09-09 00:48:17 +00:00
|
|
|
id: this.state.postId,
|
2022-07-30 13:28:08 +00:00
|
|
|
comment_id: this.state.commentId,
|
2023-01-04 16:56:24 +00:00
|
|
|
auth,
|
|
|
|
};
|
2022-07-30 13:28:08 +00:00
|
|
|
WebSocketService.Instance.send(wsClient.getPost(postForm));
|
|
|
|
|
2023-01-04 16:56:24 +00:00
|
|
|
let commentsForm: GetComments = {
|
2022-07-30 13:28:08 +00:00
|
|
|
post_id: this.state.postId,
|
|
|
|
parent_id: this.state.commentId,
|
2023-01-04 16:56:24 +00:00
|
|
|
max_depth: commentTreeMaxDepth,
|
|
|
|
sort: this.state.commentSort,
|
|
|
|
type_: ListingType.All,
|
|
|
|
saved_only: false,
|
|
|
|
auth,
|
|
|
|
};
|
2022-07-30 13:28:08 +00:00
|
|
|
WebSocketService.Instance.send(wsClient.getComments(commentsForm));
|
2020-09-09 00:48:17 +00:00
|
|
|
}
|
|
|
|
|
2021-01-24 01:41:23 +00:00
|
|
|
fetchCrossPosts() {
|
2023-01-04 16:56:24 +00:00
|
|
|
let q = this.state.postRes?.post_view.post.url;
|
|
|
|
if (q) {
|
|
|
|
let form: Search = {
|
|
|
|
q,
|
|
|
|
type_: SearchType.Url,
|
|
|
|
sort: SortType.TopAll,
|
|
|
|
listing_type: ListingType.All,
|
|
|
|
page: 1,
|
|
|
|
limit: trendingFetchLimit,
|
|
|
|
auth: myAuth(false),
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.send(wsClient.search(form));
|
|
|
|
}
|
2021-01-24 01:41:23 +00:00
|
|
|
}
|
|
|
|
|
2020-11-12 21:56:46 +00:00
|
|
|
static fetchInitialData(req: InitialFetchRequest): Promise<any>[] {
|
2021-02-22 02:39:04 +00:00
|
|
|
let pathSplit = req.path.split("/");
|
2022-07-30 13:28:08 +00:00
|
|
|
let promises: Promise<any>[] = [];
|
2020-09-09 00:48:17 +00:00
|
|
|
|
2023-01-04 16:56:24 +00:00
|
|
|
let pathType = pathSplit.at(1);
|
|
|
|
let id = pathSplit.at(2) ? Number(pathSplit.at(2)) : undefined;
|
|
|
|
let auth = req.auth;
|
2020-09-09 00:48:17 +00:00
|
|
|
|
2023-01-04 16:56:24 +00:00
|
|
|
let postForm: GetPost = {
|
|
|
|
auth,
|
|
|
|
};
|
2022-07-30 13:28:08 +00:00
|
|
|
|
2023-01-04 16:56:24 +00:00
|
|
|
let commentsForm: GetComments = {
|
|
|
|
max_depth: commentTreeMaxDepth,
|
|
|
|
sort: CommentSortType.Hot,
|
|
|
|
type_: ListingType.All,
|
|
|
|
saved_only: false,
|
|
|
|
auth,
|
|
|
|
};
|
2020-09-09 00:48:17 +00:00
|
|
|
|
2022-07-30 13:28:08 +00:00
|
|
|
// Set the correct id based on the path type
|
|
|
|
if (pathType == "post") {
|
2023-01-04 16:56:24 +00:00
|
|
|
postForm.id = id;
|
|
|
|
commentsForm.post_id = id;
|
2022-07-30 13:28:08 +00:00
|
|
|
} else {
|
2023-01-04 16:56:24 +00:00
|
|
|
postForm.comment_id = id;
|
|
|
|
commentsForm.parent_id = id;
|
2022-07-30 13:28:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
promises.push(req.client.getPost(postForm));
|
|
|
|
promises.push(req.client.getComments(commentsForm));
|
|
|
|
|
|
|
|
return promises;
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
2023-01-04 16:56:24 +00:00
|
|
|
this.subscription?.unsubscribe();
|
2021-11-16 15:37:40 +00:00
|
|
|
document.removeEventListener("scroll", this.commentScrollDebounced);
|
|
|
|
|
2021-02-02 18:36:59 +00:00
|
|
|
saveScrollPosition(this.context);
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
2021-02-22 02:39:04 +00:00
|
|
|
autosize(document.querySelectorAll("textarea"));
|
2021-11-16 14:46:12 +00:00
|
|
|
|
2021-11-16 15:37:40 +00:00
|
|
|
this.commentScrollDebounced = debounce(this.trackCommentsBoxScrolling, 100);
|
|
|
|
document.addEventListener("scroll", this.commentScrollDebounced);
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2022-02-14 19:10:11 +00:00
|
|
|
componentDidUpdate(_lastProps: any) {
|
2020-09-06 16:15:25 +00:00
|
|
|
// Necessary if you are on a post and you click another post (same route)
|
|
|
|
if (_lastProps.location.pathname !== _lastProps.history.location.pathname) {
|
2020-09-11 18:09:21 +00:00
|
|
|
// TODO Couldnt get a refresh working. This does for now.
|
2020-09-06 16:15:25 +00:00
|
|
|
location.reload();
|
|
|
|
|
|
|
|
// let currentId = this.props.match.params.id;
|
|
|
|
// WebSocketService.Instance.getPost(currentId);
|
|
|
|
// this.context.refresh();
|
|
|
|
// this.context.router.history.push(_lastProps.location.pathname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-12 01:06:54 +00:00
|
|
|
get checkScrollIntoCommentsParam() {
|
|
|
|
return Boolean(
|
|
|
|
new URLSearchParams(this.props.location.search).get("scrollToComments")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-08-12 01:00:26 +00:00
|
|
|
scrollIntoCommentSection() {
|
2023-01-04 16:56:24 +00:00
|
|
|
this.state.commentSectionRef?.current?.scrollIntoView();
|
2021-08-12 01:00:26 +00:00
|
|
|
}
|
|
|
|
|
2022-06-21 21:42:29 +00:00
|
|
|
isBottom(el: Element): boolean {
|
2021-11-22 20:04:20 +00:00
|
|
|
return el?.getBoundingClientRect().bottom <= window.innerHeight;
|
2021-11-16 14:46:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows new comments when scrolling to the bottom of the comments div
|
|
|
|
*/
|
|
|
|
trackCommentsBoxScrolling = () => {
|
|
|
|
const wrappedElement = document.getElementsByClassName("comments")[0];
|
2021-11-22 20:04:20 +00:00
|
|
|
if (wrappedElement && this.isBottom(wrappedElement)) {
|
2022-09-22 15:03:35 +00:00
|
|
|
this.setState({
|
|
|
|
maxCommentsShown: this.state.maxCommentsShown + commentsShownInterval,
|
|
|
|
});
|
2021-11-16 14:46:12 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
get documentTitle(): string {
|
2023-01-04 16:56:24 +00:00
|
|
|
let name_ = this.state.postRes?.post_view.post.name;
|
|
|
|
let siteName = this.state.siteRes.site_view.site.name;
|
|
|
|
return name_ ? `${name_} - ${siteName}` : "";
|
2020-09-11 18:09:21 +00:00
|
|
|
}
|
|
|
|
|
2023-01-04 16:56:24 +00:00
|
|
|
get imageTag(): string | undefined {
|
|
|
|
let post = this.state.postRes?.post_view.post;
|
|
|
|
let thumbnail = post?.thumbnail_url;
|
|
|
|
let url = post?.url;
|
|
|
|
return thumbnail || (url && isImage(url) ? url : undefined);
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2023-01-04 16:56:24 +00:00
|
|
|
let res = this.state.postRes;
|
|
|
|
let description = res?.post_view.post.body;
|
2020-09-06 16:15:25 +00:00
|
|
|
return (
|
2022-10-03 18:16:36 +00:00
|
|
|
<div className="container-lg">
|
2020-09-06 16:15:25 +00:00
|
|
|
{this.state.loading ? (
|
|
|
|
<h5>
|
2021-07-17 20:21:31 +00:00
|
|
|
<Spinner large />
|
2020-09-06 16:15:25 +00:00
|
|
|
</h5>
|
|
|
|
) : (
|
2023-01-04 16:56:24 +00:00
|
|
|
res && (
|
|
|
|
<div className="row">
|
|
|
|
<div className="col-12 col-md-8 mb-3">
|
|
|
|
<HtmlTags
|
|
|
|
title={this.documentTitle}
|
|
|
|
path={this.context.router.route.match.url}
|
|
|
|
image={this.imageTag}
|
|
|
|
description={description}
|
|
|
|
/>
|
|
|
|
<PostListing
|
|
|
|
post_view={res.post_view}
|
|
|
|
duplicates={this.state.crossPosts}
|
|
|
|
showBody
|
|
|
|
showCommunity
|
|
|
|
moderators={res.moderators}
|
|
|
|
admins={this.state.siteRes.admins}
|
|
|
|
enableDownvotes={enableDownvotes(this.state.siteRes)}
|
|
|
|
enableNsfw={enableNsfw(this.state.siteRes)}
|
|
|
|
allLanguages={this.state.siteRes.all_languages}
|
|
|
|
siteLanguages={this.state.siteRes.discussion_languages}
|
|
|
|
/>
|
|
|
|
<div ref={this.state.commentSectionRef} className="mb-2" />
|
|
|
|
<CommentForm
|
|
|
|
node={res.post_view.post.id}
|
|
|
|
disabled={res.post_view.post.locked}
|
|
|
|
allLanguages={this.state.siteRes.all_languages}
|
|
|
|
siteLanguages={this.state.siteRes.discussion_languages}
|
|
|
|
/>
|
|
|
|
<div className="d-block d-md-none">
|
|
|
|
<button
|
|
|
|
className="btn btn-secondary d-inline-block mb-2 mr-3"
|
|
|
|
onClick={linkEvent(this, this.handleShowSidebarMobile)}
|
|
|
|
>
|
|
|
|
{i18n.t("sidebar")}{" "}
|
|
|
|
<Icon
|
|
|
|
icon={
|
|
|
|
this.state.showSidebarMobile
|
|
|
|
? `minus-square`
|
|
|
|
: `plus-square`
|
|
|
|
}
|
|
|
|
classes="icon-inline"
|
|
|
|
/>
|
|
|
|
</button>
|
|
|
|
{this.state.showSidebarMobile && this.sidebar()}
|
2022-09-22 15:03:35 +00:00
|
|
|
</div>
|
2023-01-04 16:56:24 +00:00
|
|
|
{this.sortRadios()}
|
|
|
|
{this.state.commentViewType == CommentViewType.Tree &&
|
|
|
|
this.commentsTree()}
|
|
|
|
{this.state.commentViewType == CommentViewType.Flat &&
|
|
|
|
this.commentsFlat()}
|
2021-07-18 03:56:33 +00:00
|
|
|
</div>
|
2023-01-04 16:56:24 +00:00
|
|
|
<div className="d-none d-md-block col-md-4">{this.sidebar()}</div>
|
|
|
|
</div>
|
|
|
|
)
|
2020-09-06 16:15:25 +00:00
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
sortRadios() {
|
|
|
|
return (
|
|
|
|
<>
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="btn-group btn-group-toggle flex-wrap mr-3 mb-2">
|
2020-09-06 16:15:25 +00:00
|
|
|
<label
|
|
|
|
className={`btn btn-outline-secondary pointer ${
|
2022-07-30 13:28:08 +00:00
|
|
|
CommentSortType[this.state.commentSort] === CommentSortType.Hot &&
|
|
|
|
"active"
|
2020-09-06 16:15:25 +00:00
|
|
|
}`}
|
|
|
|
>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("hot")}
|
2020-09-06 16:15:25 +00:00
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
value={CommentSortType.Hot}
|
|
|
|
checked={this.state.commentSort === CommentSortType.Hot}
|
|
|
|
onChange={linkEvent(this, this.handleCommentSortChange)}
|
|
|
|
/>
|
|
|
|
</label>
|
|
|
|
<label
|
|
|
|
className={`btn btn-outline-secondary pointer ${
|
2022-07-30 13:28:08 +00:00
|
|
|
CommentSortType[this.state.commentSort] === CommentSortType.Top &&
|
|
|
|
"active"
|
2020-09-06 16:15:25 +00:00
|
|
|
}`}
|
|
|
|
>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("top")}
|
2020-09-06 16:15:25 +00:00
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
value={CommentSortType.Top}
|
|
|
|
checked={this.state.commentSort === CommentSortType.Top}
|
|
|
|
onChange={linkEvent(this, this.handleCommentSortChange)}
|
|
|
|
/>
|
|
|
|
</label>
|
|
|
|
<label
|
|
|
|
className={`btn btn-outline-secondary pointer ${
|
2022-07-30 13:28:08 +00:00
|
|
|
CommentSortType[this.state.commentSort] === CommentSortType.New &&
|
|
|
|
"active"
|
2020-09-06 16:15:25 +00:00
|
|
|
}`}
|
|
|
|
>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("new")}
|
2020-09-06 16:15:25 +00:00
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
value={CommentSortType.New}
|
|
|
|
checked={this.state.commentSort === CommentSortType.New}
|
|
|
|
onChange={linkEvent(this, this.handleCommentSortChange)}
|
|
|
|
/>
|
|
|
|
</label>
|
|
|
|
<label
|
|
|
|
className={`btn btn-outline-secondary pointer ${
|
2022-07-30 13:28:08 +00:00
|
|
|
CommentSortType[this.state.commentSort] === CommentSortType.Old &&
|
|
|
|
"active"
|
2020-09-06 16:15:25 +00:00
|
|
|
}`}
|
|
|
|
>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("old")}
|
2020-09-06 16:15:25 +00:00
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
value={CommentSortType.Old}
|
|
|
|
checked={this.state.commentSort === CommentSortType.Old}
|
|
|
|
onChange={linkEvent(this, this.handleCommentSortChange)}
|
|
|
|
/>
|
|
|
|
</label>
|
|
|
|
</div>
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="btn-group btn-group-toggle flex-wrap mb-2">
|
2020-09-06 16:15:25 +00:00
|
|
|
<label
|
|
|
|
className={`btn btn-outline-secondary pointer ${
|
2022-07-30 13:28:08 +00:00
|
|
|
this.state.commentViewType === CommentViewType.Flat && "active"
|
2020-09-06 16:15:25 +00:00
|
|
|
}`}
|
|
|
|
>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("chat")}
|
2020-09-06 16:15:25 +00:00
|
|
|
<input
|
|
|
|
type="radio"
|
2022-07-30 13:28:08 +00:00
|
|
|
value={CommentViewType.Flat}
|
|
|
|
checked={this.state.commentViewType === CommentViewType.Flat}
|
2020-09-06 16:15:25 +00:00
|
|
|
onChange={linkEvent(this, this.handleCommentViewTypeChange)}
|
|
|
|
/>
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
commentsFlat() {
|
2021-02-08 04:23:31 +00:00
|
|
|
// These are already sorted by new
|
2023-01-04 16:56:24 +00:00
|
|
|
let commentsRes = this.state.commentsRes;
|
|
|
|
let postRes = this.state.postRes;
|
|
|
|
return (
|
|
|
|
commentsRes &&
|
|
|
|
postRes && (
|
|
|
|
<div>
|
|
|
|
<CommentNodes
|
|
|
|
nodes={commentsToFlatNodes(commentsRes.comments)}
|
|
|
|
viewType={this.state.commentViewType}
|
|
|
|
maxCommentsShown={this.state.maxCommentsShown}
|
|
|
|
noIndent
|
|
|
|
locked={postRes.post_view.post.locked}
|
|
|
|
moderators={postRes.moderators}
|
|
|
|
admins={this.state.siteRes.admins}
|
|
|
|
enableDownvotes={enableDownvotes(this.state.siteRes)}
|
|
|
|
showContext
|
|
|
|
allLanguages={this.state.siteRes.all_languages}
|
|
|
|
siteLanguages={this.state.siteRes.discussion_languages}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
);
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sidebar() {
|
2023-01-04 16:56:24 +00:00
|
|
|
let res = this.state.postRes;
|
|
|
|
return (
|
|
|
|
res && (
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="mb-3">
|
2022-06-21 21:42:29 +00:00
|
|
|
<Sidebar
|
|
|
|
community_view={res.community_view}
|
|
|
|
moderators={res.moderators}
|
|
|
|
admins={this.state.siteRes.admins}
|
|
|
|
online={res.online}
|
|
|
|
enableNsfw={enableNsfw(this.state.siteRes)}
|
|
|
|
showIcon
|
2022-12-19 15:57:29 +00:00
|
|
|
allLanguages={this.state.siteRes.all_languages}
|
|
|
|
siteLanguages={this.state.siteRes.discussion_languages}
|
2022-06-21 21:42:29 +00:00
|
|
|
/>
|
|
|
|
</div>
|
2023-01-04 16:56:24 +00:00
|
|
|
)
|
|
|
|
);
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleCommentSortChange(i: Post, event: any) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({
|
|
|
|
commentSort: CommentSortType[event.target.value],
|
|
|
|
commentViewType: CommentViewType.Tree,
|
|
|
|
});
|
2022-07-30 13:28:08 +00:00
|
|
|
i.fetchPost();
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleCommentViewTypeChange(i: Post, event: any) {
|
2023-01-04 16:56:24 +00:00
|
|
|
let comments = i.state.commentsRes?.comments;
|
|
|
|
if (comments) {
|
|
|
|
i.setState({
|
|
|
|
commentViewType: Number(event.target.value),
|
|
|
|
commentSort: CommentSortType.New,
|
|
|
|
commentTree: buildCommentsTree(comments, !!i.state.commentId),
|
|
|
|
});
|
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2021-07-18 03:56:33 +00:00
|
|
|
handleShowSidebarMobile(i: Post) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ showSidebarMobile: !i.state.showSidebarMobile });
|
2021-07-18 03:56:33 +00:00
|
|
|
}
|
|
|
|
|
2022-07-30 13:28:08 +00:00
|
|
|
handleViewPost(i: Post) {
|
2023-01-04 16:56:24 +00:00
|
|
|
let id = i.state.postRes?.post_view.post.id;
|
|
|
|
if (id) {
|
|
|
|
i.context.router.history.push(`/post/${id}`);
|
|
|
|
}
|
2022-07-30 13:28:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleViewContext(i: Post) {
|
2023-01-04 16:56:24 +00:00
|
|
|
let parentId = getCommentParentId(
|
|
|
|
i.state.commentsRes?.comments?.at(0)?.comment
|
|
|
|
);
|
|
|
|
if (parentId) {
|
|
|
|
i.context.router.history.push(`/comment/${parentId}`);
|
|
|
|
}
|
2022-07-30 13:28:08 +00:00
|
|
|
}
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
commentsTree() {
|
2023-01-04 16:56:24 +00:00
|
|
|
let res = this.state.postRes;
|
|
|
|
let firstComment = this.state.commentTree.at(0)?.comment_view.comment;
|
|
|
|
let depth = getDepthFromComment(firstComment);
|
|
|
|
let showContextButton = depth ? depth > 0 : false;
|
2022-07-30 13:28:08 +00:00
|
|
|
|
2023-01-04 16:56:24 +00:00
|
|
|
return (
|
|
|
|
res && (
|
2022-06-21 21:42:29 +00:00
|
|
|
<div>
|
2023-01-04 16:56:24 +00:00
|
|
|
{!!this.state.commentId && (
|
2022-07-30 13:28:08 +00:00
|
|
|
<>
|
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="pl-0 d-block btn btn-link text-muted"
|
2022-07-30 13:28:08 +00:00
|
|
|
onClick={linkEvent(this, this.handleViewPost)}
|
|
|
|
>
|
|
|
|
{i18n.t("view_all_comments")} ➔
|
|
|
|
</button>
|
|
|
|
{showContextButton && (
|
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="pl-0 d-block btn btn-link text-muted"
|
2022-07-30 13:28:08 +00:00
|
|
|
onClick={linkEvent(this, this.handleViewContext)}
|
|
|
|
>
|
|
|
|
{i18n.t("show_context")} ➔
|
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
)}
|
2022-06-21 21:42:29 +00:00
|
|
|
<CommentNodes
|
|
|
|
nodes={this.state.commentTree}
|
2022-07-30 13:28:08 +00:00
|
|
|
viewType={this.state.commentViewType}
|
2023-01-04 16:56:24 +00:00
|
|
|
maxCommentsShown={this.state.maxCommentsShown}
|
2022-06-21 21:42:29 +00:00
|
|
|
locked={res.post_view.post.locked}
|
2023-01-04 16:56:24 +00:00
|
|
|
moderators={res.moderators}
|
|
|
|
admins={this.state.siteRes.admins}
|
2022-06-21 21:42:29 +00:00
|
|
|
enableDownvotes={enableDownvotes(this.state.siteRes)}
|
2022-09-22 15:14:58 +00:00
|
|
|
allLanguages={this.state.siteRes.all_languages}
|
2022-12-19 15:57:29 +00:00
|
|
|
siteLanguages={this.state.siteRes.discussion_languages}
|
2022-06-21 21:42:29 +00:00
|
|
|
/>
|
|
|
|
</div>
|
2023-01-04 16:56:24 +00:00
|
|
|
)
|
|
|
|
);
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2020-12-24 01:58:27 +00:00
|
|
|
parseMessage(msg: any) {
|
|
|
|
let op = wsUserOp(msg);
|
2021-01-13 17:06:56 +00:00
|
|
|
console.log(msg);
|
2020-09-06 16:15:25 +00:00
|
|
|
if (msg.error) {
|
2021-02-22 02:39:04 +00:00
|
|
|
toast(i18n.t(msg.error), "danger");
|
2020-09-06 16:15:25 +00:00
|
|
|
return;
|
|
|
|
} else if (msg.reconnect) {
|
2023-01-04 16:56:24 +00:00
|
|
|
let post_id = this.state.postRes?.post_view.post.id;
|
|
|
|
if (post_id) {
|
|
|
|
WebSocketService.Instance.send(wsClient.postJoin({ post_id }));
|
|
|
|
WebSocketService.Instance.send(
|
|
|
|
wsClient.getPost({
|
|
|
|
id: post_id,
|
|
|
|
auth: myAuth(false),
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.GetPost) {
|
2023-01-04 16:56:24 +00:00
|
|
|
let data = wsJsonToRes<GetPostResponse>(msg);
|
|
|
|
this.setState({ postRes: data });
|
2022-06-21 21:42:29 +00:00
|
|
|
|
|
|
|
// join the rooms
|
|
|
|
WebSocketService.Instance.send(
|
2022-07-30 13:28:08 +00:00
|
|
|
wsClient.postJoin({ post_id: data.post_view.post.id })
|
2022-06-21 21:42:29 +00:00
|
|
|
);
|
|
|
|
WebSocketService.Instance.send(
|
|
|
|
wsClient.communityJoin({
|
|
|
|
community_id: data.community_view.community.id,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
// Get cross-posts
|
2022-07-30 13:28:08 +00:00
|
|
|
// TODO move this into initial fetch and refetch
|
2021-01-24 01:41:23 +00:00
|
|
|
this.fetchCrossPosts();
|
2020-09-06 16:15:25 +00:00
|
|
|
setupTippy();
|
2023-01-04 16:56:24 +00:00
|
|
|
if (!this.state.commentId) restoreScrollPosition(this.context);
|
2021-08-12 01:06:54 +00:00
|
|
|
|
|
|
|
if (this.checkScrollIntoCommentsParam) {
|
2021-08-12 01:00:26 +00:00
|
|
|
this.scrollIntoCommentSection();
|
|
|
|
}
|
2022-07-30 13:28:08 +00:00
|
|
|
} else if (op == UserOperation.GetComments) {
|
2023-01-04 16:56:24 +00:00
|
|
|
let data = wsJsonToRes<GetCommentsResponse>(msg);
|
|
|
|
// This section sets the comments res
|
|
|
|
let comments = this.state.commentsRes?.comments;
|
|
|
|
if (comments) {
|
|
|
|
// You might need to append here, since this could be building more comments from a tree fetch
|
|
|
|
// Remove the first comment, since it is the parent
|
|
|
|
let newComments = data.comments;
|
|
|
|
newComments.shift();
|
|
|
|
comments.push(...newComments);
|
|
|
|
} else {
|
|
|
|
this.setState({ commentsRes: data });
|
|
|
|
}
|
|
|
|
|
|
|
|
let cComments = this.state.commentsRes?.comments ?? [];
|
2022-09-22 15:03:35 +00:00
|
|
|
this.setState({
|
2023-01-04 16:56:24 +00:00
|
|
|
commentTree: buildCommentsTree(cComments, !!this.state.commentId),
|
2022-09-22 15:03:35 +00:00
|
|
|
loading: false,
|
|
|
|
});
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.CreateComment) {
|
2023-01-04 16:56:24 +00:00
|
|
|
let data = wsJsonToRes<CommentResponse>(msg);
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2021-12-02 16:46:41 +00:00
|
|
|
// Don't get comments from the post room, if the creator is blocked
|
2023-01-04 16:56:24 +00:00
|
|
|
let creatorBlocked = UserService.Instance.myUserInfo?.person_blocks
|
2021-12-02 16:46:41 +00:00
|
|
|
.map(pb => pb.target.id)
|
|
|
|
.includes(data.comment_view.creator.id);
|
|
|
|
|
2021-01-13 17:06:56 +00:00
|
|
|
// Necessary since it might be a user reply, which has the recipients, to avoid double
|
2023-01-04 16:56:24 +00:00
|
|
|
let postRes = this.state.postRes;
|
|
|
|
let commentsRes = this.state.commentsRes;
|
|
|
|
if (
|
|
|
|
data.recipient_ids.length == 0 &&
|
|
|
|
!creatorBlocked &&
|
|
|
|
postRes &&
|
|
|
|
commentsRes
|
|
|
|
) {
|
|
|
|
commentsRes.comments.unshift(data.comment_view);
|
|
|
|
insertCommentIntoTree(
|
|
|
|
this.state.commentTree,
|
|
|
|
data.comment_view,
|
|
|
|
!!this.state.commentId
|
|
|
|
);
|
|
|
|
postRes.post_view.counts.comments++;
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
this.setState(this.state);
|
2021-01-23 21:40:24 +00:00
|
|
|
setupTippy();
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
} else if (
|
2020-12-24 01:58:27 +00:00
|
|
|
op == UserOperation.EditComment ||
|
|
|
|
op == UserOperation.DeleteComment ||
|
|
|
|
op == UserOperation.RemoveComment
|
2020-09-06 16:15:25 +00:00
|
|
|
) {
|
2023-01-04 16:56:24 +00:00
|
|
|
let data = wsJsonToRes<CommentResponse>(msg);
|
|
|
|
editCommentRes(data.comment_view, this.state.commentsRes?.comments);
|
2020-09-06 16:15:25 +00:00
|
|
|
this.setState(this.state);
|
2022-08-17 23:26:50 +00:00
|
|
|
setupTippy();
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.SaveComment) {
|
2023-01-04 16:56:24 +00:00
|
|
|
let data = wsJsonToRes<CommentResponse>(msg);
|
|
|
|
saveCommentRes(data.comment_view, this.state.commentsRes?.comments);
|
2020-09-06 16:15:25 +00:00
|
|
|
this.setState(this.state);
|
|
|
|
setupTippy();
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.CreateCommentLike) {
|
2023-01-04 16:56:24 +00:00
|
|
|
let data = wsJsonToRes<CommentResponse>(msg);
|
|
|
|
createCommentLikeRes(data.comment_view, this.state.commentsRes?.comments);
|
2020-09-06 16:15:25 +00:00
|
|
|
this.setState(this.state);
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.CreatePostLike) {
|
2023-01-04 16:56:24 +00:00
|
|
|
let data = wsJsonToRes<PostResponse>(msg);
|
|
|
|
createPostLikeRes(data.post_view, this.state.postRes?.post_view);
|
2020-09-06 16:15:25 +00:00
|
|
|
this.setState(this.state);
|
|
|
|
} else if (
|
2020-12-24 01:58:27 +00:00
|
|
|
op == UserOperation.EditPost ||
|
|
|
|
op == UserOperation.DeletePost ||
|
|
|
|
op == UserOperation.RemovePost ||
|
|
|
|
op == UserOperation.LockPost ||
|
2022-12-14 15:03:18 +00:00
|
|
|
op == UserOperation.FeaturePost ||
|
2020-12-24 01:58:27 +00:00
|
|
|
op == UserOperation.SavePost
|
2020-09-06 16:15:25 +00:00
|
|
|
) {
|
2023-01-04 16:56:24 +00:00
|
|
|
let data = wsJsonToRes<PostResponse>(msg);
|
|
|
|
let pv = this.state.postRes?.post_view;
|
|
|
|
if (pv) {
|
|
|
|
pv = data.post_view;
|
|
|
|
this.setState(this.state);
|
|
|
|
setupTippy();
|
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
} else if (
|
2020-12-24 01:58:27 +00:00
|
|
|
op == UserOperation.EditCommunity ||
|
|
|
|
op == UserOperation.DeleteCommunity ||
|
|
|
|
op == UserOperation.RemoveCommunity ||
|
|
|
|
op == UserOperation.FollowCommunity
|
2020-09-06 16:15:25 +00:00
|
|
|
) {
|
2023-01-04 16:56:24 +00:00
|
|
|
let data = wsJsonToRes<CommunityResponse>(msg);
|
|
|
|
let res = this.state.postRes;
|
|
|
|
if (res) {
|
|
|
|
res.community_view = data.community_view;
|
|
|
|
res.post_view.community = data.community_view.community;
|
|
|
|
this.setState(this.state);
|
|
|
|
}
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.BanFromCommunity) {
|
2023-01-04 16:56:24 +00:00
|
|
|
let data = wsJsonToRes<BanFromCommunityResponse>(msg);
|
|
|
|
|
|
|
|
let postRes = this.state.postRes;
|
|
|
|
if (postRes) {
|
|
|
|
if (postRes.post_view.creator.id == data.person_view.person.id) {
|
|
|
|
postRes.post_view.creator_banned_from_community = data.banned;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.state.commentsRes?.comments
|
|
|
|
.filter(c => c.creator.id == data.person_view.person.id)
|
|
|
|
.forEach(c => (c.creator_banned_from_community = data.banned));
|
|
|
|
this.setState(this.state);
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.AddModToCommunity) {
|
2023-01-04 16:56:24 +00:00
|
|
|
let data = wsJsonToRes<AddModToCommunityResponse>(msg);
|
|
|
|
let postRes = this.state.postRes;
|
|
|
|
if (postRes) {
|
|
|
|
postRes.moderators = data.moderators;
|
|
|
|
this.setState(this.state);
|
|
|
|
}
|
2021-03-15 18:09:31 +00:00
|
|
|
} else if (op == UserOperation.BanPerson) {
|
2023-01-04 16:56:24 +00:00
|
|
|
let data = wsJsonToRes<BanPersonResponse>(msg);
|
|
|
|
this.state.commentsRes?.comments
|
|
|
|
.filter(c => c.creator.id == data.person_view.person.id)
|
|
|
|
.forEach(c => (c.creator.banned = data.banned));
|
|
|
|
|
|
|
|
let postRes = this.state.postRes;
|
|
|
|
if (postRes) {
|
|
|
|
if (postRes.post_view.creator.id == data.person_view.person.id) {
|
|
|
|
postRes.post_view.creator.banned = data.banned;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.setState(this.state);
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.AddAdmin) {
|
2023-01-04 16:56:24 +00:00
|
|
|
let data = wsJsonToRes<AddAdminResponse>(msg);
|
2022-09-22 15:03:35 +00:00
|
|
|
this.setState(s => ((s.siteRes.admins = data.admins), s));
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.Search) {
|
2023-01-04 16:56:24 +00:00
|
|
|
let data = wsJsonToRes<SearchResponse>(msg);
|
2022-06-21 21:42:29 +00:00
|
|
|
let xPosts = data.posts.filter(
|
2020-12-24 01:58:27 +00:00
|
|
|
p => p.post.id != Number(this.props.match.params.id)
|
2020-09-06 16:15:25 +00:00
|
|
|
);
|
2023-01-04 16:56:24 +00:00
|
|
|
this.setState({ crossPosts: xPosts.length > 0 ? xPosts : undefined });
|
2022-02-14 17:27:43 +00:00
|
|
|
} else if (op == UserOperation.LeaveAdmin) {
|
2023-01-04 16:56:24 +00:00
|
|
|
let data = wsJsonToRes<GetSiteResponse>(msg);
|
2022-09-22 15:03:35 +00:00
|
|
|
this.setState({ siteRes: data });
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.TransferCommunity) {
|
2023-01-04 16:56:24 +00:00
|
|
|
let data = wsJsonToRes<GetCommunityResponse>(msg);
|
|
|
|
let postRes = this.state.postRes;
|
|
|
|
if (postRes) {
|
|
|
|
postRes.community_view = data.community_view;
|
|
|
|
postRes.post_view.community = data.community_view.community;
|
|
|
|
postRes.moderators = data.moderators;
|
|
|
|
this.setState(this.state);
|
|
|
|
}
|
2021-08-20 02:56:18 +00:00
|
|
|
} else if (op == UserOperation.BlockPerson) {
|
2023-01-04 16:56:24 +00:00
|
|
|
let data = wsJsonToRes<BlockPersonResponse>(msg);
|
2021-08-20 02:56:18 +00:00
|
|
|
updatePersonBlock(data);
|
2021-09-28 10:38:59 +00:00
|
|
|
} else if (op == UserOperation.CreatePostReport) {
|
2023-01-04 16:56:24 +00:00
|
|
|
let data = wsJsonToRes<PostReportResponse>(msg);
|
2021-09-28 10:38:59 +00:00
|
|
|
if (data) {
|
|
|
|
toast(i18n.t("report_created"));
|
|
|
|
}
|
|
|
|
} else if (op == UserOperation.CreateCommentReport) {
|
2023-01-04 16:56:24 +00:00
|
|
|
let data = wsJsonToRes<CommentReportResponse>(msg);
|
2021-09-28 10:38:59 +00:00
|
|
|
if (data) {
|
|
|
|
toast(i18n.t("report_created"));
|
|
|
|
}
|
2022-06-23 19:44:05 +00:00
|
|
|
} else if (
|
|
|
|
op == UserOperation.PurgePerson ||
|
|
|
|
op == UserOperation.PurgePost ||
|
|
|
|
op == UserOperation.PurgeComment ||
|
|
|
|
op == UserOperation.PurgeCommunity
|
|
|
|
) {
|
2023-01-04 16:56:24 +00:00
|
|
|
let data = wsJsonToRes<PurgeItemResponse>(msg);
|
2022-06-23 19:44:05 +00:00
|
|
|
if (data.success) {
|
|
|
|
toast(i18n.t("purge_success"));
|
|
|
|
this.context.router.history.push(`/`);
|
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|