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}
456 enableDownvotes={enableDownvotes(this.state.siteRes)}
457 allLanguages={this.state.siteRes.all_languages}
458 siteLanguages={this.state.siteRes.discussion_languages}
459 onSaveComment={this.handleSaveComment}
460 onBlockPerson={this.handleBlockPerson}
461 onDeleteComment={this.handleDeleteComment}
462 onRemoveComment={this.handleRemoveComment}
463 onCommentVote={this.handleCommentVote}
464 onCommentReport={this.handleCommentReport}
465 onDistinguishComment={this.handleDistinguishComment}
466 onAddModToCommunity={this.handleAddModToCommunity}
467 onAddAdmin={this.handleAddAdmin}
468 onTransferCommunity={this.handleTransferCommunity}
469 onPurgeComment={this.handlePurgeComment}
470 onPurgePerson={this.handlePurgePerson}
471 onCommentReplyRead={this.handleCommentReplyRead}
472 onPersonMentionRead={this.handlePersonMentionRead}
473 onBanPersonFromCommunity={this.handleBanFromCommunity}
474 onBanPerson={this.handleBanPerson}
475 onCreateComment={this.handleCreateComment}
476 onEditComment={this.handleEditComment}
479 case ReplyEnum.Mention:
485 comment_view: i.view as PersonMentionView,
490 finished={this.state.finished}
491 viewType={CommentViewType.Flat}
496 enableDownvotes={enableDownvotes(this.state.siteRes)}
497 allLanguages={this.state.siteRes.all_languages}
498 siteLanguages={this.state.siteRes.discussion_languages}
499 onSaveComment={this.handleSaveComment}
500 onBlockPerson={this.handleBlockPerson}
501 onDeleteComment={this.handleDeleteComment}
502 onRemoveComment={this.handleRemoveComment}
503 onCommentVote={this.handleCommentVote}
504 onCommentReport={this.handleCommentReport}
505 onDistinguishComment={this.handleDistinguishComment}
506 onAddModToCommunity={this.handleAddModToCommunity}
507 onAddAdmin={this.handleAddAdmin}
508 onTransferCommunity={this.handleTransferCommunity}
509 onPurgeComment={this.handlePurgeComment}
510 onPurgePerson={this.handlePurgePerson}
511 onCommentReplyRead={this.handleCommentReplyRead}
512 onPersonMentionRead={this.handlePersonMentionRead}
513 onBanPersonFromCommunity={this.handleBanFromCommunity}
514 onBanPerson={this.handleBanPerson}
515 onCreateComment={this.handleCreateComment}
516 onEditComment={this.handleEditComment}
519 case ReplyEnum.Message:
523 private_message_view={i.view as PrivateMessageView}
524 onDelete={this.handleDeleteMessage}
525 onMarkRead={this.handleMarkMessageAsRead}
526 onReport={this.handleMessageReport}
527 onCreate={this.handleCreateMessage}
528 onEdit={this.handleEditMessage}
538 this.state.repliesRes.state == "loading" ||
539 this.state.mentionsRes.state == "loading" ||
540 this.state.messagesRes.state == "loading"
549 <div>{this.buildCombined().map(r => this.renderReplyType(r))}</div>
555 switch (this.state.repliesRes.state) {
563 const replies = this.state.repliesRes.data.replies;
567 nodes={commentsToFlatNodes(replies)}
568 viewType={CommentViewType.Flat}
569 finished={this.state.finished}
574 enableDownvotes={enableDownvotes(this.state.siteRes)}
575 allLanguages={this.state.siteRes.all_languages}
576 siteLanguages={this.state.siteRes.discussion_languages}
577 onSaveComment={this.handleSaveComment}
578 onBlockPerson={this.handleBlockPerson}
579 onDeleteComment={this.handleDeleteComment}
580 onRemoveComment={this.handleRemoveComment}
581 onCommentVote={this.handleCommentVote}
582 onCommentReport={this.handleCommentReport}
583 onDistinguishComment={this.handleDistinguishComment}
584 onAddModToCommunity={this.handleAddModToCommunity}
585 onAddAdmin={this.handleAddAdmin}
586 onTransferCommunity={this.handleTransferCommunity}
587 onPurgeComment={this.handlePurgeComment}
588 onPurgePerson={this.handlePurgePerson}
589 onCommentReplyRead={this.handleCommentReplyRead}
590 onPersonMentionRead={this.handlePersonMentionRead}
591 onBanPersonFromCommunity={this.handleBanFromCommunity}
592 onBanPerson={this.handleBanPerson}
593 onCreateComment={this.handleCreateComment}
594 onEditComment={this.handleEditComment}
603 switch (this.state.mentionsRes.state) {
611 const mentions = this.state.mentionsRes.data.mentions;
614 {mentions.map(umv => (
616 key={umv.person_mention.id}
617 nodes={[{ comment_view: umv, children: [], depth: 0 }]}
618 viewType={CommentViewType.Flat}
619 finished={this.state.finished}
624 enableDownvotes={enableDownvotes(this.state.siteRes)}
625 allLanguages={this.state.siteRes.all_languages}
626 siteLanguages={this.state.siteRes.discussion_languages}
627 onSaveComment={this.handleSaveComment}
628 onBlockPerson={this.handleBlockPerson}
629 onDeleteComment={this.handleDeleteComment}
630 onRemoveComment={this.handleRemoveComment}
631 onCommentVote={this.handleCommentVote}
632 onCommentReport={this.handleCommentReport}
633 onDistinguishComment={this.handleDistinguishComment}
634 onAddModToCommunity={this.handleAddModToCommunity}
635 onAddAdmin={this.handleAddAdmin}
636 onTransferCommunity={this.handleTransferCommunity}
637 onPurgeComment={this.handlePurgeComment}
638 onPurgePerson={this.handlePurgePerson}
639 onCommentReplyRead={this.handleCommentReplyRead}
640 onPersonMentionRead={this.handlePersonMentionRead}
641 onBanPersonFromCommunity={this.handleBanFromCommunity}
642 onBanPerson={this.handleBanPerson}
643 onCreateComment={this.handleCreateComment}
644 onEditComment={this.handleEditComment}
654 switch (this.state.messagesRes.state) {
662 const messages = this.state.messagesRes.data.private_messages;
665 {messages.map(pmv => (
667 key={pmv.private_message.id}
668 private_message_view={pmv}
669 onDelete={this.handleDeleteMessage}
670 onMarkRead={this.handleMarkMessageAsRead}
671 onReport={this.handleMessageReport}
672 onCreate={this.handleCreateMessage}
673 onEdit={this.handleEditMessage}
682 async handlePageChange(page: number) {
683 this.setState({ page });
684 await this.refetch();
687 async handleUnreadOrAllChange(i: Inbox, event: any) {
688 i.setState({ unreadOrAll: Number(event.target.value), page: 1 });
692 async handleMessageTypeChange(i: Inbox, event: any) {
693 i.setState({ messageType: Number(event.target.value), page: 1 });
697 static async fetchInitialData({
700 }: InitialFetchRequest): Promise<InboxData> {
701 const sort: CommentSortType = "New";
705 ? await client.getPersonMentions({
712 : { state: "empty" },
714 ? await client.getPrivateMessages({
720 : { state: "empty" },
722 ? await client.getReplies({
729 : { state: "empty" },
734 const sort = this.state.sort;
735 const unread_only = this.state.unreadOrAll == UnreadOrAll.Unread;
736 const page = this.state.page;
737 const limit = fetchLimit;
738 const auth = myAuthRequired();
740 this.setState({ repliesRes: { state: "loading" } });
742 repliesRes: await HttpService.client.getReplies({
751 this.setState({ mentionsRes: { state: "loading" } });
753 mentionsRes: await HttpService.client.getPersonMentions({
762 this.setState({ messagesRes: { state: "loading" } });
764 messagesRes: await HttpService.client.getPrivateMessages({
773 async handleSortChange(val: CommentSortType) {
774 this.setState({ sort: val, page: 1 });
775 await this.refetch();
778 async handleMarkAllAsRead(i: Inbox) {
779 i.setState({ markAllAsReadRes: { state: "loading" } });
782 markAllAsReadRes: await HttpService.client.markAllAsRead({
783 auth: myAuthRequired(),
787 if (i.state.markAllAsReadRes.state == "success") {
789 repliesRes: { state: "empty" },
790 mentionsRes: { state: "empty" },
791 messagesRes: { state: "empty" },
796 async handleAddModToCommunity(form: AddModToCommunity) {
797 // TODO not sure what to do here
798 HttpService.client.addModToCommunity(form);
801 async handlePurgePerson(form: PurgePerson) {
802 const purgePersonRes = await HttpService.client.purgePerson(form);
803 this.purgeItem(purgePersonRes);
806 async handlePurgeComment(form: PurgeComment) {
807 const purgeCommentRes = await HttpService.client.purgeComment(form);
808 this.purgeItem(purgeCommentRes);
811 async handlePurgePost(form: PurgePost) {
812 const purgeRes = await HttpService.client.purgePost(form);
813 this.purgeItem(purgeRes);
816 async handleBlockPerson(form: BlockPerson) {
817 const blockPersonRes = await HttpService.client.blockPerson(form);
818 if (blockPersonRes.state == "success") {
819 updatePersonBlock(blockPersonRes.data);
823 async handleCreateComment(form: CreateComment) {
824 const res = await HttpService.client.createComment(form);
826 if (res.state === "success") {
827 toast(I18NextService.i18n.t("reply_sent"));
828 this.findAndUpdateComment(res);
834 async handleEditComment(form: EditComment) {
835 const res = await HttpService.client.editComment(form);
837 if (res.state === "success") {
838 toast(I18NextService.i18n.t("edit"));
839 this.findAndUpdateComment(res);
840 } else if (res.state === "failed") {
841 toast(res.msg, "danger");
847 async handleDeleteComment(form: DeleteComment) {
848 const res = await HttpService.client.deleteComment(form);
849 if (res.state == "success") {
850 toast(I18NextService.i18n.t("deleted"));
851 this.findAndUpdateComment(res);
855 async handleRemoveComment(form: RemoveComment) {
856 const res = await HttpService.client.removeComment(form);
857 if (res.state == "success") {
858 toast(I18NextService.i18n.t("remove_comment"));
859 this.findAndUpdateComment(res);
863 async handleSaveComment(form: SaveComment) {
864 const res = await HttpService.client.saveComment(form);
865 this.findAndUpdateComment(res);
868 async handleCommentVote(form: CreateCommentLike) {
869 const res = await HttpService.client.likeComment(form);
870 this.findAndUpdateComment(res);
873 async handleCommentReport(form: CreateCommentReport) {
874 const reportRes = await HttpService.client.createCommentReport(form);
875 this.reportToast(reportRes);
878 async handleDistinguishComment(form: DistinguishComment) {
879 const res = await HttpService.client.distinguishComment(form);
880 this.findAndUpdateComment(res);
883 async handleAddAdmin(form: AddAdmin) {
884 const addAdminRes = await HttpService.client.addAdmin(form);
886 if (addAdminRes.state === "success") {
887 this.setState(s => ((s.siteRes.admins = addAdminRes.data.admins), s));
891 async handleTransferCommunity(form: TransferCommunity) {
892 await HttpService.client.transferCommunity(form);
893 toast(I18NextService.i18n.t("transfer_community"));
896 async handleCommentReplyRead(form: MarkCommentReplyAsRead) {
897 const res = await HttpService.client.markCommentReplyAsRead(form);
898 this.findAndUpdateCommentReply(res);
901 async handlePersonMentionRead(form: MarkPersonMentionAsRead) {
902 const res = await HttpService.client.markPersonMentionAsRead(form);
903 this.findAndUpdateMention(res);
906 async handleBanFromCommunity(form: BanFromCommunity) {
907 const banRes = await HttpService.client.banFromCommunity(form);
908 this.updateBanFromCommunity(banRes);
911 async handleBanPerson(form: BanPerson) {
912 const banRes = await HttpService.client.banPerson(form);
913 this.updateBan(banRes);
916 async handleDeleteMessage(form: DeletePrivateMessage) {
917 const res = await HttpService.client.deletePrivateMessage(form);
918 this.findAndUpdateMessage(res);
921 async handleEditMessage(form: EditPrivateMessage) {
922 const res = await HttpService.client.editPrivateMessage(form);
923 this.findAndUpdateMessage(res);
926 async handleMarkMessageAsRead(form: MarkPrivateMessageAsRead) {
927 const res = await HttpService.client.markPrivateMessageAsRead(form);
928 this.findAndUpdateMessage(res);
931 async handleMessageReport(form: CreatePrivateMessageReport) {
932 const res = await HttpService.client.createPrivateMessageReport(form);
933 this.reportToast(res);
936 async handleCreateMessage(form: CreatePrivateMessage) {
937 const res = await HttpService.client.createPrivateMessage(form);
939 if (s.messagesRes.state == "success" && res.state == "success") {
940 s.messagesRes.data.private_messages.unshift(
941 res.data.private_message_view
949 findAndUpdateMessage(res: RequestState<PrivateMessageResponse>) {
951 if (s.messagesRes.state === "success" && res.state === "success") {
952 s.messagesRes.data.private_messages = editPrivateMessage(
953 res.data.private_message_view,
954 s.messagesRes.data.private_messages
961 updateBanFromCommunity(banRes: RequestState<BanFromCommunityResponse>) {
962 // Maybe not necessary
963 if (banRes.state == "success") {
965 if (s.repliesRes.state == "success") {
966 s.repliesRes.data.replies
967 .filter(c => c.creator.id == banRes.data.person_view.person.id)
969 c => (c.creator_banned_from_community = banRes.data.banned)
972 if (s.mentionsRes.state == "success") {
973 s.mentionsRes.data.mentions
974 .filter(c => c.creator.id == banRes.data.person_view.person.id)
976 c => (c.creator_banned_from_community = banRes.data.banned)
984 updateBan(banRes: RequestState<BanPersonResponse>) {
985 // Maybe not necessary
986 if (banRes.state == "success") {
988 if (s.repliesRes.state == "success") {
989 s.repliesRes.data.replies
990 .filter(c => c.creator.id == banRes.data.person_view.person.id)
991 .forEach(c => (c.creator.banned = banRes.data.banned));
993 if (s.mentionsRes.state == "success") {
994 s.mentionsRes.data.mentions
995 .filter(c => c.creator.id == banRes.data.person_view.person.id)
996 .forEach(c => (c.creator.banned = banRes.data.banned));
1003 purgeItem(purgeRes: RequestState<PurgeItemResponse>) {
1004 if (purgeRes.state == "success") {
1005 toast(I18NextService.i18n.t("purge_success"));
1006 this.context.router.history.push(`/`);
1011 res: RequestState<PrivateMessageReportResponse | CommentReportResponse>
1013 if (res.state == "success") {
1014 toast(I18NextService.i18n.t("report_created"));
1018 // A weird case, since you have only replies and mentions, not comment responses
1019 findAndUpdateComment(res: RequestState<CommentResponse>) {
1020 if (res.state == "success") {
1021 this.setState(s => {
1022 if (s.repliesRes.state == "success") {
1023 s.repliesRes.data.replies = editWith(
1024 res.data.comment_view,
1025 s.repliesRes.data.replies
1028 if (s.mentionsRes.state == "success") {
1029 s.mentionsRes.data.mentions = editWith(
1030 res.data.comment_view,
1031 s.mentionsRes.data.mentions
1034 // Set finished for the parent
1036 getCommentParentId(res.data.comment_view.comment) ?? 0,
1044 findAndUpdateCommentReply(res: RequestState<CommentReplyResponse>) {
1045 this.setState(s => {
1046 if (s.repliesRes.state == "success" && res.state == "success") {
1047 s.repliesRes.data.replies = editCommentReply(
1048 res.data.comment_reply_view,
1049 s.repliesRes.data.replies
1056 findAndUpdateMention(res: RequestState<PersonMentionResponse>) {
1057 this.setState(s => {
1058 if (s.mentionsRes.state == "success" && res.state == "success") {
1059 s.mentionsRes.data.mentions = editMention(
1060 res.data.person_mention_view,
1061 s.mentionsRes.data.mentions