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 {
|
2023-05-30 00:40:00 +00:00
|
|
|
WithPromiseKeys,
|
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
|
|
|
}
|
|
|
|
|
2023-05-30 00:40:00 +00:00
|
|
|
interface ReportsData {
|
|
|
|
commentReportsResponse: ListCommentReportsResponse;
|
|
|
|
postReportsResponse: ListPostReportsResponse;
|
|
|
|
privateMessageReportsResponse?: ListPrivateMessageReportsResponse;
|
|
|
|
}
|
|
|
|
|
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-05-30 00:40:00 +00:00
|
|
|
private isoData = setIsoData<ReportsData>(this.context);
|
2023-01-04 16:56:24 +00:00
|
|
|
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
|
2023-05-30 00:40:00 +00:00
|
|
|
if (this.isoData.path === this.context.router.route.match.url) {
|
|
|
|
const {
|
|
|
|
commentReportsResponse,
|
|
|
|
postReportsResponse,
|
|
|
|
privateMessageReportsResponse,
|
|
|
|
} = this.isoData.routeData;
|
|
|
|
|
2022-09-22 15:03:35 +00:00
|
|
|
this.state = {
|
|
|
|
...this.state,
|
2023-05-30 00:40:00 +00:00
|
|
|
listCommentReportsResponse: commentReportsResponse,
|
|
|
|
listPostReportsResponse: postReportsResponse,
|
|
|
|
listPrivateMessageReportsResponse: privateMessageReportsResponse,
|
2022-09-22 15:03:35 +00:00
|
|
|
};
|
2023-05-30 00:40:00 +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-01-04 16:56:24 +00:00
|
|
|
let mui = UserService.Instance.myUserInfo;
|
|
|
|
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));
|
|
|
|
let comments =
|
|
|
|
this.state.listCommentReportsResponse?.comment_reports.map(
|
|
|
|
this.commentReportToItemType
|
|
|
|
) ?? [];
|
|
|
|
let posts =
|
|
|
|
this.state.listPostReportsResponse?.post_reports.map(
|
|
|
|
this.postReportToItemType
|
|
|
|
) ?? [];
|
|
|
|
let privateMessages =
|
|
|
|
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-01-04 16:56:24 +00:00
|
|
|
let reports = this.state.listCommentReportsResponse?.comment_reports;
|
|
|
|
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-01-04 16:56:24 +00:00
|
|
|
let reports = this.state.listPostReportsResponse?.post_reports;
|
|
|
|
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-01-04 16:56:24 +00:00
|
|
|
let reports =
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2023-05-30 00:40:00 +00:00
|
|
|
static fetchInitialData({
|
|
|
|
auth,
|
|
|
|
client,
|
|
|
|
}: InitialFetchRequest): WithPromiseKeys<ReportsData> {
|
|
|
|
const unresolved_only = true;
|
|
|
|
const page = 1;
|
|
|
|
const limit = fetchLimit;
|
|
|
|
|
|
|
|
const commentReportsForm: ListCommentReports = {
|
|
|
|
unresolved_only,
|
|
|
|
page,
|
|
|
|
limit,
|
|
|
|
auth: auth as string,
|
|
|
|
};
|
2021-09-28 10:38:59 +00:00
|
|
|
|
2023-05-30 00:40:00 +00:00
|
|
|
const postReportsForm: ListPostReports = {
|
|
|
|
unresolved_only,
|
|
|
|
page,
|
|
|
|
limit,
|
|
|
|
auth: auth as string,
|
|
|
|
};
|
2023-01-04 16:56:24 +00:00
|
|
|
|
2023-05-30 00:40:00 +00:00
|
|
|
const data: WithPromiseKeys<ReportsData> = {
|
|
|
|
commentReportsResponse: client.listCommentReports(commentReportsForm),
|
|
|
|
postReportsResponse: client.listPostReports(postReportsForm),
|
|
|
|
};
|
2023-01-04 16:56:24 +00:00
|
|
|
|
2023-05-30 00:40:00 +00:00
|
|
|
if (amAdmin()) {
|
|
|
|
const privateMessageReportsForm: ListPrivateMessageReports = {
|
2023-01-04 16:56:24 +00:00
|
|
|
unresolved_only,
|
|
|
|
page,
|
|
|
|
limit,
|
2023-05-30 00:40:00 +00:00
|
|
|
auth: auth as string,
|
2023-01-04 16:56:24 +00:00
|
|
|
};
|
|
|
|
|
2023-05-30 00:40:00 +00:00
|
|
|
data.privateMessageReportsResponse = client.listPrivateMessageReports(
|
|
|
|
privateMessageReportsForm
|
|
|
|
);
|
2022-09-28 12:50:47 +00:00
|
|
|
}
|
|
|
|
|
2023-05-30 00:40:00 +00:00
|
|
|
return data;
|
2021-09-28 10:38:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
refetch() {
|
2023-05-30 00:40:00 +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-05-30 00:40:00 +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,
|
|
|
|
};
|
2023-05-30 00:40:00 +00:00
|
|
|
|
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-05-30 00:40:00 +00:00
|
|
|
const postReportsForm: ListPostReports = {
|
2023-01-04 16:56:24 +00:00
|
|
|
unresolved_only,
|
|
|
|
page,
|
|
|
|
limit,
|
|
|
|
auth,
|
|
|
|
};
|
2023-05-30 00:40:00 +00:00
|
|
|
|
2023-01-04 16:56:24 +00:00
|
|
|
WebSocketService.Instance.send(wsClient.listPostReports(postReportsForm));
|
|
|
|
|
|
|
|
if (amAdmin()) {
|
2023-05-30 00:40:00 +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) {
|
|
|
|
let op = wsUserOp(msg);
|
|
|
|
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-01-04 16:56:24 +00:00
|
|
|
let data = wsJsonToRes<ListCommentReportsResponse>(msg);
|
|
|
|
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-01-04 16:56:24 +00:00
|
|
|
let data = wsJsonToRes<ListPostReportsResponse>(msg);
|
|
|
|
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-01-04 16:56:24 +00:00
|
|
|
let data = wsJsonToRes<ListPrivateMessageReportsResponse>(msg);
|
|
|
|
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-01-04 16:56:24 +00:00
|
|
|
let 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
|
|
|
);
|
2021-09-28 10:38:59 +00:00
|
|
|
let urcs = UserService.Instance.unreadReportCountSub;
|
|
|
|
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-01-04 16:56:24 +00:00
|
|
|
let 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
|
|
|
);
|
|
|
|
let urcs = UserService.Instance.unreadReportCountSub;
|
|
|
|
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-01-04 16:56:24 +00:00
|
|
|
let 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
|
|
|
);
|
|
|
|
let urcs = UserService.Instance.unreadReportCountSub;
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|