moderator-toolbox-nxg-for-reddit / modules/modbutton/components/ModButtonPopup.helpers

modules/modbutton/components/ModButtonPopup.helpers

Functions

errorMessage()

errorMessage(error): string

Defined in: extension/data/modules/modbutton/components/ModButtonPopup.helpers.ts:53

Extracts a human-readable message from an unknown thrown value.

Parameters

error

unknown

The caught value.

Returns

string

error.message for Error instances, otherwise the value stringified.


fetchSubStatus()

fetchSubStatus(subreddit, user, currentUserName): Promise<{ banInfo: BanState | undefined; status: { banned: boolean; currentUserPermissions: string[]; daysLeft: number | null; isContributor: boolean; isMod: boolean; isMuted: boolean; loading: false; }; }>

Defined in: extension/data/modules/modbutton/components/ModButtonPopup.helpers.ts:140

Fetches the target user’s ban/contributor/mod/mute status for a subreddit in parallel.

Parameters

subreddit

string

The subreddit to check.

user

string

The target user’s username.

currentUserName

string

The acting moderator’s username (needed to look up their permissions).

Returns

Promise<{ banInfo: BanState | undefined; status: { banned: boolean; currentUserPermissions: string[]; daysLeft: number | null; isContributor: boolean; isMod: boolean; isMuted: boolean; loading: false; }; }>

The resolved SubStatus and raw banInfo (if any).


getDefaultActionForUrl()

getDefaultActionForUrl(): ActionKind | null

Defined in: extension/data/modules/modbutton/components/ModButtonPopup.helpers.ts:61

Returns the action that best matches the current page URL, or null if no special default applies. For example, /about/moderators defaults to 'mod'.

Returns

ActionKind | null


hasPermission()

hasPermission(permissions, …required): boolean

Defined in: extension/data/modules/modbutton/components/ModButtonPopup.helpers.ts:72

Returns true if permissions includes 'all' or any of the required permission strings.

Parameters

permissions

string[]

The current user’s mod permission list for a subreddit.

required

string[]

One or more permission names to check for.

Returns

boolean


isActionApplicable()

isActionApplicable(status, action): boolean

Defined in: extension/data/modules/modbutton/components/ModButtonPopup.helpers.ts:81

Returns true when the given action makes sense for a user with the given subreddit status. Used to disable checkboxes for non-applicable subs.

Parameters

status

SubStatus | undefined

action

ActionKind

Returns

boolean


notApplicableReason()

notApplicableReason(action): string

Defined in: extension/data/modules/modbutton/components/ModButtonPopup.helpers.ts:102

Returns a human-readable tooltip explaining why the given action is not applicable.

Parameters

action

ActionKind

Returns

string

Interfaces

ExistingBan

Defined in: extension/data/modules/modbutton/components/ModButtonPopup.helpers.ts:37

Details of an existing ban fetched from the Reddit API, shown in the ban form.

Properties

daysLeft

daysLeft: number | null

Defined in: extension/data/modules/modbutton/components/ModButtonPopup.helpers.ts:45

Remaining days on a temporary ban, or null for a permanent ban.

modName

modName: string

Defined in: extension/data/modules/modbutton/components/ModButtonPopup.helpers.ts:41

Username of the moderator who issued the ban.

note

note: string

Defined in: extension/data/modules/modbutton/components/ModButtonPopup.helpers.ts:38

timestamp

timestamp: Date

Defined in: extension/data/modules/modbutton/components/ModButtonPopup.helpers.ts:39

Variables

actionMap

const actionMap: Record<ActionKind, { action: "banned" | "contributor" | "moderator" | "muted"; kind: "positive" | "negative"; }>

Defined in: extension/data/modules/modbutton/components/ModButtonPopup.helpers.ts:22

Maps each action kind to the relationship it modifies and whether it adds or removes it.


loadingStatus

const loadingStatus: SubStatus

Defined in: extension/data/modules/modbutton/components/ModButtonPopup.helpers.ts:123

Placeholder status used while a subreddit’s relationship data is being fetched.


maxBanMessageLength

const maxBanMessageLength: 5000 = 5000

Defined in: extension/data/modules/modbutton/components/ModButtonPopup.helpers.ts:14

Reddit character limit for the ban message sent to the user.


maxBanReasonLength

const maxBanReasonLength: 300 = 300

Defined in: extension/data/modules/modbutton/components/ModButtonPopup.helpers.ts:12

Reddit character limit for the internal ban note.


maxFlairTextLength

const maxFlairTextLength: 64 = 64

Defined in: extension/data/modules/modbutton/components/ModButtonPopup.helpers.ts:19

Reddit character limit for user flair text.


removalNotice

const removalNotice: “\n\nNote: All of your posts and comments in this subreddit have been removed as a result of this ban.” = ‘\n\nNote: All of your posts and comments in this subreddit have been removed as a result of this ban.’

Defined in: extension/data/modules/modbutton/components/ModButtonPopup.helpers.ts:16

Notice appended to the ban message when “remove all content” is selected.