import { hydrate } from "inferno-hydrate";
import { Router } from "inferno-router";
import { App } from "../shared/components/app/app";
+import { HistoryService } from "../shared/services/HistoryService";
import { initializeSite } from "../shared/utils";
import "bootstrap/js/dist/collapse";
import "bootstrap/js/dist/dropdown";
-import { HistoryService } from "../shared/services/HistoryService";
-const site = window.isoData.site_res;
-initializeSite(site);
+initializeSite(window.isoData.site_res);
const wrapper = (
<Router history={HistoryService.history}>
);
const root = document.getElementById("root");
+
if (root) {
hydrate(wrapper, root);
}
import { UserService } from "../../services";
import { HttpService, RequestState } from "../../services/HttpService";
import {
- amAdmin,
- canCreateCommunity,
donateLemmyUrl,
isBrowser,
myAuth,
toast,
updateUnreadCountsInterval,
} from "../../utils";
+import { amAdmin } from "../../utils/roles/am-admin";
+import { canCreateCommunity } from "../../utils/roles/can-create-community";
import { Icon } from "../common/icon";
import { PictrsImage } from "../common/pictrs-image";
} from "../../interfaces";
import { UserService } from "../../services";
import {
- amCommunityCreator,
- canAdmin,
- canMod,
colorList,
commentTreeMaxDepth,
futureDaysToUnixTime,
getCommentParentId,
- isAdmin,
- isBanned,
- isMod,
mdToHtml,
mdToHtmlNoImages,
myAuth,
setupTippy,
showScores,
} from "../../utils";
+import { amCommunityCreator } from "../../utils/roles/am-community-creator";
+import { canAdmin } from "../../utils/roles/can-admin";
+import { canMod } from "../../utils/roles/can-mod";
+import { isAdmin } from "../../utils/roles/is-admin";
+import { isBanned } from "../../utils/roles/is-banned";
+import { isMod } from "../../utils/roles/is-mod";
import { Icon, PurgeWarning, Spinner } from "../common/icon";
import { MomentTime } from "../common/moment-time";
import { CommunityLink } from "../community/community-link";
import { i18n } from "../../i18next";
import { UserService } from "../../services";
import {
- amAdmin,
- amMod,
- amTopMod,
getUnixTime,
hostname,
mdToHtml,
myAuthRequired,
numToSI,
} from "../../utils";
+import { amAdmin } from "../../utils/roles/am-admin";
+import { amMod } from "../../utils/roles/am-mod";
+import { amTopMod } from "../../utils/roles/am-top-mod";
import { BannerIconHeader } from "../common/banner-icon-header";
import { Icon, PurgeWarning, Spinner } from "../common/icon";
import { CommunityForm } from "../community/community-form";
import { FirstLoadService } from "../../services/FirstLoadService";
import { HttpService, RequestState } from "../../services/HttpService";
import {
- canCreateCommunity,
commentsToFlatNodes,
editComment,
editPost,
trendingFetchLimit,
updatePersonBlock,
} from "../../utils";
+import { canCreateCommunity } from "../../utils/roles/can-create-community";
import { CommentNodes } from "../comment/comment-nodes";
import { DataTypeSelect } from "../common/data-type-select";
import { HtmlTags } from "../common/html-tags";
import {
Choice,
QueryParams,
- amAdmin,
- amMod,
debounce,
fetchLimit,
fetchUsers,
personToChoice,
setIsoData,
} from "../utils";
+import { amAdmin } from "../utils/roles/am-admin";
+import { amMod } from "../utils/roles/am-mod";
import { HtmlTags } from "./common/html-tags";
import { Icon, Spinner } from "./common/icon";
import { MomentTime } from "./common/moment-time";
import { HttpService, RequestState } from "../../services/HttpService";
import {
QueryParams,
- canMod,
capitalizeFirstLetter,
editComment,
editPost,
getPageFromString,
getQueryParams,
getQueryString,
- isAdmin,
- isBanned,
mdToHtml,
myAuth,
myAuthRequired,
toast,
updatePersonBlock,
} from "../../utils";
+import { canMod } from "../../utils/roles/can-mod";
+import { isAdmin } from "../../utils/roles/is-admin";
+import { isBanned } from "../../utils/roles/is-banned";
import { BannerIconHeader } from "../common/banner-icon-header";
import { HtmlTags } from "../common/html-tags";
import { Icon, Spinner } from "../common/icon";
import { FirstLoadService } from "../../services/FirstLoadService";
import { RequestState } from "../../services/HttpService";
import {
- amAdmin,
editCommentReport,
editPostReport,
editPrivateMessageReport,
myAuthRequired,
setIsoData,
} from "../../utils";
+import { amAdmin } from "../../utils/roles/am-admin";
import { CommentReport } from "../comment/comment-report";
import { HtmlTags } from "../common/html-tags";
import { Spinner } from "../common/icon";
import { BanType, PostFormParams, PurgeType, VoteType } from "../../interfaces";
import { UserService } from "../../services";
import {
- amAdmin,
- amCommunityCreator,
- amMod,
- canAdmin,
- canMod,
canShare,
futureDaysToUnixTime,
hostname,
- isAdmin,
- isBanned,
isImage,
- isMod,
isVideo,
mdNoImages,
mdToHtml,
share,
showScores,
} from "../../utils";
+import { amAdmin } from "../../utils/roles/am-admin";
+import { amCommunityCreator } from "../../utils/roles/am-community-creator";
+import { amMod } from "../../utils/roles/am-mod";
+import { canAdmin } from "../../utils/roles/can-admin";
+import { canMod } from "../../utils/roles/can-mod";
+import { isAdmin } from "../../utils/roles/is-admin";
+import { isBanned } from "../../utils/roles/is-banned";
+import { isMod } from "../../utils/roles/is-mod";
import { Icon, PurgeWarning, Spinner } from "../common/icon";
import { MomentTime } from "../common/moment-time";
import { PictrsImage } from "../common/pictrs-image";
CommentReportView,
CommentSortType,
CommentView,
- CommunityModeratorView,
CommunityView,
CustomEmojiView,
GetSiteMetadata,
Language,
LemmyHttp,
MyUserInfo,
- Person,
PersonMentionView,
PersonView,
PostReportView,
: 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))/;
return SHORTNUM_SI_FORMAT.format(value);
}
-export function isBanned(ps: Person): boolean {
- const expires = ps.ban_expires;
- // Add Z to convert from UTC date
- // TODO this check probably isn't necessary anymore
- if (expires) {
- if (ps.banned && new Date(expires + "Z") > new Date()) {
- return true;
- } else {
- return false;
- }
- } else {
- return ps.banned;
- }
-}
-
export function myAuth(): string | undefined {
return UserService.Instance.auth();
}
}
}
-export function canCreateCommunity(
- siteRes: GetSiteResponse,
- myUserInfo = UserService.Instance.myUserInfo
-): boolean {
- const adminOnly = siteRes.site_view.local_site.community_creation_admin_only;
- // TODO: Make this check if user is logged on as well
- return !adminOnly || amAdmin(myUserInfo);
-}
-
export function isPostBlocked(
pv: PostView,
myUserInfo: MyUserInfo | undefined = UserService.Instance.myUserInfo
--- /dev/null
+import { UserService } from "../../services";
+
+export function amAdmin(myUserInfo = UserService.Instance.myUserInfo): boolean {
+ return myUserInfo?.local_user_view.person.admin ?? false;
+}
--- /dev/null
+import { CommunityModeratorView } from "lemmy-js-client";
+import { UserService } from "../../services";
+
+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;
+}
--- /dev/null
+import { CommunityModeratorView } from "lemmy-js-client";
+import { UserService } from "../../services";
+import { isMod } from "./is-mod";
+
+export function amMod(
+ mods?: CommunityModeratorView[],
+ myUserInfo = UserService.Instance.myUserInfo
+): boolean {
+ return myUserInfo ? isMod(myUserInfo.local_user_view.person.id, mods) : false;
+}
--- /dev/null
+import { PersonView } from "lemmy-js-client";
+import { UserService } from "../../services";
+
+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;
+}
--- /dev/null
+import { CommunityModeratorView } from "lemmy-js-client";
+import { UserService } from "../../services";
+
+export function amTopMod(
+ mods: CommunityModeratorView[],
+ myUserInfo = UserService.Instance.myUserInfo
+): boolean {
+ return mods.at(0)?.moderator.id == myUserInfo?.local_user_view.person.id;
+}
--- /dev/null
+import { PersonView } from "lemmy-js-client";
+import { UserService } from "../../services";
+import { canMod } from "./can-mod";
+
+export function canAdmin(
+ creatorId: number,
+ admins?: PersonView[],
+ myUserInfo = UserService.Instance.myUserInfo,
+ onSelf = false
+): boolean {
+ return canMod(creatorId, undefined, admins, myUserInfo, onSelf);
+}
--- /dev/null
+import { GetSiteResponse } from "lemmy-js-client";
+import { UserService } from "../../services";
+import { amAdmin } from "./am-admin";
+
+export function canCreateCommunity(
+ siteRes: GetSiteResponse,
+ myUserInfo = UserService.Instance.myUserInfo
+): boolean {
+ const adminOnly = siteRes.site_view.local_site.community_creation_admin_only;
+ // TODO: Make this check if user is logged on as well
+ return !adminOnly || amAdmin(myUserInfo);
+}
--- /dev/null
+import { CommunityModeratorView, PersonView } from "lemmy-js-client";
+import { UserService } from "../../services";
+
+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;
+ }
+}
--- /dev/null
+import { PersonView } from "lemmy-js-client";
+
+export function isAdmin(creatorId: number, admins?: PersonView[]): boolean {
+ return admins?.map(a => a.person.id).includes(creatorId) ?? false;
+}
--- /dev/null
+import { Person } from "lemmy-js-client";
+
+export function isBanned(ps: Person): boolean {
+ const expires = ps.ban_expires;
+ // Add Z to convert from UTC date
+ // TODO this check probably isn't necessary anymore
+ if (expires) {
+ if (ps.banned && new Date(expires + "Z") > new Date()) {
+ return true;
+ } else {
+ return false;
+ }
+ } else {
+ return ps.banned;
+ }
+}
--- /dev/null
+import { CommunityModeratorView } from "lemmy-js-client";
+
+export function isMod(
+ creatorId: number,
+ mods?: CommunityModeratorView[]
+): boolean {
+ return mods?.map(m => m.moderator.id).includes(creatorId) ?? false;
+}