2021-09-28 10:38:59 +00:00
|
|
|
import { Component, linkEvent } from "inferno";
|
|
|
|
import {
|
|
|
|
CommentReportResponse,
|
|
|
|
CommentReportView,
|
2022-06-21 21:42:29 +00:00
|
|
|
GetSiteResponse,
|
2021-09-28 10:38:59 +00:00
|
|
|
ListCommentReports,
|
|
|
|
ListCommentReportsResponse,
|
|
|
|
ListPostReports,
|
|
|
|
ListPostReportsResponse,
|
2022-09-28 12:50:47 +00:00
|
|
|
ListPrivateMessageReports,
|
|
|
|
ListPrivateMessageReportsResponse,
|
2021-09-28 10:38:59 +00:00
|
|
|
PostReportResponse,
|
|
|
|
PostReportView,
|
2022-09-28 12:50:47 +00:00
|
|
|
PrivateMessageReportResponse,
|
|
|
|
PrivateMessageReportView,
|
2021-09-28 10:38:59 +00:00
|
|
|
UserOperation,
|
2022-06-21 21:42:29 +00:00
|
|
|
wsJsonToRes,
|
|
|
|
wsUserOp,
|
2021-09-28 10:38:59 +00:00
|
|
|
} from "lemmy-js-client";
|
|
|
|
import { Subscription } from "rxjs";
|
|
|
|
import { i18n } from "../../i18next";
|
|
|
|
import { InitialFetchRequest } from "../../interfaces";
|
|
|
|
import { UserService, WebSocketService } from "../../services";
|
|
|
|
import {
|
2022-09-28 12:50:47 +00:00
|
|
|
amAdmin,
|
2021-09-28 10:38:59 +00:00
|
|
|
fetchLimit,
|
|
|
|
isBrowser,
|
2023-01-04 16:56:24 +00:00
|
|
|
myAuth,
|
2021-09-28 10:38:59 +00:00
|
|
|
setIsoData,
|
|
|
|
setupTippy,
|
|
|
|
toast,
|
|
|
|
updateCommentReportRes,
|
|
|
|
updatePostReportRes,
|
2022-09-28 12:50:47 +00:00
|
|
|
updatePrivateMessageReportRes,
|
2021-09-28 10:38:59 +00:00
|
|
|
wsClient,
|
|
|
|
wsSubscribe,
|
|
|
|
} from "../../utils";
|
2021-12-30 15:26:45 +00:00
|
|
|
import { CommentReport } from "../comment/comment-report";
|
2021-09-28 10:38:59 +00:00
|
|
|
import { HtmlTags } from "../common/html-tags";
|
|
|
|
import { Spinner } from "../common/icon";
|
|
|
|
import { Paginator } from "../common/paginator";
|
2021-12-30 15:26:45 +00:00
|
|
|
import { PostReport } from "../post/post-report";
|
2022-09-28 12:50:47 +00:00
|
|
|
import { PrivateMessageReport } from "../private_message/private-message-report";
|
2021-09-28 10:38:59 +00:00
|
|
|
|
|
|
|
enum UnreadOrAll {
|
|
|
|
Unread,
|
|
|
|
All,
|
|
|
|
}
|
|
|
|
|
|
|
|
enum MessageType {
|
|
|
|
All,
|
|
|
|
CommentReport,
|
|
|
|
PostReport,
|
2022-09-28 12:50:47 +00:00
|
|
|
PrivateMessageReport,
|
2021-09-28 10:38:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
enum MessageEnum {
|
|
|
|
CommentReport,
|
|
|
|
PostReport,
|
2022-09-28 12:50:47 +00:00
|
|
|
PrivateMessageReport,
|
2021-09-28 10:38:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type ItemType = {
|
|
|
|
id: number;
|
|
|
|
type_: MessageEnum;
|
2022-09-28 12:50:47 +00:00
|
|
|
view: CommentReportView | PostReportView | PrivateMessageReportView;
|
2021-09-28 10:38:59 +00:00
|
|
|
published: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
interface ReportsState {
|
2023-01-04 16:56:24 +00:00
|
|
|
listCommentReportsResponse?: ListCommentReportsResponse;
|
|
|
|
listPostReportsResponse?: ListPostReportsResponse;
|
|
|
|
listPrivateMessageReportsResponse?: ListPrivateMessageReportsResponse;
|
2021-09-28 10:38:59 +00:00
|
|
|
unreadOrAll: UnreadOrAll;
|
|
|
|
messageType: MessageType;
|
|
|
|
combined: ItemType[];
|
2022-06-21 21:42:29 +00:00
|
|
|
siteRes: GetSiteResponse;
|
2023-05-15 19:53:29 +00:00
|
|
|
page: number;
|
2021-09-28 10:38:59 +00:00
|
|
|
loading: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
export class Reports extends Component<any, ReportsState> {
|
2023-01-04 16:56:24 +00:00
|
|
|
private isoData = setIsoData(this.context);
|
|
|
|
private subscription?: Subscription;
|
|
|
|
state: ReportsState = {
|
2021-09-28 10:38:59 +00:00
|
|
|
unreadOrAll: UnreadOrAll.Unread,
|
|
|
|
messageType: MessageType.All,
|
|
|
|
combined: [],
|
2023-05-15 19:53:29 +00:00
|
|
|
page: 1,
|
2022-06-21 21:42:29 +00:00
|
|
|
siteRes: this.isoData.site_res,
|
2021-09-28 10:38:59 +00:00
|
|
|
loading: true,
|
|
|
|
};
|
|
|
|
|
|
|
|
constructor(props: any, context: any) {
|
|
|
|
super(props, context);
|
|
|
|
|
|
|
|
this.handlePageChange = this.handlePageChange.bind(this);
|
|
|
|
|
|
|
|
this.parseMessage = this.parseMessage.bind(this);
|
|
|
|
this.subscription = wsSubscribe(this.parseMessage);
|
|
|
|
|
|
|
|
// 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,
|
2023-01-04 16:56:24 +00:00
|
|
|
listCommentReportsResponse: this.isoData
|
|
|
|
.routeData[0] as ListCommentReportsResponse,
|
|
|
|
listPostReportsResponse: this.isoData
|
|
|
|
.routeData[1] as ListPostReportsResponse,
|
2022-09-22 15:03:35 +00:00
|
|
|
};
|
2022-09-28 12:50:47 +00:00
|
|
|
if (amAdmin()) {
|
|
|
|
this.state = {
|
|
|
|
...this.state,
|
2023-01-04 16:56:24 +00:00
|
|
|
listPrivateMessageReportsResponse: this.isoData
|
|
|
|
.routeData[2] as ListPrivateMessageReportsResponse,
|
2022-09-28 12:50:47 +00:00
|
|
|
};
|
|
|
|
}
|
2022-09-22 15:03:35 +00:00
|
|
|
this.state = {
|
|
|
|
...this.state,
|
|
|
|
combined: this.buildCombined(),
|
|
|
|
loading: false,
|
|
|
|
};
|
2021-09-28 10:38:59 +00:00
|
|
|
} else {
|
|
|
|
this.refetch();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
if (isBrowser()) {
|
2023-01-04 16:56:24 +00:00
|
|
|
this.subscription?.unsubscribe();
|
2021-09-28 10:38:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
get documentTitle(): string {
|
2023-06-05 21:31:12 +00:00
|
|
|
const mui = UserService.Instance.myUserInfo;
|
2023-01-04 16:56:24 +00:00
|
|
|
return mui
|
|
|
|
? `@${mui.local_user_view.person.name} ${i18n.t("reports")} - ${
|
2022-11-09 19:53:07 +00:00
|
|
|
this.state.siteRes.site_view.site.name
|
2023-01-04 16:56:24 +00:00
|
|
|
}`
|
|
|
|
: "";
|
2021-09-28 10:38:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
2022-10-03 18:16:36 +00:00
|
|
|
<div className="container-lg">
|
2021-09-28 10:38:59 +00:00
|
|
|
{this.state.loading ? (
|
|
|
|
<h5>
|
|
|
|
<Spinner large />
|
|
|
|
</h5>
|
|
|
|
) : (
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="row">
|
|
|
|
<div className="col-12">
|
2021-09-28 10:38:59 +00:00
|
|
|
<HtmlTags
|
|
|
|
title={this.documentTitle}
|
|
|
|
path={this.context.router.route.match.url}
|
|
|
|
/>
|
2022-09-22 15:03:35 +00:00
|
|
|
<h5 className="mb-2">{i18n.t("reports")}</h5>
|
2021-09-28 10:38:59 +00:00
|
|
|
{this.selects()}
|
|
|
|
{this.state.messageType == MessageType.All && this.all()}
|
|
|
|
{this.state.messageType == MessageType.CommentReport &&
|
|
|
|
this.commentReports()}
|
|
|
|
{this.state.messageType == MessageType.PostReport &&
|
|
|
|
this.postReports()}
|
2022-09-28 12:50:47 +00:00
|
|
|
{this.state.messageType == MessageType.PrivateMessageReport &&
|
|
|
|
this.privateMessageReports()}
|
2021-09-28 10:38:59 +00:00
|
|
|
<Paginator
|
|
|
|
page={this.state.page}
|
|
|
|
onChange={this.handlePageChange}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
unreadOrAllRadios() {
|
|
|
|
return (
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="btn-group btn-group-toggle flex-wrap mb-2">
|
2021-09-28 10:38:59 +00:00
|
|
|
<label
|
|
|
|
className={`btn btn-outline-secondary pointer
|
|
|
|
${this.state.unreadOrAll == UnreadOrAll.Unread && "active"}
|
|
|
|
`}
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
value={UnreadOrAll.Unread}
|
|
|
|
checked={this.state.unreadOrAll == UnreadOrAll.Unread}
|
|
|
|
onChange={linkEvent(this, this.handleUnreadOrAllChange)}
|
|
|
|
/>
|
|
|
|
{i18n.t("unread")}
|
|
|
|
</label>
|
|
|
|
<label
|
|
|
|
className={`btn btn-outline-secondary pointer
|
|
|
|
${this.state.unreadOrAll == UnreadOrAll.All && "active"}
|
|
|
|
`}
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
value={UnreadOrAll.All}
|
|
|
|
checked={this.state.unreadOrAll == UnreadOrAll.All}
|
|
|
|
onChange={linkEvent(this, this.handleUnreadOrAllChange)}
|
|
|
|
/>
|
|
|
|
{i18n.t("all")}
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
messageTypeRadios() {
|
|
|
|
return (
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="btn-group btn-group-toggle flex-wrap mb-2">
|
2021-09-28 10:38:59 +00:00
|
|
|
<label
|
|
|
|
className={`btn btn-outline-secondary pointer
|
|
|
|
${this.state.messageType == MessageType.All && "active"}
|
|
|
|
`}
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
value={MessageType.All}
|
|
|
|
checked={this.state.messageType == MessageType.All}
|
|
|
|
onChange={linkEvent(this, this.handleMessageTypeChange)}
|
|
|
|
/>
|
|
|
|
{i18n.t("all")}
|
|
|
|
</label>
|
|
|
|
<label
|
|
|
|
className={`btn btn-outline-secondary pointer
|
|
|
|
${this.state.messageType == MessageType.CommentReport && "active"}
|
|
|
|
`}
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
value={MessageType.CommentReport}
|
|
|
|
checked={this.state.messageType == MessageType.CommentReport}
|
|
|
|
onChange={linkEvent(this, this.handleMessageTypeChange)}
|
|
|
|
/>
|
|
|
|
{i18n.t("comments")}
|
|
|
|
</label>
|
|
|
|
<label
|
|
|
|
className={`btn btn-outline-secondary pointer
|
|
|
|
${this.state.messageType == MessageType.PostReport && "active"}
|
|
|
|
`}
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
value={MessageType.PostReport}
|
|
|
|
checked={this.state.messageType == MessageType.PostReport}
|
|
|
|
onChange={linkEvent(this, this.handleMessageTypeChange)}
|
|
|
|
/>
|
|
|
|
{i18n.t("posts")}
|
|
|
|
</label>
|
2022-09-28 12:50:47 +00:00
|
|
|
{amAdmin() && (
|
|
|
|
<label
|
|
|
|
className={`btn btn-outline-secondary pointer
|
|
|
|
${
|
|
|
|
this.state.messageType == MessageType.PrivateMessageReport &&
|
|
|
|
"active"
|
|
|
|
}
|
|
|
|
`}
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
value={MessageType.PrivateMessageReport}
|
|
|
|
checked={
|
|
|
|
this.state.messageType == MessageType.PrivateMessageReport
|
|
|
|
}
|
|
|
|
onChange={linkEvent(this, this.handleMessageTypeChange)}
|
|
|
|
/>
|
|
|
|
{i18n.t("messages")}
|
|
|
|
</label>
|
|
|
|
)}
|
2021-09-28 10:38:59 +00:00
|
|
|
</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>
|
2021-09-28 10:38:59 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-09-28 12:50:47 +00:00
|
|
|
commentReportToItemType(r: CommentReportView): ItemType {
|
2021-09-28 10:38:59 +00:00
|
|
|
return {
|
|
|
|
id: r.comment_report.id,
|
|
|
|
type_: MessageEnum.CommentReport,
|
|
|
|
view: r,
|
|
|
|
published: r.comment_report.published,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-09-28 12:50:47 +00:00
|
|
|
postReportToItemType(r: PostReportView): ItemType {
|
2021-09-28 10:38:59 +00:00
|
|
|
return {
|
|
|
|
id: r.post_report.id,
|
|
|
|
type_: MessageEnum.PostReport,
|
|
|
|
view: r,
|
|
|
|
published: r.post_report.published,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-09-28 12:50:47 +00:00
|
|
|
privateMessageReportToItemType(r: PrivateMessageReportView): ItemType {
|
|
|
|
return {
|
|
|
|
id: r.private_message_report.id,
|
|
|
|
type_: MessageEnum.PrivateMessageReport,
|
|
|
|
view: r,
|
|
|
|
published: r.private_message_report.published,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-09-28 10:38:59 +00:00
|
|
|
buildCombined(): ItemType[] {
|
2023-01-04 16:56:24 +00:00
|
|
|
// let comments: ItemType[] = this.state.listCommentReportsResponse
|
|
|
|
// .map(r => r.comment_reports)
|
|
|
|
// .unwrapOr([])
|
|
|
|
// .map(r => this.commentReportToItemType(r));
|
2023-06-05 21:31:12 +00:00
|
|
|
const comments =
|
2023-01-04 16:56:24 +00:00
|
|
|
this.state.listCommentReportsResponse?.comment_reports.map(
|
|
|
|
this.commentReportToItemType
|
|
|
|
) ?? [];
|
2023-06-05 21:31:12 +00:00
|
|
|
const posts =
|
2023-01-04 16:56:24 +00:00
|
|
|
this.state.listPostReportsResponse?.post_reports.map(
|
|
|
|
this.postReportToItemType
|
|
|
|
) ?? [];
|
2023-06-05 21:31:12 +00:00
|
|
|
const privateMessages =
|
2023-01-04 16:56:24 +00:00
|
|
|
this.state.listPrivateMessageReportsResponse?.private_message_reports.map(
|
|
|
|
this.privateMessageReportToItemType
|
|
|
|
) ?? [];
|
2022-09-28 12:50:47 +00:00
|
|
|
|
|
|
|
return [...comments, ...posts, ...privateMessages].sort((a, b) =>
|
2021-09-28 10:38:59 +00:00
|
|
|
b.published.localeCompare(a.published)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderItemType(i: ItemType) {
|
|
|
|
switch (i.type_) {
|
|
|
|
case MessageEnum.CommentReport:
|
|
|
|
return (
|
|
|
|
<CommentReport key={i.id} report={i.view as CommentReportView} />
|
|
|
|
);
|
|
|
|
case MessageEnum.PostReport:
|
|
|
|
return <PostReport key={i.id} report={i.view as PostReportView} />;
|
2022-09-28 12:50:47 +00:00
|
|
|
case MessageEnum.PrivateMessageReport:
|
|
|
|
return (
|
|
|
|
<PrivateMessageReport
|
|
|
|
key={i.id}
|
|
|
|
report={i.view as PrivateMessageReportView}
|
|
|
|
/>
|
|
|
|
);
|
2021-09-28 10:38:59 +00:00
|
|
|
default:
|
|
|
|
return <div />;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
all() {
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
{this.state.combined.map(i => (
|
|
|
|
<>
|
|
|
|
<hr />
|
|
|
|
{this.renderItemType(i)}
|
|
|
|
</>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
commentReports() {
|
2023-06-05 21:31:12 +00:00
|
|
|
const reports = this.state.listCommentReportsResponse?.comment_reports;
|
2023-01-04 16:56:24 +00:00
|
|
|
return (
|
|
|
|
reports && (
|
2022-06-21 21:42:29 +00:00
|
|
|
<div>
|
2023-01-04 16:56:24 +00:00
|
|
|
{reports.map(cr => (
|
2022-06-21 21:42:29 +00:00
|
|
|
<>
|
|
|
|
<hr />
|
|
|
|
<CommentReport key={cr.comment_report.id} report={cr} />
|
|
|
|
</>
|
|
|
|
))}
|
|
|
|
</div>
|
2023-01-04 16:56:24 +00:00
|
|
|
)
|
|
|
|
);
|
2021-09-28 10:38:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
postReports() {
|
2023-06-05 21:31:12 +00:00
|
|
|
const reports = this.state.listPostReportsResponse?.post_reports;
|
2023-01-04 16:56:24 +00:00
|
|
|
return (
|
|
|
|
reports && (
|
2022-06-21 21:42:29 +00:00
|
|
|
<div>
|
2023-01-04 16:56:24 +00:00
|
|
|
{reports.map(pr => (
|
2022-06-21 21:42:29 +00:00
|
|
|
<>
|
|
|
|
<hr />
|
|
|
|
<PostReport key={pr.post_report.id} report={pr} />
|
|
|
|
</>
|
|
|
|
))}
|
|
|
|
</div>
|
2023-01-04 16:56:24 +00:00
|
|
|
)
|
|
|
|
);
|
2021-09-28 10:38:59 +00:00
|
|
|
}
|
|
|
|
|
2022-09-28 12:50:47 +00:00
|
|
|
privateMessageReports() {
|
2023-06-05 21:31:12 +00:00
|
|
|
const reports =
|
2023-01-04 16:56:24 +00:00
|
|
|
this.state.listPrivateMessageReportsResponse?.private_message_reports;
|
|
|
|
return (
|
|
|
|
reports && (
|
2022-09-28 12:50:47 +00:00
|
|
|
<div>
|
2023-01-04 16:56:24 +00:00
|
|
|
{reports.map(pmr => (
|
2022-09-28 12:50:47 +00:00
|
|
|
<>
|
|
|
|
<hr />
|
|
|
|
<PrivateMessageReport
|
|
|
|
key={pmr.private_message_report.id}
|
|
|
|
report={pmr}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
))}
|
|
|
|
</div>
|
2023-01-04 16:56:24 +00:00
|
|
|
)
|
|
|
|
);
|
2022-09-28 12:50:47 +00:00
|
|
|
}
|
|
|
|
|
2023-05-15 19:53:29 +00:00
|
|
|
handlePageChange(page: number) {
|
2021-09-28 10:38:59 +00:00
|
|
|
this.setState({ page });
|
|
|
|
this.refetch();
|
|
|
|
}
|
|
|
|
|
|
|
|
handleUnreadOrAllChange(i: Reports, event: any) {
|
2023-05-15 19:53:29 +00:00
|
|
|
i.setState({ unreadOrAll: Number(event.target.value), page: 1 });
|
2021-09-28 10:38:59 +00:00
|
|
|
i.refetch();
|
|
|
|
}
|
|
|
|
|
|
|
|
handleMessageTypeChange(i: Reports, event: any) {
|
2023-05-15 19:53:29 +00:00
|
|
|
i.setState({ messageType: Number(event.target.value), page: 1 });
|
2021-09-28 10:38:59 +00:00
|
|
|
i.refetch();
|
|
|
|
}
|
|
|
|
|
|
|
|
static fetchInitialData(req: InitialFetchRequest): Promise<any>[] {
|
2023-06-05 21:31:12 +00:00
|
|
|
const promises: Promise<any>[] = [];
|
2021-09-28 10:38:59 +00:00
|
|
|
|
2023-06-05 21:31:12 +00:00
|
|
|
const unresolved_only = true;
|
|
|
|
const page = 1;
|
|
|
|
const limit = fetchLimit;
|
|
|
|
const auth = req.auth;
|
2023-01-04 16:56:24 +00:00
|
|
|
|
|
|
|
if (auth) {
|
2023-06-05 21:31:12 +00:00
|
|
|
const commentReportsForm: ListCommentReports = {
|
2022-09-28 12:50:47 +00:00
|
|
|
unresolved_only,
|
|
|
|
page,
|
|
|
|
limit,
|
|
|
|
auth,
|
2023-01-04 16:56:24 +00:00
|
|
|
};
|
|
|
|
promises.push(req.client.listCommentReports(commentReportsForm));
|
|
|
|
|
2023-06-05 21:31:12 +00:00
|
|
|
const postReportsForm: ListPostReports = {
|
2023-01-04 16:56:24 +00:00
|
|
|
unresolved_only,
|
|
|
|
page,
|
|
|
|
limit,
|
|
|
|
auth,
|
|
|
|
};
|
|
|
|
promises.push(req.client.listPostReports(postReportsForm));
|
|
|
|
|
|
|
|
if (amAdmin()) {
|
2023-06-05 21:31:12 +00:00
|
|
|
const privateMessageReportsForm: ListPrivateMessageReports = {
|
2023-01-04 16:56:24 +00:00
|
|
|
unresolved_only,
|
|
|
|
page,
|
|
|
|
limit,
|
|
|
|
auth,
|
|
|
|
};
|
|
|
|
promises.push(
|
|
|
|
req.client.listPrivateMessageReports(privateMessageReportsForm)
|
|
|
|
);
|
|
|
|
}
|
2022-09-28 12:50:47 +00:00
|
|
|
}
|
|
|
|
|
2021-09-28 10:38:59 +00:00
|
|
|
return promises;
|
|
|
|
}
|
|
|
|
|
|
|
|
refetch() {
|
2023-06-05 21:31:12 +00:00
|
|
|
const unresolved_only = this.state.unreadOrAll == UnreadOrAll.Unread;
|
|
|
|
const page = this.state.page;
|
|
|
|
const limit = fetchLimit;
|
|
|
|
const auth = myAuth();
|
2023-01-04 16:56:24 +00:00
|
|
|
if (auth) {
|
2023-06-05 21:31:12 +00:00
|
|
|
const commentReportsForm: ListCommentReports = {
|
2022-09-28 12:50:47 +00:00
|
|
|
unresolved_only,
|
|
|
|
page,
|
|
|
|
limit,
|
2023-01-04 16:56:24 +00:00
|
|
|
auth,
|
|
|
|
};
|
2022-09-28 12:50:47 +00:00
|
|
|
WebSocketService.Instance.send(
|
2023-01-04 16:56:24 +00:00
|
|
|
wsClient.listCommentReports(commentReportsForm)
|
2022-09-28 12:50:47 +00:00
|
|
|
);
|
2023-01-04 16:56:24 +00:00
|
|
|
|
2023-06-05 21:31:12 +00:00
|
|
|
const postReportsForm: ListPostReports = {
|
2023-01-04 16:56:24 +00:00
|
|
|
unresolved_only,
|
|
|
|
page,
|
|
|
|
limit,
|
|
|
|
auth,
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.send(wsClient.listPostReports(postReportsForm));
|
|
|
|
|
|
|
|
if (amAdmin()) {
|
2023-06-05 21:31:12 +00:00
|
|
|
const privateMessageReportsForm: ListPrivateMessageReports = {
|
2023-01-04 16:56:24 +00:00
|
|
|
unresolved_only,
|
|
|
|
page,
|
|
|
|
limit,
|
|
|
|
auth,
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.send(
|
|
|
|
wsClient.listPrivateMessageReports(privateMessageReportsForm)
|
|
|
|
);
|
|
|
|
}
|
2022-09-28 12:50:47 +00:00
|
|
|
}
|
2021-09-28 10:38:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
parseMessage(msg: any) {
|
2023-06-05 21:31:12 +00:00
|
|
|
const op = wsUserOp(msg);
|
2021-09-28 10:38:59 +00:00
|
|
|
console.log(msg);
|
|
|
|
if (msg.error) {
|
|
|
|
toast(i18n.t(msg.error), "danger");
|
|
|
|
return;
|
|
|
|
} else if (msg.reconnect) {
|
|
|
|
this.refetch();
|
|
|
|
} else if (op == UserOperation.ListCommentReports) {
|
2023-06-05 21:31:12 +00:00
|
|
|
const data = wsJsonToRes<ListCommentReportsResponse>(msg);
|
2023-01-04 16:56:24 +00:00
|
|
|
this.setState({ listCommentReportsResponse: data });
|
2022-09-22 15:03:35 +00:00
|
|
|
this.setState({ combined: this.buildCombined(), loading: false });
|
2021-09-28 10:38:59 +00:00
|
|
|
// this.sendUnreadCount();
|
|
|
|
window.scrollTo(0, 0);
|
|
|
|
setupTippy();
|
|
|
|
} else if (op == UserOperation.ListPostReports) {
|
2023-06-05 21:31:12 +00:00
|
|
|
const data = wsJsonToRes<ListPostReportsResponse>(msg);
|
2023-01-04 16:56:24 +00:00
|
|
|
this.setState({ listPostReportsResponse: data });
|
2022-09-22 15:03:35 +00:00
|
|
|
this.setState({ combined: this.buildCombined(), loading: false });
|
2021-09-28 10:38:59 +00:00
|
|
|
// this.sendUnreadCount();
|
|
|
|
window.scrollTo(0, 0);
|
|
|
|
setupTippy();
|
2022-09-28 12:50:47 +00:00
|
|
|
} else if (op == UserOperation.ListPrivateMessageReports) {
|
2023-06-05 21:31:12 +00:00
|
|
|
const data = wsJsonToRes<ListPrivateMessageReportsResponse>(msg);
|
2023-01-04 16:56:24 +00:00
|
|
|
this.setState({ listPrivateMessageReportsResponse: data });
|
2022-09-28 12:50:47 +00:00
|
|
|
this.setState({ combined: this.buildCombined(), loading: false });
|
|
|
|
// this.sendUnreadCount();
|
|
|
|
window.scrollTo(0, 0);
|
|
|
|
setupTippy();
|
2021-09-28 10:38:59 +00:00
|
|
|
} else if (op == UserOperation.ResolvePostReport) {
|
2023-06-05 21:31:12 +00:00
|
|
|
const data = wsJsonToRes<PostReportResponse>(msg);
|
2022-06-21 21:42:29 +00:00
|
|
|
updatePostReportRes(
|
|
|
|
data.post_report_view,
|
2023-01-04 16:56:24 +00:00
|
|
|
this.state.listPostReportsResponse?.post_reports
|
2022-06-21 21:42:29 +00:00
|
|
|
);
|
2023-06-05 21:31:12 +00:00
|
|
|
const urcs = UserService.Instance.unreadReportCountSub;
|
2021-09-28 10:38:59 +00:00
|
|
|
if (data.post_report_view.post_report.resolved) {
|
2023-05-15 19:53:29 +00:00
|
|
|
urcs.next(urcs.getValue() - 1);
|
2021-09-28 10:38:59 +00:00
|
|
|
} else {
|
2023-05-15 19:53:29 +00:00
|
|
|
urcs.next(urcs.getValue() + 1);
|
2021-09-28 10:38:59 +00:00
|
|
|
}
|
|
|
|
this.setState(this.state);
|
|
|
|
} else if (op == UserOperation.ResolveCommentReport) {
|
2023-06-05 21:31:12 +00:00
|
|
|
const data = wsJsonToRes<CommentReportResponse>(msg);
|
2021-09-28 10:38:59 +00:00
|
|
|
updateCommentReportRes(
|
|
|
|
data.comment_report_view,
|
2023-01-04 16:56:24 +00:00
|
|
|
this.state.listCommentReportsResponse?.comment_reports
|
2021-09-28 10:38:59 +00:00
|
|
|
);
|
2023-06-05 21:31:12 +00:00
|
|
|
const urcs = UserService.Instance.unreadReportCountSub;
|
2021-09-28 10:38:59 +00:00
|
|
|
if (data.comment_report_view.comment_report.resolved) {
|
2023-05-15 19:53:29 +00:00
|
|
|
urcs.next(urcs.getValue() - 1);
|
2021-09-28 10:38:59 +00:00
|
|
|
} else {
|
2023-05-15 19:53:29 +00:00
|
|
|
urcs.next(urcs.getValue() + 1);
|
2021-09-28 10:38:59 +00:00
|
|
|
}
|
|
|
|
this.setState(this.state);
|
2022-09-28 12:50:47 +00:00
|
|
|
} else if (op == UserOperation.ResolvePrivateMessageReport) {
|
2023-06-05 21:31:12 +00:00
|
|
|
const data = wsJsonToRes<PrivateMessageReportResponse>(msg);
|
2022-09-28 12:50:47 +00:00
|
|
|
updatePrivateMessageReportRes(
|
|
|
|
data.private_message_report_view,
|
2023-01-04 16:56:24 +00:00
|
|
|
this.state.listPrivateMessageReportsResponse?.private_message_reports
|
2022-09-28 12:50:47 +00:00
|
|
|
);
|
2023-06-05 21:31:12 +00:00
|
|
|
const urcs = UserService.Instance.unreadReportCountSub;
|
2022-09-28 12:50:47 +00:00
|
|
|
if (data.private_message_report_view.private_message_report.resolved) {
|
2023-05-15 19:53:29 +00:00
|
|
|
urcs.next(urcs.getValue() - 1);
|
2022-09-28 12:50:47 +00:00
|
|
|
} else {
|
2023-05-15 19:53:29 +00:00
|
|
|
urcs.next(urcs.getValue() + 1);
|
2022-09-28 12:50:47 +00:00
|
|
|
}
|
|
|
|
this.setState(this.state);
|
2021-09-28 10:38:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|