2023-06-21 22:28:24 +00:00
|
|
|
import {
|
|
|
|
fetchUsers,
|
|
|
|
getUpdatedSearchId,
|
|
|
|
myAuth,
|
|
|
|
personToChoice,
|
|
|
|
setIsoData,
|
|
|
|
} from "@utils/app";
|
|
|
|
import {
|
|
|
|
debounce,
|
2023-06-23 14:33:07 +00:00
|
|
|
formatPastDate,
|
2023-06-21 22:28:24 +00:00
|
|
|
getIdFromString,
|
|
|
|
getPageFromString,
|
|
|
|
getQueryParams,
|
|
|
|
getQueryString,
|
|
|
|
} from "@utils/helpers";
|
2023-06-20 14:17:16 +00:00
|
|
|
import { amAdmin, amMod } from "@utils/roles";
|
|
|
|
import type { QueryParams } from "@utils/types";
|
2023-06-21 22:28:24 +00:00
|
|
|
import { Choice, RouteDataResponse } from "@utils/types";
|
2023-04-15 14:47:10 +00:00
|
|
|
import { NoOptionI18nKeys } from "i18next";
|
2022-06-04 16:47:10 +00:00
|
|
|
import { Component, linkEvent } from "inferno";
|
2023-05-04 02:06:59 +00:00
|
|
|
import { T } from "inferno-i18next-dess";
|
2021-02-22 02:39:04 +00:00
|
|
|
import { Link } from "inferno-router";
|
2023-04-15 14:47:10 +00:00
|
|
|
import { RouteComponentProps } from "inferno-router/dist/Route";
|
2020-09-06 16:15:25 +00:00
|
|
|
import {
|
2022-06-23 19:44:05 +00:00
|
|
|
AdminPurgeCommentView,
|
|
|
|
AdminPurgeCommunityView,
|
|
|
|
AdminPurgePersonView,
|
|
|
|
AdminPurgePostView,
|
2021-07-17 20:42:55 +00:00
|
|
|
GetCommunity,
|
|
|
|
GetCommunityResponse,
|
2020-12-24 01:58:27 +00:00
|
|
|
GetModlog,
|
2020-09-06 16:15:25 +00:00
|
|
|
GetModlogResponse,
|
2023-04-15 14:47:10 +00:00
|
|
|
GetPersonDetails,
|
|
|
|
GetPersonDetailsResponse,
|
2021-07-17 20:42:55 +00:00
|
|
|
ModAddCommunityView,
|
|
|
|
ModAddView,
|
|
|
|
ModBanFromCommunityView,
|
|
|
|
ModBanView,
|
2022-12-14 15:03:18 +00:00
|
|
|
ModFeaturePostView,
|
2020-12-24 01:58:27 +00:00
|
|
|
ModLockPostView,
|
|
|
|
ModRemoveCommentView,
|
|
|
|
ModRemoveCommunityView,
|
2021-07-17 20:42:55 +00:00
|
|
|
ModRemovePostView,
|
2021-08-18 23:07:54 +00:00
|
|
|
ModTransferCommunityView,
|
2023-05-11 17:06:32 +00:00
|
|
|
ModlogActionType,
|
2023-05-11 18:32:32 +00:00
|
|
|
Person,
|
2021-02-22 02:39:04 +00:00
|
|
|
} from "lemmy-js-client";
|
2023-06-21 22:28:24 +00:00
|
|
|
import { fetchLimit } from "../config";
|
2021-07-17 20:42:55 +00:00
|
|
|
import { InitialFetchRequest } from "../interfaces";
|
2023-06-22 00:54:35 +00:00
|
|
|
import { FirstLoadService, I18NextService } from "../services";
|
2023-06-14 12:20:40 +00:00
|
|
|
import { HttpService, RequestState } from "../services/HttpService";
|
2021-07-17 20:42:55 +00:00
|
|
|
import { HtmlTags } from "./common/html-tags";
|
2023-05-04 02:06:59 +00:00
|
|
|
import { Icon, Spinner } from "./common/icon";
|
2021-07-17 20:42:55 +00:00
|
|
|
import { MomentTime } from "./common/moment-time";
|
|
|
|
import { Paginator } from "./common/paginator";
|
2023-04-15 14:47:10 +00:00
|
|
|
import { SearchableSelect } from "./common/searchable-select";
|
2021-07-17 20:42:55 +00:00
|
|
|
import { CommunityLink } from "./community/community-link";
|
|
|
|
import { PersonListing } from "./person/person-listing";
|
2023-04-15 14:47:10 +00:00
|
|
|
|
|
|
|
type FilterType = "mod" | "user";
|
|
|
|
|
|
|
|
type View =
|
|
|
|
| ModRemovePostView
|
|
|
|
| ModLockPostView
|
|
|
|
| ModFeaturePostView
|
|
|
|
| ModRemoveCommentView
|
|
|
|
| ModRemoveCommunityView
|
|
|
|
| ModBanFromCommunityView
|
|
|
|
| ModBanView
|
|
|
|
| ModAddCommunityView
|
|
|
|
| ModTransferCommunityView
|
|
|
|
| ModAddView
|
|
|
|
| AdminPurgePersonView
|
|
|
|
| AdminPurgeCommunityView
|
|
|
|
| AdminPurgePostView
|
|
|
|
| AdminPurgeCommentView;
|
|
|
|
|
2023-06-16 02:08:14 +00:00
|
|
|
type ModlogData = RouteDataResponse<{
|
2023-06-16 02:39:04 +00:00
|
|
|
res: GetModlogResponse;
|
|
|
|
communityRes: GetCommunityResponse;
|
|
|
|
modUserResponse: GetPersonDetailsResponse;
|
|
|
|
userResponse: GetPersonDetailsResponse;
|
2023-06-16 02:08:14 +00:00
|
|
|
}>;
|
2023-05-30 00:40:00 +00:00
|
|
|
|
2023-04-15 14:47:10 +00:00
|
|
|
interface ModlogType {
|
2020-12-24 01:58:27 +00:00
|
|
|
id: number;
|
2022-06-04 16:47:10 +00:00
|
|
|
type_: ModlogActionType;
|
2023-05-11 18:32:32 +00:00
|
|
|
moderator?: Person;
|
2023-04-15 14:47:10 +00:00
|
|
|
view: View;
|
2020-12-24 01:58:27 +00:00
|
|
|
when_: string;
|
2022-06-04 16:47:10 +00:00
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2023-04-15 14:47:10 +00:00
|
|
|
const getModlogQueryParams = () =>
|
|
|
|
getQueryParams<ModlogProps>({
|
|
|
|
actionType: getActionFromString,
|
|
|
|
modId: getIdFromString,
|
|
|
|
userId: getIdFromString,
|
|
|
|
page: getPageFromString,
|
|
|
|
});
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
interface ModlogState {
|
2023-06-14 12:20:40 +00:00
|
|
|
res: RequestState<GetModlogResponse>;
|
|
|
|
communityRes: RequestState<GetCommunityResponse>;
|
2023-04-15 14:47:10 +00:00
|
|
|
loadingModSearch: boolean;
|
|
|
|
loadingUserSearch: boolean;
|
|
|
|
modSearchOptions: Choice[];
|
|
|
|
userSearchOptions: Choice[];
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2023-04-15 14:47:10 +00:00
|
|
|
interface ModlogProps {
|
2023-05-15 19:53:29 +00:00
|
|
|
page: number;
|
2023-04-15 14:47:10 +00:00
|
|
|
userId?: number | null;
|
|
|
|
modId?: number | null;
|
|
|
|
actionType: ModlogActionType;
|
|
|
|
}
|
2022-09-22 15:03:35 +00:00
|
|
|
|
2023-05-11 18:32:32 +00:00
|
|
|
function getActionFromString(action?: string): ModlogActionType {
|
|
|
|
return action !== undefined ? (action as ModlogActionType) : "All";
|
|
|
|
}
|
2021-07-16 19:40:56 +00:00
|
|
|
|
2023-04-15 14:47:10 +00:00
|
|
|
const getModlogActionMapper =
|
|
|
|
(
|
|
|
|
actionType: ModlogActionType,
|
|
|
|
getAction: (view: View) => { id: number; when_: string }
|
|
|
|
) =>
|
2023-05-11 18:32:32 +00:00
|
|
|
(view: View & { moderator?: Person; admin?: Person }): ModlogType => {
|
2023-04-15 14:47:10 +00:00
|
|
|
const { id, when_ } = getAction(view);
|
2020-09-09 02:40:36 +00:00
|
|
|
|
2023-04-15 14:47:10 +00:00
|
|
|
return {
|
|
|
|
id,
|
|
|
|
type_: actionType,
|
|
|
|
view,
|
|
|
|
when_,
|
|
|
|
moderator: view.moderator ?? view.admin,
|
2022-09-22 15:03:35 +00:00
|
|
|
};
|
2023-04-15 14:47:10 +00:00
|
|
|
};
|
2022-09-22 15:03:35 +00:00
|
|
|
|
2023-04-15 14:47:10 +00:00
|
|
|
function buildCombined({
|
|
|
|
removed_comments,
|
|
|
|
locked_posts,
|
|
|
|
featured_posts,
|
|
|
|
removed_communities,
|
|
|
|
removed_posts,
|
|
|
|
added,
|
|
|
|
added_to_community,
|
|
|
|
admin_purged_comments,
|
|
|
|
admin_purged_communities,
|
|
|
|
admin_purged_persons,
|
|
|
|
admin_purged_posts,
|
|
|
|
banned,
|
|
|
|
banned_from_community,
|
|
|
|
transferred_to_community,
|
|
|
|
}: GetModlogResponse): ModlogType[] {
|
|
|
|
const combined = removed_posts
|
|
|
|
.map(
|
|
|
|
getModlogActionMapper(
|
2023-05-11 18:32:32 +00:00
|
|
|
"ModRemovePost",
|
2023-04-15 14:47:10 +00:00
|
|
|
({ mod_remove_post }: ModRemovePostView) => mod_remove_post
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.concat(
|
|
|
|
locked_posts.map(
|
|
|
|
getModlogActionMapper(
|
2023-05-11 18:32:32 +00:00
|
|
|
"ModLockPost",
|
2023-04-15 14:47:10 +00:00
|
|
|
({ mod_lock_post }: ModLockPostView) => mod_lock_post
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.concat(
|
|
|
|
featured_posts.map(
|
|
|
|
getModlogActionMapper(
|
2023-05-11 18:32:32 +00:00
|
|
|
"ModFeaturePost",
|
2023-04-15 14:47:10 +00:00
|
|
|
({ mod_feature_post }: ModFeaturePostView) => mod_feature_post
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.concat(
|
|
|
|
removed_comments.map(
|
|
|
|
getModlogActionMapper(
|
2023-05-11 18:32:32 +00:00
|
|
|
"ModRemoveComment",
|
2023-04-15 14:47:10 +00:00
|
|
|
({ mod_remove_comment }: ModRemoveCommentView) => mod_remove_comment
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.concat(
|
|
|
|
removed_communities.map(
|
|
|
|
getModlogActionMapper(
|
2023-05-11 18:32:32 +00:00
|
|
|
"ModRemoveCommunity",
|
2023-04-15 14:47:10 +00:00
|
|
|
({ mod_remove_community }: ModRemoveCommunityView) =>
|
|
|
|
mod_remove_community
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.concat(
|
|
|
|
banned_from_community.map(
|
|
|
|
getModlogActionMapper(
|
2023-05-11 18:32:32 +00:00
|
|
|
"ModBanFromCommunity",
|
2023-04-15 14:47:10 +00:00
|
|
|
({ mod_ban_from_community }: ModBanFromCommunityView) =>
|
|
|
|
mod_ban_from_community
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.concat(
|
|
|
|
added_to_community.map(
|
|
|
|
getModlogActionMapper(
|
2023-05-11 18:32:32 +00:00
|
|
|
"ModAddCommunity",
|
2023-04-15 14:47:10 +00:00
|
|
|
({ mod_add_community }: ModAddCommunityView) => mod_add_community
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.concat(
|
|
|
|
transferred_to_community.map(
|
|
|
|
getModlogActionMapper(
|
2023-05-11 18:32:32 +00:00
|
|
|
"ModTransferCommunity",
|
2023-04-15 14:47:10 +00:00
|
|
|
({ mod_transfer_community }: ModTransferCommunityView) =>
|
|
|
|
mod_transfer_community
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.concat(
|
|
|
|
added.map(
|
2023-05-11 18:32:32 +00:00
|
|
|
getModlogActionMapper("ModAdd", ({ mod_add }: ModAddView) => mod_add)
|
2023-04-15 14:47:10 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
.concat(
|
|
|
|
banned.map(
|
2023-05-11 18:32:32 +00:00
|
|
|
getModlogActionMapper("ModBan", ({ mod_ban }: ModBanView) => mod_ban)
|
2023-04-15 14:47:10 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
.concat(
|
|
|
|
admin_purged_persons.map(
|
|
|
|
getModlogActionMapper(
|
2023-05-11 18:32:32 +00:00
|
|
|
"AdminPurgePerson",
|
2023-04-15 14:47:10 +00:00
|
|
|
({ admin_purge_person }: AdminPurgePersonView) => admin_purge_person
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.concat(
|
|
|
|
admin_purged_communities.map(
|
|
|
|
getModlogActionMapper(
|
2023-05-11 18:32:32 +00:00
|
|
|
"AdminPurgeCommunity",
|
2023-04-15 14:47:10 +00:00
|
|
|
({ admin_purge_community }: AdminPurgeCommunityView) =>
|
|
|
|
admin_purge_community
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.concat(
|
|
|
|
admin_purged_posts.map(
|
|
|
|
getModlogActionMapper(
|
2023-05-11 18:32:32 +00:00
|
|
|
"AdminPurgePost",
|
2023-04-15 14:47:10 +00:00
|
|
|
({ admin_purge_post }: AdminPurgePostView) => admin_purge_post
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.concat(
|
|
|
|
admin_purged_comments.map(
|
|
|
|
getModlogActionMapper(
|
2023-05-11 18:32:32 +00:00
|
|
|
"AdminPurgeComment",
|
2023-04-15 14:47:10 +00:00
|
|
|
({ admin_purge_comment }: AdminPurgeCommentView) =>
|
|
|
|
admin_purge_comment
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2021-05-04 22:17:15 +00:00
|
|
|
|
2023-04-15 14:47:10 +00:00
|
|
|
// Sort them by time
|
|
|
|
combined.sort((a, b) => b.when_.localeCompare(a.when_));
|
2023-01-04 16:56:24 +00:00
|
|
|
|
2023-04-15 14:47:10 +00:00
|
|
|
return combined;
|
|
|
|
}
|
2022-06-21 21:42:29 +00:00
|
|
|
|
2023-04-15 14:47:10 +00:00
|
|
|
function renderModlogType({ type_, view }: ModlogType) {
|
|
|
|
switch (type_) {
|
2023-05-11 18:32:32 +00:00
|
|
|
case "ModRemovePost": {
|
2023-04-15 14:47:10 +00:00
|
|
|
const mrpv = view as ModRemovePostView;
|
|
|
|
const {
|
|
|
|
mod_remove_post: { reason, removed },
|
|
|
|
post: { name, id },
|
|
|
|
} = mrpv;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<span>{removed ? "Removed " : "Restored "}</span>
|
|
|
|
<span>
|
|
|
|
Post <Link to={`/post/${id}`}>{name}</Link>
|
|
|
|
</span>
|
|
|
|
{reason && (
|
|
|
|
<span>
|
|
|
|
<div>reason: {reason}</div>
|
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
2020-09-09 02:40:36 +00:00
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2023-05-11 18:32:32 +00:00
|
|
|
case "ModLockPost": {
|
2023-04-15 14:47:10 +00:00
|
|
|
const {
|
|
|
|
mod_lock_post: { locked },
|
|
|
|
post: { id, name },
|
|
|
|
} = view as ModLockPostView;
|
2022-06-04 16:47:10 +00:00
|
|
|
|
2023-04-15 14:47:10 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<span>{locked ? "Locked " : "Unlocked "}</span>
|
|
|
|
<span>
|
|
|
|
Post <Link to={`/post/${id}`}>{name}</Link>
|
|
|
|
</span>
|
|
|
|
</>
|
|
|
|
);
|
2020-09-09 02:40:36 +00:00
|
|
|
}
|
2020-12-24 01:58:27 +00:00
|
|
|
|
2023-05-11 18:32:32 +00:00
|
|
|
case "ModFeaturePost": {
|
2023-04-15 14:47:10 +00:00
|
|
|
const {
|
|
|
|
mod_feature_post: { featured, is_featured_community },
|
|
|
|
post: { id, name },
|
|
|
|
} = view as ModFeaturePostView;
|
2022-06-23 19:44:05 +00:00
|
|
|
|
2023-04-15 14:47:10 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<span>{featured ? "Featured " : "Unfeatured "}</span>
|
|
|
|
<span>
|
|
|
|
Post <Link to={`/post/${id}`}>{name}</Link>
|
|
|
|
</span>
|
|
|
|
<span>{is_featured_community ? " In Community" : " In Local"}</span>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
2023-05-11 18:32:32 +00:00
|
|
|
case "ModRemoveComment": {
|
2023-04-15 14:47:10 +00:00
|
|
|
const mrc = view as ModRemoveCommentView;
|
|
|
|
const {
|
|
|
|
mod_remove_comment: { reason, removed },
|
|
|
|
comment: { id, content },
|
|
|
|
commenter,
|
|
|
|
} = mrc;
|
2020-12-24 01:58:27 +00:00
|
|
|
|
2023-04-15 14:47:10 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<span>{removed ? "Removed " : "Restored "}</span>
|
|
|
|
<span>
|
|
|
|
Comment <Link to={`/comment/${id}`}>{content}</Link>
|
|
|
|
</span>
|
|
|
|
<span>
|
|
|
|
{" "}
|
|
|
|
by <PersonListing person={commenter} />
|
|
|
|
</span>
|
|
|
|
{reason && (
|
2022-09-22 15:03:35 +00:00
|
|
|
<span>
|
2023-04-15 14:47:10 +00:00
|
|
|
<div>reason: {reason}</div>
|
2022-09-22 15:03:35 +00:00
|
|
|
</span>
|
2023-04-15 14:47:10 +00:00
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-05-11 18:32:32 +00:00
|
|
|
case "ModRemoveCommunity": {
|
2023-04-15 14:47:10 +00:00
|
|
|
const mrco = view as ModRemoveCommunityView;
|
|
|
|
const {
|
|
|
|
mod_remove_community: { reason, expires, removed },
|
|
|
|
community,
|
|
|
|
} = mrco;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<span>{removed ? "Removed " : "Restored "}</span>
|
|
|
|
<span>
|
|
|
|
Community <CommunityLink community={community} />
|
|
|
|
</span>
|
|
|
|
{reason && (
|
2022-09-22 15:03:35 +00:00
|
|
|
<span>
|
2023-04-15 14:47:10 +00:00
|
|
|
<div>reason: {reason}</div>
|
2022-09-22 15:03:35 +00:00
|
|
|
</span>
|
2023-04-15 14:47:10 +00:00
|
|
|
)}
|
|
|
|
{expires && (
|
2022-09-22 15:03:35 +00:00
|
|
|
<span>
|
2023-06-23 14:33:07 +00:00
|
|
|
<div>expires: {formatPastDate(expires)}</div>
|
2022-09-22 15:03:35 +00:00
|
|
|
</span>
|
2023-04-15 14:47:10 +00:00
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-05-11 18:32:32 +00:00
|
|
|
case "ModBanFromCommunity": {
|
2023-04-15 14:47:10 +00:00
|
|
|
const mbfc = view as ModBanFromCommunityView;
|
|
|
|
const {
|
|
|
|
mod_ban_from_community: { reason, expires, banned },
|
|
|
|
banned_person,
|
|
|
|
community,
|
|
|
|
} = mbfc;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<span>{banned ? "Banned " : "Unbanned "}</span>
|
|
|
|
<span>
|
|
|
|
<PersonListing person={banned_person} />
|
|
|
|
</span>
|
|
|
|
<span> from the community </span>
|
|
|
|
<span>
|
|
|
|
<CommunityLink community={community} />
|
|
|
|
</span>
|
|
|
|
{reason && (
|
2022-09-22 15:03:35 +00:00
|
|
|
<span>
|
2023-04-15 14:47:10 +00:00
|
|
|
<div>reason: {reason}</div>
|
2022-09-22 15:03:35 +00:00
|
|
|
</span>
|
2023-04-15 14:47:10 +00:00
|
|
|
)}
|
|
|
|
{expires && (
|
2022-09-22 15:03:35 +00:00
|
|
|
<span>
|
2023-06-23 14:33:07 +00:00
|
|
|
<div>expires: {formatPastDate(expires)}</div>
|
2022-09-22 15:03:35 +00:00
|
|
|
</span>
|
2023-04-15 14:47:10 +00:00
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-05-11 18:32:32 +00:00
|
|
|
case "ModAddCommunity": {
|
2023-04-15 14:47:10 +00:00
|
|
|
const {
|
|
|
|
mod_add_community: { removed },
|
|
|
|
modded_person,
|
|
|
|
community,
|
|
|
|
} = view as ModAddCommunityView;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<span>{removed ? "Removed " : "Appointed "}</span>
|
|
|
|
<span>
|
|
|
|
<PersonListing person={modded_person} />
|
|
|
|
</span>
|
|
|
|
<span> as a mod to the community </span>
|
|
|
|
<span>
|
|
|
|
<CommunityLink community={community} />
|
|
|
|
</span>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-05-11 18:32:32 +00:00
|
|
|
case "ModTransferCommunity": {
|
|
|
|
const { community, modded_person } = view as ModTransferCommunityView;
|
2023-04-15 14:47:10 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2023-05-11 18:32:32 +00:00
|
|
|
<span>Transferred</span>
|
2023-04-15 14:47:10 +00:00
|
|
|
<span>
|
|
|
|
<CommunityLink community={community} />
|
|
|
|
</span>
|
|
|
|
<span> to </span>
|
|
|
|
<span>
|
|
|
|
<PersonListing person={modded_person} />
|
|
|
|
</span>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-05-11 18:32:32 +00:00
|
|
|
case "ModBan": {
|
2023-04-15 14:47:10 +00:00
|
|
|
const {
|
|
|
|
mod_ban: { reason, expires, banned },
|
|
|
|
banned_person,
|
|
|
|
} = view as ModBanView;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<span>{banned ? "Banned " : "Unbanned "}</span>
|
|
|
|
<span>
|
|
|
|
<PersonListing person={banned_person} />
|
|
|
|
</span>
|
|
|
|
{reason && (
|
2022-09-22 15:03:35 +00:00
|
|
|
<span>
|
2023-04-15 14:47:10 +00:00
|
|
|
<div>reason: {reason}</div>
|
2022-09-22 15:03:35 +00:00
|
|
|
</span>
|
2023-04-15 14:47:10 +00:00
|
|
|
)}
|
|
|
|
{expires && (
|
2022-09-22 15:03:35 +00:00
|
|
|
<span>
|
2023-06-23 14:33:07 +00:00
|
|
|
<div>expires: {formatPastDate(expires)}</div>
|
2022-09-22 15:03:35 +00:00
|
|
|
</span>
|
2023-04-15 14:47:10 +00:00
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-05-11 18:32:32 +00:00
|
|
|
case "ModAdd": {
|
2023-04-15 14:47:10 +00:00
|
|
|
const {
|
|
|
|
mod_add: { removed },
|
|
|
|
modded_person,
|
|
|
|
} = view as ModAddView;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<span>{removed ? "Removed " : "Appointed "}</span>
|
|
|
|
<span>
|
|
|
|
<PersonListing person={modded_person} />
|
|
|
|
</span>
|
|
|
|
<span> as an admin </span>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
2023-05-11 18:32:32 +00:00
|
|
|
case "AdminPurgePerson": {
|
2023-04-15 14:47:10 +00:00
|
|
|
const {
|
|
|
|
admin_purge_person: { reason },
|
|
|
|
} = view as AdminPurgePersonView;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<span>Purged a Person</span>
|
|
|
|
{reason && (
|
2022-09-22 15:03:35 +00:00
|
|
|
<span>
|
2023-04-15 14:47:10 +00:00
|
|
|
<div>reason: {reason}</div>
|
2022-09-22 15:03:35 +00:00
|
|
|
</span>
|
2023-04-15 14:47:10 +00:00
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-05-11 18:32:32 +00:00
|
|
|
case "AdminPurgeCommunity": {
|
2023-04-15 14:47:10 +00:00
|
|
|
const {
|
|
|
|
admin_purge_community: { reason },
|
|
|
|
} = view as AdminPurgeCommunityView;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<span>Purged a Community</span>
|
|
|
|
{reason && (
|
2022-09-22 15:03:35 +00:00
|
|
|
<span>
|
2023-04-15 14:47:10 +00:00
|
|
|
<div>reason: {reason}</div>
|
2022-09-22 15:03:35 +00:00
|
|
|
</span>
|
2023-04-15 14:47:10 +00:00
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-05-11 18:32:32 +00:00
|
|
|
case "AdminPurgePost": {
|
2023-04-15 14:47:10 +00:00
|
|
|
const {
|
|
|
|
admin_purge_post: { reason },
|
|
|
|
community,
|
|
|
|
} = view as AdminPurgePostView;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<span>Purged a Post from from </span>
|
|
|
|
<CommunityLink community={community} />
|
|
|
|
{reason && (
|
2022-09-22 15:03:35 +00:00
|
|
|
<span>
|
2023-04-15 14:47:10 +00:00
|
|
|
<div>reason: {reason}</div>
|
2022-09-22 15:03:35 +00:00
|
|
|
</span>
|
2023-04-15 14:47:10 +00:00
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-05-11 18:32:32 +00:00
|
|
|
case "AdminPurgeComment": {
|
2023-04-15 14:47:10 +00:00
|
|
|
const {
|
|
|
|
admin_purge_comment: { reason },
|
|
|
|
post: { id, name },
|
|
|
|
} = view as AdminPurgeCommentView;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<span>
|
|
|
|
Purged a Comment from <Link to={`/post/${id}`}>{name}</Link>
|
|
|
|
</span>
|
|
|
|
{reason && (
|
2022-09-22 15:03:35 +00:00
|
|
|
<span>
|
2023-04-15 14:47:10 +00:00
|
|
|
<div>reason: {reason}</div>
|
2022-09-22 15:03:35 +00:00
|
|
|
</span>
|
2023-04-15 14:47:10 +00:00
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return <></>;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const Filter = ({
|
|
|
|
filterType,
|
|
|
|
onChange,
|
|
|
|
value,
|
|
|
|
onSearch,
|
|
|
|
options,
|
|
|
|
loading,
|
|
|
|
}: {
|
|
|
|
filterType: FilterType;
|
|
|
|
onChange: (option: Choice) => void;
|
|
|
|
value?: number | null;
|
|
|
|
onSearch: (text: string) => void;
|
|
|
|
options: Choice[];
|
|
|
|
loading: boolean;
|
|
|
|
}) => (
|
2023-06-20 12:01:29 +00:00
|
|
|
<div className="col-sm-6 mb-3">
|
|
|
|
<label className="mb-2" htmlFor={`filter-${filterType}`}>
|
2023-06-22 00:54:35 +00:00
|
|
|
{I18NextService.i18n.t(`filter_by_${filterType}` as NoOptionI18nKeys)}
|
2023-04-15 14:47:10 +00:00
|
|
|
</label>
|
|
|
|
<SearchableSelect
|
|
|
|
id={`filter-${filterType}`}
|
|
|
|
value={value ?? 0}
|
|
|
|
options={[
|
|
|
|
{
|
2023-06-22 00:54:35 +00:00
|
|
|
label: I18NextService.i18n.t("all"),
|
2023-04-15 14:47:10 +00:00
|
|
|
value: "0",
|
|
|
|
},
|
|
|
|
].concat(options)}
|
|
|
|
onChange={onChange}
|
|
|
|
onSearch={onSearch}
|
|
|
|
loading={loading}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
|
|
|
async function createNewOptions({
|
|
|
|
id,
|
|
|
|
oldOptions,
|
|
|
|
text,
|
|
|
|
}: {
|
|
|
|
id?: number | null;
|
|
|
|
oldOptions: Choice[];
|
|
|
|
text: string;
|
|
|
|
}) {
|
|
|
|
const newOptions: Choice[] = [];
|
|
|
|
|
|
|
|
if (id) {
|
|
|
|
const selectedUser = oldOptions.find(
|
|
|
|
({ value }) => value === id.toString()
|
|
|
|
);
|
|
|
|
|
|
|
|
if (selectedUser) {
|
|
|
|
newOptions.push(selectedUser);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (text.length > 0) {
|
|
|
|
newOptions.push(
|
2023-06-14 12:20:40 +00:00
|
|
|
...(await fetchUsers(text))
|
2023-05-11 18:32:32 +00:00
|
|
|
.slice(0, Number(fetchLimit))
|
2023-04-15 14:47:10 +00:00
|
|
|
.map<Choice>(personToChoice)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return newOptions;
|
|
|
|
}
|
|
|
|
|
|
|
|
export class Modlog extends Component<
|
|
|
|
RouteComponentProps<{ communityId?: string }>,
|
|
|
|
ModlogState
|
|
|
|
> {
|
2023-05-30 00:40:00 +00:00
|
|
|
private isoData = setIsoData<ModlogData>(this.context);
|
2023-04-15 14:47:10 +00:00
|
|
|
|
|
|
|
state: ModlogState = {
|
2023-06-14 12:20:40 +00:00
|
|
|
res: { state: "empty" },
|
|
|
|
communityRes: { state: "empty" },
|
2023-04-15 14:47:10 +00:00
|
|
|
loadingModSearch: false,
|
|
|
|
loadingUserSearch: false,
|
|
|
|
userSearchOptions: [],
|
|
|
|
modSearchOptions: [],
|
|
|
|
};
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
props: RouteComponentProps<{ communityId?: string }>,
|
|
|
|
context: any
|
|
|
|
) {
|
|
|
|
super(props, context);
|
|
|
|
this.handlePageChange = this.handlePageChange.bind(this);
|
|
|
|
this.handleUserChange = this.handleUserChange.bind(this);
|
|
|
|
this.handleModChange = this.handleModChange.bind(this);
|
|
|
|
|
|
|
|
// Only fetch the data if coming from another route
|
2023-06-14 12:20:40 +00:00
|
|
|
if (FirstLoadService.isFirstLoad) {
|
2023-06-16 02:39:04 +00:00
|
|
|
const { res, communityRes, modUserResponse, userResponse } =
|
2023-06-14 12:20:40 +00:00
|
|
|
this.isoData.routeData;
|
2023-05-30 00:40:00 +00:00
|
|
|
|
2023-04-15 14:47:10 +00:00
|
|
|
this.state = {
|
|
|
|
...this.state,
|
2023-06-14 12:20:40 +00:00
|
|
|
res,
|
|
|
|
communityRes,
|
2023-04-15 14:47:10 +00:00
|
|
|
};
|
|
|
|
|
2023-06-16 02:39:04 +00:00
|
|
|
if (modUserResponse.state === "success") {
|
2023-04-15 14:47:10 +00:00
|
|
|
this.state = {
|
|
|
|
...this.state,
|
2023-06-16 02:08:14 +00:00
|
|
|
modSearchOptions: [personToChoice(modUserResponse.data.person_view)],
|
2023-04-15 14:47:10 +00:00
|
|
|
};
|
2022-06-23 19:44:05 +00:00
|
|
|
}
|
2023-04-15 14:47:10 +00:00
|
|
|
|
2023-06-16 02:39:04 +00:00
|
|
|
if (userResponse.state === "success") {
|
2023-04-15 14:47:10 +00:00
|
|
|
this.state = {
|
|
|
|
...this.state,
|
2023-06-16 02:08:14 +00:00
|
|
|
userSearchOptions: [personToChoice(userResponse.data.person_view)],
|
2023-04-15 14:47:10 +00:00
|
|
|
};
|
2022-06-23 19:44:05 +00:00
|
|
|
}
|
2020-12-24 01:58:27 +00:00
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2023-06-22 22:44:15 +00:00
|
|
|
async componentDidMount() {
|
|
|
|
await this.refetch();
|
|
|
|
}
|
|
|
|
|
2023-04-15 14:47:10 +00:00
|
|
|
get combined() {
|
|
|
|
const res = this.state.res;
|
2023-06-14 12:20:40 +00:00
|
|
|
const combined = res.state == "success" ? buildCombined(res.data) : [];
|
2020-12-24 01:58:27 +00:00
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
return (
|
|
|
|
<tbody>
|
2020-12-24 01:58:27 +00:00
|
|
|
{combined.map(i => (
|
2022-09-22 15:03:35 +00:00
|
|
|
<tr key={i.id}>
|
2020-09-06 16:15:25 +00:00
|
|
|
<td>
|
2023-01-04 16:56:24 +00:00
|
|
|
<MomentTime published={i.when_} />
|
2020-09-06 16:15:25 +00:00
|
|
|
</td>
|
|
|
|
<td>
|
2023-01-04 16:56:24 +00:00
|
|
|
{this.amAdminOrMod && i.moderator ? (
|
|
|
|
<PersonListing person={i.moderator} />
|
2021-05-04 22:17:15 +00:00
|
|
|
) : (
|
2022-06-23 19:44:05 +00:00
|
|
|
<div>{this.modOrAdminText(i.moderator)}</div>
|
2021-05-04 22:17:15 +00:00
|
|
|
)}
|
2020-09-06 16:15:25 +00:00
|
|
|
</td>
|
2023-04-15 14:47:10 +00:00
|
|
|
<td>{renderModlogType(i)}</td>
|
2020-09-06 16:15:25 +00:00
|
|
|
</tr>
|
|
|
|
))}
|
|
|
|
</tbody>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-06-21 21:42:29 +00:00
|
|
|
get amAdminOrMod(): boolean {
|
2023-06-14 12:20:40 +00:00
|
|
|
const amMod_ =
|
|
|
|
this.state.communityRes.state == "success" &&
|
|
|
|
amMod(this.state.communityRes.data.moderators);
|
|
|
|
return amAdmin() || amMod_;
|
2021-05-04 22:17:15 +00:00
|
|
|
}
|
|
|
|
|
2023-05-11 18:32:32 +00:00
|
|
|
modOrAdminText(person?: Person): string {
|
2023-04-15 14:47:10 +00:00
|
|
|
return person &&
|
|
|
|
this.isoData.site_res.admins.some(
|
|
|
|
({ person: { id } }) => id === person.id
|
|
|
|
)
|
2023-06-22 00:54:35 +00:00
|
|
|
? I18NextService.i18n.t("admin")
|
|
|
|
: I18NextService.i18n.t("mod");
|
2022-03-14 20:09:29 +00:00
|
|
|
}
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
get documentTitle(): string {
|
2023-04-15 14:47:10 +00:00
|
|
|
return `Modlog - ${this.isoData.site_res.site_view.site.name}`;
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2023-04-15 14:47:10 +00:00
|
|
|
const {
|
|
|
|
loadingModSearch,
|
|
|
|
loadingUserSearch,
|
|
|
|
userSearchOptions,
|
|
|
|
modSearchOptions,
|
|
|
|
} = this.state;
|
2023-06-14 12:20:40 +00:00
|
|
|
const { actionType, modId, userId } = getModlogQueryParams();
|
2023-04-15 14:47:10 +00:00
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
return (
|
2023-06-20 18:46:16 +00:00
|
|
|
<div className="modlog container-lg">
|
2020-09-11 18:09:21 +00:00
|
|
|
<HtmlTags
|
|
|
|
title={this.documentTitle}
|
|
|
|
path={this.context.router.route.match.url}
|
|
|
|
/>
|
2023-04-15 14:47:10 +00:00
|
|
|
|
2023-07-02 18:29:56 +00:00
|
|
|
<h1 className="h4 mb-4">{I18NextService.i18n.t("modlog")}</h1>
|
|
|
|
|
|
|
|
<div
|
|
|
|
className="alert alert-warning text-sm-start text-xs-center"
|
|
|
|
role="alert"
|
|
|
|
>
|
|
|
|
<Icon
|
|
|
|
icon="alert-triangle"
|
|
|
|
inline
|
|
|
|
classes="me-sm-2 mx-auto d-sm-inline d-block"
|
|
|
|
/>
|
|
|
|
<T i18nKey="modlog_content_warning" class="d-inline">
|
|
|
|
#<strong>#</strong>#
|
|
|
|
</T>
|
|
|
|
</div>
|
|
|
|
{this.state.communityRes.state === "success" && (
|
|
|
|
<h5>
|
|
|
|
<Link
|
|
|
|
className="text-body"
|
|
|
|
to={`/c/${this.state.communityRes.data.community_view.community.name}`}
|
|
|
|
>
|
|
|
|
/c/{this.state.communityRes.data.community_view.community.name}{" "}
|
|
|
|
</Link>
|
|
|
|
<span>{I18NextService.i18n.t("modlog")}</span>
|
|
|
|
</h5>
|
|
|
|
)}
|
|
|
|
<div className="row mb-2">
|
|
|
|
<div className="col-sm-6">
|
|
|
|
<select
|
|
|
|
value={actionType}
|
|
|
|
onChange={linkEvent(this, this.handleFilterActionChange)}
|
|
|
|
className="form-select"
|
|
|
|
aria-label="action"
|
|
|
|
>
|
|
|
|
<option disabled aria-hidden="true">
|
|
|
|
{I18NextService.i18n.t("filter_by_action")}
|
|
|
|
</option>
|
|
|
|
<option value={"All"}>{I18NextService.i18n.t("all")}</option>
|
|
|
|
<option value={"ModRemovePost"}>Removing Posts</option>
|
|
|
|
<option value={"ModLockPost"}>Locking Posts</option>
|
|
|
|
<option value={"ModFeaturePost"}>Featuring Posts</option>
|
|
|
|
<option value={"ModRemoveComment"}>Removing Comments</option>
|
|
|
|
<option value={"ModRemoveCommunity"}>Removing Communities</option>
|
|
|
|
<option value={"ModBanFromCommunity"}>
|
|
|
|
Banning From Communities
|
|
|
|
</option>
|
|
|
|
<option value={"ModAddCommunity"}>Adding Mod to Community</option>
|
|
|
|
<option value={"ModTransferCommunity"}>
|
|
|
|
Transferring Communities
|
|
|
|
</option>
|
|
|
|
<option value={"ModAdd"}>Adding Mod to Site</option>
|
|
|
|
<option value={"ModBan"}>Banning From Site</option>
|
|
|
|
</select>
|
2023-04-15 14:47:10 +00:00
|
|
|
</div>
|
2023-07-02 18:29:56 +00:00
|
|
|
</div>
|
|
|
|
<div className="row mb-2">
|
|
|
|
<Filter
|
|
|
|
filterType="user"
|
|
|
|
onChange={this.handleUserChange}
|
|
|
|
onSearch={this.handleSearchUsers}
|
|
|
|
value={userId}
|
|
|
|
options={userSearchOptions}
|
|
|
|
loading={loadingUserSearch}
|
|
|
|
/>
|
|
|
|
{!this.isoData.site_res.site_view.local_site
|
|
|
|
.hide_modlog_mod_names && (
|
2023-04-15 14:47:10 +00:00
|
|
|
<Filter
|
2023-07-02 18:29:56 +00:00
|
|
|
filterType="mod"
|
|
|
|
onChange={this.handleModChange}
|
|
|
|
onSearch={this.handleSearchMods}
|
|
|
|
value={modId}
|
|
|
|
options={modSearchOptions}
|
|
|
|
loading={loadingModSearch}
|
2023-04-15 14:47:10 +00:00
|
|
|
/>
|
2023-07-02 18:29:56 +00:00
|
|
|
)}
|
2023-04-15 14:47:10 +00:00
|
|
|
</div>
|
2023-07-02 18:29:56 +00:00
|
|
|
{this.renderModlogTable()}
|
2020-09-06 16:15:25 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
renderModlogTable() {
|
|
|
|
switch (this.state.res.state) {
|
|
|
|
case "loading":
|
|
|
|
return (
|
|
|
|
<h5>
|
|
|
|
<Spinner large />
|
|
|
|
</h5>
|
|
|
|
);
|
|
|
|
case "success": {
|
|
|
|
const page = getModlogQueryParams().page;
|
|
|
|
return (
|
|
|
|
<div className="table-responsive">
|
|
|
|
<table id="modlog_table" className="table table-sm table-hover">
|
|
|
|
<thead className="pointer">
|
|
|
|
<tr>
|
2023-06-22 00:54:35 +00:00
|
|
|
<th> {I18NextService.i18n.t("time")}</th>
|
|
|
|
<th>{I18NextService.i18n.t("mod")}</th>
|
|
|
|
<th>{I18NextService.i18n.t("action")}</th>
|
2023-06-14 12:20:40 +00:00
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
{this.combined}
|
|
|
|
</table>
|
|
|
|
<Paginator page={page} onChange={this.handlePageChange} />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-04 16:47:10 +00:00
|
|
|
handleFilterActionChange(i: Modlog, event: any) {
|
2023-04-15 14:47:10 +00:00
|
|
|
i.updateUrl({
|
2023-05-11 18:32:32 +00:00
|
|
|
actionType: event.target.value as ModlogActionType,
|
2023-05-15 19:53:29 +00:00
|
|
|
page: 1,
|
2023-04-15 14:47:10 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-05-15 19:53:29 +00:00
|
|
|
handlePageChange(page: number) {
|
2023-04-15 14:47:10 +00:00
|
|
|
this.updateUrl({ page });
|
|
|
|
}
|
|
|
|
|
|
|
|
handleUserChange(option: Choice) {
|
2023-05-15 19:53:29 +00:00
|
|
|
this.updateUrl({ userId: getIdFromString(option.value) ?? null, page: 1 });
|
2023-04-15 14:47:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleModChange(option: Choice) {
|
2023-05-15 19:53:29 +00:00
|
|
|
this.updateUrl({ modId: getIdFromString(option.value) ?? null, page: 1 });
|
2022-06-04 16:47:10 +00:00
|
|
|
}
|
|
|
|
|
2023-04-15 14:47:10 +00:00
|
|
|
handleSearchUsers = debounce(async (text: string) => {
|
|
|
|
const { userId } = getModlogQueryParams();
|
|
|
|
const { userSearchOptions } = this.state;
|
|
|
|
this.setState({ loadingUserSearch: true });
|
|
|
|
|
|
|
|
const newOptions = await createNewOptions({
|
|
|
|
id: userId,
|
|
|
|
text,
|
|
|
|
oldOptions: userSearchOptions,
|
|
|
|
});
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
userSearchOptions: newOptions,
|
|
|
|
loadingUserSearch: false,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
handleSearchMods = debounce(async (text: string) => {
|
|
|
|
const { modId } = getModlogQueryParams();
|
|
|
|
const { modSearchOptions } = this.state;
|
|
|
|
this.setState({ loadingModSearch: true });
|
|
|
|
|
|
|
|
const newOptions = await createNewOptions({
|
|
|
|
id: modId,
|
|
|
|
text,
|
|
|
|
oldOptions: modSearchOptions,
|
|
|
|
});
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
modSearchOptions: newOptions,
|
|
|
|
loadingModSearch: false,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async updateUrl({ actionType, modId, page, userId }: Partial<ModlogProps>) {
|
2023-04-15 14:47:10 +00:00
|
|
|
const {
|
|
|
|
page: urlPage,
|
|
|
|
actionType: urlActionType,
|
|
|
|
modId: urlModId,
|
|
|
|
userId: urlUserId,
|
|
|
|
} = getModlogQueryParams();
|
|
|
|
|
|
|
|
const queryParams: QueryParams<ModlogProps> = {
|
|
|
|
page: (page ?? urlPage).toString(),
|
|
|
|
actionType: actionType ?? urlActionType,
|
|
|
|
modId: getUpdatedSearchId(modId, urlModId),
|
|
|
|
userId: getUpdatedSearchId(userId, urlUserId),
|
|
|
|
};
|
|
|
|
|
|
|
|
const communityId = this.props.match.params.communityId;
|
|
|
|
|
|
|
|
this.props.history.push(
|
|
|
|
`/modlog${communityId ? `/${communityId}` : ""}${getQueryString(
|
|
|
|
queryParams
|
|
|
|
)}`
|
|
|
|
);
|
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
await this.refetch();
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async refetch() {
|
|
|
|
const auth = myAuth();
|
2023-04-15 14:47:10 +00:00
|
|
|
const { actionType, page, modId, userId } = getModlogQueryParams();
|
|
|
|
const { communityId: urlCommunityId } = this.props.match.params;
|
|
|
|
const communityId = getIdFromString(urlCommunityId);
|
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
this.setState({ res: { state: "loading" } });
|
|
|
|
this.setState({
|
|
|
|
res: await HttpService.client.getModlog({
|
|
|
|
community_id: communityId,
|
|
|
|
page,
|
|
|
|
limit: fetchLimit,
|
|
|
|
type_: actionType,
|
|
|
|
other_person_id: userId ?? undefined,
|
|
|
|
mod_person_id: !this.isoData.site_res.site_view.local_site
|
|
|
|
.hide_modlog_mod_names
|
|
|
|
? modId ?? undefined
|
|
|
|
: undefined,
|
2023-01-04 16:56:24 +00:00
|
|
|
auth,
|
2023-06-14 12:20:40 +00:00
|
|
|
}),
|
|
|
|
});
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
if (communityId) {
|
|
|
|
this.setState({ communityRes: { state: "loading" } });
|
|
|
|
this.setState({
|
|
|
|
communityRes: await HttpService.client.getCommunity({
|
|
|
|
id: communityId,
|
|
|
|
auth,
|
|
|
|
}),
|
|
|
|
});
|
2022-06-04 16:47:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-16 02:08:14 +00:00
|
|
|
static async fetchInitialData({
|
2023-04-15 14:47:10 +00:00
|
|
|
client,
|
|
|
|
path,
|
|
|
|
query: { modId: urlModId, page, userId: urlUserId, actionType },
|
|
|
|
auth,
|
|
|
|
site,
|
2023-06-16 02:08:14 +00:00
|
|
|
}: InitialFetchRequest<QueryParams<ModlogProps>>): Promise<ModlogData> {
|
2023-04-15 14:47:10 +00:00
|
|
|
const pathSplit = path.split("/");
|
|
|
|
const communityId = getIdFromString(pathSplit[2]);
|
|
|
|
const modId = !site.site_view.local_site.hide_modlog_mod_names
|
|
|
|
? getIdFromString(urlModId)
|
|
|
|
: undefined;
|
|
|
|
const userId = getIdFromString(urlUserId);
|
2020-09-09 02:40:36 +00:00
|
|
|
|
2023-04-15 14:47:10 +00:00
|
|
|
const modlogForm: GetModlog = {
|
|
|
|
page: getPageFromString(page),
|
2023-01-04 16:56:24 +00:00
|
|
|
limit: fetchLimit,
|
2022-06-21 21:42:29 +00:00
|
|
|
community_id: communityId,
|
2023-04-15 14:47:10 +00:00
|
|
|
type_: getActionFromString(actionType),
|
|
|
|
mod_person_id: modId,
|
|
|
|
other_person_id: userId,
|
2023-01-04 16:56:24 +00:00
|
|
|
auth,
|
|
|
|
};
|
2020-09-09 02:40:36 +00:00
|
|
|
|
2023-06-16 02:39:04 +00:00
|
|
|
let communityResponse: RequestState<GetCommunityResponse> = {
|
|
|
|
state: "empty",
|
|
|
|
};
|
2021-05-04 22:17:15 +00:00
|
|
|
|
2023-01-04 16:56:24 +00:00
|
|
|
if (communityId) {
|
2023-04-15 14:47:10 +00:00
|
|
|
const communityForm: GetCommunity = {
|
2022-06-21 21:42:29 +00:00
|
|
|
id: communityId,
|
2023-04-15 14:47:10 +00:00
|
|
|
auth,
|
2023-01-04 16:56:24 +00:00
|
|
|
};
|
2023-05-30 00:40:00 +00:00
|
|
|
|
2023-06-16 02:08:14 +00:00
|
|
|
communityResponse = await client.getCommunity(communityForm);
|
2021-05-04 22:17:15 +00:00
|
|
|
}
|
2023-04-15 14:47:10 +00:00
|
|
|
|
2023-06-16 02:39:04 +00:00
|
|
|
let modUserResponse: RequestState<GetPersonDetailsResponse> = {
|
|
|
|
state: "empty",
|
|
|
|
};
|
2023-05-30 00:40:00 +00:00
|
|
|
|
2023-04-15 14:47:10 +00:00
|
|
|
if (modId) {
|
|
|
|
const getPersonForm: GetPersonDetails = {
|
|
|
|
person_id: modId,
|
|
|
|
auth,
|
|
|
|
};
|
|
|
|
|
2023-06-16 02:08:14 +00:00
|
|
|
modUserResponse = await client.getPersonDetails(getPersonForm);
|
2023-04-15 14:47:10 +00:00
|
|
|
}
|
|
|
|
|
2023-06-16 02:39:04 +00:00
|
|
|
let userResponse: RequestState<GetPersonDetailsResponse> = {
|
|
|
|
state: "empty",
|
|
|
|
};
|
2023-05-30 00:40:00 +00:00
|
|
|
|
2023-04-15 14:47:10 +00:00
|
|
|
if (userId) {
|
|
|
|
const getPersonForm: GetPersonDetails = {
|
|
|
|
person_id: userId,
|
|
|
|
auth,
|
|
|
|
};
|
|
|
|
|
2023-06-16 02:08:14 +00:00
|
|
|
userResponse = await client.getPersonDetails(getPersonForm);
|
2023-04-15 14:47:10 +00:00
|
|
|
}
|
|
|
|
|
2023-05-30 00:40:00 +00:00
|
|
|
return {
|
2023-06-16 02:39:04 +00:00
|
|
|
res: await client.getModlog(modlogForm),
|
|
|
|
communityRes: communityResponse,
|
2023-05-30 00:40:00 +00:00
|
|
|
modUserResponse,
|
|
|
|
userResponse,
|
|
|
|
};
|
2020-09-09 02:40:36 +00:00
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|