]> Untitled Git - lemmy.git/commitdiff
Fix issue with not being able to lock / sticky your own posts.
authorDessalines <tyhou13@gmx.com>
Mon, 9 Sep 2019 19:58:04 +0000 (12:58 -0700)
committerDessalines <tyhou13@gmx.com>
Mon, 9 Sep 2019 19:58:04 +0000 (12:58 -0700)
ui/src/components/post-listing.tsx
ui/src/utils.ts

index 94cbef106d2ddbaf1315b9b1ddc46c3ac9712dcf..9409a372ed679367094aeb00a6c1e8aaea1ca15a 100644 (file)
@@ -194,14 +194,8 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
                     </li>
                   </>
                 }
-                {this.canMod &&
+                {this.canModOnSelf &&
                   <>
-                    <li className="list-inline-item">
-                      {!post.removed ? 
-                      <span class="pointer" onClick={linkEvent(this, this.handleModRemoveShow)}><T i18nKey="remove">#</T></span> :
-                      <span class="pointer" onClick={linkEvent(this, this.handleModRemoveSubmit)}><T i18nKey="restore">#</T></span>
-                      }
-                    </li>
                     <li className="list-inline-item">
                       <span class="pointer" onClick={linkEvent(this, this.handleModLock)}>{post.locked ? i18n.t('unlock') : i18n.t('lock')}</span>
                     </li>
@@ -213,6 +207,12 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
                 {/* Mods can ban from community, and appoint as mods to community */}
                 {this.canMod &&
                   <>
+                    <li className="list-inline-item">
+                      {!post.removed ? 
+                      <span class="pointer" onClick={linkEvent(this, this.handleModRemoveShow)}><T i18nKey="remove">#</T></span> :
+                      <span class="pointer" onClick={linkEvent(this, this.handleModRemoveSubmit)}><T i18nKey="restore">#</T></span>
+                      }
+                    </li>
                     {!this.isMod && 
                       <li className="list-inline-item">
                         {!post.banned_from_community ? 
@@ -326,14 +326,22 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
     return this.props.admins && isMod(this.props.admins.map(a => a.id), this.props.post.creator_id);
   }
 
+  get adminsThenMods(): Array<number> {
+    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;
   }
 
index d9c8528fb9c6cbfe6b3753a8f50681a10534fb7a..8fb64c6e6e6e020e9346ac3628cd38ad4e036c2b 100644 (file)
@@ -82,14 +82,15 @@ export function addTypeInfo<T>(arr: Array<T>, name: string): Array<{type_: strin
   return arr.map(e => {return {type_: name, data: e}});
 }
 
-export function canMod(user: User, modIds: Array<number>, creator_id: number): boolean {
+export function canMod(user: User, modIds: Array<number>, 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 {