14 import { capitalizeFirstLetter } from "@utils/helpers";
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 (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 capitalizeFirstLetter(
248 I18NextService.i18n.t("mark_all_as_read")
256 page={this.state.page}
257 onChange={this.handlePageChange}
266 switch (this.state.messageType) {
267 case MessageType.All: {
270 case MessageType.Replies: {
271 return this.replies();
273 case MessageType.Mentions: {
274 return this.mentions();
276 case MessageType.Messages: {
277 return this.messages();
285 unreadOrAllRadios() {
287 <div className="btn-group btn-group-toggle flex-wrap mb-2">
289 className={`btn btn-outline-secondary pointer
290 ${this.state.unreadOrAll == UnreadOrAll.Unread && "active"}
295 className="btn-check"
296 value={UnreadOrAll.Unread}
297 checked={this.state.unreadOrAll == UnreadOrAll.Unread}
298 onChange={linkEvent(this, this.handleUnreadOrAllChange)}
300 {I18NextService.i18n.t("unread")}
303 className={`btn btn-outline-secondary pointer
304 ${this.state.unreadOrAll == UnreadOrAll.All && "active"}
309 className="btn-check"
310 value={UnreadOrAll.All}
311 checked={this.state.unreadOrAll == UnreadOrAll.All}
312 onChange={linkEvent(this, this.handleUnreadOrAllChange)}
314 {I18NextService.i18n.t("all")}
320 messageTypeRadios() {
322 <div className="btn-group btn-group-toggle flex-wrap mb-2">
324 className={`btn btn-outline-secondary pointer
325 ${this.state.messageType == MessageType.All && "active"}
330 className="btn-check"
331 value={MessageType.All}
332 checked={this.state.messageType == MessageType.All}
333 onChange={linkEvent(this, this.handleMessageTypeChange)}
335 {I18NextService.i18n.t("all")}
338 className={`btn btn-outline-secondary pointer
339 ${this.state.messageType == MessageType.Replies && "active"}
344 className="btn-check"
345 value={MessageType.Replies}
346 checked={this.state.messageType == MessageType.Replies}
347 onChange={linkEvent(this, this.handleMessageTypeChange)}
349 {I18NextService.i18n.t("replies")}
352 className={`btn btn-outline-secondary pointer
353 ${this.state.messageType == MessageType.Mentions && "active"}
358 className="btn-check"
359 value={MessageType.Mentions}
360 checked={this.state.messageType == MessageType.Mentions}
361 onChange={linkEvent(this, this.handleMessageTypeChange)}
363 {I18NextService.i18n.t("mentions")}
366 className={`btn btn-outline-secondary pointer
367 ${this.state.messageType == MessageType.Messages && "active"}
372 className="btn-check"
373 value={MessageType.Messages}
374 checked={this.state.messageType == MessageType.Messages}
375 onChange={linkEvent(this, this.handleMessageTypeChange)}
377 {I18NextService.i18n.t("messages")}
385 <div className="mb-2">
386 <span className="me-3">{this.unreadOrAllRadios()}</span>
387 <span className="me-3">{this.messageTypeRadios()}</span>
389 sort={this.state.sort}
390 onChange={this.handleSortChange}
396 replyToReplyType(r: CommentReplyView): ReplyType {
398 id: r.comment_reply.id,
399 type_: ReplyEnum.Reply,
401 published: r.comment.published,
405 mentionToReplyType(r: PersonMentionView): ReplyType {
407 id: r.person_mention.id,
408 type_: ReplyEnum.Mention,
410 published: r.comment.published,
414 messageToReplyType(r: PrivateMessageView): ReplyType {
416 id: r.private_message.id,
417 type_: ReplyEnum.Message,
419 published: r.private_message.published,
423 buildCombined(): ReplyType[] {
424 const replies: ReplyType[] =
425 this.state.repliesRes.state == "success"
426 ? this.state.repliesRes.data.replies.map(this.replyToReplyType)
428 const mentions: ReplyType[] =
429 this.state.mentionsRes.state == "success"
430 ? this.state.mentionsRes.data.mentions.map(this.mentionToReplyType)
432 const messages: ReplyType[] =
433 this.state.messagesRes.state == "success"
434 ? this.state.messagesRes.data.private_messages.map(
435 this.messageToReplyType
439 return [...replies, ...mentions, ...messages].sort((a, b) =>
440 b.published.localeCompare(a.published)
444 renderReplyType(i: ReplyType) {
446 case ReplyEnum.Reply:
451 { comment_view: i.view as CommentView, children: [], depth: 0 },
453 viewType={CommentViewType.Flat}
454 finished={this.state.finished}
458 enableDownvotes={enableDownvotes(this.state.siteRes)}
459 allLanguages={this.state.siteRes.all_languages}
460 siteLanguages={this.state.siteRes.discussion_languages}
461 onSaveComment={this.handleSaveComment}
462 onBlockPerson={this.handleBlockPerson}
463 onDeleteComment={this.handleDeleteComment}
464 onRemoveComment={this.handleRemoveComment}
465 onCommentVote={this.handleCommentVote}
466 onCommentReport={this.handleCommentReport}
467 onDistinguishComment={this.handleDistinguishComment}
468 onAddModToCommunity={this.handleAddModToCommunity}
469 onAddAdmin={this.handleAddAdmin}
470 onTransferCommunity={this.handleTransferCommunity}
471 onPurgeComment={this.handlePurgeComment}
472 onPurgePerson={this.handlePurgePerson}
473 onCommentReplyRead={this.handleCommentReplyRead}
474 onPersonMentionRead={this.handlePersonMentionRead}
475 onBanPersonFromCommunity={this.handleBanFromCommunity}
476 onBanPerson={this.handleBanPerson}
477 onCreateComment={this.handleCreateComment}
478 onEditComment={this.handleEditComment}
481 case ReplyEnum.Mention:
487 comment_view: i.view as PersonMentionView,
492 finished={this.state.finished}
493 viewType={CommentViewType.Flat}
497 enableDownvotes={enableDownvotes(this.state.siteRes)}
498 allLanguages={this.state.siteRes.all_languages}
499 siteLanguages={this.state.siteRes.discussion_languages}
500 onSaveComment={this.handleSaveComment}
501 onBlockPerson={this.handleBlockPerson}
502 onDeleteComment={this.handleDeleteComment}
503 onRemoveComment={this.handleRemoveComment}
504 onCommentVote={this.handleCommentVote}
505 onCommentReport={this.handleCommentReport}
506 onDistinguishComment={this.handleDistinguishComment}
507 onAddModToCommunity={this.handleAddModToCommunity}
508 onAddAdmin={this.handleAddAdmin}
509 onTransferCommunity={this.handleTransferCommunity}
510 onPurgeComment={this.handlePurgeComment}
511 onPurgePerson={this.handlePurgePerson}
512 onCommentReplyRead={this.handleCommentReplyRead}
513 onPersonMentionRead={this.handlePersonMentionRead}
514 onBanPersonFromCommunity={this.handleBanFromCommunity}
515 onBanPerson={this.handleBanPerson}
516 onCreateComment={this.handleCreateComment}
517 onEditComment={this.handleEditComment}
520 case ReplyEnum.Message:
524 private_message_view={i.view as PrivateMessageView}
525 onDelete={this.handleDeleteMessage}
526 onMarkRead={this.handleMarkMessageAsRead}
527 onReport={this.handleMessageReport}
528 onCreate={this.handleCreateMessage}
529 onEdit={this.handleEditMessage}
539 this.state.repliesRes.state == "loading" ||
540 this.state.mentionsRes.state == "loading" ||
541 this.state.messagesRes.state == "loading"
550 <div>{this.buildCombined().map(r => this.renderReplyType(r))}</div>
556 switch (this.state.repliesRes.state) {
564 const replies = this.state.repliesRes.data.replies;
568 nodes={commentsToFlatNodes(replies)}
569 viewType={CommentViewType.Flat}
570 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}
623 enableDownvotes={enableDownvotes(this.state.siteRes)}
624 allLanguages={this.state.siteRes.all_languages}
625 siteLanguages={this.state.siteRes.discussion_languages}
626 onSaveComment={this.handleSaveComment}
627 onBlockPerson={this.handleBlockPerson}
628 onDeleteComment={this.handleDeleteComment}
629 onRemoveComment={this.handleRemoveComment}
630 onCommentVote={this.handleCommentVote}
631 onCommentReport={this.handleCommentReport}
632 onDistinguishComment={this.handleDistinguishComment}
633 onAddModToCommunity={this.handleAddModToCommunity}
634 onAddAdmin={this.handleAddAdmin}
635 onTransferCommunity={this.handleTransferCommunity}
636 onPurgeComment={this.handlePurgeComment}
637 onPurgePerson={this.handlePurgePerson}
638 onCommentReplyRead={this.handleCommentReplyRead}
639 onPersonMentionRead={this.handlePersonMentionRead}
640 onBanPersonFromCommunity={this.handleBanFromCommunity}
641 onBanPerson={this.handleBanPerson}
642 onCreateComment={this.handleCreateComment}
643 onEditComment={this.handleEditComment}
653 switch (this.state.messagesRes.state) {
661 const messages = this.state.messagesRes.data.private_messages;
664 {messages.map(pmv => (
666 key={pmv.private_message.id}
667 private_message_view={pmv}
668 onDelete={this.handleDeleteMessage}
669 onMarkRead={this.handleMarkMessageAsRead}
670 onReport={this.handleMessageReport}
671 onCreate={this.handleCreateMessage}
672 onEdit={this.handleEditMessage}
681 async handlePageChange(page: number) {
682 this.setState({ page });
683 await this.refetch();
686 async handleUnreadOrAllChange(i: Inbox, event: any) {
687 i.setState({ unreadOrAll: Number(event.target.value), page: 1 });
691 async handleMessageTypeChange(i: Inbox, event: any) {
692 i.setState({ messageType: Number(event.target.value), page: 1 });
696 static async fetchInitialData({
699 }: InitialFetchRequest): Promise<InboxData> {
700 const sort: CommentSortType = "New";
704 ? await client.getPersonMentions({
711 : { state: "empty" },
713 ? await client.getPrivateMessages({
719 : { state: "empty" },
721 ? await client.getReplies({
728 : { state: "empty" },
733 const sort = this.state.sort;
734 const unread_only = this.state.unreadOrAll == UnreadOrAll.Unread;
735 const page = this.state.page;
736 const limit = fetchLimit;
737 const auth = myAuthRequired();
739 this.setState({ repliesRes: { state: "loading" } });
741 repliesRes: await HttpService.client.getReplies({
750 this.setState({ mentionsRes: { state: "loading" } });
752 mentionsRes: await HttpService.client.getPersonMentions({
761 this.setState({ messagesRes: { state: "loading" } });
763 messagesRes: await HttpService.client.getPrivateMessages({
772 async handleSortChange(val: CommentSortType) {
773 this.setState({ sort: val, page: 1 });
774 await this.refetch();
777 async handleMarkAllAsRead(i: Inbox) {
778 i.setState({ markAllAsReadRes: { state: "loading" } });
781 markAllAsReadRes: await HttpService.client.markAllAsRead({
782 auth: myAuthRequired(),
786 if (i.state.markAllAsReadRes.state == "success") {
788 repliesRes: { state: "empty" },
789 mentionsRes: { state: "empty" },
790 messagesRes: { state: "empty" },
795 async handleAddModToCommunity(form: AddModToCommunity) {
796 // TODO not sure what to do here
797 HttpService.client.addModToCommunity(form);
800 async handlePurgePerson(form: PurgePerson) {
801 const purgePersonRes = await HttpService.client.purgePerson(form);
802 this.purgeItem(purgePersonRes);
805 async handlePurgeComment(form: PurgeComment) {
806 const purgeCommentRes = await HttpService.client.purgeComment(form);
807 this.purgeItem(purgeCommentRes);
810 async handlePurgePost(form: PurgePost) {
811 const purgeRes = await HttpService.client.purgePost(form);
812 this.purgeItem(purgeRes);
815 async handleBlockPerson(form: BlockPerson) {
816 const blockPersonRes = await HttpService.client.blockPerson(form);
817 if (blockPersonRes.state == "success") {
818 updatePersonBlock(blockPersonRes.data);
822 async handleCreateComment(form: CreateComment) {
823 const res = await HttpService.client.createComment(form);
825 if (res.state === "success") {
826 toast(I18NextService.i18n.t("reply_sent"));
827 this.findAndUpdateComment(res);
833 async handleEditComment(form: EditComment) {
834 const res = await HttpService.client.editComment(form);
836 if (res.state === "success") {
837 toast(I18NextService.i18n.t("edit"));
838 this.findAndUpdateComment(res);
839 } else if (res.state === "failed") {
840 toast(res.msg, "danger");
846 async handleDeleteComment(form: DeleteComment) {
847 const res = await HttpService.client.deleteComment(form);
848 if (res.state == "success") {
849 toast(I18NextService.i18n.t("deleted"));
850 this.findAndUpdateComment(res);
854 async handleRemoveComment(form: RemoveComment) {
855 const res = await HttpService.client.removeComment(form);
856 if (res.state == "success") {
857 toast(I18NextService.i18n.t("remove_comment"));
858 this.findAndUpdateComment(res);
862 async handleSaveComment(form: SaveComment) {
863 const res = await HttpService.client.saveComment(form);
864 this.findAndUpdateComment(res);
867 async handleCommentVote(form: CreateCommentLike) {
868 const res = await HttpService.client.likeComment(form);
869 this.findAndUpdateComment(res);
872 async handleCommentReport(form: CreateCommentReport) {
873 const reportRes = await HttpService.client.createCommentReport(form);
874 this.reportToast(reportRes);
877 async handleDistinguishComment(form: DistinguishComment) {
878 const res = await HttpService.client.distinguishComment(form);
879 this.findAndUpdateComment(res);
882 async handleAddAdmin(form: AddAdmin) {
883 const addAdminRes = await HttpService.client.addAdmin(form);
885 if (addAdminRes.state === "success") {
886 this.setState(s => ((s.siteRes.admins = addAdminRes.data.admins), s));
890 async handleTransferCommunity(form: TransferCommunity) {
891 await HttpService.client.transferCommunity(form);
892 toast(I18NextService.i18n.t("transfer_community"));
895 async handleCommentReplyRead(form: MarkCommentReplyAsRead) {
896 const res = await HttpService.client.markCommentReplyAsRead(form);
897 this.findAndUpdateCommentReply(res);
900 async handlePersonMentionRead(form: MarkPersonMentionAsRead) {
901 const res = await HttpService.client.markPersonMentionAsRead(form);
902 this.findAndUpdateMention(res);
905 async handleBanFromCommunity(form: BanFromCommunity) {
906 const banRes = await HttpService.client.banFromCommunity(form);
907 this.updateBanFromCommunity(banRes);
910 async handleBanPerson(form: BanPerson) {
911 const banRes = await HttpService.client.banPerson(form);
912 this.updateBan(banRes);
915 async handleDeleteMessage(form: DeletePrivateMessage) {
916 const res = await HttpService.client.deletePrivateMessage(form);
917 this.findAndUpdateMessage(res);
920 async handleEditMessage(form: EditPrivateMessage) {
921 const res = await HttpService.client.editPrivateMessage(form);
922 this.findAndUpdateMessage(res);
925 async handleMarkMessageAsRead(form: MarkPrivateMessageAsRead) {
926 const res = await HttpService.client.markPrivateMessageAsRead(form);
927 this.findAndUpdateMessage(res);
930 async handleMessageReport(form: CreatePrivateMessageReport) {
931 const res = await HttpService.client.createPrivateMessageReport(form);
932 this.reportToast(res);
935 async handleCreateMessage(form: CreatePrivateMessage) {
936 const res = await HttpService.client.createPrivateMessage(form);
938 if (s.messagesRes.state == "success" && res.state == "success") {
939 s.messagesRes.data.private_messages.unshift(
940 res.data.private_message_view
948 findAndUpdateMessage(res: RequestState<PrivateMessageResponse>) {
950 if (s.messagesRes.state === "success" && res.state === "success") {
951 s.messagesRes.data.private_messages = editPrivateMessage(
952 res.data.private_message_view,
953 s.messagesRes.data.private_messages
960 updateBanFromCommunity(banRes: RequestState<BanFromCommunityResponse>) {
961 // Maybe not necessary
962 if (banRes.state == "success") {
964 if (s.repliesRes.state == "success") {
965 s.repliesRes.data.replies
966 .filter(c => c.creator.id == banRes.data.person_view.person.id)
968 c => (c.creator_banned_from_community = banRes.data.banned)
971 if (s.mentionsRes.state == "success") {
972 s.mentionsRes.data.mentions
973 .filter(c => c.creator.id == banRes.data.person_view.person.id)
975 c => (c.creator_banned_from_community = banRes.data.banned)
983 updateBan(banRes: RequestState<BanPersonResponse>) {
984 // Maybe not necessary
985 if (banRes.state == "success") {
987 if (s.repliesRes.state == "success") {
988 s.repliesRes.data.replies
989 .filter(c => c.creator.id == banRes.data.person_view.person.id)
990 .forEach(c => (c.creator.banned = banRes.data.banned));
992 if (s.mentionsRes.state == "success") {
993 s.mentionsRes.data.mentions
994 .filter(c => c.creator.id == banRes.data.person_view.person.id)
995 .forEach(c => (c.creator.banned = banRes.data.banned));
1002 purgeItem(purgeRes: RequestState<PurgeItemResponse>) {
1003 if (purgeRes.state == "success") {
1004 toast(I18NextService.i18n.t("purge_success"));
1005 this.context.router.history.push(`/`);
1010 res: RequestState<PrivateMessageReportResponse | CommentReportResponse>
1012 if (res.state == "success") {
1013 toast(I18NextService.i18n.t("report_created"));
1017 // A weird case, since you have only replies and mentions, not comment responses
1018 findAndUpdateComment(res: RequestState<CommentResponse>) {
1019 if (res.state == "success") {
1020 this.setState(s => {
1021 if (s.repliesRes.state == "success") {
1022 s.repliesRes.data.replies = editWith(
1023 res.data.comment_view,
1024 s.repliesRes.data.replies
1027 if (s.mentionsRes.state == "success") {
1028 s.mentionsRes.data.mentions = editWith(
1029 res.data.comment_view,
1030 s.mentionsRes.data.mentions
1033 // Set finished for the parent
1035 getCommentParentId(res.data.comment_view.comment) ?? 0,
1043 findAndUpdateCommentReply(res: RequestState<CommentReplyResponse>) {
1044 this.setState(s => {
1045 if (s.repliesRes.state == "success" && res.state == "success") {
1046 s.repliesRes.data.replies = editCommentReply(
1047 res.data.comment_reply_view,
1048 s.repliesRes.data.replies
1055 findAndUpdateMention(res: RequestState<PersonMentionResponse>) {
1056 this.setState(s => {
1057 if (s.mentionsRes.state == "success" && res.state == "success") {
1058 s.mentionsRes.data.mentions = editMention(
1059 res.data.person_mention_view,
1060 s.mentionsRes.data.mentions