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()) {
: 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);