mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-11-29 07:41:13 +00:00
Hide names of mods / admins without priveleges. Fixes #285
This commit is contained in:
parent
d174b53876
commit
68cc228a96
1 changed files with 48 additions and 2 deletions
|
@ -15,8 +15,11 @@ import {
|
||||||
ModBanView,
|
ModBanView,
|
||||||
ModAddCommunityView,
|
ModAddCommunityView,
|
||||||
ModAddView,
|
ModAddView,
|
||||||
|
GetCommunity,
|
||||||
|
GetCommunityResponse,
|
||||||
|
CommunityModeratorView,
|
||||||
} from "lemmy-js-client";
|
} from "lemmy-js-client";
|
||||||
import { WebSocketService } from "../services";
|
import { WebSocketService, UserService } from "../services";
|
||||||
import {
|
import {
|
||||||
wsJsonToRes,
|
wsJsonToRes,
|
||||||
fetchLimit,
|
fetchLimit,
|
||||||
|
@ -68,6 +71,7 @@ interface ModlogState {
|
||||||
res: GetModlogResponse;
|
res: GetModlogResponse;
|
||||||
communityId?: number;
|
communityId?: number;
|
||||||
communityName?: string;
|
communityName?: string;
|
||||||
|
communityMods?: CommunityModeratorView[];
|
||||||
page: number;
|
page: number;
|
||||||
site_view: SiteView;
|
site_view: SiteView;
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
|
@ -109,6 +113,11 @@ export class Modlog extends Component<any, ModlogState> {
|
||||||
let data = this.isoData.routeData[0];
|
let data = this.isoData.routeData[0];
|
||||||
this.state.res = data;
|
this.state.res = data;
|
||||||
this.state.loading = false;
|
this.state.loading = false;
|
||||||
|
|
||||||
|
// Getting the moderators
|
||||||
|
if (this.isoData.routeData[1]) {
|
||||||
|
this.state.communityMods = this.isoData.routeData[1].moderators;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
this.refetch();
|
this.refetch();
|
||||||
}
|
}
|
||||||
|
@ -353,7 +362,11 @@ export class Modlog extends Component<any, ModlogState> {
|
||||||
<MomentTime data={i} />
|
<MomentTime data={i} />
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<PersonListing person={i.view.moderator} />
|
{this.isAdminOrMod ? (
|
||||||
|
<PersonListing person={i.view.moderator} />
|
||||||
|
) : (
|
||||||
|
<div>{i18n.t("mod")}</div>
|
||||||
|
)}
|
||||||
</td>
|
</td>
|
||||||
<td>{this.renderModlogType(i)}</td>
|
<td>{this.renderModlogType(i)}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -362,6 +375,21 @@ export class Modlog extends Component<any, ModlogState> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
get documentTitle(): string {
|
||||||
return `Modlog - ${this.state.site_view.site.name}`;
|
return `Modlog - ${this.state.site_view.site.name}`;
|
||||||
}
|
}
|
||||||
|
@ -449,6 +477,14 @@ export class Modlog extends Component<any, ModlogState> {
|
||||||
limit: fetchLimit,
|
limit: fetchLimit,
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.send(wsClient.getModlog(modlogForm));
|
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<any>[] {
|
static fetchInitialData(req: InitialFetchRequest): Promise<any>[] {
|
||||||
|
@ -466,6 +502,13 @@ export class Modlog extends Component<any, ModlogState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
promises.push(req.client.getModlog(modlogForm));
|
promises.push(req.client.getModlog(modlogForm));
|
||||||
|
|
||||||
|
if (communityId) {
|
||||||
|
let communityForm: GetCommunity = {
|
||||||
|
id: Number(communityId),
|
||||||
|
};
|
||||||
|
promises.push(req.client.getCommunity(communityForm));
|
||||||
|
}
|
||||||
return promises;
|
return promises;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -481,6 +524,9 @@ export class Modlog extends Component<any, ModlogState> {
|
||||||
window.scrollTo(0, 0);
|
window.scrollTo(0, 0);
|
||||||
this.state.res = data;
|
this.state.res = data;
|
||||||
this.setState(this.state);
|
this.setState(this.state);
|
||||||
|
} else if (op == UserOperation.GetCommunity) {
|
||||||
|
let data = wsJsonToRes<GetCommunityResponse>(msg).data;
|
||||||
|
this.state.communityMods = data.moderators;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue