ModBanView,
ModAddCommunityView,
ModAddView,
+ GetCommunity,
+ GetCommunityResponse,
+ CommunityModeratorView,
} from "lemmy-js-client";
-import { WebSocketService } from "../services";
+import { WebSocketService, UserService } from "../services";
import {
wsJsonToRes,
fetchLimit,
res: GetModlogResponse;
communityId?: number;
communityName?: string;
+ communityMods?: CommunityModeratorView[];
page: number;
site_view: SiteView;
loading: boolean;
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();
}
<MomentTime data={i} />
</td>
<td>
- <PersonListing person={i.view.moderator} />
+ {this.isAdminOrMod ? (
+ <PersonListing person={i.view.moderator} />
+ ) : (
+ <div>{i18n.t("mod")}</div>
+ )}
</td>
<td>{this.renderModlogType(i)}</td>
</tr>
);
}
+ 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}`;
}
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<any>[] {
}
promises.push(req.client.getModlog(modlogForm));
+
+ if (communityId) {
+ let communityForm: GetCommunity = {
+ id: Number(communityId),
+ };
+ promises.push(req.client.getCommunity(communityForm));
+ }
return promises;
}
window.scrollTo(0, 0);
this.state.res = data;
this.setState(this.state);
+ } else if (op == UserOperation.GetCommunity) {
+ let data = wsJsonToRes<GetCommunityResponse>(msg).data;
+ this.state.communityMods = data.moderators;
}
}
}