2021-07-16 19:40:56 +00:00
|
|
|
import { Component } from "inferno";
|
2021-02-22 02:39:04 +00:00
|
|
|
import { Link } from "inferno-router";
|
2020-09-06 16:15:25 +00:00
|
|
|
import {
|
2021-07-17 20:42:55 +00:00
|
|
|
CommunityModeratorView,
|
|
|
|
GetCommunity,
|
|
|
|
GetCommunityResponse,
|
2020-12-24 01:58:27 +00:00
|
|
|
GetModlog,
|
2020-09-06 16:15:25 +00:00
|
|
|
GetModlogResponse,
|
2021-07-17 20:42:55 +00:00
|
|
|
ModAddCommunityView,
|
|
|
|
ModAddView,
|
|
|
|
ModBanFromCommunityView,
|
|
|
|
ModBanView,
|
2020-12-24 01:58:27 +00:00
|
|
|
ModLockPostView,
|
|
|
|
ModRemoveCommentView,
|
|
|
|
ModRemoveCommunityView,
|
2021-07-17 20:42:55 +00:00
|
|
|
ModRemovePostView,
|
|
|
|
ModStickyPostView,
|
2021-08-18 23:07:54 +00:00
|
|
|
ModTransferCommunityView,
|
2022-03-14 20:09:29 +00:00
|
|
|
PersonSafe,
|
2021-07-17 20:42:55 +00:00
|
|
|
SiteView,
|
|
|
|
UserOperation,
|
2021-02-22 02:39:04 +00:00
|
|
|
} from "lemmy-js-client";
|
2021-07-17 20:42:55 +00:00
|
|
|
import moment from "moment";
|
|
|
|
import { Subscription } from "rxjs";
|
|
|
|
import { i18n } from "../i18next";
|
|
|
|
import { InitialFetchRequest } from "../interfaces";
|
|
|
|
import { UserService, WebSocketService } from "../services";
|
2020-09-09 02:40:36 +00:00
|
|
|
import {
|
2021-12-30 15:26:45 +00:00
|
|
|
authField,
|
2020-09-09 02:40:36 +00:00
|
|
|
fetchLimit,
|
2021-07-17 20:42:55 +00:00
|
|
|
isBrowser,
|
2020-09-09 02:40:36 +00:00
|
|
|
setIsoData,
|
2021-12-30 15:26:45 +00:00
|
|
|
setOptionalAuth,
|
2021-07-17 20:42:55 +00:00
|
|
|
toast,
|
|
|
|
wsClient,
|
|
|
|
wsJsonToRes,
|
2020-09-09 02:40:36 +00:00
|
|
|
wsSubscribe,
|
2020-12-24 01:58:27 +00:00
|
|
|
wsUserOp,
|
2021-02-22 02:39:04 +00:00
|
|
|
} from "../utils";
|
2021-07-17 20:42:55 +00:00
|
|
|
import { HtmlTags } from "./common/html-tags";
|
|
|
|
import { Spinner } from "./common/icon";
|
|
|
|
import { MomentTime } from "./common/moment-time";
|
|
|
|
import { Paginator } from "./common/paginator";
|
|
|
|
import { CommunityLink } from "./community/community-link";
|
|
|
|
import { PersonListing } from "./person/person-listing";
|
2020-12-24 01:58:27 +00:00
|
|
|
|
|
|
|
enum ModlogEnum {
|
|
|
|
ModRemovePost,
|
|
|
|
ModLockPost,
|
|
|
|
ModStickyPost,
|
|
|
|
ModRemoveComment,
|
|
|
|
ModRemoveCommunity,
|
|
|
|
ModBanFromCommunity,
|
|
|
|
ModAddCommunity,
|
2021-08-18 23:07:54 +00:00
|
|
|
ModTransferCommunity,
|
2020-12-24 01:58:27 +00:00
|
|
|
ModAdd,
|
|
|
|
ModBan,
|
|
|
|
}
|
|
|
|
|
|
|
|
type ModlogType = {
|
|
|
|
id: number;
|
|
|
|
type_: ModlogEnum;
|
|
|
|
view:
|
|
|
|
| ModRemovePostView
|
|
|
|
| ModLockPostView
|
|
|
|
| ModStickyPostView
|
|
|
|
| ModRemoveCommentView
|
|
|
|
| ModRemoveCommunityView
|
|
|
|
| ModBanFromCommunityView
|
|
|
|
| ModBanView
|
|
|
|
| ModAddCommunityView
|
2021-08-18 23:07:54 +00:00
|
|
|
| ModTransferCommunityView
|
2020-12-24 01:58:27 +00:00
|
|
|
| ModAddView;
|
|
|
|
when_: string;
|
|
|
|
};
|
2020-09-06 16:15:25 +00:00
|
|
|
|
|
|
|
interface ModlogState {
|
2020-12-24 01:58:27 +00:00
|
|
|
res: GetModlogResponse;
|
2020-09-06 16:15:25 +00:00
|
|
|
communityId?: number;
|
|
|
|
communityName?: string;
|
2021-05-04 22:17:15 +00:00
|
|
|
communityMods?: CommunityModeratorView[];
|
2020-09-06 16:15:25 +00:00
|
|
|
page: number;
|
2020-12-24 01:58:27 +00:00
|
|
|
site_view: SiteView;
|
2020-09-06 16:15:25 +00:00
|
|
|
loading: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
export class Modlog extends Component<any, ModlogState> {
|
2020-09-09 02:40:36 +00:00
|
|
|
private isoData = setIsoData(this.context);
|
2020-09-06 16:15:25 +00:00
|
|
|
private subscription: Subscription;
|
|
|
|
private emptyState: ModlogState = {
|
2020-12-24 01:58:27 +00:00
|
|
|
res: {
|
|
|
|
removed_posts: [],
|
|
|
|
locked_posts: [],
|
|
|
|
stickied_posts: [],
|
|
|
|
removed_comments: [],
|
|
|
|
removed_communities: [],
|
|
|
|
banned_from_community: [],
|
|
|
|
banned: [],
|
|
|
|
added_to_community: [],
|
2021-08-18 23:07:54 +00:00
|
|
|
transferred_to_community: [],
|
2020-12-24 01:58:27 +00:00
|
|
|
added: [],
|
|
|
|
},
|
2020-09-06 16:15:25 +00:00
|
|
|
page: 1,
|
|
|
|
loading: true,
|
2020-12-24 01:58:27 +00:00
|
|
|
site_view: this.isoData.site_res.site_view,
|
2020-09-06 16:15:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
constructor(props: any, context: any) {
|
|
|
|
super(props, context);
|
|
|
|
|
|
|
|
this.state = this.emptyState;
|
2021-07-16 19:40:56 +00:00
|
|
|
this.handlePageChange = this.handlePageChange.bind(this);
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
this.state.communityId = this.props.match.params.community_id
|
|
|
|
? Number(this.props.match.params.community_id)
|
|
|
|
: undefined;
|
|
|
|
|
2020-09-09 02:40:36 +00:00
|
|
|
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) {
|
|
|
|
let data = this.isoData.routeData[0];
|
2020-12-24 01:58:27 +00:00
|
|
|
this.state.res = data;
|
2020-09-09 02:40:36 +00:00
|
|
|
this.state.loading = false;
|
2021-05-04 22:17:15 +00:00
|
|
|
|
|
|
|
// Getting the moderators
|
|
|
|
if (this.isoData.routeData[1]) {
|
|
|
|
this.state.communityMods = this.isoData.routeData[1].moderators;
|
|
|
|
}
|
2020-09-09 02:40:36 +00:00
|
|
|
} else {
|
|
|
|
this.refetch();
|
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
2020-09-09 02:40:36 +00:00
|
|
|
if (isBrowser()) {
|
|
|
|
this.subscription.unsubscribe();
|
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2020-12-24 01:58:27 +00:00
|
|
|
buildCombined(res: GetModlogResponse): ModlogType[] {
|
|
|
|
let removed_posts: ModlogType[] = res.removed_posts.map(r => ({
|
|
|
|
id: r.mod_remove_post.id,
|
|
|
|
type_: ModlogEnum.ModRemovePost,
|
|
|
|
view: r,
|
|
|
|
when_: r.mod_remove_post.when_,
|
|
|
|
}));
|
|
|
|
|
|
|
|
let locked_posts: ModlogType[] = res.locked_posts.map(r => ({
|
|
|
|
id: r.mod_lock_post.id,
|
|
|
|
type_: ModlogEnum.ModLockPost,
|
|
|
|
view: r,
|
|
|
|
when_: r.mod_lock_post.when_,
|
|
|
|
}));
|
|
|
|
|
|
|
|
let stickied_posts: ModlogType[] = res.stickied_posts.map(r => ({
|
|
|
|
id: r.mod_sticky_post.id,
|
|
|
|
type_: ModlogEnum.ModStickyPost,
|
|
|
|
view: r,
|
|
|
|
when_: r.mod_sticky_post.when_,
|
|
|
|
}));
|
|
|
|
|
|
|
|
let removed_comments: ModlogType[] = res.removed_comments.map(r => ({
|
|
|
|
id: r.mod_remove_comment.id,
|
|
|
|
type_: ModlogEnum.ModRemoveComment,
|
|
|
|
view: r,
|
|
|
|
when_: r.mod_remove_comment.when_,
|
|
|
|
}));
|
|
|
|
|
|
|
|
let removed_communities: ModlogType[] = res.removed_communities.map(r => ({
|
|
|
|
id: r.mod_remove_community.id,
|
|
|
|
type_: ModlogEnum.ModRemoveCommunity,
|
|
|
|
view: r,
|
|
|
|
when_: r.mod_remove_community.when_,
|
|
|
|
}));
|
|
|
|
|
|
|
|
let banned_from_community: ModlogType[] = res.banned_from_community.map(
|
|
|
|
r => ({
|
|
|
|
id: r.mod_ban_from_community.id,
|
|
|
|
type_: ModlogEnum.ModBanFromCommunity,
|
|
|
|
view: r,
|
|
|
|
when_: r.mod_ban_from_community.when_,
|
|
|
|
})
|
2020-09-06 16:15:25 +00:00
|
|
|
);
|
2020-12-24 01:58:27 +00:00
|
|
|
|
|
|
|
let added_to_community: ModlogType[] = res.added_to_community.map(r => ({
|
|
|
|
id: r.mod_add_community.id,
|
|
|
|
type_: ModlogEnum.ModAddCommunity,
|
|
|
|
view: r,
|
|
|
|
when_: r.mod_add_community.when_,
|
|
|
|
}));
|
|
|
|
|
2021-08-18 23:07:54 +00:00
|
|
|
let transferred_to_community: ModlogType[] =
|
|
|
|
res.transferred_to_community.map(r => ({
|
|
|
|
id: r.mod_transfer_community.id,
|
|
|
|
type_: ModlogEnum.ModTransferCommunity,
|
|
|
|
view: r,
|
|
|
|
when_: r.mod_transfer_community.when_,
|
|
|
|
}));
|
|
|
|
|
2020-12-24 01:58:27 +00:00
|
|
|
let added: ModlogType[] = res.added.map(r => ({
|
|
|
|
id: r.mod_add.id,
|
|
|
|
type_: ModlogEnum.ModAdd,
|
|
|
|
view: r,
|
|
|
|
when_: r.mod_add.when_,
|
|
|
|
}));
|
|
|
|
|
|
|
|
let banned: ModlogType[] = res.banned.map(r => ({
|
|
|
|
id: r.mod_ban.id,
|
|
|
|
type_: ModlogEnum.ModBan,
|
|
|
|
view: r,
|
|
|
|
when_: r.mod_ban.when_,
|
|
|
|
}));
|
|
|
|
|
|
|
|
let combined: ModlogType[] = [];
|
|
|
|
|
|
|
|
combined.push(...removed_posts);
|
|
|
|
combined.push(...locked_posts);
|
|
|
|
combined.push(...stickied_posts);
|
|
|
|
combined.push(...removed_comments);
|
|
|
|
combined.push(...removed_communities);
|
|
|
|
combined.push(...banned_from_community);
|
|
|
|
combined.push(...added_to_community);
|
2021-08-18 23:07:54 +00:00
|
|
|
combined.push(...transferred_to_community);
|
2020-12-24 01:58:27 +00:00
|
|
|
combined.push(...added);
|
|
|
|
combined.push(...banned);
|
|
|
|
|
|
|
|
if (this.state.communityId && combined.length > 0) {
|
2021-07-16 19:40:56 +00:00
|
|
|
this.state.communityName = (
|
|
|
|
combined[0].view as ModRemovePostView
|
|
|
|
).community.name;
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Sort them by time
|
2020-12-24 01:58:27 +00:00
|
|
|
combined.sort((a, b) => b.when_.localeCompare(a.when_));
|
|
|
|
|
|
|
|
return combined;
|
|
|
|
}
|
|
|
|
|
|
|
|
renderModlogType(i: ModlogType) {
|
|
|
|
switch (i.type_) {
|
2021-02-22 02:24:09 +00:00
|
|
|
case ModlogEnum.ModRemovePost: {
|
2020-12-24 01:58:27 +00:00
|
|
|
let mrpv = i.view as ModRemovePostView;
|
|
|
|
return [
|
2021-02-22 02:39:04 +00:00
|
|
|
mrpv.mod_remove_post.removed ? "Removed " : "Restored ",
|
2020-12-24 01:58:27 +00:00
|
|
|
<span>
|
|
|
|
Post <Link to={`/post/${mrpv.post.id}`}>{mrpv.post.name}</Link>
|
|
|
|
</span>,
|
|
|
|
mrpv.mod_remove_post.reason &&
|
|
|
|
` reason: ${mrpv.mod_remove_post.reason}`,
|
|
|
|
];
|
2021-02-22 02:24:09 +00:00
|
|
|
}
|
|
|
|
case ModlogEnum.ModLockPost: {
|
2020-12-24 01:58:27 +00:00
|
|
|
let mlpv = i.view as ModLockPostView;
|
|
|
|
return [
|
2021-02-22 02:39:04 +00:00
|
|
|
mlpv.mod_lock_post.locked ? "Locked " : "Unlocked ",
|
2020-12-24 01:58:27 +00:00
|
|
|
<span>
|
|
|
|
Post <Link to={`/post/${mlpv.post.id}`}>{mlpv.post.name}</Link>
|
|
|
|
</span>,
|
|
|
|
];
|
2021-02-22 02:24:09 +00:00
|
|
|
}
|
|
|
|
case ModlogEnum.ModStickyPost: {
|
2020-12-24 01:58:27 +00:00
|
|
|
let mspv = i.view as ModStickyPostView;
|
|
|
|
return [
|
2021-02-22 02:39:04 +00:00
|
|
|
mspv.mod_sticky_post.stickied ? "Stickied " : "Unstickied ",
|
2020-12-24 01:58:27 +00:00
|
|
|
<span>
|
|
|
|
Post <Link to={`/post/${mspv.post.id}`}>{mspv.post.name}</Link>
|
|
|
|
</span>,
|
|
|
|
];
|
2021-02-22 02:24:09 +00:00
|
|
|
}
|
|
|
|
case ModlogEnum.ModRemoveComment: {
|
2020-12-24 01:58:27 +00:00
|
|
|
let mrc = i.view as ModRemoveCommentView;
|
|
|
|
return [
|
2021-02-22 02:39:04 +00:00
|
|
|
mrc.mod_remove_comment.removed ? "Removed " : "Restored ",
|
2020-12-24 01:58:27 +00:00
|
|
|
<span>
|
2021-02-22 02:39:04 +00:00
|
|
|
Comment{" "}
|
2020-12-24 01:58:27 +00:00
|
|
|
<Link to={`/post/${mrc.post.id}/comment/${mrc.comment.id}`}>
|
|
|
|
{mrc.comment.content}
|
|
|
|
</Link>
|
|
|
|
</span>,
|
|
|
|
<span>
|
2021-02-22 02:39:04 +00:00
|
|
|
{" "}
|
2021-03-15 18:09:31 +00:00
|
|
|
by <PersonListing person={mrc.commenter} />
|
2020-12-24 01:58:27 +00:00
|
|
|
</span>,
|
|
|
|
mrc.mod_remove_comment.reason &&
|
|
|
|
` reason: ${mrc.mod_remove_comment.reason}`,
|
|
|
|
];
|
2021-02-22 02:24:09 +00:00
|
|
|
}
|
|
|
|
case ModlogEnum.ModRemoveCommunity: {
|
2020-12-24 01:58:27 +00:00
|
|
|
let mrco = i.view as ModRemoveCommunityView;
|
|
|
|
return [
|
2021-02-22 02:39:04 +00:00
|
|
|
mrco.mod_remove_community.removed ? "Removed " : "Restored ",
|
2020-12-24 01:58:27 +00:00
|
|
|
<span>
|
|
|
|
Community <CommunityLink community={mrco.community} />
|
|
|
|
</span>,
|
|
|
|
mrco.mod_remove_community.reason &&
|
|
|
|
` reason: ${mrco.mod_remove_community.reason}`,
|
|
|
|
mrco.mod_remove_community.expires &&
|
|
|
|
` expires: ${moment
|
|
|
|
.utc(mrco.mod_remove_community.expires)
|
|
|
|
.fromNow()}`,
|
|
|
|
];
|
2021-02-22 02:24:09 +00:00
|
|
|
}
|
|
|
|
case ModlogEnum.ModBanFromCommunity: {
|
2020-12-24 01:58:27 +00:00
|
|
|
let mbfc = i.view as ModBanFromCommunityView;
|
|
|
|
return [
|
|
|
|
<span>
|
2021-02-22 02:39:04 +00:00
|
|
|
{mbfc.mod_ban_from_community.banned ? "Banned " : "Unbanned "}{" "}
|
2020-12-24 01:58:27 +00:00
|
|
|
</span>,
|
|
|
|
<span>
|
2021-03-15 18:09:31 +00:00
|
|
|
<PersonListing person={mbfc.banned_person} />
|
2020-12-24 01:58:27 +00:00
|
|
|
</span>,
|
|
|
|
<span> from the community </span>,
|
|
|
|
<span>
|
|
|
|
<CommunityLink community={mbfc.community} />
|
|
|
|
</span>,
|
|
|
|
<div>
|
|
|
|
{mbfc.mod_ban_from_community.reason &&
|
|
|
|
` reason: ${mbfc.mod_ban_from_community.reason}`}
|
|
|
|
</div>,
|
|
|
|
<div>
|
|
|
|
{mbfc.mod_ban_from_community.expires &&
|
|
|
|
` expires: ${moment
|
|
|
|
.utc(mbfc.mod_ban_from_community.expires)
|
|
|
|
.fromNow()}`}
|
|
|
|
</div>,
|
|
|
|
];
|
2021-02-22 02:24:09 +00:00
|
|
|
}
|
|
|
|
case ModlogEnum.ModAddCommunity: {
|
2020-12-24 01:58:27 +00:00
|
|
|
let mac = i.view as ModAddCommunityView;
|
|
|
|
return [
|
|
|
|
<span>
|
2021-02-22 02:39:04 +00:00
|
|
|
{mac.mod_add_community.removed ? "Removed " : "Appointed "}{" "}
|
2020-12-24 01:58:27 +00:00
|
|
|
</span>,
|
|
|
|
<span>
|
2021-03-15 18:09:31 +00:00
|
|
|
<PersonListing person={mac.modded_person} />
|
2020-12-24 01:58:27 +00:00
|
|
|
</span>,
|
|
|
|
<span> as a mod to the community </span>,
|
|
|
|
<span>
|
|
|
|
<CommunityLink community={mac.community} />
|
|
|
|
</span>,
|
|
|
|
];
|
2021-02-22 02:24:09 +00:00
|
|
|
}
|
2021-08-18 23:07:54 +00:00
|
|
|
case ModlogEnum.ModTransferCommunity: {
|
|
|
|
let mtc = i.view as ModTransferCommunityView;
|
|
|
|
return [
|
|
|
|
<span>
|
|
|
|
{mtc.mod_transfer_community.removed ? "Removed " : "Transferred "}{" "}
|
|
|
|
</span>,
|
|
|
|
<span>
|
|
|
|
<CommunityLink community={mtc.community} />
|
|
|
|
</span>,
|
|
|
|
<span> to </span>,
|
|
|
|
<span>
|
|
|
|
<PersonListing person={mtc.modded_person} />
|
|
|
|
</span>,
|
|
|
|
];
|
|
|
|
}
|
2021-02-22 02:24:09 +00:00
|
|
|
case ModlogEnum.ModBan: {
|
2020-12-24 01:58:27 +00:00
|
|
|
let mb = i.view as ModBanView;
|
|
|
|
return [
|
2021-02-22 02:39:04 +00:00
|
|
|
<span>{mb.mod_ban.banned ? "Banned " : "Unbanned "} </span>,
|
2020-12-24 01:58:27 +00:00
|
|
|
<span>
|
2021-03-15 18:09:31 +00:00
|
|
|
<PersonListing person={mb.banned_person} />
|
2020-12-24 01:58:27 +00:00
|
|
|
</span>,
|
|
|
|
<div>{mb.mod_ban.reason && ` reason: ${mb.mod_ban.reason}`}</div>,
|
|
|
|
<div>
|
|
|
|
{mb.mod_ban.expires &&
|
|
|
|
` expires: ${moment.utc(mb.mod_ban.expires).fromNow()}`}
|
|
|
|
</div>,
|
|
|
|
];
|
2021-02-22 02:24:09 +00:00
|
|
|
}
|
|
|
|
case ModlogEnum.ModAdd: {
|
2020-12-24 01:58:27 +00:00
|
|
|
let ma = i.view as ModAddView;
|
|
|
|
return [
|
2021-02-22 02:39:04 +00:00
|
|
|
<span>{ma.mod_add.removed ? "Removed " : "Appointed "} </span>,
|
2020-12-24 01:58:27 +00:00
|
|
|
<span>
|
2021-03-15 18:09:31 +00:00
|
|
|
<PersonListing person={ma.modded_person} />
|
2020-12-24 01:58:27 +00:00
|
|
|
</span>,
|
|
|
|
<span> as an admin </span>,
|
|
|
|
];
|
2021-02-22 02:24:09 +00:00
|
|
|
}
|
2020-12-24 01:58:27 +00:00
|
|
|
default:
|
|
|
|
return <div />;
|
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
combined() {
|
2020-12-24 01:58:27 +00:00
|
|
|
let combined = this.buildCombined(this.state.res);
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
return (
|
|
|
|
<tbody>
|
2020-12-24 01:58:27 +00:00
|
|
|
{combined.map(i => (
|
2020-09-06 16:15:25 +00:00
|
|
|
<tr>
|
|
|
|
<td>
|
2020-12-24 01:58:27 +00:00
|
|
|
<MomentTime data={i} />
|
2020-09-06 16:15:25 +00:00
|
|
|
</td>
|
|
|
|
<td>
|
2021-05-04 22:17:15 +00:00
|
|
|
{this.isAdminOrMod ? (
|
|
|
|
<PersonListing person={i.view.moderator} />
|
|
|
|
) : (
|
2022-03-14 20:09:29 +00:00
|
|
|
<div>{this.modOrAdminText(i.view.moderator)}</div>
|
2021-05-04 22:17:15 +00:00
|
|
|
)}
|
2020-09-06 16:15:25 +00:00
|
|
|
</td>
|
2020-12-24 01:58:27 +00:00
|
|
|
<td>{this.renderModlogType(i)}</td>
|
2020-09-06 16:15:25 +00:00
|
|
|
</tr>
|
|
|
|
))}
|
|
|
|
</tbody>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-05-04 22:17:15 +00:00
|
|
|
get isAdminOrMod(): boolean {
|
|
|
|
let isAdmin =
|
2021-08-20 02:56:18 +00:00
|
|
|
UserService.Instance.myUserInfo &&
|
2021-05-04 22:17:15 +00:00
|
|
|
this.isoData.site_res.admins
|
|
|
|
.map(a => a.person.id)
|
2021-08-20 02:56:18 +00:00
|
|
|
.includes(UserService.Instance.myUserInfo.local_user_view.person.id);
|
2021-05-04 22:17:15 +00:00
|
|
|
let isMod =
|
2021-08-20 02:56:18 +00:00
|
|
|
UserService.Instance.myUserInfo &&
|
2021-05-04 22:17:15 +00:00
|
|
|
this.state.communityMods &&
|
|
|
|
this.state.communityMods
|
|
|
|
.map(m => m.moderator.id)
|
2021-08-20 02:56:18 +00:00
|
|
|
.includes(UserService.Instance.myUserInfo.local_user_view.person.id);
|
2021-05-04 22:17:15 +00:00
|
|
|
return isAdmin || isMod;
|
|
|
|
}
|
|
|
|
|
2022-03-14 20:09:29 +00:00
|
|
|
modOrAdminText(person: PersonSafe): Text {
|
|
|
|
if (
|
|
|
|
this.isoData.site_res.admins.map(a => a.person.id).includes(person.id)
|
|
|
|
) {
|
|
|
|
return i18n.t("admin");
|
|
|
|
} else {
|
|
|
|
return i18n.t("mod");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
get documentTitle(): string {
|
2020-12-24 01:58:27 +00:00
|
|
|
return `Modlog - ${this.state.site_view.site.name}`;
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div class="container">
|
2020-09-11 18:09:21 +00:00
|
|
|
<HtmlTags
|
|
|
|
title={this.documentTitle}
|
|
|
|
path={this.context.router.route.match.url}
|
|
|
|
/>
|
2020-09-06 16:15:25 +00:00
|
|
|
{this.state.loading ? (
|
2021-02-11 20:35:27 +00:00
|
|
|
<h5>
|
2021-07-17 20:21:31 +00:00
|
|
|
<Spinner large />
|
2020-09-06 16:15:25 +00:00
|
|
|
</h5>
|
|
|
|
) : (
|
|
|
|
<div>
|
|
|
|
<h5>
|
|
|
|
{this.state.communityName && (
|
|
|
|
<Link
|
|
|
|
className="text-body"
|
|
|
|
to={`/c/${this.state.communityName}`}
|
|
|
|
>
|
2021-02-22 02:39:04 +00:00
|
|
|
/c/{this.state.communityName}{" "}
|
2020-09-06 16:15:25 +00:00
|
|
|
</Link>
|
|
|
|
)}
|
2021-02-22 02:39:04 +00:00
|
|
|
<span>{i18n.t("modlog")}</span>
|
2020-09-06 16:15:25 +00:00
|
|
|
</h5>
|
|
|
|
<div class="table-responsive">
|
|
|
|
<table id="modlog_table" class="table table-sm table-hover">
|
|
|
|
<thead class="pointer">
|
|
|
|
<tr>
|
2021-02-22 02:39:04 +00:00
|
|
|
<th> {i18n.t("time")}</th>
|
|
|
|
<th>{i18n.t("mod")}</th>
|
|
|
|
<th>{i18n.t("action")}</th>
|
2020-09-06 16:15:25 +00:00
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
{this.combined()}
|
|
|
|
</table>
|
2021-07-16 19:40:56 +00:00
|
|
|
<Paginator
|
|
|
|
page={this.state.page}
|
|
|
|
onChange={this.handlePageChange}
|
|
|
|
/>
|
2020-09-06 16:15:25 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-07-16 19:40:56 +00:00
|
|
|
handlePageChange(val: number) {
|
|
|
|
this.setState({ page: val });
|
|
|
|
this.refetch();
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
refetch() {
|
2020-12-24 01:58:27 +00:00
|
|
|
let modlogForm: GetModlog = {
|
2020-09-06 16:15:25 +00:00
|
|
|
community_id: this.state.communityId,
|
|
|
|
page: this.state.page,
|
|
|
|
limit: fetchLimit,
|
2021-12-30 15:26:45 +00:00
|
|
|
auth: authField(false),
|
2020-09-06 16:15:25 +00:00
|
|
|
};
|
2020-12-24 22:05:57 +00:00
|
|
|
WebSocketService.Instance.send(wsClient.getModlog(modlogForm));
|
2021-05-04 22:17:15 +00:00
|
|
|
|
|
|
|
if (this.state.communityId) {
|
|
|
|
let communityForm: GetCommunity = {
|
|
|
|
id: this.state.communityId,
|
|
|
|
name: this.state.communityName,
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.send(wsClient.getCommunity(communityForm));
|
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2020-11-12 21:56:46 +00:00
|
|
|
static fetchInitialData(req: InitialFetchRequest): Promise<any>[] {
|
2021-02-22 02:39:04 +00:00
|
|
|
let pathSplit = req.path.split("/");
|
2020-09-09 02:40:36 +00:00
|
|
|
let communityId = pathSplit[3];
|
|
|
|
let promises: Promise<any>[] = [];
|
|
|
|
|
2020-12-24 01:58:27 +00:00
|
|
|
let modlogForm: GetModlog = {
|
2020-09-09 02:40:36 +00:00
|
|
|
page: 1,
|
|
|
|
limit: fetchLimit,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (communityId) {
|
|
|
|
modlogForm.community_id = Number(communityId);
|
|
|
|
}
|
2021-12-30 15:26:45 +00:00
|
|
|
setOptionalAuth(modlogForm, req.auth);
|
2020-09-09 02:40:36 +00:00
|
|
|
|
2020-11-12 21:56:46 +00:00
|
|
|
promises.push(req.client.getModlog(modlogForm));
|
2021-05-04 22:17:15 +00:00
|
|
|
|
|
|
|
if (communityId) {
|
|
|
|
let communityForm: GetCommunity = {
|
|
|
|
id: Number(communityId),
|
|
|
|
};
|
2021-12-30 15:26:45 +00:00
|
|
|
setOptionalAuth(communityForm, req.auth);
|
2021-05-04 22:17:15 +00:00
|
|
|
promises.push(req.client.getCommunity(communityForm));
|
|
|
|
}
|
2020-09-09 02:40:36 +00:00
|
|
|
return promises;
|
|
|
|
}
|
|
|
|
|
2020-12-24 01:58:27 +00:00
|
|
|
parseMessage(msg: any) {
|
|
|
|
let op = wsUserOp(msg);
|
2021-04-07 15:54:38 +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;
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.GetModlog) {
|
|
|
|
let data = wsJsonToRes<GetModlogResponse>(msg).data;
|
2020-09-06 16:15:25 +00:00
|
|
|
this.state.loading = false;
|
|
|
|
window.scrollTo(0, 0);
|
2020-12-24 01:58:27 +00:00
|
|
|
this.state.res = data;
|
2020-09-06 16:15:25 +00:00
|
|
|
this.setState(this.state);
|
2021-05-04 22:17:15 +00:00
|
|
|
} else if (op == UserOperation.GetCommunity) {
|
|
|
|
let data = wsJsonToRes<GetCommunityResponse>(msg).data;
|
|
|
|
this.state.communityMods = data.moderators;
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|