diff options
Diffstat (limited to 'ui/src/utils.ts')
-rw-r--r-- | ui/src/utils.ts | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/ui/src/utils.ts b/ui/src/utils.ts index c7f3bad8..61744e90 100644 --- a/ui/src/utils.ts +++ b/ui/src/utils.ts @@ -1,4 +1,4 @@ -import { UserOperation, Comment } from './interfaces'; +import { UserOperation, Comment, User } from './interfaces'; import * as markdown_it from 'markdown-it'; export let repoUrl = 'https://github.com/dessalines/lemmy'; @@ -40,4 +40,23 @@ 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 { + // 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 + return !modIds.includes(creator_id); + } + } else { + return false; + } +} + +export function isMod(modIds: Array<number>, creator_id: number): boolean { + return modIds.includes(creator_id); +} + export let fetchLimit: number = 20; |