14 import { RouteDataResponse } from "@utils/types";
15 import { Component, linkEvent } from "inferno";
20 BanFromCommunityResponse,
27 CommentReportResponse,
35 CreatePrivateMessageReport,
41 GetPersonMentionsResponse,
44 MarkCommentReplyAsRead,
45 MarkPersonMentionAsRead,
46 MarkPrivateMessageAsRead,
47 PersonMentionResponse,
49 PrivateMessageReportResponse,
50 PrivateMessageResponse,
52 PrivateMessagesResponse,
60 } from "lemmy-js-client";
61 import { fetchLimit, relTags } from "../../config";
62 import { CommentViewType, InitialFetchRequest } from "../../interfaces";
63 import { FirstLoadService, I18NextService, UserService } from "../../services";
64 import { HttpService, RequestState } from "../../services/HttpService";
65 import { toast } from "../../toast";
66 import { CommentNodes } from "../comment/comment-nodes";
67 import { CommentSortSelect } from "../common/comment-sort-select";
68 import { HtmlTags } from "../common/html-tags";
69 import { Icon, Spinner } from "../common/icon";
70 import { Paginator } from "../common/paginator";
71 import { PrivateMessage } from "../private_message/private-message";
91 type InboxData = RouteDataResponse<{
92 repliesRes: GetRepliesResponse;
93 mentionsRes: GetPersonMentionsResponse;
94 messagesRes: PrivateMessagesResponse;
100 view: CommentView | PrivateMessageView | PersonMentionView | CommentReplyView;
104 interface InboxState {
105 unreadOrAll: UnreadOrAll;
106 messageType: MessageType;
107 repliesRes: RequestState<GetRepliesResponse>;
108 mentionsRes: RequestState<GetPersonMentionsResponse>;
109 messagesRes: RequestState<PrivateMessagesResponse>;
110 markAllAsReadRes: RequestState<GetRepliesResponse>;
111 sort: CommentSortType;
113 siteRes: GetSiteResponse;
114 finished: Map<CommentId, boolean | undefined>;
115 isIsomorphic: boolean;
118 export class Inbox extends Component<any, InboxState> {
119 private isoData = setIsoData<InboxData>(this.context);
120 state: InboxState = {
121 unreadOrAll: UnreadOrAll.Unread,
122 messageType: MessageType.All,
125 siteRes: this.isoData.site_res,
126 repliesRes: { state: "empty" },
127 mentionsRes: { state: "empty" },
128 messagesRes: { state: "empty" },
129 markAllAsReadRes: { state: "empty" },
134 constructor(props: any, context: any) {
135 super(props, context);
137 this.handleSortChange = this.handleSortChange.bind(this);
138 this.handlePageChange = this.handlePageChange.bind(this);
140 this.handleCreateComment = this.handleCreateComment.bind(this);
141 this.handleEditComment = this.handleEditComment.bind(this);
142 this.handleSaveComment = this.handleSaveComment.bind(this);
143 this.handleBlockPerson = this.handleBlockPerson.bind(this);
144 this.handleDeleteComment = this.handleDeleteComment.bind(this);
145 this.handleRemoveComment = this.handleRemoveComment.bind(this);
146 this.handleCommentVote = this.handleCommentVote.bind(this);
147 this.handleAddModToCommunity = this.handleAddModToCommunity.bind(this);
148 this.handleAddAdmin = this.handleAddAdmin.bind(this);
149 this.handlePurgePerson = this.handlePurgePerson.bind(this);
150 this.handlePurgeComment = this.handlePurgeComment.bind(this);
151 this.handleCommentReport = this.handleCommentReport.bind(this);
152 this.handleDistinguishComment = this.handleDistinguishComment.bind(this);
153 this.handleTransferCommunity = this.handleTransferCommunity.bind(this);
154 this.handleCommentReplyRead = this.handleCommentReplyRead.bind(this);
155 this.handlePersonMentionRead = this.handlePersonMentionRead.bind(this);
156 this.handleBanFromCommunity = this.handleBanFromCommunity.bind(this);
157 this.handleBanPerson = this.handleBanPerson.bind(this);
159 this.handleDeleteMessage = this.handleDeleteMessage.bind(this);
160 this.handleMarkMessageAsRead = this.handleMarkMessageAsRead.bind(this);
161 this.handleMessageReport = this.handleMessageReport.bind(this);
162 this.handleCreateMessage = this.handleCreateMessage.bind(this);
163 this.handleEditMessage = this.handleEditMessage.bind(this);
165 // Only fetch the data if coming from another route
166 if (FirstLoadService.isFirstLoad) {
167 const { mentionsRes, messagesRes, repliesRes } = this.isoData.routeData;
179 async componentDidMount() {
180 if (!this.state.isIsomorphic) {
181 await this.refetch();
185 get documentTitle(): string {
186 const mui = UserService.Instance.myUserInfo;
188 ? `@${mui.local_user_view.person.name} ${I18NextService.i18n.t(
190 )} - ${this.state.siteRes.site_view.site.name}`
194 get hasUnreads(): boolean {
195 if (this.state.unreadOrAll == UnreadOrAll.Unread) {
196 const { repliesRes, mentionsRes, messagesRes } = this.state;
198 repliesRes.state == "success" ? repliesRes.data.replies.length : 0;
200 mentionsRes.state == "success" ? mentionsRes.data.mentions.length : 0;
202 messagesRes.state == "success"
203 ? messagesRes.data.private_messages.length
206 return replyCount + mentionCount + messageCount > 0;
213 const auth = myAuth();
214 const inboxRss = auth ? `/feeds/inbox/${auth}.xml` : undefined;
216 <div className="inbox container-lg">
217 <div className="row">
218 <div className="col-12">
220 title={this.documentTitle}
221 path={this.context.router.route.match.url}
223 <h5 className="mb-2">
224 {I18NextService.i18n.t("inbox")}
227 <a href={inboxRss} title="RSS" rel={relTags}>
228 <Icon icon="rss" classes="ms-2 text-muted small" />
232 type="application/atom+xml"
238 {this.hasUnreads && (
240 className="btn btn-secondary mb-2"
241 onClick={linkEvent(this, this.handleMarkAllAsRead)}
243 {this.state.markAllAsReadRes.state == "loading" ? (
246 I18NextService.i18n.t("mark_all_as_read")
253 page={this.state.page}
254 onChange={this.handlePageChange}
263 switch (this.state.messageType) {
264 case MessageType.All: {
267 case MessageType.Replies: {
268 return this.replies();
270 case MessageType.Mentions: {
271 return this.mentions();
273 case MessageType.Messages: {
274 return this.messages();
282 unreadOrAllRadios() {
284 <div className="btn-group btn-group-toggle flex-wrap mb-2">
286 className={`btn btn-outline-secondary pointer
287 ${this.state.unreadOrAll == UnreadOrAll.Unread && "active"}
292 className="btn-check"
293 value={UnreadOrAll.Unread}
294 checked={this.state.unreadOrAll == UnreadOrAll.Unread}
295 onChange={linkEvent(this, this.handleUnreadOrAllChange)}
297 {I18NextService.i18n.t("unread")}
300 className={`btn btn-outline-secondary pointer
301 ${this.state.unreadOrAll == UnreadOrAll.All && "active"}
306 className="btn-check"
307 value={UnreadOrAll.All}
308 checked={this.state.unreadOrAll == UnreadOrAll.All}
309 onChange={linkEvent(this, this.handleUnreadOrAllChange)}
311 {I18NextService.i18n.t("all")}
317 messageTypeRadios() {
319 <div className="btn-group btn-group-toggle flex-wrap mb-2">
321 className={`btn btn-outline-secondary pointer
322 ${this.state.messageType == MessageType.All && "active"}
327 className="btn-check"
328 value={MessageType.All}
329 checked={this.state.messageType == MessageType.All}
330 onChange={linkEvent(this, this.handleMessageTypeChange)}
332 {I18NextService.i18n.t("all")}
335 className={`btn btn-outline-secondary pointer
336 ${this.state.messageType == MessageType.Replies && "active"}
341 className="btn-check"
342 value={MessageType.Replies}
343 checked={this.state.messageType == MessageType.Replies}
344 onChange={linkEvent(this, this.handleMessageTypeChange)}
346 {I18NextService.i18n.t("replies")}
349 className={`btn btn-outline-secondary pointer
350 ${this.state.messageType == MessageType.Mentions && "active"}
355 className="btn-check"
356 value={MessageType.Mentions}
357 checked={this.state.messageType == MessageType.Mentions}
358 onChange={linkEvent(this, this.handleMessageTypeChange)}
360 {I18NextService.i18n.t("mentions")}
363 className={`btn btn-outline-secondary pointer
364 ${this.state.messageType == MessageType.Messages && "active"}
369 className="btn-check"
370 value={MessageType.Messages}
371 checked={this.state.messageType == MessageType.Messages}
372 onChange={linkEvent(this, this.handleMessageTypeChange)}
374 {I18NextService.i18n.t("messages")}
382 <div className="mb-2">
383 <span className="me-3">{this.unreadOrAllRadios()}</span>
384 <span className="me-3">{this.messageTypeRadios()}</span>
386 sort={this.state.sort}
387 onChange={this.handleSortChange}
393 replyToReplyType(r: CommentReplyView): ReplyType {
395 id: r.comment_reply.id,
396 type_: ReplyEnum.Reply,
398 published: r.comment.published,
402 mentionToReplyType(r: PersonMentionView): ReplyType {
404 id: r.person_mention.id,
405 type_: ReplyEnum.Mention,
407 published: r.comment.published,
411 messageToReplyType(r: PrivateMessageView): ReplyType {
413 id: r.private_message.id,
414 type_: ReplyEnum.Message,
416 published: r.private_message.published,
420 buildCombined(): ReplyType[] {
421 const replies: ReplyType[] =
422 this.state.repliesRes.state == "success"
423 ? this.state.repliesRes.data.replies.map(this.replyToReplyType)
425 const mentions: ReplyType[] =
426 this.state.mentionsRes.state == "success"
427 ? this.state.mentionsRes.data.mentions.map(this.mentionToReplyType)
429 const messages: ReplyType[] =
430 this.state.messagesRes.state == "success"
431 ? this.state.messagesRes.data.private_messages.map(
432 this.messageToReplyType
436 return [...replies, ...mentions, ...messages].sort((a, b) =>
437 b.published.localeCompare(a.published)
441 renderReplyType(i: ReplyType) {
443 case ReplyEnum.Reply:
448 { comment_view: i.view as CommentView, children: [], depth: 0 },
450 viewType={CommentViewType.Flat}
451 finished={this.state.finished}
455 enableDownvotes={enableDownvotes(this.state.siteRes)}
456 allLanguages={this.state.siteRes.all_languages}
457 siteLanguages={this.state.siteRes.discussion_languages}
458 onSaveComment={this.handleSaveComment}
459 onBlockPerson={this.handleBlockPerson}
460 onDeleteComment={this.handleDeleteComment}
461 onRemoveComment={this.handleRemoveComment}
462 onCommentVote={this.handleCommentVote}
463 onCommentReport={this.handleCommentReport}
464 onDistinguishComment={this.handleDistinguishComment}
465 onAddModToCommunity={this.handleAddModToCommunity}
466 onAddAdmin={this.handleAddAdmin}
467 onTransferCommunity={this.handleTransferCommunity}
468 onPurgeComment={this.handlePurgeComment}
469 onPurgePerson={this.handlePurgePerson}
470 onCommentReplyRead={this.handleCommentReplyRead}
471 onPersonMentionRead={this.handlePersonMentionRead}
472 onBanPersonFromCommunity={this.handleBanFromCommunity}
473 onBanPerson={this.handleBanPerson}
474 onCreateComment={this.handleCreateComment}
475 onEditComment={this.handleEditComment}
478 case ReplyEnum.Mention:
484 comment_view: i.view as PersonMentionView,
489 finished={this.state.finished}
490 viewType={CommentViewType.Flat}
494 enableDownvotes={enableDownvotes(this.state.siteRes)}
495 allLanguages={this.state.siteRes.all_languages}
496 siteLanguages={this.state.siteRes.discussion_languages}
497 onSaveComment={this.handleSaveComment}
498 onBlockPerson={this.handleBlockPerson}
499 onDeleteComment={this.handleDeleteComment}
500 onRemoveComment={this.handleRemoveComment}
501 onCommentVote={this.handleCommentVote}
502 onCommentReport={this.handleCommentReport}
503 onDistinguishComment={this.handleDistinguishComment}
504 onAddModToCommunity={this.handleAddModToCommunity}
505 onAddAdmin={this.handleAddAdmin}
506 onTransferCommunity={this.handleTransferCommunity}
507 onPurgeComment={this.handlePurgeComment}
508 onPurgePerson={this.handlePurgePerson}
509 onCommentReplyRead={this.handleCommentReplyRead}
510 onPersonMentionRead={this.handlePersonMentionRead}
511 onBanPersonFromCommunity={this.handleBanFromCommunity}
512 onBanPerson={this.handleBanPerson}
513 onCreateComment={this.handleCreateComment}
514 onEditComment={this.handleEditComment}
517 case ReplyEnum.Message:
521 private_message_view={i.view as PrivateMessageView}
522 onDelete={this.handleDeleteMessage}
523 onMarkRead={this.handleMarkMessageAsRead}
524 onReport={this.handleMessageReport}
525 onCreate={this.handleCreateMessage}
526 onEdit={this.handleEditMessage}
536 this.state.repliesRes.state == "loading" ||
537 this.state.mentionsRes.state == "loading" ||
538 this.state.messagesRes.state == "loading"
547 <div>{this.buildCombined().map(r => this.renderReplyType(r))}</div>
553 switch (this.state.repliesRes.state) {
561 const replies = this.state.repliesRes.data.replies;
565 nodes={commentsToFlatNodes(replies)}
566 viewType={CommentViewType.Flat}
567 finished={this.state.finished}
571 enableDownvotes={enableDownvotes(this.state.siteRes)}
572 allLanguages={this.state.siteRes.all_languages}
573 siteLanguages={this.state.siteRes.discussion_languages}
574 onSaveComment={this.handleSaveComment}
575 onBlockPerson={this.handleBlockPerson}
576 onDeleteComment={this.handleDeleteComment}
577 onRemoveComment={this.handleRemoveComment}
578 onCommentVote={this.handleCommentVote}
579 onCommentReport={this.handleCommentReport}
580 onDistinguishComment={this.handleDistinguishComment}
581 onAddModToCommunity={this.handleAddModToCommunity}
582 onAddAdmin={this.handleAddAdmin}
583 onTransferCommunity={this.handleTransferCommunity}
584 onPurgeComment={this.handlePurgeComment}
585 onPurgePerson={this.handlePurgePerson}
586 onCommentReplyRead={this.handleCommentReplyRead}
587 onPersonMentionRead={this.handlePersonMentionRead}
588 onBanPersonFromCommunity={this.handleBanFromCommunity}
589 onBanPerson={this.handleBanPerson}
590 onCreateComment={this.handleCreateComment}
591 onEditComment={this.handleEditComment}
600 switch (this.state.mentionsRes.state) {
608 const mentions = this.state.mentionsRes.data.mentions;
611 {mentions.map(umv => (
613 key={umv.person_mention.id}
614 nodes={[{ comment_view: umv, children: [], depth: 0 }]}
615 viewType={CommentViewType.Flat}
616 finished={this.state.finished}
620 enableDownvotes={enableDownvotes(this.state.siteRes)}
621 allLanguages={this.state.siteRes.all_languages}
622 siteLanguages={this.state.siteRes.discussion_languages}
623 onSaveComment={this.handleSaveComment}
624 onBlockPerson={this.handleBlockPerson}
625 onDeleteComment={this.handleDeleteComment}
626 onRemoveComment={this.handleRemoveComment}
627 onCommentVote={this.handleCommentVote}
628 onCommentReport={this.handleCommentReport}
629 onDistinguishComment={this.handleDistinguishComment}
630 onAddModToCommunity={this.handleAddModToCommunity}
631 onAddAdmin={this.handleAddAdmin}
632 onTransferCommunity={this.handleTransferCommunity}
633 onPurgeComment={this.handlePurgeComment}
634 onPurgePerson={this.handlePurgePerson}
635 onCommentReplyRead={this.handleCommentReplyRead}
636 onPersonMentionRead={this.handlePersonMentionRead}
637 onBanPersonFromCommunity={this.handleBanFromCommunity}
638 onBanPerson={this.handleBanPerson}
639 onCreateComment={this.handleCreateComment}
640 onEditComment={this.handleEditComment}
650 switch (this.state.messagesRes.state) {
658 const messages = this.state.messagesRes.data.private_messages;
661 {messages.map(pmv => (
663 key={pmv.private_message.id}
664 private_message_view={pmv}
665 onDelete={this.handleDeleteMessage}
666 onMarkRead={this.handleMarkMessageAsRead}
667 onReport={this.handleMessageReport}
668 onCreate={this.handleCreateMessage}
669 onEdit={this.handleEditMessage}
678 async handlePageChange(page: number) {
679 this.setState({ page });
680 await this.refetch();
683 async handleUnreadOrAllChange(i: Inbox, event: any) {
684 i.setState({ unreadOrAll: Number(event.target.value), page: 1 });
688 async handleMessageTypeChange(i: Inbox, event: any) {
689 i.setState({ messageType: Number(event.target.value), page: 1 });
693 static async fetchInitialData({
696 }: InitialFetchRequest): Promise<InboxData> {
697 const sort: CommentSortType = "New";
701 ? await client.getPersonMentions({
708 : { state: "empty" },
710 ? await client.getPrivateMessages({
716 : { state: "empty" },
718 ? await client.getReplies({
725 : { state: "empty" },
730 const sort = this.state.sort;
731 const unread_only = this.state.unreadOrAll == UnreadOrAll.Unread;
732 const page = this.state.page;
733 const limit = fetchLimit;
734 const auth = myAuthRequired();
736 this.setState({ repliesRes: { state: "loading" } });
738 repliesRes: await HttpService.client.getReplies({
747 this.setState({ mentionsRes: { state: "loading" } });
749 mentionsRes: await HttpService.client.getPersonMentions({
758 this.setState({ messagesRes: { state: "loading" } });
760 messagesRes: await HttpService.client.getPrivateMessages({
769 async handleSortChange(val: CommentSortType) {
770 this.setState({ sort: val, page: 1 });
771 await this.refetch();
774 async handleMarkAllAsRead(i: Inbox) {
775 i.setState({ markAllAsReadRes: { state: "loading" } });
778 markAllAsReadRes: await HttpService.client.markAllAsRead({
779 auth: myAuthRequired(),
783 if (i.state.markAllAsReadRes.state == "success") {
785 repliesRes: { state: "empty" },
786 mentionsRes: { state: "empty" },
787 messagesRes: { state: "empty" },
792 async handleAddModToCommunity(form: AddModToCommunity) {
793 // TODO not sure what to do here
794 HttpService.client.addModToCommunity(form);
797 async handlePurgePerson(form: PurgePerson) {
798 const purgePersonRes = await HttpService.client.purgePerson(form);
799 this.purgeItem(purgePersonRes);
802 async handlePurgeComment(form: PurgeComment) {
803 const purgeCommentRes = await HttpService.client.purgeComment(form);
804 this.purgeItem(purgeCommentRes);
807 async handlePurgePost(form: PurgePost) {
808 const purgeRes = await HttpService.client.purgePost(form);
809 this.purgeItem(purgeRes);
812 async handleBlockPerson(form: BlockPerson) {
813 const blockPersonRes = await HttpService.client.blockPerson(form);
814 if (blockPersonRes.state == "success") {
815 updatePersonBlock(blockPersonRes.data);
819 async handleCreateComment(form: CreateComment) {
820 const res = await HttpService.client.createComment(form);
822 if (res.state === "success") {
823 toast(I18NextService.i18n.t("reply_sent"));
824 this.findAndUpdateComment(res);
830 async handleEditComment(form: EditComment) {
831 const res = await HttpService.client.editComment(form);
833 if (res.state === "success") {
834 toast(I18NextService.i18n.t("edit"));
835 this.findAndUpdateComment(res);
836 } else if (res.state === "failed") {
837 toast(res.msg, "danger");
843 async handleDeleteComment(form: DeleteComment) {
844 const res = await HttpService.client.deleteComment(form);
845 if (res.state == "success") {
846 toast(I18NextService.i18n.t("deleted"));
847 this.findAndUpdateComment(res);
851 async handleRemoveComment(form: RemoveComment) {
852 const res = await HttpService.client.removeComment(form);
853 if (res.state == "success") {
854 toast(I18NextService.i18n.t("remove_comment"));
855 this.findAndUpdateComment(res);
859 async handleSaveComment(form: SaveComment) {
860 const res = await HttpService.client.saveComment(form);
861 this.findAndUpdateComment(res);
864 async handleCommentVote(form: CreateCommentLike) {
865 const res = await HttpService.client.likeComment(form);
866 this.findAndUpdateComment(res);
869 async handleCommentReport(form: CreateCommentReport) {
870 const reportRes = await HttpService.client.createCommentReport(form);
871 this.reportToast(reportRes);
874 async handleDistinguishComment(form: DistinguishComment) {
875 const res = await HttpService.client.distinguishComment(form);
876 this.findAndUpdateComment(res);
879 async handleAddAdmin(form: AddAdmin) {
880 const addAdminRes = await HttpService.client.addAdmin(form);
882 if (addAdminRes.state === "success") {
883 this.setState(s => ((s.siteRes.admins = addAdminRes.data.admins), s));
887 async handleTransferCommunity(form: TransferCommunity) {
888 await HttpService.client.transferCommunity(form);
889 toast(I18NextService.i18n.t("transfer_community"));
892 async handleCommentReplyRead(form: MarkCommentReplyAsRead) {
893 const res = await HttpService.client.markCommentReplyAsRead(form);
894 this.findAndUpdateCommentReply(res);
897 async handlePersonMentionRead(form: MarkPersonMentionAsRead) {
898 const res = await HttpService.client.markPersonMentionAsRead(form);
899 this.findAndUpdateMention(res);
902 async handleBanFromCommunity(form: BanFromCommunity) {
903 const banRes = await HttpService.client.banFromCommunity(form);
904 this.updateBanFromCommunity(banRes);
907 async handleBanPerson(form: BanPerson) {
908 const banRes = await HttpService.client.banPerson(form);
909 this.updateBan(banRes);
912 async handleDeleteMessage(form: DeletePrivateMessage) {
913 const res = await HttpService.client.deletePrivateMessage(form);
914 this.findAndUpdateMessage(res);
917 async handleEditMessage(form: EditPrivateMessage) {
918 const res = await HttpService.client.editPrivateMessage(form);
919 this.findAndUpdateMessage(res);
922 async handleMarkMessageAsRead(form: MarkPrivateMessageAsRead) {
923 const res = await HttpService.client.markPrivateMessageAsRead(form);
924 this.findAndUpdateMessage(res);
927 async handleMessageReport(form: CreatePrivateMessageReport) {
928 const res = await HttpService.client.createPrivateMessageReport(form);
929 this.reportToast(res);
932 async handleCreateMessage(form: CreatePrivateMessage) {
933 const res = await HttpService.client.createPrivateMessage(form);
935 if (s.messagesRes.state == "success" && res.state == "success") {
936 s.messagesRes.data.private_messages.unshift(
937 res.data.private_message_view
945 findAndUpdateMessage(res: RequestState<PrivateMessageResponse>) {
947 if (s.messagesRes.state === "success" && res.state === "success") {
948 s.messagesRes.data.private_messages = editPrivateMessage(
949 res.data.private_message_view,
950 s.messagesRes.data.private_messages
957 updateBanFromCommunity(banRes: RequestState<BanFromCommunityResponse>) {
958 // Maybe not necessary
959 if (banRes.state == "success") {
961 if (s.repliesRes.state == "success") {
962 s.repliesRes.data.replies
963 .filter(c => c.creator.id == banRes.data.person_view.person.id)
965 c => (c.creator_banned_from_community = banRes.data.banned)
968 if (s.mentionsRes.state == "success") {
969 s.mentionsRes.data.mentions
970 .filter(c => c.creator.id == banRes.data.person_view.person.id)
972 c => (c.creator_banned_from_community = banRes.data.banned)
980 updateBan(banRes: RequestState<BanPersonResponse>) {
981 // Maybe not necessary
982 if (banRes.state == "success") {
984 if (s.repliesRes.state == "success") {
985 s.repliesRes.data.replies
986 .filter(c => c.creator.id == banRes.data.person_view.person.id)
987 .forEach(c => (c.creator.banned = banRes.data.banned));
989 if (s.mentionsRes.state == "success") {
990 s.mentionsRes.data.mentions
991 .filter(c => c.creator.id == banRes.data.person_view.person.id)
992 .forEach(c => (c.creator.banned = banRes.data.banned));
999 purgeItem(purgeRes: RequestState<PurgeItemResponse>) {
1000 if (purgeRes.state == "success") {
1001 toast(I18NextService.i18n.t("purge_success"));
1002 this.context.router.history.push(`/`);
1007 res: RequestState<PrivateMessageReportResponse | CommentReportResponse>
1009 if (res.state == "success") {
1010 toast(I18NextService.i18n.t("report_created"));
1014 // A weird case, since you have only replies and mentions, not comment responses
1015 findAndUpdateComment(res: RequestState<CommentResponse>) {
1016 if (res.state == "success") {
1017 this.setState(s => {
1018 if (s.repliesRes.state == "success") {
1019 s.repliesRes.data.replies = editWith(
1020 res.data.comment_view,
1021 s.repliesRes.data.replies
1024 if (s.mentionsRes.state == "success") {
1025 s.mentionsRes.data.mentions = editWith(
1026 res.data.comment_view,
1027 s.mentionsRes.data.mentions
1030 // Set finished for the parent
1032 getCommentParentId(res.data.comment_view.comment) ?? 0,
1040 findAndUpdateCommentReply(res: RequestState<CommentReplyResponse>) {
1041 this.setState(s => {
1042 if (s.repliesRes.state == "success" && res.state == "success") {
1043 s.repliesRes.data.replies = editCommentReply(
1044 res.data.comment_reply_view,
1045 s.repliesRes.data.replies
1052 findAndUpdateMention(res: RequestState<PersonMentionResponse>) {
1053 this.setState(s => {
1054 if (s.mentionsRes.state == "success" && res.state == "success") {
1055 s.mentionsRes.data.mentions = editMention(
1056 res.data.person_mention_view,
1057 s.mentionsRes.data.mentions