diff --git a/src/shared/components/person/profile.tsx b/src/shared/components/person/profile.tsx index cf3e7954..42cb2491 100644 --- a/src/shared/components/person/profile.tsx +++ b/src/shared/components/person/profile.tsx @@ -2,6 +2,7 @@ import { Component, linkEvent } from "inferno"; import { Link } from "inferno-router"; import { AddAdminResponse, + BanPerson, BanPersonResponse, BlockPerson, BlockPersonResponse, @@ -20,12 +21,17 @@ import { InitialFetchRequest, PersonDetailsView } from "../../interfaces"; import { UserService, WebSocketService } from "../../services"; import { authField, + canMod, + capitalizeFirstLetter, createCommentLikeRes, createPostLikeFindRes, editCommentRes, editPostFindRes, fetchLimit, + futureDaysToUnixTime, getUsernameFromProps, + isBanned, + isMod, mdToHtml, numToSI, previewLines, @@ -62,6 +68,10 @@ interface ProfileState { loading: boolean; personBlocked: boolean; siteRes: GetSiteResponse; + showBanDialog: boolean; + banReason: string; + banExpireDays: number; + removeData: boolean; } interface ProfileProps { @@ -90,6 +100,10 @@ export class Profile extends Component { page: Profile.getPageFromProps(this.props.match.page), personBlocked: false, siteRes: this.isoData.site_res, + showBanDialog: false, + banReason: null, + banExpireDays: null, + removeData: false, }; constructor(props: any, context: any) { @@ -128,7 +142,7 @@ export class Profile extends Component { get isCurrentUser() { return ( UserService.Instance.myUserInfo?.local_user_view.person.id == - this.state.personRes.person_view.person.id + this.state.personRes?.person_view.person.id ); } @@ -379,7 +393,7 @@ export class Profile extends Component { hideAvatar /> - {pv.person.banned && ( + {isBanned(pv.person) && (
  • {i18n.t("banned")}
  • @@ -396,6 +410,7 @@ export class Profile extends Component { )} + {this.banDialog()}
    {!this.isCurrentUser && UserService.Instance.myUserInfo && ( <> @@ -416,7 +431,9 @@ export class Profile extends Component { {this.state.personBlocked ? ( ) : ( + ) : ( + + ))} {pv.person.bio && (
    @@ -476,6 +516,82 @@ export class Profile extends Component { ); } + banDialog() { + let pv = this.state.personRes?.person_view; + return ( + <> + {this.state.showBanDialog && ( +
    +
    + + + + +
    +
    + + +
    +
    +
    + {/* TODO hold off on expires until later */} + {/*
    */} + {/* */} + {/* */} + {/*
    */} +
    + + +
    +
    + )} + + ); + } + moderates() { return (
    @@ -534,6 +650,27 @@ export class Profile extends Component { this.fetchUserData(); } + get canAdmin(): boolean { + return ( + this.state.siteRes?.admins && + canMod( + UserService.Instance.myUserInfo, + this.state.siteRes.admins.map(a => a.person.id), + this.state.personRes?.person_view.person.id + ) + ); + } + + get personIsAdmin(): boolean { + return ( + this.state.siteRes?.admins && + isMod( + this.state.siteRes.admins.map(a => a.person.id), + this.state.personRes?.person_view.person.id + ) + ); + } + handlePageChange(page: number) { this.updateUrl({ page }); } @@ -549,6 +686,55 @@ export class Profile extends Component { }); } + handleModBanShow(i: Profile) { + i.state.showBanDialog = true; + i.setState(i.state); + } + + handleModBanReasonChange(i: Profile, event: any) { + i.state.banReason = event.target.value; + i.setState(i.state); + } + + handleModBanExpireDaysChange(i: Profile, event: any) { + i.state.banExpireDays = event.target.value; + i.setState(i.state); + } + + handleModRemoveDataChange(i: Profile, event: any) { + i.state.removeData = event.target.checked; + i.setState(i.state); + } + + handleModBanSubmitCancel(i: Profile, event?: any) { + event.preventDefault(); + i.state.showBanDialog = false; + i.setState(i.state); + } + + handleModBanSubmit(i: Profile, event?: any) { + if (event) event.preventDefault(); + + let pv = i.state.personRes.person_view; + // If its an unban, restore all their data + let ban = !pv.person.banned; + if (ban == false) { + i.state.removeData = false; + } + let form: BanPerson = { + person_id: pv.person.id, + ban, + remove_data: i.state.removeData, + reason: i.state.banReason, + expires: futureDaysToUnixTime(i.state.banExpireDays), + auth: authField(), + }; + WebSocketService.Instance.send(wsClient.banPerson(form)); + + i.state.showBanDialog = false; + i.setState(i.state); + } + parseMessage(msg: any) { let op = wsUserOp(msg); console.log(msg); @@ -623,6 +809,11 @@ export class Profile extends Component { this.state.personRes.posts .filter(c => c.creator.id == data.person_view.person.id) .forEach(c => (c.creator.banned = data.banned)); + let pv = this.state.personRes.person_view; + + if (pv.person.id == data.person_view.person.id) { + pv.person.banned = data.banned; + } this.setState(this.state); } else if (op == UserOperation.BlockPerson) { let data = wsJsonToRes(msg).data; diff --git a/src/shared/components/post/post-listing.tsx b/src/shared/components/post/post-listing.tsx index 51ea8b3c..3a315492 100644 --- a/src/shared/components/post/post-listing.tsx +++ b/src/shared/components/post/post-listing.tsx @@ -54,10 +54,10 @@ interface PostListingState { showRemoveDialog: boolean; removeReason: string; showBanDialog: boolean; - removeData: boolean; banReason: string; banExpireDays: number; banType: BanType; + removeData: boolean; showConfirmTransferSite: boolean; showConfirmTransferCommunity: boolean; imageExpanded: boolean; @@ -91,10 +91,10 @@ export class PostListing extends Component { showRemoveDialog: false, removeReason: null, showBanDialog: false, - removeData: false, banReason: null, banExpireDays: null, banType: BanType.Community, + removeData: false, showConfirmTransferSite: false, showConfirmTransferCommunity: false, imageExpanded: false,