From: Dessalines Date: Tue, 4 May 2021 22:17:15 +0000 (-0400) Subject: Hide names of mods / admins without priveleges. Fixes #285 X-Git-Url: http://these/git/%22https:/join-lemmy.org/%7B%60%24%7BarchiveTodayUrl%7D/%7BallRss%7D?a=commitdiff_plain;h=68cc228a96b58145959190ff8d2dec424a4ab093;p=lemmy-ui.git Hide names of mods / admins without priveleges. Fixes #285 --- diff --git a/src/shared/components/modlog.tsx b/src/shared/components/modlog.tsx index 960eeb2..eb0dac8 100644 --- a/src/shared/components/modlog.tsx +++ b/src/shared/components/modlog.tsx @@ -15,8 +15,11 @@ import { ModBanView, ModAddCommunityView, ModAddView, + GetCommunity, + GetCommunityResponse, + CommunityModeratorView, } from "lemmy-js-client"; -import { WebSocketService } from "../services"; +import { WebSocketService, UserService } from "../services"; import { wsJsonToRes, fetchLimit, @@ -68,6 +71,7 @@ interface ModlogState { res: GetModlogResponse; communityId?: number; communityName?: string; + communityMods?: CommunityModeratorView[]; page: number; site_view: SiteView; loading: boolean; @@ -109,6 +113,11 @@ export class Modlog extends Component { let data = this.isoData.routeData[0]; this.state.res = data; this.state.loading = false; + + // Getting the moderators + if (this.isoData.routeData[1]) { + this.state.communityMods = this.isoData.routeData[1].moderators; + } } else { this.refetch(); } @@ -353,7 +362,11 @@ export class Modlog extends Component { - + {this.isAdminOrMod ? ( + + ) : ( +
{i18n.t("mod")}
+ )} {this.renderModlogType(i)} @@ -362,6 +375,21 @@ export class Modlog extends Component { ); } + get isAdminOrMod(): boolean { + let isAdmin = + UserService.Instance.localUserView && + this.isoData.site_res.admins + .map(a => a.person.id) + .includes(UserService.Instance.localUserView.person.id); + let isMod = + UserService.Instance.localUserView && + this.state.communityMods && + this.state.communityMods + .map(m => m.moderator.id) + .includes(UserService.Instance.localUserView.person.id); + return isAdmin || isMod; + } + get documentTitle(): string { return `Modlog - ${this.state.site_view.site.name}`; } @@ -449,6 +477,14 @@ export class Modlog extends Component { limit: fetchLimit, }; WebSocketService.Instance.send(wsClient.getModlog(modlogForm)); + + if (this.state.communityId) { + let communityForm: GetCommunity = { + id: this.state.communityId, + name: this.state.communityName, + }; + WebSocketService.Instance.send(wsClient.getCommunity(communityForm)); + } } static fetchInitialData(req: InitialFetchRequest): Promise[] { @@ -466,6 +502,13 @@ export class Modlog extends Component { } promises.push(req.client.getModlog(modlogForm)); + + if (communityId) { + let communityForm: GetCommunity = { + id: Number(communityId), + }; + promises.push(req.client.getCommunity(communityForm)); + } return promises; } @@ -481,6 +524,9 @@ export class Modlog extends Component { window.scrollTo(0, 0); this.state.res = data; this.setState(this.state); + } else if (op == UserOperation.GetCommunity) { + let data = wsJsonToRes(msg).data; + this.state.communityMods = data.moderators; } } }