2021-02-22 02:39:04 +00:00
|
|
|
import { Component, linkEvent } from "inferno";
|
2020-09-06 16:15:25 +00:00
|
|
|
import {
|
2023-06-14 12:20:40 +00:00
|
|
|
AddAdmin,
|
|
|
|
AddModToCommunity,
|
|
|
|
BanFromCommunity,
|
|
|
|
BanFromCommunityResponse,
|
|
|
|
BanPerson,
|
|
|
|
BanPersonResponse,
|
|
|
|
BlockPerson,
|
|
|
|
CommentId,
|
2022-07-30 13:28:08 +00:00
|
|
|
CommentReplyResponse,
|
|
|
|
CommentReplyView,
|
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,
|
2020-12-24 01:58:27 +00:00
|
|
|
CommentView,
|
2023-06-14 12:20:40 +00:00
|
|
|
CreateComment,
|
|
|
|
CreateCommentLike,
|
|
|
|
CreateCommentReport,
|
|
|
|
CreatePrivateMessage,
|
|
|
|
CreatePrivateMessageReport,
|
|
|
|
DeleteComment,
|
|
|
|
DeletePrivateMessage,
|
|
|
|
DistinguishComment,
|
|
|
|
EditComment,
|
|
|
|
EditPrivateMessage,
|
2021-03-15 18:09:31 +00:00
|
|
|
GetPersonMentionsResponse,
|
2021-07-17 20:42:55 +00:00
|
|
|
GetRepliesResponse,
|
2022-06-21 21:42:29 +00:00
|
|
|
GetSiteResponse,
|
2023-06-14 12:20:40 +00:00
|
|
|
MarkCommentReplyAsRead,
|
|
|
|
MarkPersonMentionAsRead,
|
|
|
|
MarkPrivateMessageAsRead,
|
2021-07-17 20:42:55 +00:00
|
|
|
PersonMentionResponse,
|
|
|
|
PersonMentionView,
|
2022-09-28 12:50:47 +00:00
|
|
|
PrivateMessageReportResponse,
|
2020-09-06 16:15:25 +00:00
|
|
|
PrivateMessageResponse,
|
2021-07-17 20:42:55 +00:00
|
|
|
PrivateMessageView,
|
2023-05-11 17:06:32 +00:00
|
|
|
PrivateMessagesResponse,
|
2023-06-14 12:20:40 +00:00
|
|
|
PurgeComment,
|
|
|
|
PurgeItemResponse,
|
|
|
|
PurgePerson,
|
|
|
|
PurgePost,
|
|
|
|
RemoveComment,
|
|
|
|
SaveComment,
|
|
|
|
TransferCommunity,
|
2021-02-22 02:39:04 +00:00
|
|
|
} from "lemmy-js-client";
|
2021-07-17 20:42:55 +00:00
|
|
|
import { i18n } from "../../i18next";
|
2022-07-30 13:28:08 +00:00
|
|
|
import { CommentViewType, InitialFetchRequest } from "../../interfaces";
|
2023-06-14 12:20:40 +00:00
|
|
|
import { UserService } from "../../services";
|
|
|
|
import { FirstLoadService } from "../../services/FirstLoadService";
|
|
|
|
import { HttpService, RequestState } from "../../services/HttpService";
|
2020-09-06 16:15:25 +00:00
|
|
|
import {
|
2023-06-16 02:08:14 +00:00
|
|
|
RouteDataResponse,
|
2021-07-17 20:42:55 +00:00
|
|
|
commentsToFlatNodes,
|
2023-06-14 12:20:40 +00:00
|
|
|
editCommentReply,
|
|
|
|
editMention,
|
|
|
|
editPrivateMessage,
|
|
|
|
editWith,
|
2022-06-21 21:42:29 +00:00
|
|
|
enableDownvotes,
|
2021-07-17 20:42:55 +00:00
|
|
|
fetchLimit,
|
2023-06-14 12:20:40 +00:00
|
|
|
getCommentParentId,
|
2023-01-04 16:56:24 +00:00
|
|
|
myAuth,
|
2023-06-14 12:20:40 +00:00
|
|
|
myAuthRequired,
|
2022-02-24 15:31:44 +00:00
|
|
|
relTags,
|
2020-09-09 00:48:17 +00:00
|
|
|
setIsoData,
|
2021-07-17 20:42:55 +00:00
|
|
|
toast,
|
2021-08-20 02:56:18 +00:00
|
|
|
updatePersonBlock,
|
2021-07-17 20:42:55 +00:00
|
|
|
} from "../../utils";
|
|
|
|
import { CommentNodes } from "../comment/comment-nodes";
|
2022-07-30 13:28:08 +00:00
|
|
|
import { CommentSortSelect } from "../common/comment-sort-select";
|
2021-07-17 20:42:55 +00:00
|
|
|
import { HtmlTags } from "../common/html-tags";
|
|
|
|
import { Icon, Spinner } from "../common/icon";
|
|
|
|
import { Paginator } from "../common/paginator";
|
|
|
|
import { PrivateMessage } from "../private_message/private-message";
|
2020-09-06 16:15:25 +00:00
|
|
|
|
|
|
|
enum UnreadOrAll {
|
|
|
|
Unread,
|
|
|
|
All,
|
|
|
|
}
|
|
|
|
|
|
|
|
enum MessageType {
|
|
|
|
All,
|
|
|
|
Replies,
|
|
|
|
Mentions,
|
|
|
|
Messages,
|
|
|
|
}
|
|
|
|
|
2020-12-24 01:58:27 +00:00
|
|
|
enum ReplyEnum {
|
|
|
|
Reply,
|
|
|
|
Mention,
|
|
|
|
Message,
|
|
|
|
}
|
2023-05-30 00:40:00 +00:00
|
|
|
|
2023-06-16 02:08:14 +00:00
|
|
|
type InboxData = RouteDataResponse<{
|
2023-06-16 02:39:04 +00:00
|
|
|
repliesRes: GetRepliesResponse;
|
|
|
|
mentionsRes: GetPersonMentionsResponse;
|
|
|
|
messagesRes: PrivateMessagesResponse;
|
2023-06-16 02:08:14 +00:00
|
|
|
}>;
|
2023-05-30 00:40:00 +00:00
|
|
|
|
2020-12-24 01:58:27 +00:00
|
|
|
type ReplyType = {
|
|
|
|
id: number;
|
|
|
|
type_: ReplyEnum;
|
2022-07-30 13:28:08 +00:00
|
|
|
view: CommentView | PrivateMessageView | PersonMentionView | CommentReplyView;
|
2020-12-24 01:58:27 +00:00
|
|
|
published: string;
|
|
|
|
};
|
2020-09-06 16:15:25 +00:00
|
|
|
|
|
|
|
interface InboxState {
|
|
|
|
unreadOrAll: UnreadOrAll;
|
|
|
|
messageType: MessageType;
|
2023-06-14 12:20:40 +00:00
|
|
|
repliesRes: RequestState<GetRepliesResponse>;
|
|
|
|
mentionsRes: RequestState<GetPersonMentionsResponse>;
|
|
|
|
messagesRes: RequestState<PrivateMessagesResponse>;
|
|
|
|
markAllAsReadRes: RequestState<GetRepliesResponse>;
|
2022-07-30 13:28:08 +00:00
|
|
|
sort: CommentSortType;
|
2023-05-15 19:53:29 +00:00
|
|
|
page: number;
|
2022-06-21 21:42:29 +00:00
|
|
|
siteRes: GetSiteResponse;
|
2023-06-14 12:20:40 +00:00
|
|
|
finished: Map<CommentId, boolean | undefined>;
|
|
|
|
isIsomorphic: boolean;
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export class Inbox extends Component<any, InboxState> {
|
2023-05-30 00:40:00 +00:00
|
|
|
private isoData = setIsoData<InboxData>(this.context);
|
2023-01-04 16:56:24 +00:00
|
|
|
state: InboxState = {
|
2020-09-06 16:15:25 +00:00
|
|
|
unreadOrAll: UnreadOrAll.Unread,
|
|
|
|
messageType: MessageType.All,
|
2023-05-11 18:32:32 +00:00
|
|
|
sort: "New",
|
2023-05-15 19:53:29 +00:00
|
|
|
page: 1,
|
2022-06-21 21:42:29 +00:00
|
|
|
siteRes: this.isoData.site_res,
|
2023-06-14 12:20:40 +00:00
|
|
|
repliesRes: { state: "empty" },
|
|
|
|
mentionsRes: { state: "empty" },
|
|
|
|
messagesRes: { state: "empty" },
|
|
|
|
markAllAsReadRes: { state: "empty" },
|
|
|
|
finished: new Map(),
|
|
|
|
isIsomorphic: false,
|
2020-09-06 16:15:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
constructor(props: any, context: any) {
|
|
|
|
super(props, context);
|
|
|
|
|
|
|
|
this.handleSortChange = this.handleSortChange.bind(this);
|
2021-07-16 19:40:56 +00:00
|
|
|
this.handlePageChange = this.handlePageChange.bind(this);
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
this.handleCreateComment = this.handleCreateComment.bind(this);
|
|
|
|
this.handleEditComment = this.handleEditComment.bind(this);
|
|
|
|
this.handleSaveComment = this.handleSaveComment.bind(this);
|
|
|
|
this.handleBlockPerson = this.handleBlockPerson.bind(this);
|
|
|
|
this.handleDeleteComment = this.handleDeleteComment.bind(this);
|
|
|
|
this.handleRemoveComment = this.handleRemoveComment.bind(this);
|
|
|
|
this.handleCommentVote = this.handleCommentVote.bind(this);
|
|
|
|
this.handleAddModToCommunity = this.handleAddModToCommunity.bind(this);
|
|
|
|
this.handleAddAdmin = this.handleAddAdmin.bind(this);
|
|
|
|
this.handlePurgePerson = this.handlePurgePerson.bind(this);
|
|
|
|
this.handlePurgeComment = this.handlePurgeComment.bind(this);
|
|
|
|
this.handleCommentReport = this.handleCommentReport.bind(this);
|
|
|
|
this.handleDistinguishComment = this.handleDistinguishComment.bind(this);
|
|
|
|
this.handleTransferCommunity = this.handleTransferCommunity.bind(this);
|
|
|
|
this.handleCommentReplyRead = this.handleCommentReplyRead.bind(this);
|
|
|
|
this.handlePersonMentionRead = this.handlePersonMentionRead.bind(this);
|
|
|
|
this.handleBanFromCommunity = this.handleBanFromCommunity.bind(this);
|
|
|
|
this.handleBanPerson = this.handleBanPerson.bind(this);
|
|
|
|
|
|
|
|
this.handleDeleteMessage = this.handleDeleteMessage.bind(this);
|
|
|
|
this.handleMarkMessageAsRead = this.handleMarkMessageAsRead.bind(this);
|
|
|
|
this.handleMessageReport = this.handleMessageReport.bind(this);
|
|
|
|
this.handleCreateMessage = this.handleCreateMessage.bind(this);
|
|
|
|
this.handleEditMessage = this.handleEditMessage.bind(this);
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2020-09-09 00:48:17 +00:00
|
|
|
// Only fetch the data if coming from another route
|
2023-06-14 12:20:40 +00:00
|
|
|
if (FirstLoadService.isFirstLoad) {
|
2023-06-16 02:39:04 +00:00
|
|
|
const { mentionsRes, messagesRes, repliesRes } = this.isoData.routeData;
|
2023-05-30 00:40:00 +00:00
|
|
|
|
2022-09-22 15:03:35 +00:00
|
|
|
this.state = {
|
|
|
|
...this.state,
|
2023-06-14 12:20:40 +00:00
|
|
|
repliesRes,
|
|
|
|
mentionsRes,
|
|
|
|
messagesRes,
|
|
|
|
isIsomorphic: true,
|
2022-09-22 15:03:35 +00:00
|
|
|
};
|
2020-09-09 00:48:17 +00:00
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async componentDidMount() {
|
|
|
|
if (!this.state.isIsomorphic) {
|
|
|
|
await this.refetch();
|
2020-09-09 00:48:17 +00:00
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get documentTitle(): string {
|
2023-06-05 21:31:12 +00:00
|
|
|
const mui = UserService.Instance.myUserInfo;
|
2023-01-04 16:56:24 +00:00
|
|
|
return mui
|
|
|
|
? `@${mui.local_user_view.person.name} ${i18n.t("inbox")} - ${
|
2022-11-09 19:53:07 +00:00
|
|
|
this.state.siteRes.site_view.site.name
|
2023-01-04 16:56:24 +00:00
|
|
|
}`
|
|
|
|
: "";
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
get hasUnreads(): boolean {
|
|
|
|
if (this.state.unreadOrAll == UnreadOrAll.Unread) {
|
|
|
|
const { repliesRes, mentionsRes, messagesRes } = this.state;
|
|
|
|
const replyCount =
|
|
|
|
repliesRes.state == "success" ? repliesRes.data.replies.length : 0;
|
|
|
|
const mentionCount =
|
|
|
|
mentionsRes.state == "success" ? mentionsRes.data.mentions.length : 0;
|
|
|
|
const messageCount =
|
|
|
|
messagesRes.state == "success"
|
|
|
|
? messagesRes.data.private_messages.length
|
|
|
|
: 0;
|
|
|
|
|
|
|
|
return replyCount + mentionCount + messageCount > 0;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
render() {
|
2023-06-05 21:31:12 +00:00
|
|
|
const auth = myAuth();
|
|
|
|
const inboxRss = auth ? `/feeds/inbox/${auth}.xml` : undefined;
|
2020-09-06 16:15:25 +00:00
|
|
|
return (
|
2022-10-03 18:16:36 +00:00
|
|
|
<div className="container-lg">
|
2023-06-14 12:20:40 +00:00
|
|
|
<div className="row">
|
|
|
|
<div className="col-12">
|
|
|
|
<HtmlTags
|
|
|
|
title={this.documentTitle}
|
|
|
|
path={this.context.router.route.match.url}
|
|
|
|
/>
|
|
|
|
<h5 className="mb-2">
|
|
|
|
{i18n.t("inbox")}
|
|
|
|
{inboxRss && (
|
|
|
|
<small>
|
|
|
|
<a href={inboxRss} title="RSS" rel={relTags}>
|
2023-06-20 12:01:29 +00:00
|
|
|
<Icon icon="rss" classes="ms-2 text-muted small" />
|
2023-06-14 12:20:40 +00:00
|
|
|
</a>
|
|
|
|
<link
|
|
|
|
rel="alternate"
|
|
|
|
type="application/atom+xml"
|
|
|
|
href={inboxRss}
|
|
|
|
/>
|
|
|
|
</small>
|
|
|
|
)}
|
|
|
|
</h5>
|
|
|
|
{this.hasUnreads && (
|
|
|
|
<button
|
|
|
|
className="btn btn-secondary mb-2"
|
|
|
|
onClick={linkEvent(this, this.handleMarkAllAsRead)}
|
|
|
|
>
|
|
|
|
{this.state.markAllAsReadRes.state == "loading" ? (
|
|
|
|
<Spinner />
|
|
|
|
) : (
|
|
|
|
i18n.t("mark_all_as_read")
|
2023-01-04 16:56:24 +00:00
|
|
|
)}
|
2023-06-14 12:20:40 +00:00
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
{this.selects()}
|
|
|
|
{this.section}
|
|
|
|
<Paginator
|
|
|
|
page={this.state.page}
|
|
|
|
onChange={this.handlePageChange}
|
|
|
|
/>
|
2020-09-06 16:15:25 +00:00
|
|
|
</div>
|
2023-06-14 12:20:40 +00:00
|
|
|
</div>
|
2020-09-06 16:15:25 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
get section() {
|
|
|
|
switch (this.state.messageType) {
|
|
|
|
case MessageType.All: {
|
|
|
|
return this.all();
|
|
|
|
}
|
|
|
|
case MessageType.Replies: {
|
|
|
|
return this.replies();
|
|
|
|
}
|
|
|
|
case MessageType.Mentions: {
|
|
|
|
return this.mentions();
|
|
|
|
}
|
|
|
|
case MessageType.Messages: {
|
|
|
|
return this.messages();
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
unreadOrAllRadios() {
|
|
|
|
return (
|
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
|
2021-02-22 02:39:04 +00:00
|
|
|
${this.state.unreadOrAll == UnreadOrAll.Unread && "active"}
|
2020-09-06 16:15:25 +00:00
|
|
|
`}
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
type="radio"
|
2023-06-20 12:01:29 +00:00
|
|
|
className="btn-check"
|
2020-09-06 16:15:25 +00:00
|
|
|
value={UnreadOrAll.Unread}
|
|
|
|
checked={this.state.unreadOrAll == UnreadOrAll.Unread}
|
|
|
|
onChange={linkEvent(this, this.handleUnreadOrAllChange)}
|
|
|
|
/>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("unread")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</label>
|
|
|
|
<label
|
|
|
|
className={`btn btn-outline-secondary pointer
|
2021-02-22 02:39:04 +00:00
|
|
|
${this.state.unreadOrAll == UnreadOrAll.All && "active"}
|
2020-09-06 16:15:25 +00:00
|
|
|
`}
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
type="radio"
|
2023-06-20 12:01:29 +00:00
|
|
|
className="btn-check"
|
2020-09-06 16:15:25 +00:00
|
|
|
value={UnreadOrAll.All}
|
|
|
|
checked={this.state.unreadOrAll == UnreadOrAll.All}
|
|
|
|
onChange={linkEvent(this, this.handleUnreadOrAllChange)}
|
|
|
|
/>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("all")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
messageTypeRadios() {
|
|
|
|
return (
|
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
|
2021-02-22 02:39:04 +00:00
|
|
|
${this.state.messageType == MessageType.All && "active"}
|
2020-09-06 16:15:25 +00:00
|
|
|
`}
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
type="radio"
|
2023-06-20 12:01:29 +00:00
|
|
|
className="btn-check"
|
2020-09-06 16:15:25 +00:00
|
|
|
value={MessageType.All}
|
|
|
|
checked={this.state.messageType == MessageType.All}
|
|
|
|
onChange={linkEvent(this, this.handleMessageTypeChange)}
|
|
|
|
/>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("all")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</label>
|
|
|
|
<label
|
|
|
|
className={`btn btn-outline-secondary pointer
|
2021-02-22 02:39:04 +00:00
|
|
|
${this.state.messageType == MessageType.Replies && "active"}
|
2020-09-06 16:15:25 +00:00
|
|
|
`}
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
type="radio"
|
2023-06-20 12:01:29 +00:00
|
|
|
className="btn-check"
|
2020-09-06 16:15:25 +00:00
|
|
|
value={MessageType.Replies}
|
|
|
|
checked={this.state.messageType == MessageType.Replies}
|
|
|
|
onChange={linkEvent(this, this.handleMessageTypeChange)}
|
|
|
|
/>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("replies")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</label>
|
|
|
|
<label
|
|
|
|
className={`btn btn-outline-secondary pointer
|
2021-02-22 02:39:04 +00:00
|
|
|
${this.state.messageType == MessageType.Mentions && "active"}
|
2020-09-06 16:15:25 +00:00
|
|
|
`}
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
type="radio"
|
2023-06-20 12:01:29 +00:00
|
|
|
className="btn-check"
|
2020-09-06 16:15:25 +00:00
|
|
|
value={MessageType.Mentions}
|
|
|
|
checked={this.state.messageType == MessageType.Mentions}
|
|
|
|
onChange={linkEvent(this, this.handleMessageTypeChange)}
|
|
|
|
/>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("mentions")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</label>
|
|
|
|
<label
|
|
|
|
className={`btn btn-outline-secondary pointer
|
2021-02-22 02:39:04 +00:00
|
|
|
${this.state.messageType == MessageType.Messages && "active"}
|
2020-09-06 16:15:25 +00:00
|
|
|
`}
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
type="radio"
|
2023-06-20 12:01:29 +00:00
|
|
|
className="btn-check"
|
2020-09-06 16:15:25 +00:00
|
|
|
value={MessageType.Messages}
|
|
|
|
checked={this.state.messageType == MessageType.Messages}
|
|
|
|
onChange={linkEvent(this, this.handleMessageTypeChange)}
|
|
|
|
/>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("messages")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
selects() {
|
|
|
|
return (
|
|
|
|
<div className="mb-2">
|
2023-06-20 12:01:29 +00:00
|
|
|
<span className="me-3">{this.unreadOrAllRadios()}</span>
|
|
|
|
<span className="me-3">{this.messageTypeRadios()}</span>
|
2022-07-30 13:28:08 +00:00
|
|
|
<CommentSortSelect
|
2020-09-06 16:15:25 +00:00
|
|
|
sort={this.state.sort}
|
|
|
|
onChange={this.handleSortChange}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-07-30 13:28:08 +00:00
|
|
|
replyToReplyType(r: CommentReplyView): ReplyType {
|
2021-02-02 20:24:25 +00:00
|
|
|
return {
|
2022-07-30 13:28:08 +00:00
|
|
|
id: r.comment_reply.id,
|
2020-12-24 01:58:27 +00:00
|
|
|
type_: ReplyEnum.Reply,
|
|
|
|
view: r,
|
|
|
|
published: r.comment.published,
|
2021-02-02 20:24:25 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-03-15 18:09:31 +00:00
|
|
|
mentionToReplyType(r: PersonMentionView): ReplyType {
|
2021-02-02 20:24:25 +00:00
|
|
|
return {
|
2021-03-15 18:09:31 +00:00
|
|
|
id: r.person_mention.id,
|
2020-12-24 01:58:27 +00:00
|
|
|
type_: ReplyEnum.Mention,
|
|
|
|
view: r,
|
|
|
|
published: r.comment.published,
|
2021-02-02 20:24:25 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
messageToReplyType(r: PrivateMessageView): ReplyType {
|
|
|
|
return {
|
|
|
|
id: r.private_message.id,
|
2020-12-24 01:58:27 +00:00
|
|
|
type_: ReplyEnum.Message,
|
|
|
|
view: r,
|
|
|
|
published: r.private_message.published,
|
2021-02-02 20:24:25 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
buildCombined(): ReplyType[] {
|
2023-06-14 12:20:40 +00:00
|
|
|
const replies: ReplyType[] =
|
|
|
|
this.state.repliesRes.state == "success"
|
|
|
|
? this.state.repliesRes.data.replies.map(this.replyToReplyType)
|
|
|
|
: [];
|
|
|
|
const mentions: ReplyType[] =
|
|
|
|
this.state.mentionsRes.state == "success"
|
|
|
|
? this.state.mentionsRes.data.mentions.map(this.mentionToReplyType)
|
|
|
|
: [];
|
|
|
|
const messages: ReplyType[] =
|
|
|
|
this.state.messagesRes.state == "success"
|
|
|
|
? this.state.messagesRes.data.private_messages.map(
|
|
|
|
this.messageToReplyType
|
|
|
|
)
|
|
|
|
: [];
|
2020-12-24 01:58:27 +00:00
|
|
|
|
|
|
|
return [...replies, ...mentions, ...messages].sort((a, b) =>
|
|
|
|
b.published.localeCompare(a.published)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderReplyType(i: ReplyType) {
|
|
|
|
switch (i.type_) {
|
|
|
|
case ReplyEnum.Reply:
|
|
|
|
return (
|
|
|
|
<CommentNodes
|
|
|
|
key={i.id}
|
2022-07-30 13:28:08 +00:00
|
|
|
nodes={[
|
|
|
|
{ comment_view: i.view as CommentView, children: [], depth: 0 },
|
|
|
|
]}
|
|
|
|
viewType={CommentViewType.Flat}
|
2023-06-14 12:20:40 +00:00
|
|
|
finished={this.state.finished}
|
2020-12-24 01:58:27 +00:00
|
|
|
noIndent
|
|
|
|
markable
|
|
|
|
showCommunity
|
|
|
|
showContext
|
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}
|
2023-06-14 12:20:40 +00:00
|
|
|
onSaveComment={this.handleSaveComment}
|
|
|
|
onBlockPerson={this.handleBlockPerson}
|
|
|
|
onDeleteComment={this.handleDeleteComment}
|
|
|
|
onRemoveComment={this.handleRemoveComment}
|
|
|
|
onCommentVote={this.handleCommentVote}
|
|
|
|
onCommentReport={this.handleCommentReport}
|
|
|
|
onDistinguishComment={this.handleDistinguishComment}
|
|
|
|
onAddModToCommunity={this.handleAddModToCommunity}
|
|
|
|
onAddAdmin={this.handleAddAdmin}
|
|
|
|
onTransferCommunity={this.handleTransferCommunity}
|
|
|
|
onPurgeComment={this.handlePurgeComment}
|
|
|
|
onPurgePerson={this.handlePurgePerson}
|
|
|
|
onCommentReplyRead={this.handleCommentReplyRead}
|
|
|
|
onPersonMentionRead={this.handlePersonMentionRead}
|
|
|
|
onBanPersonFromCommunity={this.handleBanFromCommunity}
|
|
|
|
onBanPerson={this.handleBanPerson}
|
|
|
|
onCreateComment={this.handleCreateComment}
|
|
|
|
onEditComment={this.handleEditComment}
|
2020-12-24 01:58:27 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
case ReplyEnum.Mention:
|
|
|
|
return (
|
|
|
|
<CommentNodes
|
|
|
|
key={i.id}
|
2022-07-30 13:28:08 +00:00
|
|
|
nodes={[
|
|
|
|
{
|
|
|
|
comment_view: i.view as PersonMentionView,
|
|
|
|
children: [],
|
|
|
|
depth: 0,
|
|
|
|
},
|
|
|
|
]}
|
2023-06-14 12:20:40 +00:00
|
|
|
finished={this.state.finished}
|
2022-07-30 13:28:08 +00:00
|
|
|
viewType={CommentViewType.Flat}
|
2020-12-24 01:58:27 +00:00
|
|
|
noIndent
|
|
|
|
markable
|
|
|
|
showCommunity
|
|
|
|
showContext
|
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}
|
2023-06-14 12:20:40 +00:00
|
|
|
onSaveComment={this.handleSaveComment}
|
|
|
|
onBlockPerson={this.handleBlockPerson}
|
|
|
|
onDeleteComment={this.handleDeleteComment}
|
|
|
|
onRemoveComment={this.handleRemoveComment}
|
|
|
|
onCommentVote={this.handleCommentVote}
|
|
|
|
onCommentReport={this.handleCommentReport}
|
|
|
|
onDistinguishComment={this.handleDistinguishComment}
|
|
|
|
onAddModToCommunity={this.handleAddModToCommunity}
|
|
|
|
onAddAdmin={this.handleAddAdmin}
|
|
|
|
onTransferCommunity={this.handleTransferCommunity}
|
|
|
|
onPurgeComment={this.handlePurgeComment}
|
|
|
|
onPurgePerson={this.handlePurgePerson}
|
|
|
|
onCommentReplyRead={this.handleCommentReplyRead}
|
|
|
|
onPersonMentionRead={this.handlePersonMentionRead}
|
|
|
|
onBanPersonFromCommunity={this.handleBanFromCommunity}
|
|
|
|
onBanPerson={this.handleBanPerson}
|
|
|
|
onCreateComment={this.handleCreateComment}
|
|
|
|
onEditComment={this.handleEditComment}
|
2020-12-24 01:58:27 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
case ReplyEnum.Message:
|
|
|
|
return (
|
|
|
|
<PrivateMessage
|
|
|
|
key={i.id}
|
|
|
|
private_message_view={i.view as PrivateMessageView}
|
2023-06-14 12:20:40 +00:00
|
|
|
onDelete={this.handleDeleteMessage}
|
|
|
|
onMarkRead={this.handleMarkMessageAsRead}
|
|
|
|
onReport={this.handleMessageReport}
|
|
|
|
onCreate={this.handleCreateMessage}
|
|
|
|
onEdit={this.handleEditMessage}
|
2020-12-24 01:58:27 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
default:
|
|
|
|
return <div />;
|
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
all() {
|
2023-06-14 12:20:40 +00:00
|
|
|
if (
|
|
|
|
this.state.repliesRes.state == "loading" ||
|
|
|
|
this.state.mentionsRes.state == "loading" ||
|
|
|
|
this.state.messagesRes.state == "loading"
|
|
|
|
) {
|
|
|
|
return (
|
|
|
|
<h5>
|
|
|
|
<Spinner large />
|
|
|
|
</h5>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return (
|
|
|
|
<div>{this.buildCombined().map(r => this.renderReplyType(r))}</div>
|
|
|
|
);
|
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
replies() {
|
2023-06-14 12:20:40 +00:00
|
|
|
switch (this.state.repliesRes.state) {
|
|
|
|
case "loading":
|
|
|
|
return (
|
|
|
|
<h5>
|
|
|
|
<Spinner large />
|
|
|
|
</h5>
|
|
|
|
);
|
|
|
|
case "success": {
|
|
|
|
const replies = this.state.repliesRes.data.replies;
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<CommentNodes
|
|
|
|
nodes={commentsToFlatNodes(replies)}
|
|
|
|
viewType={CommentViewType.Flat}
|
|
|
|
finished={this.state.finished}
|
|
|
|
noIndent
|
|
|
|
markable
|
|
|
|
showCommunity
|
|
|
|
showContext
|
|
|
|
enableDownvotes={enableDownvotes(this.state.siteRes)}
|
|
|
|
allLanguages={this.state.siteRes.all_languages}
|
|
|
|
siteLanguages={this.state.siteRes.discussion_languages}
|
|
|
|
onSaveComment={this.handleSaveComment}
|
|
|
|
onBlockPerson={this.handleBlockPerson}
|
|
|
|
onDeleteComment={this.handleDeleteComment}
|
|
|
|
onRemoveComment={this.handleRemoveComment}
|
|
|
|
onCommentVote={this.handleCommentVote}
|
|
|
|
onCommentReport={this.handleCommentReport}
|
|
|
|
onDistinguishComment={this.handleDistinguishComment}
|
|
|
|
onAddModToCommunity={this.handleAddModToCommunity}
|
|
|
|
onAddAdmin={this.handleAddAdmin}
|
|
|
|
onTransferCommunity={this.handleTransferCommunity}
|
|
|
|
onPurgeComment={this.handlePurgeComment}
|
|
|
|
onPurgePerson={this.handlePurgePerson}
|
|
|
|
onCommentReplyRead={this.handleCommentReplyRead}
|
|
|
|
onPersonMentionRead={this.handlePersonMentionRead}
|
|
|
|
onBanPersonFromCommunity={this.handleBanFromCommunity}
|
|
|
|
onBanPerson={this.handleBanPerson}
|
|
|
|
onCreateComment={this.handleCreateComment}
|
|
|
|
onEditComment={this.handleEditComment}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mentions() {
|
2023-06-14 12:20:40 +00:00
|
|
|
switch (this.state.mentionsRes.state) {
|
|
|
|
case "loading":
|
|
|
|
return (
|
|
|
|
<h5>
|
|
|
|
<Spinner large />
|
|
|
|
</h5>
|
|
|
|
);
|
|
|
|
case "success": {
|
|
|
|
const mentions = this.state.mentionsRes.data.mentions;
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
{mentions.map(umv => (
|
|
|
|
<CommentNodes
|
|
|
|
key={umv.person_mention.id}
|
|
|
|
nodes={[{ comment_view: umv, children: [], depth: 0 }]}
|
|
|
|
viewType={CommentViewType.Flat}
|
|
|
|
finished={this.state.finished}
|
|
|
|
noIndent
|
|
|
|
markable
|
|
|
|
showCommunity
|
|
|
|
showContext
|
|
|
|
enableDownvotes={enableDownvotes(this.state.siteRes)}
|
|
|
|
allLanguages={this.state.siteRes.all_languages}
|
|
|
|
siteLanguages={this.state.siteRes.discussion_languages}
|
|
|
|
onSaveComment={this.handleSaveComment}
|
|
|
|
onBlockPerson={this.handleBlockPerson}
|
|
|
|
onDeleteComment={this.handleDeleteComment}
|
|
|
|
onRemoveComment={this.handleRemoveComment}
|
|
|
|
onCommentVote={this.handleCommentVote}
|
|
|
|
onCommentReport={this.handleCommentReport}
|
|
|
|
onDistinguishComment={this.handleDistinguishComment}
|
|
|
|
onAddModToCommunity={this.handleAddModToCommunity}
|
|
|
|
onAddAdmin={this.handleAddAdmin}
|
|
|
|
onTransferCommunity={this.handleTransferCommunity}
|
|
|
|
onPurgeComment={this.handlePurgeComment}
|
|
|
|
onPurgePerson={this.handlePurgePerson}
|
|
|
|
onCommentReplyRead={this.handleCommentReplyRead}
|
|
|
|
onPersonMentionRead={this.handlePersonMentionRead}
|
|
|
|
onBanPersonFromCommunity={this.handleBanFromCommunity}
|
|
|
|
onBanPerson={this.handleBanPerson}
|
|
|
|
onCreateComment={this.handleCreateComment}
|
|
|
|
onEditComment={this.handleEditComment}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
messages() {
|
2023-06-14 12:20:40 +00:00
|
|
|
switch (this.state.messagesRes.state) {
|
|
|
|
case "loading":
|
|
|
|
return (
|
|
|
|
<h5>
|
|
|
|
<Spinner large />
|
|
|
|
</h5>
|
|
|
|
);
|
|
|
|
case "success": {
|
|
|
|
const messages = this.state.messagesRes.data.private_messages;
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
{messages.map(pmv => (
|
|
|
|
<PrivateMessage
|
|
|
|
key={pmv.private_message.id}
|
|
|
|
private_message_view={pmv}
|
|
|
|
onDelete={this.handleDeleteMessage}
|
|
|
|
onMarkRead={this.handleMarkMessageAsRead}
|
|
|
|
onReport={this.handleMessageReport}
|
|
|
|
onCreate={this.handleCreateMessage}
|
|
|
|
onEdit={this.handleEditMessage}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async handlePageChange(page: number) {
|
2021-07-16 19:40:56 +00:00
|
|
|
this.setState({ page });
|
2023-06-14 12:20:40 +00:00
|
|
|
await this.refetch();
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async handleUnreadOrAllChange(i: Inbox, event: any) {
|
2023-05-15 19:53:29 +00:00
|
|
|
i.setState({ unreadOrAll: Number(event.target.value), page: 1 });
|
2023-06-14 12:20:40 +00:00
|
|
|
await i.refetch();
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async handleMessageTypeChange(i: Inbox, event: any) {
|
2023-05-15 19:53:29 +00:00
|
|
|
i.setState({ messageType: Number(event.target.value), page: 1 });
|
2023-06-14 12:20:40 +00:00
|
|
|
await i.refetch();
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2023-06-16 02:08:14 +00:00
|
|
|
static async fetchInitialData({
|
2023-05-30 00:40:00 +00:00
|
|
|
client,
|
2023-06-14 12:20:40 +00:00
|
|
|
auth,
|
2023-06-16 02:08:14 +00:00
|
|
|
}: InitialFetchRequest): Promise<InboxData> {
|
2023-05-30 00:40:00 +00:00
|
|
|
const sort: CommentSortType = "New";
|
|
|
|
|
|
|
|
return {
|
2023-06-16 02:39:04 +00:00
|
|
|
mentionsRes: auth
|
2023-06-16 02:08:14 +00:00
|
|
|
? await client.getPersonMentions({
|
|
|
|
sort,
|
|
|
|
unread_only: true,
|
|
|
|
page: 1,
|
|
|
|
limit: fetchLimit,
|
|
|
|
auth,
|
|
|
|
})
|
|
|
|
: { state: "empty" },
|
2023-06-16 02:39:04 +00:00
|
|
|
messagesRes: auth
|
2023-06-16 02:08:14 +00:00
|
|
|
? await client.getPrivateMessages({
|
|
|
|
unread_only: true,
|
|
|
|
page: 1,
|
|
|
|
limit: fetchLimit,
|
|
|
|
auth,
|
|
|
|
})
|
|
|
|
: { state: "empty" },
|
2023-06-16 02:39:04 +00:00
|
|
|
repliesRes: auth
|
2023-06-16 02:08:14 +00:00
|
|
|
? await client.getReplies({
|
|
|
|
sort,
|
|
|
|
unread_only: true,
|
|
|
|
page: 1,
|
|
|
|
limit: fetchLimit,
|
|
|
|
auth,
|
|
|
|
})
|
|
|
|
: { state: "empty" },
|
2023-05-30 00:40:00 +00:00
|
|
|
};
|
2020-09-09 00:48:17 +00:00
|
|
|
}
|
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async refetch() {
|
2023-06-05 21:31:12 +00:00
|
|
|
const sort = this.state.sort;
|
|
|
|
const unread_only = this.state.unreadOrAll == UnreadOrAll.Unread;
|
|
|
|
const page = this.state.page;
|
2023-05-30 00:40:00 +00:00
|
|
|
const limit = fetchLimit;
|
2023-06-14 12:20:40 +00:00
|
|
|
const auth = myAuthRequired();
|
2023-01-04 16:56:24 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
this.setState({ repliesRes: { state: "loading" } });
|
|
|
|
this.setState({
|
|
|
|
repliesRes: await HttpService.client.getReplies({
|
2023-01-04 16:56:24 +00:00
|
|
|
sort,
|
|
|
|
unread_only,
|
|
|
|
page,
|
|
|
|
limit,
|
|
|
|
auth,
|
2023-06-14 12:20:40 +00:00
|
|
|
}),
|
|
|
|
});
|
2023-01-04 16:56:24 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
this.setState({ mentionsRes: { state: "loading" } });
|
|
|
|
this.setState({
|
|
|
|
mentionsRes: await HttpService.client.getPersonMentions({
|
2023-01-04 16:56:24 +00:00
|
|
|
sort,
|
|
|
|
unread_only,
|
|
|
|
page,
|
|
|
|
limit,
|
|
|
|
auth,
|
2023-06-14 12:20:40 +00:00
|
|
|
}),
|
|
|
|
});
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
this.setState({ messagesRes: { state: "loading" } });
|
|
|
|
this.setState({
|
|
|
|
messagesRes: await HttpService.client.getPrivateMessages({
|
2023-01-04 16:56:24 +00:00
|
|
|
unread_only,
|
|
|
|
page,
|
|
|
|
limit,
|
|
|
|
auth,
|
2023-06-14 12:20:40 +00:00
|
|
|
}),
|
|
|
|
});
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async handleSortChange(val: CommentSortType) {
|
2023-05-15 19:53:29 +00:00
|
|
|
this.setState({ sort: val, page: 1 });
|
2023-06-14 12:20:40 +00:00
|
|
|
await this.refetch();
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async handleMarkAllAsRead(i: Inbox) {
|
|
|
|
i.setState({ markAllAsReadRes: { state: "loading" } });
|
|
|
|
|
|
|
|
i.setState({
|
|
|
|
markAllAsReadRes: await HttpService.client.markAllAsRead({
|
|
|
|
auth: myAuthRequired(),
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
|
|
|
|
if (i.state.markAllAsReadRes.state == "success") {
|
|
|
|
i.setState({
|
|
|
|
repliesRes: { state: "empty" },
|
|
|
|
mentionsRes: { state: "empty" },
|
|
|
|
messagesRes: { state: "empty" },
|
|
|
|
});
|
2023-01-04 16:56:24 +00:00
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async handleAddModToCommunity(form: AddModToCommunity) {
|
|
|
|
// TODO not sure what to do here
|
|
|
|
HttpService.client.addModToCommunity(form);
|
|
|
|
}
|
|
|
|
|
|
|
|
async handlePurgePerson(form: PurgePerson) {
|
|
|
|
const purgePersonRes = await HttpService.client.purgePerson(form);
|
|
|
|
this.purgeItem(purgePersonRes);
|
|
|
|
}
|
|
|
|
|
|
|
|
async handlePurgeComment(form: PurgeComment) {
|
|
|
|
const purgeCommentRes = await HttpService.client.purgeComment(form);
|
|
|
|
this.purgeItem(purgeCommentRes);
|
|
|
|
}
|
|
|
|
|
|
|
|
async handlePurgePost(form: PurgePost) {
|
|
|
|
const purgeRes = await HttpService.client.purgePost(form);
|
|
|
|
this.purgeItem(purgeRes);
|
|
|
|
}
|
|
|
|
|
|
|
|
async handleBlockPerson(form: BlockPerson) {
|
|
|
|
const blockPersonRes = await HttpService.client.blockPerson(form);
|
|
|
|
if (blockPersonRes.state == "success") {
|
|
|
|
updatePersonBlock(blockPersonRes.data);
|
2021-10-17 17:42:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async handleCreateComment(form: CreateComment) {
|
|
|
|
const res = await HttpService.client.createComment(form);
|
|
|
|
|
|
|
|
if (res.state === "success") {
|
|
|
|
toast(i18n.t("reply_sent"));
|
|
|
|
this.findAndUpdateComment(res);
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
async handleEditComment(form: EditComment) {
|
|
|
|
const res = await HttpService.client.editComment(form);
|
|
|
|
|
|
|
|
if (res.state === "success") {
|
|
|
|
toast(i18n.t("edit"));
|
|
|
|
this.findAndUpdateComment(res);
|
|
|
|
} else if (res.state === "failed") {
|
|
|
|
toast(res.msg, "danger");
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
async handleDeleteComment(form: DeleteComment) {
|
|
|
|
const res = await HttpService.client.deleteComment(form);
|
|
|
|
if (res.state == "success") {
|
|
|
|
toast(i18n.t("deleted"));
|
|
|
|
this.findAndUpdateComment(res);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async handleRemoveComment(form: RemoveComment) {
|
|
|
|
const res = await HttpService.client.removeComment(form);
|
|
|
|
if (res.state == "success") {
|
|
|
|
toast(i18n.t("remove_comment"));
|
|
|
|
this.findAndUpdateComment(res);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async handleSaveComment(form: SaveComment) {
|
|
|
|
const res = await HttpService.client.saveComment(form);
|
|
|
|
this.findAndUpdateComment(res);
|
|
|
|
}
|
|
|
|
|
|
|
|
async handleCommentVote(form: CreateCommentLike) {
|
|
|
|
const res = await HttpService.client.likeComment(form);
|
|
|
|
this.findAndUpdateComment(res);
|
|
|
|
}
|
|
|
|
|
|
|
|
async handleCommentReport(form: CreateCommentReport) {
|
|
|
|
const reportRes = await HttpService.client.createCommentReport(form);
|
|
|
|
this.reportToast(reportRes);
|
|
|
|
}
|
|
|
|
|
|
|
|
async handleDistinguishComment(form: DistinguishComment) {
|
|
|
|
const res = await HttpService.client.distinguishComment(form);
|
|
|
|
this.findAndUpdateComment(res);
|
|
|
|
}
|
|
|
|
|
|
|
|
async handleAddAdmin(form: AddAdmin) {
|
|
|
|
const addAdminRes = await HttpService.client.addAdmin(form);
|
|
|
|
|
|
|
|
if (addAdminRes.state === "success") {
|
|
|
|
this.setState(s => ((s.siteRes.admins = addAdminRes.data.admins), s));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async handleTransferCommunity(form: TransferCommunity) {
|
|
|
|
await HttpService.client.transferCommunity(form);
|
|
|
|
toast(i18n.t("transfer_community"));
|
|
|
|
}
|
|
|
|
|
|
|
|
async handleCommentReplyRead(form: MarkCommentReplyAsRead) {
|
|
|
|
const res = await HttpService.client.markCommentReplyAsRead(form);
|
|
|
|
this.findAndUpdateCommentReply(res);
|
|
|
|
}
|
|
|
|
|
|
|
|
async handlePersonMentionRead(form: MarkPersonMentionAsRead) {
|
|
|
|
const res = await HttpService.client.markPersonMentionAsRead(form);
|
|
|
|
this.findAndUpdateMention(res);
|
|
|
|
}
|
|
|
|
|
|
|
|
async handleBanFromCommunity(form: BanFromCommunity) {
|
|
|
|
const banRes = await HttpService.client.banFromCommunity(form);
|
|
|
|
this.updateBanFromCommunity(banRes);
|
|
|
|
}
|
|
|
|
|
|
|
|
async handleBanPerson(form: BanPerson) {
|
|
|
|
const banRes = await HttpService.client.banPerson(form);
|
|
|
|
this.updateBan(banRes);
|
|
|
|
}
|
|
|
|
|
|
|
|
async handleDeleteMessage(form: DeletePrivateMessage) {
|
|
|
|
const res = await HttpService.client.deletePrivateMessage(form);
|
|
|
|
this.findAndUpdateMessage(res);
|
|
|
|
}
|
|
|
|
|
|
|
|
async handleEditMessage(form: EditPrivateMessage) {
|
|
|
|
const res = await HttpService.client.editPrivateMessage(form);
|
|
|
|
this.findAndUpdateMessage(res);
|
|
|
|
}
|
|
|
|
|
|
|
|
async handleMarkMessageAsRead(form: MarkPrivateMessageAsRead) {
|
|
|
|
const res = await HttpService.client.markPrivateMessageAsRead(form);
|
|
|
|
this.findAndUpdateMessage(res);
|
|
|
|
}
|
|
|
|
|
|
|
|
async handleMessageReport(form: CreatePrivateMessageReport) {
|
|
|
|
const res = await HttpService.client.createPrivateMessageReport(form);
|
|
|
|
this.reportToast(res);
|
|
|
|
}
|
|
|
|
|
|
|
|
async handleCreateMessage(form: CreatePrivateMessage) {
|
|
|
|
const res = await HttpService.client.createPrivateMessage(form);
|
|
|
|
this.setState(s => {
|
|
|
|
if (s.messagesRes.state == "success" && res.state == "success") {
|
|
|
|
s.messagesRes.data.private_messages.unshift(
|
|
|
|
res.data.private_message_view
|
|
|
|
);
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
2023-06-14 12:20:40 +00:00
|
|
|
|
|
|
|
return s;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
findAndUpdateMessage(res: RequestState<PrivateMessageResponse>) {
|
|
|
|
this.setState(s => {
|
|
|
|
if (s.messagesRes.state === "success" && res.state === "success") {
|
|
|
|
s.messagesRes.data.private_messages = editPrivateMessage(
|
|
|
|
res.data.private_message_view,
|
|
|
|
s.messagesRes.data.private_messages
|
|
|
|
);
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
2023-06-14 12:20:40 +00:00
|
|
|
return s;
|
|
|
|
});
|
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
updateBanFromCommunity(banRes: RequestState<BanFromCommunityResponse>) {
|
|
|
|
// Maybe not necessary
|
|
|
|
if (banRes.state == "success") {
|
|
|
|
this.setState(s => {
|
|
|
|
if (s.repliesRes.state == "success") {
|
|
|
|
s.repliesRes.data.replies
|
|
|
|
.filter(c => c.creator.id == banRes.data.person_view.person.id)
|
|
|
|
.forEach(
|
|
|
|
c => (c.creator_banned_from_community = banRes.data.banned)
|
|
|
|
);
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
2023-06-14 12:20:40 +00:00
|
|
|
if (s.mentionsRes.state == "success") {
|
|
|
|
s.mentionsRes.data.mentions
|
|
|
|
.filter(c => c.creator.id == banRes.data.person_view.person.id)
|
|
|
|
.forEach(
|
|
|
|
c => (c.creator_banned_from_community = banRes.data.banned)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2022-07-30 13:28:08 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
updateBan(banRes: RequestState<BanPersonResponse>) {
|
|
|
|
// Maybe not necessary
|
|
|
|
if (banRes.state == "success") {
|
|
|
|
this.setState(s => {
|
|
|
|
if (s.repliesRes.state == "success") {
|
|
|
|
s.repliesRes.data.replies
|
|
|
|
.filter(c => c.creator.id == banRes.data.person_view.person.id)
|
|
|
|
.forEach(c => (c.creator.banned = banRes.data.banned));
|
2022-07-30 13:28:08 +00:00
|
|
|
}
|
2023-06-14 12:20:40 +00:00
|
|
|
if (s.mentionsRes.state == "success") {
|
|
|
|
s.mentionsRes.data.mentions
|
|
|
|
.filter(c => c.creator.id == banRes.data.person_view.person.id)
|
|
|
|
.forEach(c => (c.creator.banned = banRes.data.banned));
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
purgeItem(purgeRes: RequestState<PurgeItemResponse>) {
|
|
|
|
if (purgeRes.state == "success") {
|
|
|
|
toast(i18n.t("purge_success"));
|
|
|
|
this.context.router.history.push(`/`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
reportToast(
|
|
|
|
res: RequestState<PrivateMessageReportResponse | CommentReportResponse>
|
|
|
|
) {
|
|
|
|
if (res.state == "success") {
|
|
|
|
toast(i18n.t("report_created"));
|
|
|
|
}
|
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
// A weird case, since you have only replies and mentions, not comment responses
|
|
|
|
findAndUpdateComment(res: RequestState<CommentResponse>) {
|
|
|
|
if (res.state == "success") {
|
|
|
|
this.setState(s => {
|
|
|
|
if (s.repliesRes.state == "success") {
|
|
|
|
s.repliesRes.data.replies = editWith(
|
|
|
|
res.data.comment_view,
|
|
|
|
s.repliesRes.data.replies
|
|
|
|
);
|
2021-02-02 20:24:25 +00:00
|
|
|
}
|
2023-06-14 12:20:40 +00:00
|
|
|
if (s.mentionsRes.state == "success") {
|
|
|
|
s.mentionsRes.data.mentions = editWith(
|
|
|
|
res.data.comment_view,
|
|
|
|
s.mentionsRes.data.mentions
|
|
|
|
);
|
|
|
|
}
|
|
|
|
// Set finished for the parent
|
|
|
|
s.finished.set(
|
|
|
|
getCommentParentId(res.data.comment_view.comment) ?? 0,
|
|
|
|
true
|
2023-01-04 16:56:24 +00:00
|
|
|
);
|
2023-06-14 12:20:40 +00:00
|
|
|
return s;
|
|
|
|
});
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
findAndUpdateCommentReply(res: RequestState<CommentReplyResponse>) {
|
|
|
|
this.setState(s => {
|
|
|
|
if (s.repliesRes.state == "success" && res.state == "success") {
|
|
|
|
s.repliesRes.data.replies = editCommentReply(
|
|
|
|
res.data.comment_reply_view,
|
|
|
|
s.repliesRes.data.replies
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
});
|
2021-10-12 17:01:49 +00:00
|
|
|
}
|
2022-07-30 13:28:08 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
findAndUpdateMention(res: RequestState<PersonMentionResponse>) {
|
|
|
|
this.setState(s => {
|
|
|
|
if (s.mentionsRes.state == "success" && res.state == "success") {
|
|
|
|
s.mentionsRes.data.mentions = editMention(
|
|
|
|
res.data.person_mention_view,
|
|
|
|
s.mentionsRes.data.mentions
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
});
|
2022-07-30 13:28:08 +00:00
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|