From: Alec Armbruster <35377827+alectrocute@users.noreply.github.com> Date: Fri, 16 Jun 2023 21:33:46 +0000 (-0400) Subject: Merge branch 'main' into breakout-role-utils X-Git-Url: http://these/git/%7B%24%7B%60data:application/%22%7Burl%7D/readmes/README.zh.hant.md?a=commitdiff_plain;h=9c37cea106571a492e0b951fa66a182395053b67;p=lemmy-ui.git Merge branch 'main' into breakout-role-utils --- 9c37cea106571a492e0b951fa66a182395053b67 diff --cc src/shared/utils.ts index 54b5a3f,df7673a..bc6e76f --- a/src/shared/utils.ts +++ b/src/shared/utils.ts @@@ -40,11 -42,9 +40,11 @@@ import moment from "moment" import tippy from "tippy.js"; import Toastify from "toastify-js"; import { getHttpBase } from "./env"; - import { i18n, languages } from "./i18next"; + import { i18n } from "./i18next"; import { CommentNodeI, DataType, IsoData, VoteType } from "./interfaces"; import { HttpService, UserService } from "./services"; +import { isBrowser } from "./utils/browser/is-browser"; +import { groupBy } from "./utils/helpers/group-by"; let Tribute: any; if (isBrowser()) { @@@ -228,8 -228,95 +228,9 @@@ export function futureDaysToUnixTime(da : undefined; } -export function canMod( - creator_id: number, - mods?: CommunityModeratorView[], - admins?: PersonView[], - myUserInfo = UserService.Instance.myUserInfo, - onSelf = false -): boolean { - // You can do moderator actions only on the mods added after you. - let adminsThenMods = - admins - ?.map(a => a.person.id) - .concat(mods?.map(m => m.moderator.id) ?? []) ?? []; - - if (myUserInfo) { - const myIndex = adminsThenMods.findIndex( - id => id == myUserInfo.local_user_view.person.id - ); - if (myIndex == -1) { - return false; - } else { - // onSelf +1 on mod actions not for yourself, IE ban, remove, etc - adminsThenMods = adminsThenMods.slice(0, myIndex + (onSelf ? 0 : 1)); - return !adminsThenMods.includes(creator_id); - } - } else { - return false; - } -} - -export function canAdmin( - creatorId: number, - admins?: PersonView[], - myUserInfo = UserService.Instance.myUserInfo, - onSelf = false -): boolean { - return canMod(creatorId, undefined, admins, myUserInfo, onSelf); -} - -export function isMod( - creatorId: number, - mods?: CommunityModeratorView[] -): boolean { - return mods?.map(m => m.moderator.id).includes(creatorId) ?? false; -} - -export function amMod( - mods?: CommunityModeratorView[], - myUserInfo = UserService.Instance.myUserInfo -): boolean { - return myUserInfo ? isMod(myUserInfo.local_user_view.person.id, mods) : false; -} - -export function isAdmin(creatorId: number, admins?: PersonView[]): boolean { - return admins?.map(a => a.person.id).includes(creatorId) ?? false; -} - -export function amAdmin(myUserInfo = UserService.Instance.myUserInfo): boolean { - return myUserInfo?.local_user_view.person.admin ?? false; -} - -export function amCommunityCreator( - creator_id: number, - mods?: CommunityModeratorView[], - myUserInfo = UserService.Instance.myUserInfo -): boolean { - const myId = myUserInfo?.local_user_view.person.id; - // Don't allow mod actions on yourself - return myId == mods?.at(0)?.moderator.id && myId != creator_id; -} - -export function amSiteCreator( - creator_id: number, - admins?: PersonView[], - myUserInfo = UserService.Instance.myUserInfo -): boolean { - const myId = myUserInfo?.local_user_view.person.id; - return myId == admins?.at(0)?.person.id && myId != creator_id; -} - -export function amTopMod( - mods: CommunityModeratorView[], - myUserInfo = UserService.Instance.myUserInfo -): boolean { - return mods.at(0)?.moderator.id == myUserInfo?.local_user_view.person.id; -} - const imageRegex = /(http)?s?:?(\/\/[^"']*\.(?:jpg|jpeg|gif|png|svg|webp))/; const videoRegex = /(http)?s?:?(\/\/[^"']*\.(?:mp4|webm))/; + const tldRegex = /([a-z0-9]+\.)*[a-z0-9]+\.[a-z]+/; export function isImage(url: string) { return imageRegex.test(url);