2022-06-21 21:42:29 +00:00
|
|
|
import { None, Some } from "@sniptt/monads";
|
2021-02-22 02:39:04 +00:00
|
|
|
import { Component, linkEvent } from "inferno";
|
2020-09-06 16:15:25 +00:00
|
|
|
import {
|
2021-08-20 02:56:18 +00:00
|
|
|
BlockPersonResponse,
|
2022-07-30 13:28:08 +00:00
|
|
|
CommentReplyResponse,
|
|
|
|
CommentReplyView,
|
2021-09-28 10:38:59 +00:00
|
|
|
CommentReportResponse,
|
2021-07-17 20:42:55 +00:00
|
|
|
CommentResponse,
|
2022-07-30 13:28:08 +00:00
|
|
|
CommentSortType,
|
2020-12-24 01:58:27 +00:00
|
|
|
CommentView,
|
2021-03-15 18:09:31 +00:00
|
|
|
GetPersonMentions,
|
|
|
|
GetPersonMentionsResponse,
|
2020-12-24 01:58:27 +00:00
|
|
|
GetPrivateMessages,
|
2021-07-17 20:42:55 +00:00
|
|
|
GetReplies,
|
|
|
|
GetRepliesResponse,
|
2022-06-21 21:42:29 +00:00
|
|
|
GetSiteResponse,
|
2021-07-17 20:42:55 +00:00
|
|
|
PersonMentionResponse,
|
|
|
|
PersonMentionView,
|
2021-09-28 10:38:59 +00:00
|
|
|
PostReportResponse,
|
2022-09-28 12:50:47 +00:00
|
|
|
PrivateMessageReportResponse,
|
2020-09-06 16:15:25 +00:00
|
|
|
PrivateMessageResponse,
|
2021-07-17 20:42:55 +00:00
|
|
|
PrivateMessagesResponse,
|
|
|
|
PrivateMessageView,
|
|
|
|
UserOperation,
|
2022-06-21 21:42:29 +00:00
|
|
|
wsJsonToRes,
|
|
|
|
wsUserOp,
|
2021-02-22 02:39:04 +00:00
|
|
|
} from "lemmy-js-client";
|
2021-07-17 20:42:55 +00:00
|
|
|
import { Subscription } from "rxjs";
|
|
|
|
import { i18n } from "../../i18next";
|
2022-07-30 13:28:08 +00:00
|
|
|
import { CommentViewType, InitialFetchRequest } from "../../interfaces";
|
2021-07-17 20:42:55 +00:00
|
|
|
import { UserService, WebSocketService } from "../../services";
|
2020-09-06 16:15:25 +00:00
|
|
|
import {
|
2022-06-21 21:42:29 +00:00
|
|
|
auth,
|
2021-07-17 20:42:55 +00:00
|
|
|
commentsToFlatNodes,
|
|
|
|
createCommentLikeRes,
|
2020-09-06 16:15:25 +00:00
|
|
|
editCommentRes,
|
2022-06-21 21:42:29 +00:00
|
|
|
enableDownvotes,
|
2021-07-17 20:42:55 +00:00
|
|
|
fetchLimit,
|
|
|
|
isBrowser,
|
2022-02-24 15:31:44 +00:00
|
|
|
relTags,
|
2020-09-06 16:15:25 +00:00
|
|
|
saveCommentRes,
|
2020-09-09 00:48:17 +00:00
|
|
|
setIsoData,
|
2021-07-17 20:42:55 +00:00
|
|
|
setupTippy,
|
|
|
|
toast,
|
2021-08-20 02:56:18 +00:00
|
|
|
updatePersonBlock,
|
2021-07-17 20:42:55 +00:00
|
|
|
wsClient,
|
2020-09-09 00:48:17 +00:00
|
|
|
wsSubscribe,
|
2021-07-17 20:42:55 +00:00
|
|
|
} from "../../utils";
|
|
|
|
import { CommentNodes } from "../comment/comment-nodes";
|
2022-07-30 13:28:08 +00:00
|
|
|
import { CommentSortSelect } from "../common/comment-sort-select";
|
2021-07-17 20:42:55 +00:00
|
|
|
import { HtmlTags } from "../common/html-tags";
|
|
|
|
import { Icon, Spinner } from "../common/icon";
|
|
|
|
import { Paginator } from "../common/paginator";
|
|
|
|
import { PrivateMessage } from "../private_message/private-message";
|
2020-09-06 16:15:25 +00:00
|
|
|
|
|
|
|
enum UnreadOrAll {
|
|
|
|
Unread,
|
|
|
|
All,
|
|
|
|
}
|
|
|
|
|
|
|
|
enum MessageType {
|
|
|
|
All,
|
|
|
|
Replies,
|
|
|
|
Mentions,
|
|
|
|
Messages,
|
|
|
|
}
|
|
|
|
|
2020-12-24 01:58:27 +00:00
|
|
|
enum ReplyEnum {
|
|
|
|
Reply,
|
|
|
|
Mention,
|
|
|
|
Message,
|
|
|
|
}
|
|
|
|
type ReplyType = {
|
|
|
|
id: number;
|
|
|
|
type_: ReplyEnum;
|
2022-07-30 13:28:08 +00:00
|
|
|
view: CommentView | PrivateMessageView | PersonMentionView | CommentReplyView;
|
2020-12-24 01:58:27 +00:00
|
|
|
published: string;
|
|
|
|
};
|
2020-09-06 16:15:25 +00:00
|
|
|
|
|
|
|
interface InboxState {
|
|
|
|
unreadOrAll: UnreadOrAll;
|
|
|
|
messageType: MessageType;
|
2022-07-30 13:28:08 +00:00
|
|
|
replies: CommentReplyView[];
|
2021-03-15 18:09:31 +00:00
|
|
|
mentions: PersonMentionView[];
|
2020-12-24 01:58:27 +00:00
|
|
|
messages: PrivateMessageView[];
|
2021-02-02 20:24:25 +00:00
|
|
|
combined: ReplyType[];
|
2022-07-30 13:28:08 +00:00
|
|
|
sort: CommentSortType;
|
2020-09-06 16:15:25 +00:00
|
|
|
page: number;
|
2022-06-21 21:42:29 +00:00
|
|
|
siteRes: GetSiteResponse;
|
2020-09-09 00:48:17 +00:00
|
|
|
loading: boolean;
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export class Inbox extends Component<any, InboxState> {
|
2022-06-21 21:42:29 +00:00
|
|
|
private isoData = setIsoData(
|
|
|
|
this.context,
|
|
|
|
GetRepliesResponse,
|
|
|
|
GetPersonMentionsResponse,
|
|
|
|
PrivateMessagesResponse
|
|
|
|
);
|
2020-09-06 16:15:25 +00:00
|
|
|
private subscription: Subscription;
|
|
|
|
private emptyState: InboxState = {
|
|
|
|
unreadOrAll: UnreadOrAll.Unread,
|
|
|
|
messageType: MessageType.All,
|
|
|
|
replies: [],
|
|
|
|
mentions: [],
|
|
|
|
messages: [],
|
2021-02-02 20:24:25 +00:00
|
|
|
combined: [],
|
2022-07-30 13:28:08 +00:00
|
|
|
sort: CommentSortType.New,
|
2020-09-06 16:15:25 +00:00
|
|
|
page: 1,
|
2022-06-21 21:42:29 +00:00
|
|
|
siteRes: this.isoData.site_res,
|
2020-09-09 00:48:17 +00:00
|
|
|
loading: true,
|
2020-09-06 16:15:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
constructor(props: any, context: any) {
|
|
|
|
super(props, context);
|
|
|
|
|
|
|
|
this.state = this.emptyState;
|
|
|
|
this.handleSortChange = this.handleSortChange.bind(this);
|
2021-07-16 19:40:56 +00:00
|
|
|
this.handlePageChange = this.handlePageChange.bind(this);
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2022-06-21 21:42:29 +00:00
|
|
|
if (UserService.Instance.myUserInfo.isNone() && isBrowser()) {
|
2021-02-22 02:39:04 +00:00
|
|
|
toast(i18n.t("not_logged_in"), "danger");
|
2020-12-15 23:43:35 +00:00
|
|
|
this.context.router.history.push(`/login`);
|
|
|
|
}
|
|
|
|
|
2020-09-09 00:48:17 +00:00
|
|
|
this.parseMessage = this.parseMessage.bind(this);
|
|
|
|
this.subscription = wsSubscribe(this.parseMessage);
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2020-09-09 00:48:17 +00:00
|
|
|
// Only fetch the data if coming from another route
|
|
|
|
if (this.isoData.path == this.context.router.route.match.url) {
|
2022-09-22 15:03:35 +00:00
|
|
|
this.state = {
|
|
|
|
...this.state,
|
|
|
|
replies:
|
|
|
|
(this.isoData.routeData[0] as GetRepliesResponse).replies || [],
|
|
|
|
mentions:
|
|
|
|
(this.isoData.routeData[1] as GetPersonMentionsResponse).mentions ||
|
|
|
|
[],
|
|
|
|
messages:
|
|
|
|
(this.isoData.routeData[2] as PrivateMessagesResponse)
|
|
|
|
.private_messages || [],
|
|
|
|
loading: false,
|
|
|
|
};
|
|
|
|
this.state = { ...this.state, combined: this.buildCombined() };
|
2020-09-09 00:48:17 +00:00
|
|
|
} else {
|
|
|
|
this.refetch();
|
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
2020-09-09 00:48:17 +00:00
|
|
|
if (isBrowser()) {
|
|
|
|
this.subscription.unsubscribe();
|
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get documentTitle(): string {
|
2022-11-09 19:53:07 +00:00
|
|
|
return UserService.Instance.myUserInfo.match({
|
|
|
|
some: mui =>
|
|
|
|
`@${mui.local_user_view.person.name} ${i18n.t("inbox")} - ${
|
|
|
|
this.state.siteRes.site_view.site.name
|
|
|
|
}`,
|
2022-06-21 21:42:29 +00:00
|
|
|
none: "",
|
|
|
|
});
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2022-06-21 21:42:29 +00:00
|
|
|
let inboxRss = auth()
|
|
|
|
.ok()
|
|
|
|
.map(a => `/feeds/inbox/${a}.xml`);
|
2020-09-06 16:15:25 +00:00
|
|
|
return (
|
2022-10-03 18:16:36 +00:00
|
|
|
<div className="container-lg">
|
2020-09-09 00:48:17 +00:00
|
|
|
{this.state.loading ? (
|
|
|
|
<h5>
|
2021-07-17 20:21:31 +00:00
|
|
|
<Spinner large />
|
2020-09-09 00:48:17 +00:00
|
|
|
</h5>
|
|
|
|
) : (
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="row">
|
|
|
|
<div className="col-12">
|
2020-09-11 18:09:21 +00:00
|
|
|
<HtmlTags
|
|
|
|
title={this.documentTitle}
|
|
|
|
path={this.context.router.route.match.url}
|
2022-06-21 21:42:29 +00:00
|
|
|
description={None}
|
|
|
|
image={None}
|
2020-09-11 18:09:21 +00:00
|
|
|
/>
|
2022-09-22 15:03:35 +00:00
|
|
|
<h5 className="mb-2">
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("inbox")}
|
2022-06-21 21:42:29 +00:00
|
|
|
{inboxRss.match({
|
|
|
|
some: rss => (
|
|
|
|
<small>
|
|
|
|
<a href={rss} title="RSS" rel={relTags}>
|
|
|
|
<Icon icon="rss" classes="ml-2 text-muted small" />
|
|
|
|
</a>
|
|
|
|
<link
|
|
|
|
rel="alternate"
|
|
|
|
type="application/atom+xml"
|
|
|
|
href={rss}
|
|
|
|
/>
|
|
|
|
</small>
|
|
|
|
),
|
|
|
|
none: <></>,
|
|
|
|
})}
|
2020-09-09 00:48:17 +00:00
|
|
|
</h5>
|
|
|
|
{this.state.replies.length +
|
|
|
|
this.state.mentions.length +
|
|
|
|
this.state.messages.length >
|
|
|
|
0 &&
|
|
|
|
this.state.unreadOrAll == UnreadOrAll.Unread && (
|
2021-07-17 20:42:55 +00:00
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-secondary mb-2"
|
2021-07-17 20:42:55 +00:00
|
|
|
onClick={linkEvent(this, this.markAllAsRead)}
|
|
|
|
>
|
|
|
|
{i18n.t("mark_all_as_read")}
|
|
|
|
</button>
|
2020-09-09 00:48:17 +00:00
|
|
|
)}
|
|
|
|
{this.selects()}
|
|
|
|
{this.state.messageType == MessageType.All && this.all()}
|
|
|
|
{this.state.messageType == MessageType.Replies && this.replies()}
|
|
|
|
{this.state.messageType == MessageType.Mentions &&
|
|
|
|
this.mentions()}
|
|
|
|
{this.state.messageType == MessageType.Messages &&
|
|
|
|
this.messages()}
|
2021-07-16 19:40:56 +00:00
|
|
|
<Paginator
|
|
|
|
page={this.state.page}
|
|
|
|
onChange={this.handlePageChange}
|
|
|
|
/>
|
2020-09-09 00:48:17 +00:00
|
|
|
</div>
|
2020-09-06 16:15:25 +00:00
|
|
|
</div>
|
2020-09-09 00:48:17 +00:00
|
|
|
)}
|
2020-09-06 16:15:25 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
unreadOrAllRadios() {
|
|
|
|
return (
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="btn-group btn-group-toggle flex-wrap mb-2">
|
2020-09-06 16:15:25 +00:00
|
|
|
<label
|
|
|
|
className={`btn btn-outline-secondary pointer
|
2021-02-22 02:39:04 +00:00
|
|
|
${this.state.unreadOrAll == UnreadOrAll.Unread && "active"}
|
2020-09-06 16:15:25 +00:00
|
|
|
`}
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
value={UnreadOrAll.Unread}
|
|
|
|
checked={this.state.unreadOrAll == UnreadOrAll.Unread}
|
|
|
|
onChange={linkEvent(this, this.handleUnreadOrAllChange)}
|
|
|
|
/>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("unread")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</label>
|
|
|
|
<label
|
|
|
|
className={`btn btn-outline-secondary pointer
|
2021-02-22 02:39:04 +00:00
|
|
|
${this.state.unreadOrAll == UnreadOrAll.All && "active"}
|
2020-09-06 16:15:25 +00:00
|
|
|
`}
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
value={UnreadOrAll.All}
|
|
|
|
checked={this.state.unreadOrAll == UnreadOrAll.All}
|
|
|
|
onChange={linkEvent(this, this.handleUnreadOrAllChange)}
|
|
|
|
/>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("all")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
messageTypeRadios() {
|
|
|
|
return (
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="btn-group btn-group-toggle flex-wrap mb-2">
|
2020-09-06 16:15:25 +00:00
|
|
|
<label
|
|
|
|
className={`btn btn-outline-secondary pointer
|
2021-02-22 02:39:04 +00:00
|
|
|
${this.state.messageType == MessageType.All && "active"}
|
2020-09-06 16:15:25 +00:00
|
|
|
`}
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
value={MessageType.All}
|
|
|
|
checked={this.state.messageType == MessageType.All}
|
|
|
|
onChange={linkEvent(this, this.handleMessageTypeChange)}
|
|
|
|
/>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("all")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</label>
|
|
|
|
<label
|
|
|
|
className={`btn btn-outline-secondary pointer
|
2021-02-22 02:39:04 +00:00
|
|
|
${this.state.messageType == MessageType.Replies && "active"}
|
2020-09-06 16:15:25 +00:00
|
|
|
`}
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
value={MessageType.Replies}
|
|
|
|
checked={this.state.messageType == MessageType.Replies}
|
|
|
|
onChange={linkEvent(this, this.handleMessageTypeChange)}
|
|
|
|
/>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("replies")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</label>
|
|
|
|
<label
|
|
|
|
className={`btn btn-outline-secondary pointer
|
2021-02-22 02:39:04 +00:00
|
|
|
${this.state.messageType == MessageType.Mentions && "active"}
|
2020-09-06 16:15:25 +00:00
|
|
|
`}
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
value={MessageType.Mentions}
|
|
|
|
checked={this.state.messageType == MessageType.Mentions}
|
|
|
|
onChange={linkEvent(this, this.handleMessageTypeChange)}
|
|
|
|
/>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("mentions")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</label>
|
|
|
|
<label
|
|
|
|
className={`btn btn-outline-secondary pointer
|
2021-02-22 02:39:04 +00:00
|
|
|
${this.state.messageType == MessageType.Messages && "active"}
|
2020-09-06 16:15:25 +00:00
|
|
|
`}
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
value={MessageType.Messages}
|
|
|
|
checked={this.state.messageType == MessageType.Messages}
|
|
|
|
onChange={linkEvent(this, this.handleMessageTypeChange)}
|
|
|
|
/>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("messages")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
selects() {
|
|
|
|
return (
|
|
|
|
<div className="mb-2">
|
2022-09-22 15:03:35 +00:00
|
|
|
<span className="mr-3">{this.unreadOrAllRadios()}</span>
|
|
|
|
<span className="mr-3">{this.messageTypeRadios()}</span>
|
2022-07-30 13:28:08 +00:00
|
|
|
<CommentSortSelect
|
2020-09-06 16:15:25 +00:00
|
|
|
sort={this.state.sort}
|
|
|
|
onChange={this.handleSortChange}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-07-30 13:28:08 +00:00
|
|
|
replyToReplyType(r: CommentReplyView): ReplyType {
|
2021-02-02 20:24:25 +00:00
|
|
|
return {
|
2022-07-30 13:28:08 +00:00
|
|
|
id: r.comment_reply.id,
|
2020-12-24 01:58:27 +00:00
|
|
|
type_: ReplyEnum.Reply,
|
|
|
|
view: r,
|
|
|
|
published: r.comment.published,
|
2021-02-02 20:24:25 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-03-15 18:09:31 +00:00
|
|
|
mentionToReplyType(r: PersonMentionView): ReplyType {
|
2021-02-02 20:24:25 +00:00
|
|
|
return {
|
2021-03-15 18:09:31 +00:00
|
|
|
id: r.person_mention.id,
|
2020-12-24 01:58:27 +00:00
|
|
|
type_: ReplyEnum.Mention,
|
|
|
|
view: r,
|
|
|
|
published: r.comment.published,
|
2021-02-02 20:24:25 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
messageToReplyType(r: PrivateMessageView): ReplyType {
|
|
|
|
return {
|
|
|
|
id: r.private_message.id,
|
2020-12-24 01:58:27 +00:00
|
|
|
type_: ReplyEnum.Message,
|
|
|
|
view: r,
|
|
|
|
published: r.private_message.published,
|
2021-02-02 20:24:25 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
buildCombined(): ReplyType[] {
|
|
|
|
let replies: ReplyType[] = this.state.replies.map(r =>
|
|
|
|
this.replyToReplyType(r)
|
|
|
|
);
|
|
|
|
let mentions: ReplyType[] = this.state.mentions.map(r =>
|
|
|
|
this.mentionToReplyType(r)
|
|
|
|
);
|
|
|
|
let messages: ReplyType[] = this.state.messages.map(r =>
|
|
|
|
this.messageToReplyType(r)
|
|
|
|
);
|
2020-12-24 01:58:27 +00:00
|
|
|
|
|
|
|
return [...replies, ...mentions, ...messages].sort((a, b) =>
|
|
|
|
b.published.localeCompare(a.published)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderReplyType(i: ReplyType) {
|
|
|
|
switch (i.type_) {
|
|
|
|
case ReplyEnum.Reply:
|
|
|
|
return (
|
|
|
|
<CommentNodes
|
|
|
|
key={i.id}
|
2022-07-30 13:28:08 +00:00
|
|
|
nodes={[
|
|
|
|
{ comment_view: i.view as CommentView, children: [], depth: 0 },
|
|
|
|
]}
|
|
|
|
viewType={CommentViewType.Flat}
|
2022-06-21 21:42:29 +00:00
|
|
|
moderators={None}
|
|
|
|
admins={None}
|
|
|
|
maxCommentsShown={None}
|
2020-12-24 01:58:27 +00:00
|
|
|
noIndent
|
|
|
|
markable
|
|
|
|
showCommunity
|
|
|
|
showContext
|
2022-06-21 21:42:29 +00:00
|
|
|
enableDownvotes={enableDownvotes(this.state.siteRes)}
|
2022-09-22 15:14:58 +00:00
|
|
|
allLanguages={this.state.siteRes.all_languages}
|
2020-12-24 01:58:27 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
case ReplyEnum.Mention:
|
|
|
|
return (
|
|
|
|
<CommentNodes
|
|
|
|
key={i.id}
|
2022-07-30 13:28:08 +00:00
|
|
|
nodes={[
|
|
|
|
{
|
|
|
|
comment_view: i.view as PersonMentionView,
|
|
|
|
children: [],
|
|
|
|
depth: 0,
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
viewType={CommentViewType.Flat}
|
2022-06-21 21:42:29 +00:00
|
|
|
moderators={None}
|
|
|
|
admins={None}
|
|
|
|
maxCommentsShown={None}
|
2020-12-24 01:58:27 +00:00
|
|
|
noIndent
|
|
|
|
markable
|
|
|
|
showCommunity
|
|
|
|
showContext
|
2022-06-21 21:42:29 +00:00
|
|
|
enableDownvotes={enableDownvotes(this.state.siteRes)}
|
2022-09-22 15:14:58 +00:00
|
|
|
allLanguages={this.state.siteRes.all_languages}
|
2020-12-24 01:58:27 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
case ReplyEnum.Message:
|
|
|
|
return (
|
|
|
|
<PrivateMessage
|
|
|
|
key={i.id}
|
|
|
|
private_message_view={i.view as PrivateMessageView}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
default:
|
|
|
|
return <div />;
|
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
all() {
|
2021-02-02 20:24:25 +00:00
|
|
|
return <div>{this.state.combined.map(i => this.renderReplyType(i))}</div>;
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
replies() {
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<CommentNodes
|
|
|
|
nodes={commentsToFlatNodes(this.state.replies)}
|
2022-07-30 13:28:08 +00:00
|
|
|
viewType={CommentViewType.Flat}
|
2022-06-21 21:42:29 +00:00
|
|
|
moderators={None}
|
|
|
|
admins={None}
|
|
|
|
maxCommentsShown={None}
|
2020-09-06 16:15:25 +00:00
|
|
|
noIndent
|
|
|
|
markable
|
|
|
|
showCommunity
|
|
|
|
showContext
|
2022-06-21 21:42:29 +00:00
|
|
|
enableDownvotes={enableDownvotes(this.state.siteRes)}
|
2022-09-22 15:14:58 +00:00
|
|
|
allLanguages={this.state.siteRes.all_languages}
|
2020-09-06 16:15:25 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
mentions() {
|
|
|
|
return (
|
|
|
|
<div>
|
2020-12-24 01:58:27 +00:00
|
|
|
{this.state.mentions.map(umv => (
|
2020-09-06 16:15:25 +00:00
|
|
|
<CommentNodes
|
2021-03-15 18:09:31 +00:00
|
|
|
key={umv.person_mention.id}
|
2022-07-30 13:28:08 +00:00
|
|
|
nodes={[{ comment_view: umv, children: [], depth: 0 }]}
|
|
|
|
viewType={CommentViewType.Flat}
|
2022-06-21 21:42:29 +00:00
|
|
|
moderators={None}
|
|
|
|
admins={None}
|
|
|
|
maxCommentsShown={None}
|
2020-09-06 16:15:25 +00:00
|
|
|
noIndent
|
|
|
|
markable
|
|
|
|
showCommunity
|
|
|
|
showContext
|
2022-06-21 21:42:29 +00:00
|
|
|
enableDownvotes={enableDownvotes(this.state.siteRes)}
|
2022-09-22 15:14:58 +00:00
|
|
|
allLanguages={this.state.siteRes.all_languages}
|
2020-09-06 16:15:25 +00:00
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
messages() {
|
|
|
|
return (
|
|
|
|
<div>
|
2020-12-24 01:58:27 +00:00
|
|
|
{this.state.messages.map(pmv => (
|
|
|
|
<PrivateMessage
|
|
|
|
key={pmv.private_message.id}
|
|
|
|
private_message_view={pmv}
|
|
|
|
/>
|
2020-09-06 16:15:25 +00:00
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-07-16 19:40:56 +00:00
|
|
|
handlePageChange(page: number) {
|
|
|
|
this.setState({ page });
|
|
|
|
this.refetch();
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleUnreadOrAllChange(i: Inbox, event: any) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ unreadOrAll: Number(event.target.value), page: 1 });
|
2020-09-06 16:15:25 +00:00
|
|
|
i.refetch();
|
|
|
|
}
|
|
|
|
|
|
|
|
handleMessageTypeChange(i: Inbox, event: any) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ messageType: Number(event.target.value), page: 1 });
|
2020-09-06 16:15:25 +00:00
|
|
|
i.refetch();
|
|
|
|
}
|
|
|
|
|
2020-11-12 21:56:46 +00:00
|
|
|
static fetchInitialData(req: InitialFetchRequest): Promise<any>[] {
|
2020-09-09 00:48:17 +00:00
|
|
|
let promises: Promise<any>[] = [];
|
|
|
|
|
2022-07-30 13:28:08 +00:00
|
|
|
let sort = Some(CommentSortType.New);
|
|
|
|
|
2020-09-09 00:48:17 +00:00
|
|
|
// It can be /u/me, or /username/1
|
2022-06-21 21:42:29 +00:00
|
|
|
let repliesForm = new GetReplies({
|
2022-07-30 13:28:08 +00:00
|
|
|
sort,
|
2022-06-21 21:42:29 +00:00
|
|
|
unread_only: Some(true),
|
|
|
|
page: Some(1),
|
|
|
|
limit: Some(fetchLimit),
|
|
|
|
auth: req.auth.unwrap(),
|
|
|
|
});
|
2020-11-12 21:56:46 +00:00
|
|
|
promises.push(req.client.getReplies(repliesForm));
|
2020-09-09 00:48:17 +00:00
|
|
|
|
2022-06-21 21:42:29 +00:00
|
|
|
let personMentionsForm = new GetPersonMentions({
|
2022-07-30 13:28:08 +00:00
|
|
|
sort,
|
2022-06-21 21:42:29 +00:00
|
|
|
unread_only: Some(true),
|
|
|
|
page: Some(1),
|
|
|
|
limit: Some(fetchLimit),
|
|
|
|
auth: req.auth.unwrap(),
|
|
|
|
});
|
2021-03-15 18:09:31 +00:00
|
|
|
promises.push(req.client.getPersonMentions(personMentionsForm));
|
2020-09-09 00:48:17 +00:00
|
|
|
|
2022-06-21 21:42:29 +00:00
|
|
|
let privateMessagesForm = new GetPrivateMessages({
|
|
|
|
unread_only: Some(true),
|
|
|
|
page: Some(1),
|
|
|
|
limit: Some(fetchLimit),
|
|
|
|
auth: req.auth.unwrap(),
|
|
|
|
});
|
2020-11-12 21:56:46 +00:00
|
|
|
promises.push(req.client.getPrivateMessages(privateMessagesForm));
|
2020-09-09 00:48:17 +00:00
|
|
|
|
|
|
|
return promises;
|
|
|
|
}
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
refetch() {
|
2022-06-21 21:42:29 +00:00
|
|
|
let sort = Some(this.state.sort);
|
|
|
|
let unread_only = Some(this.state.unreadOrAll == UnreadOrAll.Unread);
|
|
|
|
let page = Some(this.state.page);
|
|
|
|
let limit = Some(fetchLimit);
|
|
|
|
|
|
|
|
let repliesForm = new GetReplies({
|
|
|
|
sort,
|
|
|
|
unread_only,
|
|
|
|
page,
|
|
|
|
limit,
|
|
|
|
auth: auth().unwrap(),
|
|
|
|
});
|
2020-12-24 22:05:57 +00:00
|
|
|
WebSocketService.Instance.send(wsClient.getReplies(repliesForm));
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2022-06-21 21:42:29 +00:00
|
|
|
let personMentionsForm = new GetPersonMentions({
|
|
|
|
sort,
|
|
|
|
unread_only,
|
|
|
|
page,
|
|
|
|
limit,
|
|
|
|
auth: auth().unwrap(),
|
|
|
|
});
|
2021-03-15 18:09:31 +00:00
|
|
|
WebSocketService.Instance.send(
|
|
|
|
wsClient.getPersonMentions(personMentionsForm)
|
|
|
|
);
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2022-06-21 21:42:29 +00:00
|
|
|
let privateMessagesForm = new GetPrivateMessages({
|
|
|
|
unread_only,
|
|
|
|
page,
|
|
|
|
limit,
|
|
|
|
auth: auth().unwrap(),
|
|
|
|
});
|
2020-12-24 22:05:57 +00:00
|
|
|
WebSocketService.Instance.send(
|
|
|
|
wsClient.getPrivateMessages(privateMessagesForm)
|
|
|
|
);
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2022-07-30 13:28:08 +00:00
|
|
|
handleSortChange(val: CommentSortType) {
|
2022-09-22 15:03:35 +00:00
|
|
|
this.setState({ sort: val, page: 1 });
|
2020-09-06 16:15:25 +00:00
|
|
|
this.refetch();
|
|
|
|
}
|
|
|
|
|
|
|
|
markAllAsRead(i: Inbox) {
|
2020-12-24 22:05:57 +00:00
|
|
|
WebSocketService.Instance.send(
|
|
|
|
wsClient.markAllAsRead({
|
2022-06-21 21:42:29 +00:00
|
|
|
auth: auth().unwrap(),
|
2020-12-24 22:05:57 +00:00
|
|
|
})
|
|
|
|
);
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ replies: [], mentions: [], messages: [] });
|
|
|
|
i.setState({ combined: i.buildCombined() });
|
2021-10-17 17:42:30 +00:00
|
|
|
UserService.Instance.unreadInboxCountSub.next(0);
|
2020-09-06 16:15:25 +00:00
|
|
|
window.scrollTo(0, 0);
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
2021-10-17 17:42:30 +00:00
|
|
|
sendUnreadCount(read: boolean) {
|
|
|
|
let urcs = UserService.Instance.unreadInboxCountSub;
|
|
|
|
if (read) {
|
|
|
|
urcs.next(urcs.getValue() - 1);
|
|
|
|
} else {
|
|
|
|
urcs.next(urcs.getValue() + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-24 01:58:27 +00:00
|
|
|
parseMessage(msg: any) {
|
|
|
|
let op = wsUserOp(msg);
|
2021-02-02 20:24:25 +00:00
|
|
|
console.log(msg);
|
2020-09-06 16:15:25 +00:00
|
|
|
if (msg.error) {
|
2021-02-22 02:39:04 +00:00
|
|
|
toast(i18n.t(msg.error), "danger");
|
2020-09-06 16:15:25 +00:00
|
|
|
return;
|
|
|
|
} else if (msg.reconnect) {
|
|
|
|
this.refetch();
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.GetReplies) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let data = wsJsonToRes<GetRepliesResponse>(msg, GetRepliesResponse);
|
2022-09-22 15:03:35 +00:00
|
|
|
this.setState({ replies: data.replies });
|
|
|
|
this.setState({ combined: this.buildCombined(), loading: false });
|
2020-09-06 16:15:25 +00:00
|
|
|
window.scrollTo(0, 0);
|
|
|
|
setupTippy();
|
2021-03-15 18:09:31 +00:00
|
|
|
} else if (op == UserOperation.GetPersonMentions) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let data = wsJsonToRes<GetPersonMentionsResponse>(
|
|
|
|
msg,
|
|
|
|
GetPersonMentionsResponse
|
|
|
|
);
|
2022-09-22 15:03:35 +00:00
|
|
|
this.setState({ mentions: data.mentions });
|
|
|
|
this.setState({ combined: this.buildCombined() });
|
2020-09-06 16:15:25 +00:00
|
|
|
window.scrollTo(0, 0);
|
|
|
|
setupTippy();
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.GetPrivateMessages) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let data = wsJsonToRes<PrivateMessagesResponse>(
|
|
|
|
msg,
|
|
|
|
PrivateMessagesResponse
|
|
|
|
);
|
2022-09-22 15:03:35 +00:00
|
|
|
this.setState({ messages: data.private_messages });
|
|
|
|
this.setState({ combined: this.buildCombined() });
|
2020-09-06 16:15:25 +00:00
|
|
|
window.scrollTo(0, 0);
|
|
|
|
setupTippy();
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.EditPrivateMessage) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let data = wsJsonToRes<PrivateMessageResponse>(
|
|
|
|
msg,
|
|
|
|
PrivateMessageResponse
|
|
|
|
);
|
2020-12-24 01:58:27 +00:00
|
|
|
let found: PrivateMessageView = this.state.messages.find(
|
|
|
|
m =>
|
|
|
|
m.private_message.id === data.private_message_view.private_message.id
|
2020-09-06 16:15:25 +00:00
|
|
|
);
|
|
|
|
if (found) {
|
2021-02-02 20:24:25 +00:00
|
|
|
let combinedView = this.state.combined.find(
|
|
|
|
i => i.id == data.private_message_view.private_message.id
|
|
|
|
).view as PrivateMessageView;
|
|
|
|
found.private_message.content = combinedView.private_message.content =
|
2020-12-24 01:58:27 +00:00
|
|
|
data.private_message_view.private_message.content;
|
2021-02-02 20:24:25 +00:00
|
|
|
found.private_message.updated = combinedView.private_message.updated =
|
2020-12-24 01:58:27 +00:00
|
|
|
data.private_message_view.private_message.updated;
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
this.setState(this.state);
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.DeletePrivateMessage) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let data = wsJsonToRes<PrivateMessageResponse>(
|
|
|
|
msg,
|
|
|
|
PrivateMessageResponse
|
|
|
|
);
|
2020-12-24 01:58:27 +00:00
|
|
|
let found: PrivateMessageView = this.state.messages.find(
|
|
|
|
m =>
|
|
|
|
m.private_message.id === data.private_message_view.private_message.id
|
2020-09-06 16:15:25 +00:00
|
|
|
);
|
|
|
|
if (found) {
|
2021-02-02 20:24:25 +00:00
|
|
|
let combinedView = this.state.combined.find(
|
|
|
|
i => i.id == data.private_message_view.private_message.id
|
|
|
|
).view as PrivateMessageView;
|
|
|
|
found.private_message.deleted = combinedView.private_message.deleted =
|
2020-12-24 01:58:27 +00:00
|
|
|
data.private_message_view.private_message.deleted;
|
2021-02-02 20:24:25 +00:00
|
|
|
found.private_message.updated = combinedView.private_message.updated =
|
2020-12-24 01:58:27 +00:00
|
|
|
data.private_message_view.private_message.updated;
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
this.setState(this.state);
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.MarkPrivateMessageAsRead) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let data = wsJsonToRes<PrivateMessageResponse>(
|
|
|
|
msg,
|
|
|
|
PrivateMessageResponse
|
|
|
|
);
|
2020-12-24 01:58:27 +00:00
|
|
|
let found: PrivateMessageView = this.state.messages.find(
|
|
|
|
m =>
|
|
|
|
m.private_message.id === data.private_message_view.private_message.id
|
2020-09-06 16:15:25 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
if (found) {
|
2021-02-02 20:24:25 +00:00
|
|
|
let combinedView = this.state.combined.find(
|
2022-09-22 15:03:35 +00:00
|
|
|
i =>
|
|
|
|
i.id == data.private_message_view.private_message.id &&
|
|
|
|
i.type_ == ReplyEnum.Message
|
2021-02-02 20:24:25 +00:00
|
|
|
).view as PrivateMessageView;
|
|
|
|
found.private_message.updated = combinedView.private_message.updated =
|
2020-12-24 01:58:27 +00:00
|
|
|
data.private_message_view.private_message.updated;
|
2020-09-06 16:15:25 +00:00
|
|
|
|
|
|
|
// If youre in the unread view, just remove it from the list
|
2020-12-24 01:58:27 +00:00
|
|
|
if (
|
|
|
|
this.state.unreadOrAll == UnreadOrAll.Unread &&
|
|
|
|
data.private_message_view.private_message.read
|
|
|
|
) {
|
2022-09-22 15:03:35 +00:00
|
|
|
this.setState({
|
|
|
|
messages: this.state.messages.filter(
|
|
|
|
r =>
|
|
|
|
r.private_message.id !==
|
|
|
|
data.private_message_view.private_message.id
|
|
|
|
),
|
|
|
|
});
|
|
|
|
this.setState({
|
|
|
|
combined: this.state.combined.filter(
|
|
|
|
r => r.id !== data.private_message_view.private_message.id
|
|
|
|
),
|
|
|
|
});
|
2021-02-02 20:24:25 +00:00
|
|
|
} else {
|
|
|
|
found.private_message.read = combinedView.private_message.read =
|
2020-12-24 01:58:27 +00:00
|
|
|
data.private_message_view.private_message.read;
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
2021-10-17 17:42:30 +00:00
|
|
|
this.sendUnreadCount(data.private_message_view.private_message.read);
|
2020-09-06 16:15:25 +00:00
|
|
|
this.setState(this.state);
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.MarkAllAsRead) {
|
2020-09-06 16:15:25 +00:00
|
|
|
// Moved to be instant
|
|
|
|
} else if (
|
2020-12-24 01:58:27 +00:00
|
|
|
op == UserOperation.EditComment ||
|
|
|
|
op == UserOperation.DeleteComment ||
|
|
|
|
op == UserOperation.RemoveComment
|
2020-09-06 16:15:25 +00:00
|
|
|
) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let data = wsJsonToRes<CommentResponse>(msg, CommentResponse);
|
2020-12-24 01:58:27 +00:00
|
|
|
editCommentRes(data.comment_view, this.state.replies);
|
2020-09-06 16:15:25 +00:00
|
|
|
this.setState(this.state);
|
2022-07-30 13:28:08 +00:00
|
|
|
} else if (op == UserOperation.MarkCommentReplyAsRead) {
|
|
|
|
let data = wsJsonToRes<CommentReplyResponse>(msg, CommentReplyResponse);
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2022-07-30 13:28:08 +00:00
|
|
|
let found = this.state.replies.find(
|
|
|
|
c => c.comment_reply.id == data.comment_reply_view.comment_reply.id
|
|
|
|
);
|
|
|
|
|
|
|
|
if (found) {
|
2021-02-02 20:24:25 +00:00
|
|
|
let combinedView = this.state.combined.find(
|
2022-09-22 15:03:35 +00:00
|
|
|
i =>
|
|
|
|
i.id == data.comment_reply_view.comment_reply.id &&
|
|
|
|
i.type_ == ReplyEnum.Reply
|
2022-07-30 13:28:08 +00:00
|
|
|
).view as CommentReplyView;
|
|
|
|
found.comment.content = combinedView.comment.content =
|
|
|
|
data.comment_reply_view.comment.content;
|
|
|
|
found.comment.updated = combinedView.comment.updated =
|
|
|
|
data.comment_reply_view.comment.updated;
|
|
|
|
found.comment.removed = combinedView.comment.removed =
|
|
|
|
data.comment_reply_view.comment.removed;
|
|
|
|
found.comment.deleted = combinedView.comment.deleted =
|
|
|
|
data.comment_reply_view.comment.deleted;
|
|
|
|
found.counts.upvotes = combinedView.counts.upvotes =
|
|
|
|
data.comment_reply_view.counts.upvotes;
|
|
|
|
found.counts.downvotes = combinedView.counts.downvotes =
|
|
|
|
data.comment_reply_view.counts.downvotes;
|
|
|
|
found.counts.score = combinedView.counts.score =
|
|
|
|
data.comment_reply_view.counts.score;
|
2021-10-17 17:42:30 +00:00
|
|
|
|
2022-07-30 13:28:08 +00:00
|
|
|
// If youre in the unread view, just remove it from the list
|
|
|
|
if (
|
|
|
|
this.state.unreadOrAll == UnreadOrAll.Unread &&
|
|
|
|
data.comment_reply_view.comment_reply.read
|
|
|
|
) {
|
2022-09-22 15:03:35 +00:00
|
|
|
this.setState({
|
|
|
|
replies: this.state.replies.filter(
|
|
|
|
r =>
|
|
|
|
r.comment_reply.id !== data.comment_reply_view.comment_reply.id
|
|
|
|
),
|
|
|
|
});
|
|
|
|
this.setState({
|
|
|
|
combined: this.state.combined.filter(
|
|
|
|
r => r.id !== data.comment_reply_view.comment_reply.id
|
|
|
|
),
|
|
|
|
});
|
2022-07-30 13:28:08 +00:00
|
|
|
} else {
|
|
|
|
found.comment_reply.read = combinedView.comment_reply.read =
|
|
|
|
data.comment_reply_view.comment_reply.read;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.sendUnreadCount(data.comment_reply_view.comment_reply.read);
|
2020-09-06 16:15:25 +00:00
|
|
|
this.setState(this.state);
|
2021-03-15 18:09:31 +00:00
|
|
|
} else if (op == UserOperation.MarkPersonMentionAsRead) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let data = wsJsonToRes<PersonMentionResponse>(msg, PersonMentionResponse);
|
2020-12-24 01:58:27 +00:00
|
|
|
|
|
|
|
// TODO this might not be correct, it might need to use the comment id
|
|
|
|
let found = this.state.mentions.find(
|
2021-03-15 18:09:31 +00:00
|
|
|
c => c.person_mention.id == data.person_mention_view.person_mention.id
|
2020-12-24 01:58:27 +00:00
|
|
|
);
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2021-02-02 20:24:25 +00:00
|
|
|
if (found) {
|
|
|
|
let combinedView = this.state.combined.find(
|
2022-09-22 15:03:35 +00:00
|
|
|
i =>
|
|
|
|
i.id == data.person_mention_view.person_mention.id &&
|
|
|
|
i.type_ == ReplyEnum.Mention
|
2021-03-15 18:09:31 +00:00
|
|
|
).view as PersonMentionView;
|
2021-02-02 20:24:25 +00:00
|
|
|
found.comment.content = combinedView.comment.content =
|
2021-03-15 18:09:31 +00:00
|
|
|
data.person_mention_view.comment.content;
|
2021-02-02 20:24:25 +00:00
|
|
|
found.comment.updated = combinedView.comment.updated =
|
2021-03-15 18:09:31 +00:00
|
|
|
data.person_mention_view.comment.updated;
|
2021-02-02 20:24:25 +00:00
|
|
|
found.comment.removed = combinedView.comment.removed =
|
2021-03-15 18:09:31 +00:00
|
|
|
data.person_mention_view.comment.removed;
|
2021-02-02 20:24:25 +00:00
|
|
|
found.comment.deleted = combinedView.comment.deleted =
|
2021-03-15 18:09:31 +00:00
|
|
|
data.person_mention_view.comment.deleted;
|
2021-02-02 20:24:25 +00:00
|
|
|
found.counts.upvotes = combinedView.counts.upvotes =
|
2021-03-15 18:09:31 +00:00
|
|
|
data.person_mention_view.counts.upvotes;
|
2021-02-02 20:24:25 +00:00
|
|
|
found.counts.downvotes = combinedView.counts.downvotes =
|
2021-03-15 18:09:31 +00:00
|
|
|
data.person_mention_view.counts.downvotes;
|
2021-02-02 20:24:25 +00:00
|
|
|
found.counts.score = combinedView.counts.score =
|
2021-03-15 18:09:31 +00:00
|
|
|
data.person_mention_view.counts.score;
|
2021-02-02 20:24:25 +00:00
|
|
|
|
|
|
|
// If youre in the unread view, just remove it from the list
|
|
|
|
if (
|
|
|
|
this.state.unreadOrAll == UnreadOrAll.Unread &&
|
2021-03-15 18:09:31 +00:00
|
|
|
data.person_mention_view.person_mention.read
|
2021-02-02 20:24:25 +00:00
|
|
|
) {
|
2022-09-22 15:03:35 +00:00
|
|
|
this.setState({
|
|
|
|
mentions: this.state.mentions.filter(
|
|
|
|
r =>
|
|
|
|
r.person_mention.id !==
|
|
|
|
data.person_mention_view.person_mention.id
|
|
|
|
),
|
|
|
|
});
|
|
|
|
this.setState({
|
|
|
|
combined: this.state.combined.filter(
|
|
|
|
r => r.id !== data.person_mention_view.person_mention.id
|
|
|
|
),
|
|
|
|
});
|
2021-02-02 20:24:25 +00:00
|
|
|
} else {
|
|
|
|
// TODO test to make sure these mentions are getting marked as read
|
2021-03-15 18:09:31 +00:00
|
|
|
found.person_mention.read = combinedView.person_mention.read =
|
|
|
|
data.person_mention_view.person_mention.read;
|
2021-02-02 20:24:25 +00:00
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
2021-10-17 17:42:30 +00:00
|
|
|
this.sendUnreadCount(data.person_mention_view.person_mention.read);
|
2020-09-06 16:15:25 +00:00
|
|
|
this.setState(this.state);
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.CreatePrivateMessage) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let data = wsJsonToRes<PrivateMessageResponse>(
|
|
|
|
msg,
|
|
|
|
PrivateMessageResponse
|
|
|
|
);
|
|
|
|
UserService.Instance.myUserInfo.match({
|
|
|
|
some: mui => {
|
|
|
|
if (
|
|
|
|
data.private_message_view.recipient.id ==
|
|
|
|
mui.local_user_view.person.id
|
|
|
|
) {
|
|
|
|
this.state.messages.unshift(data.private_message_view);
|
|
|
|
this.state.combined.unshift(
|
|
|
|
this.messageToReplyType(data.private_message_view)
|
|
|
|
);
|
|
|
|
this.setState(this.state);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
none: void 0,
|
|
|
|
});
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.SaveComment) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let data = wsJsonToRes<CommentResponse>(msg, CommentResponse);
|
2020-12-24 01:58:27 +00:00
|
|
|
saveCommentRes(data.comment_view, this.state.replies);
|
2020-09-06 16:15:25 +00:00
|
|
|
this.setState(this.state);
|
|
|
|
setupTippy();
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.CreateCommentLike) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let data = wsJsonToRes<CommentResponse>(msg, CommentResponse);
|
2020-12-24 01:58:27 +00:00
|
|
|
createCommentLikeRes(data.comment_view, this.state.replies);
|
2020-09-06 16:15:25 +00:00
|
|
|
this.setState(this.state);
|
2021-08-20 02:56:18 +00:00
|
|
|
} else if (op == UserOperation.BlockPerson) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let data = wsJsonToRes<BlockPersonResponse>(msg, BlockPersonResponse);
|
2021-08-20 02:56:18 +00:00
|
|
|
updatePersonBlock(data);
|
2021-09-28 10:38:59 +00:00
|
|
|
} else if (op == UserOperation.CreatePostReport) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let data = wsJsonToRes<PostReportResponse>(msg, PostReportResponse);
|
2021-09-28 10:38:59 +00:00
|
|
|
if (data) {
|
|
|
|
toast(i18n.t("report_created"));
|
|
|
|
}
|
|
|
|
} else if (op == UserOperation.CreateCommentReport) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let data = wsJsonToRes<CommentReportResponse>(msg, CommentReportResponse);
|
2021-09-28 10:38:59 +00:00
|
|
|
if (data) {
|
|
|
|
toast(i18n.t("report_created"));
|
|
|
|
}
|
2022-09-28 12:50:47 +00:00
|
|
|
} else if (op == UserOperation.CreatePrivateMessageReport) {
|
|
|
|
let data = wsJsonToRes<PrivateMessageReportResponse>(
|
|
|
|
msg,
|
|
|
|
PrivateMessageReportResponse
|
|
|
|
);
|
|
|
|
if (data) {
|
|
|
|
toast(i18n.t("report_created"));
|
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-12 17:01:49 +00:00
|
|
|
isMention(view: any): view is PersonMentionView {
|
|
|
|
return (view as PersonMentionView).person_mention !== undefined;
|
|
|
|
}
|
2022-07-30 13:28:08 +00:00
|
|
|
|
|
|
|
isReply(view: any): view is CommentReplyView {
|
|
|
|
return (view as CommentReplyView).comment_reply !== undefined;
|
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|