From: Dessalines Date: Mon, 9 Sep 2019 19:58:04 +0000 (-0700) Subject: Fix issue with not being able to lock / sticky your own posts. X-Git-Url: http://these/git/readmes/%7B%60%24%7BwebArchiveUrl%7D/save/%7Burl%7D?a=commitdiff_plain;h=c8131d304b6833113e0f062b0d9561e5ab4df06d;p=lemmy.git Fix issue with not being able to lock / sticky your own posts. --- diff --git a/ui/src/components/post-listing.tsx b/ui/src/components/post-listing.tsx index 94cbef10..9409a372 100644 --- a/ui/src/components/post-listing.tsx +++ b/ui/src/components/post-listing.tsx @@ -194,14 +194,8 @@ export class PostListing extends Component { } - {this.canMod && + {this.canModOnSelf && <> -
  • - {!post.removed ? - # : - # - } -
  • {post.locked ? i18n.t('unlock') : i18n.t('lock')}
  • @@ -213,6 +207,12 @@ export class PostListing extends Component { {/* Mods can ban from community, and appoint as mods to community */} {this.canMod && <> +
  • + {!post.removed ? + # : + # + } +
  • {!this.isMod &&
  • {!post.banned_from_community ? @@ -326,14 +326,22 @@ export class PostListing extends Component { return this.props.admins && isMod(this.props.admins.map(a => a.id), this.props.post.creator_id); } + get adminsThenMods(): Array { + return this.props.admins.map(a => a.id) + .concat(this.props.moderators.map(m => m.user_id)); + } + get canMod(): boolean { if (this.props.editable) { - let adminsThenMods = this.props.admins.map(a => a.id) - .concat(this.props.moderators.map(m => m.user_id)); + return canMod(UserService.Instance.user, this.adminsThenMods, this.props.post.creator_id); + } else return false; + } - return canMod(UserService.Instance.user, adminsThenMods, this.props.post.creator_id); + get canModOnSelf(): boolean { + if (this.props.editable) { + return canMod(UserService.Instance.user, this.adminsThenMods, this.props.post.creator_id, true); } else return false; } diff --git a/ui/src/utils.ts b/ui/src/utils.ts index d9c8528f..8fb64c6e 100644 --- a/ui/src/utils.ts +++ b/ui/src/utils.ts @@ -82,14 +82,15 @@ export function addTypeInfo(arr: Array, name: string): Array<{type_: strin return arr.map(e => {return {type_: name, data: e}}); } -export function canMod(user: User, modIds: Array, creator_id: number): boolean { +export function canMod(user: User, modIds: Array, creator_id: number, onSelf: boolean = false): boolean { // You can do moderator actions only on the mods added after you. if (user) { let yourIndex = modIds.findIndex(id => id == user.id); if (yourIndex == -1) { return false; } else { - modIds = modIds.slice(0, yourIndex+1); // +1 cause you cant mod yourself + // onSelf +1 on mod actions not for yourself, IE ban, remove, etc + modIds = modIds.slice(0, yourIndex+(onSelf ? 0 : 1)); return !modIds.includes(creator_id); } } else {