14 import { isBrowser } from "@utils/browser";
15 import { RouteDataResponse } from "@utils/types";
16 import { Component, linkEvent } from "inferno";
21 BanFromCommunityResponse,
28 CommentReportResponse,
36 CreatePrivateMessageReport,
42 GetPersonMentionsResponse,
45 MarkCommentReplyAsRead,
46 MarkPersonMentionAsRead,
47 MarkPrivateMessageAsRead,
48 PersonMentionResponse,
50 PrivateMessageReportResponse,
51 PrivateMessageResponse,
53 PrivateMessagesResponse,
61 } from "lemmy-js-client";
62 import { fetchLimit, relTags } from "../../config";
63 import { CommentViewType, InitialFetchRequest } from "../../interfaces";
64 import { FirstLoadService, I18NextService, UserService } from "../../services";
65 import { HttpService, RequestState } from "../../services/HttpService";
66 import { toast } from "../../toast";
67 import { CommentNodes } from "../comment/comment-nodes";
68 import { CommentSortSelect } from "../common/comment-sort-select";
69 import { HtmlTags } from "../common/html-tags";
70 import { Icon, Spinner } from "../common/icon";
71 import { Paginator } from "../common/paginator";
72 import { PrivateMessage } from "../private_message/private-message";
92 type InboxData = RouteDataResponse<{
93 repliesRes: GetRepliesResponse;
94 mentionsRes: GetPersonMentionsResponse;
95 messagesRes: PrivateMessagesResponse;
101 view: CommentView | PrivateMessageView | PersonMentionView | CommentReplyView;
105 interface InboxState {
106 unreadOrAll: UnreadOrAll;
107 messageType: MessageType;
108 repliesRes: RequestState<GetRepliesResponse>;
109 mentionsRes: RequestState<GetPersonMentionsResponse>;
110 messagesRes: RequestState<PrivateMessagesResponse>;
111 markAllAsReadRes: RequestState<GetRepliesResponse>;
112 sort: CommentSortType;
114 siteRes: GetSiteResponse;
115 finished: Map<CommentId, boolean | undefined>;
116 isIsomorphic: boolean;
119 export class Inbox extends Component<any, InboxState> {
120 private isoData = setIsoData<InboxData>(this.context);
121 state: InboxState = {
122 unreadOrAll: UnreadOrAll.Unread,
123 messageType: MessageType.All,
126 siteRes: this.isoData.site_res,
127 repliesRes: { state: "empty" },
128 mentionsRes: { state: "empty" },
129 messagesRes: { state: "empty" },
130 markAllAsReadRes: { state: "empty" },
135 constructor(props: any, context: any) {
136 super(props, context);
138 this.handleSortChange = this.handleSortChange.bind(this);
139 this.handlePageChange = this.handlePageChange.bind(this);
141 this.handleCreateComment = this.handleCreateComment.bind(this);
142 this.handleEditComment = this.handleEditComment.bind(this);
143 this.handleSaveComment = this.handleSaveComment.bind(this);
144 this.handleBlockPerson = this.handleBlockPerson.bind(this);
145 this.handleDeleteComment = this.handleDeleteComment.bind(this);
146 this.handleRemoveComment = this.handleRemoveComment.bind(this);
147 this.handleCommentVote = this.handleCommentVote.bind(this);
148 this.handleAddModToCommunity = this.handleAddModToCommunity.bind(this);
149 this.handleAddAdmin = this.handleAddAdmin.bind(this);
150 this.handlePurgePerson = this.handlePurgePerson.bind(this);
151 this.handlePurgeComment = this.handlePurgeComment.bind(this);
152 this.handleCommentReport = this.handleCommentReport.bind(this);
153 this.handleDistinguishComment = this.handleDistinguishComment.bind(this);
154 this.handleTransferCommunity = this.handleTransferCommunity.bind(this);
155 this.handleCommentReplyRead = this.handleCommentReplyRead.bind(this);
156 this.handlePersonMentionRead = this.handlePersonMentionRead.bind(this);
157 this.handleBanFromCommunity = this.handleBanFromCommunity.bind(this);
158 this.handleBanPerson = this.handleBanPerson.bind(this);
160 this.handleDeleteMessage = this.handleDeleteMessage.bind(this);
161 this.handleMarkMessageAsRead = this.handleMarkMessageAsRead.bind(this);
162 this.handleMessageReport = this.handleMessageReport.bind(this);
163 this.handleCreateMessage = this.handleCreateMessage.bind(this);
164 this.handleEditMessage = this.handleEditMessage.bind(this);
166 // Only fetch the data if coming from another route
167 if (!isBrowser() || FirstLoadService.isFirstLoad) {
168 const { mentionsRes, messagesRes, repliesRes } = this.isoData.routeData;
180 async componentDidMount() {
181 if (!this.state.isIsomorphic) {
182 await this.refetch();
186 get documentTitle(): string {
187 const mui = UserService.Instance.myUserInfo;
189 ? `@${mui.local_user_view.person.name} ${I18NextService.i18n.t(
191 )} - ${this.state.siteRes.site_view.site.name}`
195 get hasUnreads(): boolean {
196 if (this.state.unreadOrAll == UnreadOrAll.Unread) {
197 const { repliesRes, mentionsRes, messagesRes } = this.state;
199 repliesRes.state == "success" ? repliesRes.data.replies.length : 0;
201 mentionsRes.state == "success" ? mentionsRes.data.mentions.length : 0;
203 messagesRes.state == "success"
204 ? messagesRes.data.private_messages.length
207 return replyCount + mentionCount + messageCount > 0;
214 const auth = myAuth();
215 const inboxRss = auth ? `/feeds/inbox/${auth}.xml` : undefined;
217 <div className="inbox container-lg">
218 <div className="row">
219 <div className="col-12">
221 title={this.documentTitle}
222 path={this.context.router.route.match.url}
224 <h5 className="mb-2">
225 {I18NextService.i18n.t("inbox")}
228 <a href={inboxRss} title="RSS" rel={relTags}>
229 <Icon icon="rss" classes="ms-2 text-muted small" />
233 type="application/atom+xml"
239 {this.hasUnreads && (
241 className="btn btn-secondary mb-2"
242 onClick={linkEvent(this, this.handleMarkAllAsRead)}
244 {this.state.markAllAsReadRes.state == "loading" ? (
247 I18NextService.i18n.t("mark_all_as_read")
254 page={this.state.page}
255 onChange={this.handlePageChange}
264 switch (this.state.messageType) {
265 case MessageType.All: {
268 case MessageType.Replies: {
269 return this.replies();
271 case MessageType.Mentions: {
272 return this.mentions();
274 case MessageType.Messages: {
275 return this.messages();
283 unreadOrAllRadios() {
285 <div className="btn-group btn-group-toggle flex-wrap mb-2">
287 className={`btn btn-outline-secondary pointer
288 ${this.state.unreadOrAll == UnreadOrAll.Unread && "active"}
293 className="btn-check"
294 value={UnreadOrAll.Unread}
295 checked={this.state.unreadOrAll == UnreadOrAll.Unread}
296 onChange={linkEvent(this, this.handleUnreadOrAllChange)}
298 {I18NextService.i18n.t("unread")}
301 className={`btn btn-outline-secondary pointer
302 ${this.state.unreadOrAll == UnreadOrAll.All && "active"}
307 className="btn-check"
308 value={UnreadOrAll.All}
309 checked={this.state.unreadOrAll == UnreadOrAll.All}
310 onChange={linkEvent(this, this.handleUnreadOrAllChange)}
312 {I18NextService.i18n.t("all")}
318 messageTypeRadios() {
320 <div className="btn-group btn-group-toggle flex-wrap mb-2">
322 className={`btn btn-outline-secondary pointer
323 ${this.state.messageType == MessageType.All && "active"}
328 className="btn-check"
329 value={MessageType.All}
330 checked={this.state.messageType == MessageType.All}
331 onChange={linkEvent(this, this.handleMessageTypeChange)}
333 {I18NextService.i18n.t("all")}
336 className={`btn btn-outline-secondary pointer
337 ${this.state.messageType == MessageType.Replies && "active"}
342 className="btn-check"
343 value={MessageType.Replies}
344 checked={this.state.messageType == MessageType.Replies}
345 onChange={linkEvent(this, this.handleMessageTypeChange)}
347 {I18NextService.i18n.t("replies")}
350 className={`btn btn-outline-secondary pointer
351 ${this.state.messageType == MessageType.Mentions && "active"}
356 className="btn-check"
357 value={MessageType.Mentions}
358 checked={this.state.messageType == MessageType.Mentions}
359 onChange={linkEvent(this, this.handleMessageTypeChange)}
361 {I18NextService.i18n.t("mentions")}
364 className={`btn btn-outline-secondary pointer
365 ${this.state.messageType == MessageType.Messages && "active"}
370 className="btn-check"
371 value={MessageType.Messages}
372 checked={this.state.messageType == MessageType.Messages}
373 onChange={linkEvent(this, this.handleMessageTypeChange)}
375 {I18NextService.i18n.t("messages")}
383 <div className="mb-2">
384 <span className="me-3">{this.unreadOrAllRadios()}</span>
385 <span className="me-3">{this.messageTypeRadios()}</span>
387 sort={this.state.sort}
388 onChange={this.handleSortChange}
394 replyToReplyType(r: CommentReplyView): ReplyType {
396 id: r.comment_reply.id,
397 type_: ReplyEnum.Reply,
399 published: r.comment.published,
403 mentionToReplyType(r: PersonMentionView): ReplyType {
405 id: r.person_mention.id,
406 type_: ReplyEnum.Mention,
408 published: r.comment.published,
412 messageToReplyType(r: PrivateMessageView): ReplyType {
414 id: r.private_message.id,
415 type_: ReplyEnum.Message,
417 published: r.private_message.published,
421 buildCombined(): ReplyType[] {
422 const replies: ReplyType[] =
423 this.state.repliesRes.state == "success"
424 ? this.state.repliesRes.data.replies.map(this.replyToReplyType)
426 const mentions: ReplyType[] =
427 this.state.mentionsRes.state == "success"
428 ? this.state.mentionsRes.data.mentions.map(this.mentionToReplyType)
430 const messages: ReplyType[] =
431 this.state.messagesRes.state == "success"
432 ? this.state.messagesRes.data.private_messages.map(
433 this.messageToReplyType
437 return [...replies, ...mentions, ...messages].sort((a, b) =>
438 b.published.localeCompare(a.published)
442 renderReplyType(i: ReplyType) {
444 case ReplyEnum.Reply:
449 { comment_view: i.view as CommentView, children: [], depth: 0 },
451 viewType={CommentViewType.Flat}
452 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}
495 enableDownvotes={enableDownvotes(this.state.siteRes)}
496 allLanguages={this.state.siteRes.all_languages}
497 siteLanguages={this.state.siteRes.discussion_languages}
498 onSaveComment={this.handleSaveComment}
499 onBlockPerson={this.handleBlockPerson}
500 onDeleteComment={this.handleDeleteComment}
501 onRemoveComment={this.handleRemoveComment}
502 onCommentVote={this.handleCommentVote}
503 onCommentReport={this.handleCommentReport}
504 onDistinguishComment={this.handleDistinguishComment}
505 onAddModToCommunity={this.handleAddModToCommunity}
506 onAddAdmin={this.handleAddAdmin}
507 onTransferCommunity={this.handleTransferCommunity}
508 onPurgeComment={this.handlePurgeComment}
509 onPurgePerson={this.handlePurgePerson}
510 onCommentReplyRead={this.handleCommentReplyRead}
511 onPersonMentionRead={this.handlePersonMentionRead}
512 onBanPersonFromCommunity={this.handleBanFromCommunity}
513 onBanPerson={this.handleBanPerson}
514 onCreateComment={this.handleCreateComment}
515 onEditComment={this.handleEditComment}
518 case ReplyEnum.Message:
522 private_message_view={i.view as PrivateMessageView}
523 onDelete={this.handleDeleteMessage}
524 onMarkRead={this.handleMarkMessageAsRead}
525 onReport={this.handleMessageReport}
526 onCreate={this.handleCreateMessage}
527 onEdit={this.handleEditMessage}
537 this.state.repliesRes.state == "loading" ||
538 this.state.mentionsRes.state == "loading" ||
539 this.state.messagesRes.state == "loading"
548 <div>{this.buildCombined().map(r => this.renderReplyType(r))}</div>
554 switch (this.state.repliesRes.state) {
562 const replies = this.state.repliesRes.data.replies;
566 nodes={commentsToFlatNodes(replies)}
567 viewType={CommentViewType.Flat}
568 finished={this.state.finished}
572 enableDownvotes={enableDownvotes(this.state.siteRes)}
573 allLanguages={this.state.siteRes.all_languages}
574 siteLanguages={this.state.siteRes.discussion_languages}
575 onSaveComment={this.handleSaveComment}
576 onBlockPerson={this.handleBlockPerson}
577 onDeleteComment={this.handleDeleteComment}
578 onRemoveComment={this.handleRemoveComment}
579 onCommentVote={this.handleCommentVote}
580 onCommentReport={this.handleCommentReport}
581 onDistinguishComment={this.handleDistinguishComment}
582 onAddModToCommunity={this.handleAddModToCommunity}
583 onAddAdmin={this.handleAddAdmin}
584 onTransferCommunity={this.handleTransferCommunity}
585 onPurgeComment={this.handlePurgeComment}
586 onPurgePerson={this.handlePurgePerson}
587 onCommentReplyRead={this.handleCommentReplyRead}
588 onPersonMentionRead={this.handlePersonMentionRead}
589 onBanPersonFromCommunity={this.handleBanFromCommunity}
590 onBanPerson={this.handleBanPerson}
591 onCreateComment={this.handleCreateComment}
592 onEditComment={this.handleEditComment}
601 switch (this.state.mentionsRes.state) {
609 const mentions = this.state.mentionsRes.data.mentions;
612 {mentions.map(umv => (
614 key={umv.person_mention.id}
615 nodes={[{ comment_view: umv, children: [], depth: 0 }]}
616 viewType={CommentViewType.Flat}
617 finished={this.state.finished}
621 enableDownvotes={enableDownvotes(this.state.siteRes)}
622 allLanguages={this.state.siteRes.all_languages}
623 siteLanguages={this.state.siteRes.discussion_languages}
624 onSaveComment={this.handleSaveComment}
625 onBlockPerson={this.handleBlockPerson}
626 onDeleteComment={this.handleDeleteComment}
627 onRemoveComment={this.handleRemoveComment}
628 onCommentVote={this.handleCommentVote}
629 onCommentReport={this.handleCommentReport}
630 onDistinguishComment={this.handleDistinguishComment}
631 onAddModToCommunity={this.handleAddModToCommunity}
632 onAddAdmin={this.handleAddAdmin}
633 onTransferCommunity={this.handleTransferCommunity}
634 onPurgeComment={this.handlePurgeComment}
635 onPurgePerson={this.handlePurgePerson}
636 onCommentReplyRead={this.handleCommentReplyRead}
637 onPersonMentionRead={this.handlePersonMentionRead}
638 onBanPersonFromCommunity={this.handleBanFromCommunity}
639 onBanPerson={this.handleBanPerson}
640 onCreateComment={this.handleCreateComment}
641 onEditComment={this.handleEditComment}
651 switch (this.state.messagesRes.state) {
659 const messages = this.state.messagesRes.data.private_messages;
662 {messages.map(pmv => (
664 key={pmv.private_message.id}
665 private_message_view={pmv}
666 onDelete={this.handleDeleteMessage}
667 onMarkRead={this.handleMarkMessageAsRead}
668 onReport={this.handleMessageReport}
669 onCreate={this.handleCreateMessage}
670 onEdit={this.handleEditMessage}
679 async handlePageChange(page: number) {
680 this.setState({ page });
681 await this.refetch();
684 async handleUnreadOrAllChange(i: Inbox, event: any) {
685 i.setState({ unreadOrAll: Number(event.target.value), page: 1 });
689 async handleMessageTypeChange(i: Inbox, event: any) {
690 i.setState({ messageType: Number(event.target.value), page: 1 });
694 static async fetchInitialData({
697 }: InitialFetchRequest): Promise<InboxData> {
698 const sort: CommentSortType = "New";
702 ? await client.getPersonMentions({
709 : { state: "empty" },
711 ? await client.getPrivateMessages({
717 : { state: "empty" },
719 ? await client.getReplies({
726 : { state: "empty" },
731 const sort = this.state.sort;
732 const unread_only = this.state.unreadOrAll == UnreadOrAll.Unread;
733 const page = this.state.page;
734 const limit = fetchLimit;
735 const auth = myAuthRequired();
737 this.setState({ repliesRes: { state: "loading" } });
739 repliesRes: await HttpService.client.getReplies({
748 this.setState({ mentionsRes: { state: "loading" } });
750 mentionsRes: await HttpService.client.getPersonMentions({
759 this.setState({ messagesRes: { state: "loading" } });
761 messagesRes: await HttpService.client.getPrivateMessages({
770 async handleSortChange(val: CommentSortType) {
771 this.setState({ sort: val, page: 1 });
772 await this.refetch();
775 async handleMarkAllAsRead(i: Inbox) {
776 i.setState({ markAllAsReadRes: { state: "loading" } });
779 markAllAsReadRes: await HttpService.client.markAllAsRead({
780 auth: myAuthRequired(),
784 if (i.state.markAllAsReadRes.state == "success") {
786 repliesRes: { state: "empty" },
787 mentionsRes: { state: "empty" },
788 messagesRes: { state: "empty" },
793 async handleAddModToCommunity(form: AddModToCommunity) {
794 // TODO not sure what to do here
795 HttpService.client.addModToCommunity(form);
798 async handlePurgePerson(form: PurgePerson) {
799 const purgePersonRes = await HttpService.client.purgePerson(form);
800 this.purgeItem(purgePersonRes);
803 async handlePurgeComment(form: PurgeComment) {
804 const purgeCommentRes = await HttpService.client.purgeComment(form);
805 this.purgeItem(purgeCommentRes);
808 async handlePurgePost(form: PurgePost) {
809 const purgeRes = await HttpService.client.purgePost(form);
810 this.purgeItem(purgeRes);
813 async handleBlockPerson(form: BlockPerson) {
814 const blockPersonRes = await HttpService.client.blockPerson(form);
815 if (blockPersonRes.state == "success") {
816 updatePersonBlock(blockPersonRes.data);
820 async handleCreateComment(form: CreateComment) {
821 const res = await HttpService.client.createComment(form);
823 if (res.state === "success") {
824 toast(I18NextService.i18n.t("reply_sent"));
825 this.findAndUpdateComment(res);
831 async handleEditComment(form: EditComment) {
832 const res = await HttpService.client.editComment(form);
834 if (res.state === "success") {
835 toast(I18NextService.i18n.t("edit"));
836 this.findAndUpdateComment(res);
837 } else if (res.state === "failed") {
838 toast(res.msg, "danger");
844 async handleDeleteComment(form: DeleteComment) {
845 const res = await HttpService.client.deleteComment(form);
846 if (res.state == "success") {
847 toast(I18NextService.i18n.t("deleted"));
848 this.findAndUpdateComment(res);
852 async handleRemoveComment(form: RemoveComment) {
853 const res = await HttpService.client.removeComment(form);
854 if (res.state == "success") {
855 toast(I18NextService.i18n.t("remove_comment"));
856 this.findAndUpdateComment(res);
860 async handleSaveComment(form: SaveComment) {
861 const res = await HttpService.client.saveComment(form);
862 this.findAndUpdateComment(res);
865 async handleCommentVote(form: CreateCommentLike) {
866 const res = await HttpService.client.likeComment(form);
867 this.findAndUpdateComment(res);
870 async handleCommentReport(form: CreateCommentReport) {
871 const reportRes = await HttpService.client.createCommentReport(form);
872 this.reportToast(reportRes);
875 async handleDistinguishComment(form: DistinguishComment) {
876 const res = await HttpService.client.distinguishComment(form);
877 this.findAndUpdateComment(res);
880 async handleAddAdmin(form: AddAdmin) {
881 const addAdminRes = await HttpService.client.addAdmin(form);
883 if (addAdminRes.state === "success") {
884 this.setState(s => ((s.siteRes.admins = addAdminRes.data.admins), s));
888 async handleTransferCommunity(form: TransferCommunity) {
889 await HttpService.client.transferCommunity(form);
890 toast(I18NextService.i18n.t("transfer_community"));
893 async handleCommentReplyRead(form: MarkCommentReplyAsRead) {
894 const res = await HttpService.client.markCommentReplyAsRead(form);
895 this.findAndUpdateCommentReply(res);
898 async handlePersonMentionRead(form: MarkPersonMentionAsRead) {
899 const res = await HttpService.client.markPersonMentionAsRead(form);
900 this.findAndUpdateMention(res);
903 async handleBanFromCommunity(form: BanFromCommunity) {
904 const banRes = await HttpService.client.banFromCommunity(form);
905 this.updateBanFromCommunity(banRes);
908 async handleBanPerson(form: BanPerson) {
909 const banRes = await HttpService.client.banPerson(form);
910 this.updateBan(banRes);
913 async handleDeleteMessage(form: DeletePrivateMessage) {
914 const res = await HttpService.client.deletePrivateMessage(form);
915 this.findAndUpdateMessage(res);
918 async handleEditMessage(form: EditPrivateMessage) {
919 const res = await HttpService.client.editPrivateMessage(form);
920 this.findAndUpdateMessage(res);
923 async handleMarkMessageAsRead(form: MarkPrivateMessageAsRead) {
924 const res = await HttpService.client.markPrivateMessageAsRead(form);
925 this.findAndUpdateMessage(res);
928 async handleMessageReport(form: CreatePrivateMessageReport) {
929 const res = await HttpService.client.createPrivateMessageReport(form);
930 this.reportToast(res);
933 async handleCreateMessage(form: CreatePrivateMessage) {
934 const res = await HttpService.client.createPrivateMessage(form);
936 if (s.messagesRes.state == "success" && res.state == "success") {
937 s.messagesRes.data.private_messages.unshift(
938 res.data.private_message_view
946 findAndUpdateMessage(res: RequestState<PrivateMessageResponse>) {
948 if (s.messagesRes.state === "success" && res.state === "success") {
949 s.messagesRes.data.private_messages = editPrivateMessage(
950 res.data.private_message_view,
951 s.messagesRes.data.private_messages
958 updateBanFromCommunity(banRes: RequestState<BanFromCommunityResponse>) {
959 // Maybe not necessary
960 if (banRes.state == "success") {
962 if (s.repliesRes.state == "success") {
963 s.repliesRes.data.replies
964 .filter(c => c.creator.id == banRes.data.person_view.person.id)
966 c => (c.creator_banned_from_community = banRes.data.banned)
969 if (s.mentionsRes.state == "success") {
970 s.mentionsRes.data.mentions
971 .filter(c => c.creator.id == banRes.data.person_view.person.id)
973 c => (c.creator_banned_from_community = banRes.data.banned)
981 updateBan(banRes: RequestState<BanPersonResponse>) {
982 // Maybe not necessary
983 if (banRes.state == "success") {
985 if (s.repliesRes.state == "success") {
986 s.repliesRes.data.replies
987 .filter(c => c.creator.id == banRes.data.person_view.person.id)
988 .forEach(c => (c.creator.banned = banRes.data.banned));
990 if (s.mentionsRes.state == "success") {
991 s.mentionsRes.data.mentions
992 .filter(c => c.creator.id == banRes.data.person_view.person.id)
993 .forEach(c => (c.creator.banned = banRes.data.banned));
1000 purgeItem(purgeRes: RequestState<PurgeItemResponse>) {
1001 if (purgeRes.state == "success") {
1002 toast(I18NextService.i18n.t("purge_success"));
1003 this.context.router.history.push(`/`);
1008 res: RequestState<PrivateMessageReportResponse | CommentReportResponse>
1010 if (res.state == "success") {
1011 toast(I18NextService.i18n.t("report_created"));
1015 // A weird case, since you have only replies and mentions, not comment responses
1016 findAndUpdateComment(res: RequestState<CommentResponse>) {
1017 if (res.state == "success") {
1018 this.setState(s => {
1019 if (s.repliesRes.state == "success") {
1020 s.repliesRes.data.replies = editWith(
1021 res.data.comment_view,
1022 s.repliesRes.data.replies
1025 if (s.mentionsRes.state == "success") {
1026 s.mentionsRes.data.mentions = editWith(
1027 res.data.comment_view,
1028 s.mentionsRes.data.mentions
1031 // Set finished for the parent
1033 getCommentParentId(res.data.comment_view.comment) ?? 0,
1041 findAndUpdateCommentReply(res: RequestState<CommentReplyResponse>) {
1042 this.setState(s => {
1043 if (s.repliesRes.state == "success" && res.state == "success") {
1044 s.repliesRes.data.replies = editCommentReply(
1045 res.data.comment_reply_view,
1046 s.repliesRes.data.replies
1053 findAndUpdateMention(res: RequestState<PersonMentionResponse>) {
1054 this.setState(s => {
1055 if (s.mentionsRes.state == "success" && res.state == "success") {
1056 s.mentionsRes.data.mentions = editMention(
1057 res.data.person_mention_view,
1058 s.mentionsRes.data.mentions