mirror of
https://github.com/Vendicated/Vencord.git
synced 2024-09-20 06:30:35 +00:00
Progress
This commit is contained in:
parent
9f6725f536
commit
abf69425ea
9 changed files with 554 additions and 220 deletions
|
@ -68,7 +68,7 @@
|
|||
"stylelint-config-standard": "^33.0.0",
|
||||
"tsx": "^3.12.7",
|
||||
"type-fest": "^3.9.0",
|
||||
"typescript": "^5.0.4",
|
||||
"typescript": "^5.4.5",
|
||||
"zip-local": "^0.3.5",
|
||||
"zustand": "^3.7.2"
|
||||
},
|
||||
|
|
|
@ -22,7 +22,7 @@ import { Settings } from "@api/Settings";
|
|||
import { Logger } from "@utils/Logger";
|
||||
import { Patch, Plugin, StartAt } from "@utils/types";
|
||||
import { FluxDispatcher } from "@webpack/common";
|
||||
import { FluxEvents } from "@webpack/types";
|
||||
import type { FluxActionType } from "@webpack/types";
|
||||
|
||||
import Plugins from "~plugins";
|
||||
|
||||
|
@ -129,7 +129,7 @@ export function subscribePluginFluxEvents(p: Plugin, fluxDispatcher: typeof Flux
|
|||
|
||||
logger.debug("Subscribing to flux events of plugin", p.name);
|
||||
for (const [event, handler] of Object.entries(p.flux)) {
|
||||
fluxDispatcher.subscribe(event as FluxEvents, handler);
|
||||
fluxDispatcher.subscribe(event as FluxActionType, handler);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -140,7 +140,7 @@ export function unsubscribePluginFluxEvents(p: Plugin, fluxDispatcher: typeof Fl
|
|||
|
||||
logger.debug("Unsubscribing from flux events of plugin", p.name);
|
||||
for (const [event, handler] of Object.entries(p.flux)) {
|
||||
fluxDispatcher.unsubscribe(event as FluxEvents, handler);
|
||||
fluxDispatcher.unsubscribe(event as FluxActionType, handler);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,12 +46,12 @@ export let ReadStateStore: GenericStore;
|
|||
export let PresenceStore: GenericStore;
|
||||
|
||||
export let GuildStore: t.GuildStore;
|
||||
export let UserStore: Stores.UserStore & t.FluxStore;
|
||||
export let UserProfileStore: GenericStore;
|
||||
export let UserStore: t.UserStore;
|
||||
export let UserProfileStore: t.UserProfileStore;
|
||||
export let SelectedChannelStore: Stores.SelectedChannelStore & t.FluxStore;
|
||||
export let SelectedGuildStore: t.FluxStore & Record<string, any>;
|
||||
export let ChannelStore: Stores.ChannelStore & t.FluxStore;
|
||||
export let GuildMemberStore: Stores.GuildMemberStore & t.FluxStore;
|
||||
export let GuildMemberStore: t.GuildMemberStore;
|
||||
export let RelationshipStore: Stores.RelationshipStore & t.FluxStore & {
|
||||
/** Get the date (as a string) that the relationship was created */
|
||||
getSince(userId: string): string;
|
||||
|
@ -65,28 +65,28 @@ export let DraftStore: t.DraftStore;
|
|||
* React hook that returns stateful data for one or more stores
|
||||
* You might need a custom comparator (4th argument) if your store data is an object
|
||||
* @param stores The stores to listen to
|
||||
* @param mapper A function that returns the data you need
|
||||
* @param getStateFromStores A function that returns the data you need
|
||||
* @param dependencies An array of reactive values which the hook depends on. Use this if your mapper or equality function depends on the value of another hook
|
||||
* @param isEqual A custom comparator for the data returned by mapper
|
||||
* @param areStatesEqual A custom comparator for the data returned by mapper
|
||||
*
|
||||
* @example const user = useStateFromStores([UserStore], () => UserStore.getCurrentUser(), null, (old, current) => old.id === current.id);
|
||||
*/
|
||||
// eslint-disable-next-line prefer-destructuring
|
||||
export const useStateFromStores: t.useStateFromStores = findByPropsLazy("useStateFromStores").useStateFromStores;
|
||||
|
||||
waitForStore("DraftStore", s => DraftStore = s);
|
||||
waitForStore("UserStore", s => UserStore = s);
|
||||
waitForStore("UserProfileStore", m => UserProfileStore = m);
|
||||
waitForStore("ChannelStore", m => ChannelStore = m);
|
||||
waitForStore("SelectedChannelStore", m => SelectedChannelStore = m);
|
||||
waitForStore("SelectedGuildStore", m => SelectedGuildStore = m);
|
||||
waitForStore("GuildStore", m => GuildStore = m);
|
||||
waitForStore("DraftStore", s => DraftStore = s);
|
||||
waitForStore("EmojiStore", m => EmojiStore = m);
|
||||
waitForStore("GuildChannelStore", m => GuildChannelStore = m);
|
||||
waitForStore("GuildMemberStore", m => GuildMemberStore = m);
|
||||
waitForStore("RelationshipStore", m => RelationshipStore = m);
|
||||
waitForStore("GuildStore", m => GuildStore = m);
|
||||
waitForStore("MessageStore", m => MessageStore = m);
|
||||
waitForStore("PermissionStore", m => PermissionStore = m);
|
||||
waitForStore("PresenceStore", m => PresenceStore = m);
|
||||
waitForStore("ReadStateStore", m => ReadStateStore = m);
|
||||
waitForStore("GuildChannelStore", m => GuildChannelStore = m);
|
||||
waitForStore("MessageStore", m => MessageStore = m);
|
||||
waitForStore("RelationshipStore", m => RelationshipStore = m);
|
||||
waitForStore("SelectedChannelStore", m => SelectedChannelStore = m);
|
||||
waitForStore("SelectedGuildStore", m => SelectedGuildStore = m);
|
||||
waitForStore("UserProfileStore", m => UserProfileStore = m);
|
||||
waitForStore("UserStore", s => UserStore = s);
|
||||
waitForStore("WindowStore", m => WindowStore = m);
|
||||
waitForStore("EmojiStore", m => EmojiStore = m);
|
||||
|
|
2
src/webpack/common/types/components.d.ts
vendored
2
src/webpack/common/types/components.d.ts
vendored
|
@ -16,7 +16,7 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import type { ComponentType, CSSProperties, FunctionComponent, HtmlHTMLAttributes, HTMLProps, KeyboardEvent, MouseEvent, PropsWithChildren, PropsWithRef, ReactNode, Ref } from "react";
|
||||
import type { ComponentType, CSSProperties, FunctionComponent, HtmlHTMLAttributes, HTMLProps, KeyboardEvent, MouseEvent, PropsWithChildren, PropsWithRef, ReactNode, Ref, RefObject } from "react";
|
||||
|
||||
export type TextVariant = "heading-sm/normal" | "heading-sm/medium" | "heading-sm/semibold" | "heading-sm/bold" | "heading-md/normal" | "heading-md/medium" | "heading-md/semibold" | "heading-md/bold" | "heading-lg/normal" | "heading-lg/medium" | "heading-lg/semibold" | "heading-lg/bold" | "heading-xl/normal" | "heading-xl/medium" | "heading-xl/bold" | "heading-xxl/normal" | "heading-xxl/medium" | "heading-xxl/bold" | "eyebrow" | "heading-deprecated-14/normal" | "heading-deprecated-14/medium" | "heading-deprecated-14/bold" | "text-xxs/normal" | "text-xxs/medium" | "text-xxs/semibold" | "text-xxs/bold" | "text-xs/normal" | "text-xs/medium" | "text-xs/semibold" | "text-xs/bold" | "text-sm/normal" | "text-sm/medium" | "text-sm/semibold" | "text-sm/bold" | "text-md/normal" | "text-md/medium" | "text-md/semibold" | "text-md/bold" | "text-lg/normal" | "text-lg/medium" | "text-lg/semibold" | "text-lg/bold" | "display-sm" | "display-md" | "display-lg" | "code";
|
||||
export type FormTextTypes = Record<"DEFAULT" | "INPUT_PLACEHOLDER" | "DESCRIPTION" | "LABEL_BOLD" | "LABEL_SELECTED" | "LABEL_DESCRIPTOR" | "ERROR" | "SUCCESS", string>;
|
||||
|
|
52
src/webpack/common/types/fluxActionType.d.ts
vendored
52
src/webpack/common/types/fluxActionType.d.ts
vendored
File diff suppressed because one or more lines are too long
57
src/webpack/common/types/fluxActions.d.ts
vendored
Normal file
57
src/webpack/common/types/fluxActions.d.ts
vendored
Normal file
File diff suppressed because one or more lines are too long
460
src/webpack/common/types/stores.d.ts
vendored
460
src/webpack/common/types/stores.d.ts
vendored
|
@ -17,19 +17,16 @@
|
|||
*/
|
||||
|
||||
import type { DraftType } from "@webpack/common";
|
||||
import type { APIUser, ApplicationFlags, OAuth2Scopes, UserFlags, UserPremiumType } from "discord-api-types/v9";
|
||||
import type { Channel, Guild, Role } from "discord-types/general"; // TODO
|
||||
import type { APIGuild, APIRoleTags, APIUser } from "discord-api-types/v9";
|
||||
import type { Channel } from "discord-types/general"; // TODO
|
||||
|
||||
import type { FluxAction, FluxActionHandlers, FluxActionType, FluxDispatchBand, FluxDispatcher } from "./utils";
|
||||
import type { ExcludeAction, ExtractAction, FluxAction, FluxActionHandlerMap, FluxDispatchBand, FluxDispatcher } from "./utils";
|
||||
|
||||
type Nullish = null | undefined;
|
||||
|
||||
type DispatcherAction<Dispatcher extends FluxDispatcher<FluxAction<string>>>
|
||||
= Dispatcher extends FluxDispatcher<infer Action> ? Action : never;
|
||||
|
||||
type FluxChangeListener = () => boolean;
|
||||
|
||||
class FluxChangeListeners {
|
||||
declare class FluxChangeListeners {
|
||||
has(listener: FluxChangeListener): boolean;
|
||||
hasAny(): boolean;
|
||||
invokeAll(): void;
|
||||
|
@ -43,19 +40,16 @@ class FluxChangeListeners {
|
|||
remove: (listener: FluxChangeListener) => void;
|
||||
}
|
||||
|
||||
export class FluxStore<
|
||||
Dispatcher extends FluxDispatcher<FluxAction<string>> = FluxDispatcher,
|
||||
Action extends DispatcherAction<Dispatcher> = DispatcherAction<Dispatcher>
|
||||
> {
|
||||
export class FluxStore<Action extends FluxAction = FluxAction> {
|
||||
constructor(
|
||||
dispatcher: Dispatcher,
|
||||
actionHandlers: FluxActionHandlers<Action>,
|
||||
band?: FluxDispatchBand | Nullish
|
||||
dispatcher: FluxDispatcher,
|
||||
actionHandlers: FluxActionHandlerMap<Action>,
|
||||
dispatchBand?: FluxDispatchBand | Nullish
|
||||
);
|
||||
|
||||
static displayName: undefined;
|
||||
static displayName: string | undefined; // undefined on FluxStore's constructor
|
||||
static destroy(): void;
|
||||
static getAll(): FluxStore<FluxDispatcher<FluxAction<string>>, FluxAction<string>>[];
|
||||
static getAll(): FluxStore[];
|
||||
static initialize(): void;
|
||||
static initialized: Promise<undefined>;
|
||||
|
||||
|
@ -64,28 +58,30 @@ export class FluxStore<
|
|||
getName(): string;
|
||||
initialize(): void;
|
||||
initializeIfNeeded(): void;
|
||||
mustEmitChanges: (mustEmitChanges?: ((action: Action) => boolean) | Nullish /* = () => true */) => void;
|
||||
mustEmitChanges(
|
||||
mustEmitChanges?: ((action: Action) => boolean) | Nullish /* = () => true */
|
||||
): void;
|
||||
registerActionHandlers(
|
||||
actionHandlers: FluxActionHandlers<Action>,
|
||||
band?: FluxDispatchBand | Nullish
|
||||
actionHandlers: FluxActionHandlerMap<Action>,
|
||||
dispatchBand?: FluxDispatchBand | Nullish
|
||||
): void;
|
||||
syncWith(
|
||||
stores: FluxStore<Dispatcher>[],
|
||||
stores: FluxStore[],
|
||||
func: () => boolean | void,
|
||||
timeout?: number | Nullish
|
||||
): void;
|
||||
waitFor(...stores: FluxStore<Dispatcher>[]): void;
|
||||
waitFor(...stores: FluxStore[]): void;
|
||||
|
||||
__getLocalVars: undefined;
|
||||
_changeCallbacks: FluxChangeListeners;
|
||||
_dispatcher: Dispatcher;
|
||||
_dispatcher: FluxDispatcher;
|
||||
_dispatchToken: string;
|
||||
_isInitialized: boolean;
|
||||
_mustEmitChanges: ((action: Action) => boolean) | Nullish;
|
||||
_reactChangeCallbacks: FluxChangeListeners;
|
||||
_syncWiths: {
|
||||
func: () => boolean | void;
|
||||
store: FluxStore<Dispatcher>;
|
||||
store: FluxStore;
|
||||
}[];
|
||||
addChangeListener: FluxChangeListeners["add"];
|
||||
addConditionalChangeListener: FluxChangeListeners["addConditional"];
|
||||
|
@ -94,21 +90,24 @@ export class FluxStore<
|
|||
removeReactChangeListener: FluxChangeListeners["remove"];
|
||||
}
|
||||
|
||||
type FluxSnapshotStoreActionType = Exclude<FluxActionType, "CLEAR_CACHES" | "WRITE_CACHES">;
|
||||
interface GenericConstructor { new (...args: any[]): any }
|
||||
|
||||
interface FluxSnapshot<Data = any> {
|
||||
data: Data;
|
||||
interface FluxSnapshot<SnapshotData = any> {
|
||||
data: SnapshotData;
|
||||
version: number;
|
||||
}
|
||||
|
||||
type FluxSnapshotStoreAction = ExcludeAction<FluxAction, "CLEAR_CACHES" | "WRITE_CACHES">;
|
||||
|
||||
export class FluxSnapshotStore<
|
||||
Constructor extends typeof FluxSnapshotStore = typeof FluxSnapshotStore,
|
||||
Constructor extends GenericConstructor = GenericConstructor,
|
||||
SnapshotData = any,
|
||||
Action extends FluxSnapshotStoreActionType = FluxSnapshotStoreActionType
|
||||
> extends FluxStore<FluxDispatcher, Action> {
|
||||
constructor(actionHandlers: FluxActionHandlers<Action>);
|
||||
Action extends FluxSnapshotStoreAction = FluxSnapshotStoreAction
|
||||
> extends FluxStore<Action & Exclude<FluxAction, FluxSnapshotStoreAction>> {
|
||||
constructor(actionHandlers: FluxActionHandlerMap<Action>);
|
||||
|
||||
static allStores: FluxSnapshotStore[];
|
||||
static displayName: string; // not actually defined on SnapshotStore's constructor, but all subclasses are required to have it
|
||||
static clearAll(): void;
|
||||
|
||||
clear(): void;
|
||||
|
@ -123,9 +122,9 @@ export interface Flux {
|
|||
}
|
||||
|
||||
export type useStateFromStores = <State>(
|
||||
stores: FluxStore<FluxDispatcher<FluxAction<string>>, FluxAction<string>>[],
|
||||
stores: FluxStore[],
|
||||
getStateFromStores: () => State,
|
||||
dependencies?: any[] | Nullish,
|
||||
dependencies?: unknown[] | Nullish,
|
||||
areStatesEqual?: ((prevState: State, currState: State) => boolean) | undefined
|
||||
) => State;
|
||||
|
||||
|
@ -267,44 +266,292 @@ export class EmojiStore extends FluxStore {
|
|||
};
|
||||
}
|
||||
|
||||
/*
|
||||
export class GuildMemberStore extends FluxStore {
|
||||
interface AvatarDecorationData {
|
||||
asset: string;
|
||||
skuId: string;
|
||||
}
|
||||
|
||||
export const enum GuildMemberFlags {
|
||||
DID_REJOIN = 1 << 0,
|
||||
COMPLETED_ONBOARDING = 1 << 1,
|
||||
BYPASSES_VERIFICATION = 1 << 2,
|
||||
STARTED_ONBOARDING = 1 << 3,
|
||||
IS_GUEST = 1 << 4,
|
||||
STARTED_HOME_ACTIONS = 1 << 5,
|
||||
COMPLETED_HOME_ACTIONS = 1 << 6,
|
||||
AUTOMOD_QUARANTINED_USERNAME_OR_GUILD_NICKNAME = 1 << 7,
|
||||
AUTOMOD_QUARANTINED_BIO = 1 << 8,
|
||||
DM_SETTINGS_UPSELL_ACKNOWLEDGED = 1 << 9,
|
||||
AUTOMOD_QUARANTINED_CLAN_TAG = 1 << 10
|
||||
}
|
||||
|
||||
export interface GuildMember {
|
||||
avatar: string | null;
|
||||
avatarDecoration: AvatarDecorationData | undefined;
|
||||
colorRoleId: string | undefined;
|
||||
colorString: string | undefined;
|
||||
communicationDisabledUntil: string | Nullish;
|
||||
flags: GuildMemberFlags;
|
||||
fullProfileLoadedTimestamp: number | undefined;
|
||||
guildId: string;
|
||||
highestRoleId: string | undefined;
|
||||
hoistRoleId: string | undefined;
|
||||
iconRoleId: string | undefined;
|
||||
isPending: boolean;
|
||||
joinedAt: string;
|
||||
nick: string | null;
|
||||
premiumSince: string | null;
|
||||
roles: string[];
|
||||
unusualDMActivityUntil: string | Nullish;
|
||||
userId: string;
|
||||
}
|
||||
|
||||
type GuildMemberStoreAction = ExtractAction<FluxAction, "CACHE_LOADED" | "CLEAR_PENDING_CHANNEL_AND_ROLE_UPDATES" | "CONNECTION_OPEN" | "CONNECTION_OPEN_SUPPLEMENTAL" | "GUILD_CREATE" | "GUILD_DELETE" | "GUILD_MEMBERS_CHUNK_BATCH" | "GUILD_MEMBER_ADD" | "GUILD_MEMBER_PROFILE_UPDATE" | "GUILD_MEMBER_REMOVE" | "GUILD_MEMBER_UPDATE" | "GUILD_MEMBER_UPDATE_LOCAL" | "GUILD_ROLE_DELETE" | "GUILD_ROLE_MEMBER_ADD" | "GUILD_ROLE_MEMBER_REMOVE" | "GUILD_ROLE_UPDATE" | "IMPERSONATE_STOP" | "IMPERSONATE_UPDATE" | "LOAD_ARCHIVED_THREADS_SUCCESS" | "LOAD_FORUM_POSTS" | "LOAD_MESSAGES_AROUND_SUCCESS" | "LOAD_MESSAGES_SUCCESS" | "LOAD_PINNED_MESSAGES_SUCCESS" | "LOAD_RECENT_MENTIONS_SUCCESS" | "LOCAL_MESSAGES_LOADED" | "MEMBER_SAFETY_GUILD_MEMBER_SEARCH_SUCCESS" | "MESSAGE_CREATE" | "MESSAGE_UPDATE" | "MOD_VIEW_SEARCH_FINISH" | "OVERLAY_INITIALIZE" | "PASSIVE_UPDATE_V1" | "SEARCH_FINISH" | "THREAD_MEMBERS_UPDATE" | "THREAD_MEMBER_LIST_UPDATE">;
|
||||
|
||||
export class GuildMemberStore<Action extends FluxAction = GuildMemberStoreAction> extends FluxStore<Action> {
|
||||
static displayName: "GuildMemberStore";
|
||||
|
||||
getCommunicationDisabledUserMap(): ;
|
||||
getCommunicationDisabledVersion(): ;
|
||||
getMember(e: , t: ): ;
|
||||
getMemberIds(e: ): ;
|
||||
getMemberRoleWithPendingUpdates(e: , t: ): ;
|
||||
getMembers(e: ): ;
|
||||
getMemberVersion(): ;
|
||||
getMutableAllGuildsAndMembers(): ;
|
||||
getNick(e: , t: ): ;
|
||||
getNicknameGuildsMapping(e: ): ;
|
||||
getNicknames(e: ): ;: ;
|
||||
getPendingRoleUpdates(e: ): ;
|
||||
getSelfMember(e: ): ;
|
||||
getTrueMember(e: , t: ): ;
|
||||
isCurrentUserGuest(e: ): ;
|
||||
isGuestOrLurker(e: , t: ): ;
|
||||
isMember(e: , t: ): ;
|
||||
memberOf(e: ): ;
|
||||
getCommunicationDisabledUserMap(): Record</* userId: */string, /* communicationDisabledUntil: */string>;
|
||||
getCommunicationDisabledVersion(): number;
|
||||
getMember(guildId: string, userId: string): GuildMember | null; // TEMP
|
||||
getMemberIds(guildId?: string | Nullish): string[];
|
||||
getMemberRoleWithPendingUpdates(guildId: string, userId: string): string[];
|
||||
getMembers(guildId?: string | Nullish): GuildMember[];
|
||||
getMemberVersion(): number;
|
||||
getMutableAllGuildsAndMembers(): Record</* guildId: */string, Record</* userId: */string, GuildMember>>;
|
||||
getNick(guildId?: string | Nullish, userId?: string | Nullish): string | null;
|
||||
getNicknameGuildsMapping(userId: string): Record</* nickname: */string, /* guildIds: */string[]>;
|
||||
getNicknames(userId: string): string[];
|
||||
getPendingRoleUpdates(guildId: string): {
|
||||
added: string[]
|
||||
removed: string[]
|
||||
};
|
||||
getSelfMember(guildId: string): GuildMember | null;
|
||||
getTrueMember(guildId: string, userId: string): GuildMember | null;
|
||||
isCurrentUserGuest(guildId?: string | Nullish): boolean;
|
||||
isGuestOrLurker(guildId?: string | Nullish, userId?: string | Nullish): boolean;
|
||||
isMember(guildId?: string | Nullish, userId?: string | Nullish): boolean;
|
||||
memberOf(userId: string): string[];
|
||||
}
|
||||
|
||||
export const enum RoleFlags {
|
||||
IN_PROMPT = 1
|
||||
}
|
||||
|
||||
/*
|
||||
// bigint enums are not yet possible: https://github.com/microsoft/TypeScript/issues/37783
|
||||
export const enum Permissions {
|
||||
CREATE_INSTANT_INVITE = 1n << 0n,
|
||||
KICK_MEMBERS = 1n << 1n,
|
||||
BAN_MEMBERS = 1n << 2n,
|
||||
ADMINISTRATOR = 1n << 3n,
|
||||
MANAGE_CHANNELS = 1n << 4n,
|
||||
MANAGE_GUILD = 1n << 5n,
|
||||
ADD_REACTIONS = 1n << 6n,
|
||||
VIEW_AUDIT_LOG = 1n << 7n,
|
||||
PRIORITY_SPEAKER = 1n << 8n,
|
||||
STREAM = 1n << 9n,
|
||||
VIEW_CHANNEL = 1n << 10n,
|
||||
SEND_MESSAGES = 1n << 11n,
|
||||
SEND_TTS_MESSAGES = 1n << 12n,
|
||||
MANAGE_MESSAGES = 1n << 13n,
|
||||
EMBED_LINKS = 1n << 14n,
|
||||
ATTACH_FILES = 1n << 15n,
|
||||
READ_MESSAGE_HISTORY = 1n << 16n,
|
||||
MENTION_EVERYONE = 1n << 17n,
|
||||
USE_EXTERNAL_EMOJIS = 1n << 18n,
|
||||
VIEW_GUILD_ANALYTICS = 1n << 19n,
|
||||
CONNECT = 1n << 20n,
|
||||
SPEAK = 1n << 21n,
|
||||
MUTE_MEMBERS = 1n << 22n,
|
||||
DEAFEN_MEMBERS = 1n << 23n,
|
||||
MOVE_MEMBERS = 1n << 24n,
|
||||
USE_VAD = 1n << 25n,
|
||||
CHANGE_NICKNAME = 1n << 26n,
|
||||
MANAGE_NICKNAMES = 1n << 27n,
|
||||
MANAGE_ROLES = 1n << 28n,
|
||||
MANAGE_WEBHOOKS = 1n << 29n,
|
||||
MANAGE_GUILD_EXPRESSIONS = 1n << 30n,
|
||||
USE_APPLICATION_COMMANDS = 1n << 31n,
|
||||
REQUEST_TO_SPEAK = 1n << 32n,
|
||||
MANAGE_EVENTS = 1n << 33n,
|
||||
MANAGE_THREADS = 1n << 34n,
|
||||
CREATE_PUBLIC_THREADS = 1n << 35n,
|
||||
CREATE_PRIVATE_THREADS = 1n << 36n,
|
||||
USE_EXTERNAL_STICKERS = 1n << 37n,
|
||||
SEND_MESSAGES_IN_THREADS = 1n << 38n,
|
||||
USE_EMBEDDED_ACTIVITIES = 1n << 39n,
|
||||
MODERATE_MEMBERS = 1n << 40n,
|
||||
VIEW_CREATOR_MONETIZATION_ANALYTICS = 1n << 41n,
|
||||
USE_SOUNDBOARD = 1n << 42n,
|
||||
CREATE_GUILD_EXPRESSIONS = 1n << 43n,
|
||||
CREATE_EVENTS = 1n << 44n,
|
||||
USE_EXTERNAL_SOUNDS = 1n << 45n,
|
||||
SEND_VOICE_MESSAGES = 1n << 46n,
|
||||
USE_CLYDE_AI = 1n << 47n,
|
||||
SET_VOICE_CHANNEL_STATUS = 1n << 48n,
|
||||
SEND_POLLS = 1n << 49n
|
||||
}
|
||||
*/
|
||||
|
||||
export class GuildStore extends FluxStore {
|
||||
getGuild(guildId: string): Guild;
|
||||
getGuildCount(): number;
|
||||
getGuilds(): Record<string, Guild>;
|
||||
getGuildIds(): string[];
|
||||
getRole(guildId: string, roleId: string): Role;
|
||||
getRoles(guildId: string): Record<string, Role>;
|
||||
getAllGuildRoles(): Record<string, Record<string, Role>>;
|
||||
export interface Role {
|
||||
color: number;
|
||||
colorString: string | null;
|
||||
flags: RoleFlags;
|
||||
hoist: boolean;
|
||||
icon: string | null;
|
||||
id: string;
|
||||
managed: boolean;
|
||||
mentionable: boolean;
|
||||
name: string;
|
||||
originalPosition: number;
|
||||
permissions: bigint /* Permissions */;
|
||||
position: number;
|
||||
tags: APIRoleTags;
|
||||
unicodeEmoji: string | null;
|
||||
}
|
||||
|
||||
enum ApplicationIntegrationType {
|
||||
GUILD_INSTALL,
|
||||
USER_INSTALL
|
||||
type GuildRecordOwnProperties = Pick<GuildRecord, "afkChannelId" | "afkTimeout" | "application_id" | "banner" | "clan" | "defaultMessageNotifications" | "description" | "discoverySplash" | "explicitContentFilter" | "features" | "homeHeader" | "hubType" | "icon" | "id" | "joinedAt" | "latestOnboardingQuestionId" | "maxMembers" | "maxStageVideoChannelUsers" | "maxVideoChannelUsers" | "mfaLevel" | "name" | "nsfwLevel" | "ownerId" | "preferredLocale" | "premiumProgressBarEnabled" | "premiumSubscriberCount" | "premiumTier" | "publicUpdatesChannelId" | "rulesChannelId" | "safetyAlertsChannelId" | "splash" | "systemChannelFlags" | "systemChannelId" | "vanityURLCode" | "verificationLevel">;
|
||||
|
||||
export class GuildRecord<
|
||||
OwnProperties extends GuildRecordOwnProperties = GuildRecordOwnProperties
|
||||
> extends ImmutableRecord<OwnProperties> {
|
||||
constructor(guildFromServer: APIGuild);
|
||||
|
||||
get acronym(): ; // TEMP
|
||||
canHaveRaidActivityAlerts(): ; // TEMP
|
||||
getApplicationId(): ; // TEMP
|
||||
getEveryoneRoleId(): ; // TEMP
|
||||
getIconSource(e: ): ; // TEMP
|
||||
getIconURL(e: ): ; // TEMP
|
||||
getMaxEmojiSlots(): ; // TEMP
|
||||
getMaxRoleSubscriptionEmojiSlots(): ; // TEMP
|
||||
getMaxSoundboardSlots(): ; // TEMP
|
||||
getSafetyAlertsChannelId(): ; // TEMP
|
||||
isCommunity(): ; // TEMP
|
||||
isLurker(): ; // TEMP
|
||||
isNew(): ; // TEMP
|
||||
isOwner(e: ): ; // TEMP
|
||||
isOwnerWithRequiredMfaLevel(e: ): ; // TEMP
|
||||
hasCommunityInfoSubheader(): ; // TEMP
|
||||
hasFeature(e: ): ; // TEMP
|
||||
hasVerificationGate(): ; // TEMP
|
||||
merge(e: ): ; // TEMP
|
||||
updateJoinedAt(e: ): ; // TEMP
|
||||
|
||||
afkChannelId: ; // TEMP
|
||||
afkTimeout: ; // TEMP
|
||||
application_id: ; // TEMP
|
||||
banner: ; // TEMP
|
||||
clan: ; // TEMP
|
||||
defaultMessageNotifications: ; // TEMP
|
||||
description: ; // TEMP
|
||||
discoverySplash: ; // TEMP
|
||||
explicitContentFilter: ; // TEMP
|
||||
features: ; // TEMP
|
||||
homeHeader: ; // TEMP
|
||||
hubType: ; // TEMP
|
||||
icon: ; // TEMP
|
||||
id: ; // TEMP
|
||||
joinedAt: ; // TEMP
|
||||
latestOnboardingQuestionId: ; // TEMP
|
||||
maxMembers: ; // TEMP
|
||||
maxStageVideoChannelUsers: ; // TEMP
|
||||
maxVideoChannelUsers: ; // TEMP
|
||||
mfaLevel: ; // TEMP
|
||||
name: ; // TEMP
|
||||
nsfwLevel: ; // TEMP
|
||||
ownerId: ; // TEMP
|
||||
preferredLocale: ; // TEMP
|
||||
premiumProgressBarEnabled: ; // TEMP
|
||||
premiumSubscriberCount: ; // TEMP
|
||||
premiumTier: ; // TEMP
|
||||
publicUpdatesChannelId: ; // TEMP
|
||||
rulesChannelId: ; // TEMP
|
||||
safetyAlertsChannelId: ; // TEMP
|
||||
splash: ; // TEMP
|
||||
systemChannelFlags: ; // TEMP
|
||||
systemChannelId: ; // TEMP
|
||||
vanityURLCode: ; // TEMP
|
||||
verificationLevel: ; // TEMP
|
||||
}
|
||||
|
||||
type GuildStoreAction = ExtractAction<FluxAction, "BACKGROUND_SYNC" | "CACHE_LOADED" | "CACHE_LOADED_LAZY" | "CONNECTION_OPEN" | "GUILD_CREATE" | "GUILD_DELETE" | "GUILD_GEO_RESTRICTED" | "GUILD_MEMBER_ADD" | "GUILD_ROLE_CREATE" | "GUILD_ROLE_DELETE" | "GUILD_ROLE_UPDATE" | "GUILD_SETTINGS_SUBMIT_SUCCESS" | "GUILD_UPDATE" | "OVERLAY_INITIALIZE">;
|
||||
|
||||
export class GuildStore<Action extends FluxAction = GuildStoreAction> extends FluxStore<Action> {
|
||||
static displayName: "GuildStore";
|
||||
|
||||
getAllGuildsRoles(): Record</* guildId: */string, Record</* roleId: */string, Role>>;
|
||||
getGeoRestrictedGuilds(): Record</* guildId: */string, GuildRecord>;
|
||||
getGuild(guildId?: string | Nullish): GuildRecord;
|
||||
getGuildCount(): number;
|
||||
getGuildIds(): string[];
|
||||
getGuilds(): Record</* guildId: */string, GuildRecord>;
|
||||
getRole(guildId: string, roleId: string): Role;
|
||||
getRoles(guildId: string): Record</* roleId: */string, Role>;
|
||||
isLoaded(): boolean;
|
||||
}
|
||||
|
||||
export const enum ApplicationFlags {
|
||||
EMBEDDED_RELEASED = 1 << 1,
|
||||
EMBEDDED_IAP = 1 << 3,
|
||||
APPLICATION_AUTO_MODERATION_RULE_CREATE_BADGE = 1 << 6,
|
||||
GATEWAY_PRESENCE = 1 << 12,
|
||||
GATEWAY_PRESENCE_LIMITED = 1 << 13,
|
||||
GATEWAY_GUILD_MEMBERS = 1 << 14,
|
||||
GATEWAY_GUILD_MEMBERS_LIMITED = 1 << 15,
|
||||
EMBEDDED = 1 << 17,
|
||||
GATEWAY_MESSAGE_CONTENT = 1 << 18,
|
||||
GATEWAY_MESSAGE_CONTENT_LIMITED = 1 << 19,
|
||||
EMBEDDED_FIRST_PARTY = 1 << 20,
|
||||
APPLICATION_COMMAND_BADGE = 1 << 23,
|
||||
SOCIAL_LAYER_INTEGRATION = 1 << 27
|
||||
}
|
||||
|
||||
export const enum OAuth2Scopes {
|
||||
ACTIVITIES_READ = "activities.read",
|
||||
ACTIVITIES_WRITE = "activities.write",
|
||||
APPLICATIONS_BUILDS_READ = "applications.builds.read",
|
||||
APPLICATIONS_BUILDS_UPLOAD = "applications.builds.upload",
|
||||
APPLICATIONS_COMMANDS = "applications.commands",
|
||||
APPLICATIONS_COMMANDS_PERMISSIONS_UPDATE = "applications.commands.permissions.update",
|
||||
APPLICATIONS_COMMANDS_UPDATE = "applications.commands.update",
|
||||
APPLICATIONS_ENTITLEMENTS = "applications.entitlements",
|
||||
APPLICATIONS_STORE_UPDATE = "applications.store.update",
|
||||
BOT = "bot",
|
||||
CONNECTIONS = "connections",
|
||||
DM_CHANNELS_MESSAGES_READ = "dm_channels.messages.read",
|
||||
DM_CHANNELS_MESSAGES_WRITE = "dm_channels.messages.write",
|
||||
DM_CHANNELS_READ = "dm_channels.read",
|
||||
EMAIL = "email",
|
||||
GDM_JOIN = "gdm.join",
|
||||
GUILDS = "guilds",
|
||||
GUILDS_JOIN = "guilds.join",
|
||||
GUILDS_MEMBERS_READ = "guilds.members.read",
|
||||
IDENTIFY = "identify",
|
||||
MESSAGES_READ = "messages.read",
|
||||
OPENID = "openid",
|
||||
PRESENCES_READ = "presences.read",
|
||||
PRESENCES_WRITE = "presences.write",
|
||||
RELATIONSHIPS_READ = "relationships.read",
|
||||
RELATIONSHIPS_WRITE = "relationships.write",
|
||||
ROLE_CONNECTIONS_WRITE = "role_connections.write",
|
||||
RPC = "rpc",
|
||||
RPC_ACTIVITIES_WRITE = "rpc.activities.write",
|
||||
RPC_NOTIFICATIONS_READ = "rpc.notifications.read",
|
||||
RPC_SCREENSHARE_READ = "rpc.screenshare.read",
|
||||
RPC_SCREENSHARE_WRITE = "rpc.screenshare.write",
|
||||
RPC_VIDEO_READ = "rpc.video.read",
|
||||
RPC_VIDEO_WRITE = "rpc.video.write",
|
||||
RPC_VOICE_READ = "rpc.voice.read",
|
||||
RPC_VOICE_WRITE = "rpc.voice.write",
|
||||
VOICE = "voice",
|
||||
WEBHOOK_INCOMING = "webhook.incoming"
|
||||
}
|
||||
|
||||
export const enum ApplicationIntegrationType {
|
||||
GUILD_INSTALL = 0,
|
||||
USER_INSTALL = 1
|
||||
}
|
||||
|
||||
interface UserProfileFetchFailed {
|
||||
|
@ -359,7 +606,7 @@ interface UserProfileFetchSucceeded {
|
|||
popoutAnimationParticleType: Nullish; // TEMP
|
||||
premiumGuildSince: Date | null;
|
||||
premiumSince: Date | null;
|
||||
premiumType: UserPremiumType | Nullish;
|
||||
premiumType: PremiumTypes | Nullish;
|
||||
profileEffectId: string | undefined;
|
||||
profileFetchFailed: false;
|
||||
pronouns: string;
|
||||
|
@ -371,21 +618,41 @@ export type UserProfile<FetchFailed extends boolean = boolean> = FetchFailed ext
|
|||
? UserProfileFetchFailed
|
||||
: UserProfileFetchSucceeded;
|
||||
|
||||
|
||||
export const enum StatusTypes {
|
||||
DND = "dnd",
|
||||
IDLE = "idle",
|
||||
INVISIBLE = "invisible",
|
||||
OFFLINE = "offline",
|
||||
ONLINE = "online",
|
||||
STREAMING = "streaming",
|
||||
UNKNOWN = "unknown"
|
||||
}
|
||||
|
||||
interface UserProfileStoreSnapshotData {
|
||||
userId: string;
|
||||
profile: UserProfile | undefined;
|
||||
}
|
||||
|
||||
type UserProfileStoreAction = ExtractAction<FluxAction, "CACHE_LOADED_LAZY" | "GUILD_DELETE" | "GUILD_JOIN" | "GUILD_MEMBER_ADD" | "GUILD_MEMBER_REMOVE" | "GUILD_MEMBER_UPDATE" | "LOGOUT" | "MUTUAL_FRIENDS_FETCH_FAILURE" | "MUTUAL_FRIENDS_FETCH_START" | "MUTUAL_FRIENDS_FETCH_SUCCESS" | "USER_PROFILE_ACCESSIBILITY_TOOLTIP_VIEWED" | "USER_PROFILE_FETCH_FAILURE" | "USER_PROFILE_FETCH_START" | "USER_PROFILE_FETCH_SUCCESS" | "USER_PROFILE_UPDATE_FAILURE" | "USER_PROFILE_UPDATE_START" | "USER_PROFILE_UPDATE_SUCCESS" | "USER_UPDATE">;
|
||||
|
||||
export class UserProfileStore extends FluxSnapshotStore<typeof UserProfileStore, UserProfileStoreSnapshotData> {
|
||||
static displayName: "UserProfileStore";
|
||||
static LATEST_SNAPSHOT_VERSION: number;
|
||||
|
||||
getUserProfile<FetchFailed extends boolean = boolean>(userId: string): UserProfile<FetchFailed> | undefined;
|
||||
getGuildMemberProfile<T extends string | Nullish>(userId: string, guildId: T): T extends Nullish ? null : any | undefined; // TEMP
|
||||
getGuildMemberProfile(userId: string, guildId?: string | Nullish): Record<string, any> /* | Nullish */; // TEMP
|
||||
getIsAccessibilityTooltipViewed(): boolean;
|
||||
getMutualFriends(userId: string): any; // TEMP
|
||||
getMutualFriends(userId: string): {
|
||||
key: string; // userId
|
||||
status: StatusTypes;
|
||||
user: UserRecord;
|
||||
}[];
|
||||
getMutualFriendsCount(userId: string): number;
|
||||
getMutualGuilds(userId: string): any; // TEMP
|
||||
getMutualGuilds(userId: string): {
|
||||
guild: Record<string, any>; // TEMP
|
||||
nick: string | null;
|
||||
}[];
|
||||
isFetchingFriends(userId: string): boolean;
|
||||
isFetchingProfile(userId: string): boolean;
|
||||
get isSubmitting(): boolean;
|
||||
|
@ -394,14 +661,43 @@ export class UserProfileStore extends FluxSnapshotStore<typeof UserProfileStore,
|
|||
loadCache: () => void;
|
||||
}
|
||||
|
||||
interface AvatarDecorationData {
|
||||
asset: string;
|
||||
skuId: string;
|
||||
export const enum UserFlags {
|
||||
STAFF = 1 << 0,
|
||||
PARTNER = 1 << 1,
|
||||
HYPESQUAD = 1 << 2,
|
||||
BUG_HUNTER_LEVEL_1 = 1 << 3,
|
||||
MFA_SMS = 1 << 4,
|
||||
PREMIUM_PROMO_DISMISSED = 1 << 5,
|
||||
HYPESQUAD_ONLINE_HOUSE_1 = 1 << 6,
|
||||
HYPESQUAD_ONLINE_HOUSE_2 = 1 << 7,
|
||||
HYPESQUAD_ONLINE_HOUSE_3 = 1 << 8,
|
||||
PREMIUM_EARLY_SUPPORTER = 1 << 9,
|
||||
TEAM_PSEUDO_USER = 1 << 10,
|
||||
HAS_UNREAD_URGENT_MESSAGES = 1 << 13,
|
||||
BUG_HUNTER_LEVEL_2 = 1 << 14,
|
||||
VERIFIED_BOT = 1 << 16,
|
||||
VERIFIED_DEVELOPER = 1 << 17,
|
||||
CERTIFIED_MODERATOR = 1 << 18,
|
||||
BOT_HTTP_INTERACTIONS = 1 << 19,
|
||||
SPAMMER = 1 << 20,
|
||||
DISABLE_PREMIUM = 1 << 21,
|
||||
ACTIVE_DEVELOPER = 1 << 22,
|
||||
QUARANTINED = 0x100_000_000_000,
|
||||
COLLABORATOR = 0x4_000_000_000_000,
|
||||
RESTRICTED_COLLABORATOR = 0x8_000_000_000_000
|
||||
}
|
||||
|
||||
export const enum PremiumTypes {
|
||||
TIER_1 = 1,
|
||||
TIER_2 = 2,
|
||||
TIER_0 = 3
|
||||
}
|
||||
|
||||
type UserRecordOwnProperties = Pick<UserRecord, "avatar" | "avatarDecorationData" | "bot" | "clan" | "desktop" | "discriminator" | "email" | "flags" | "globalName" | "guildMemberAvatars" | "hasAnyStaffLevel" | "hasBouncedEmail" | "hasFlag" | "id" | "isStaff" | "isStaffPersonal" | "mfaEnabled" | "mobile" | "nsfwAllowed" | "personalConnectionId" | "phone" | "premiumType" | "premiumUsageFlags" | "publicFlags" | "purchasedFlags" | "system" | "username" | "verified">;
|
||||
|
||||
export class UserRecord extends ImmutableRecord<UserRecordOwnProperties> {
|
||||
export class UserRecord<
|
||||
OwnProperties extends UserRecordOwnProperties = UserRecordOwnProperties
|
||||
> extends ImmutableRecord<OwnProperties> {
|
||||
constructor(userFromServer: APIUser);
|
||||
|
||||
addGuildAvatarHash(guildId: string, avatarHash: string): this;
|
||||
|
@ -410,10 +706,18 @@ export class UserRecord extends ImmutableRecord<UserRecordOwnProperties> {
|
|||
asset: string;
|
||||
skuId?: string;
|
||||
sku_id?: string;
|
||||
} | null): void;
|
||||
} | null);
|
||||
get createdAt(): Date;
|
||||
getAvatarSource(guildId?: string | Nullish, canAnimate?: boolean | undefined, avatarSize?: number | undefined): { uri: string; };
|
||||
getAvatarURL(guildId?: string | Nullish, avatarSize?: number | undefined, canAnimate?: boolean | undefined): string;
|
||||
getAvatarSource(
|
||||
guildId?: string | Nullish,
|
||||
canAnimate?: boolean | undefined,
|
||||
avatarSize?: number | undefined
|
||||
): { uri: string; };
|
||||
getAvatarURL(
|
||||
guildId?: string | Nullish,
|
||||
avatarSize?: number | undefined,
|
||||
canAnimate?: boolean | undefined
|
||||
): string;
|
||||
hasAvatarForGuild(guildId?: string | Nullish): boolean;
|
||||
hasDisabledPremium(): boolean;
|
||||
hasFreePremium(): boolean;
|
||||
|
@ -461,7 +765,7 @@ export class UserRecord extends ImmutableRecord<UserRecordOwnProperties> {
|
|||
nsfwAllowed: boolean;
|
||||
personalConnectionId: string | null;
|
||||
phone: string | null;
|
||||
premiumType: UserPremiumType | Nullish; // discord seems to have recently made it so that premiumType is nullish for every UserRecord
|
||||
premiumType: PremiumTypes | Nullish; // discord seems to have recently made it so that premiumType is nullish for every UserRecord
|
||||
premiumUsageFlags: number;
|
||||
publicFlags: UserFlags;
|
||||
purchasedFlags: number;
|
||||
|
@ -472,7 +776,11 @@ export class UserRecord extends ImmutableRecord<UserRecordOwnProperties> {
|
|||
|
||||
interface UserStoreSnapshotData { users: [UserRecord] | []; }
|
||||
|
||||
export class UserStore extends FluxSnapshotStore<typeof UserStore, UserStoreSnapshotData> {
|
||||
type UserStoreAction = ExtractAction<FluxAction, "AUDIT_LOG_FETCH_NEXT_PAGE_SUCCESS" | "AUDIT_LOG_FETCH_SUCCESS" | "CACHE_LOADED" | "CHANNEL_CREATE" | "CHANNEL_RECIPIENT_ADD" | "CHANNEL_RECIPIENT_REMOVE" | "CHANNEL_UPDATES" | "CONNECTION_OPEN" | "CONNECTION_OPEN_SUPPLEMENTAL" | "CURRENT_USER_UPDATE" | "FAMILY_CENTER_INITIAL_LOAD" | "FAMILY_CENTER_LINKED_USERS_FETCH_SUCCESS" | "FAMILY_CENTER_REQUEST_LINK_SUCCESS" | "FAMILY_CENTER_TEEN_ACTIVITY_FETCH_SUCCESS" | "FAMILY_CENTER_TEEN_ACTIVITY_MORE_FETCH_SUCCESS" | "FETCH_PRIVATE_CHANNEL_INTEGRATIONS_SUCCESS" | "FRIEND_SUGGESTION_CREATE" | "GIFT_CODE_RESOLVE_SUCCESS" | "GUILD_APPLIED_BOOSTS_FETCH_SUCCESS" | "GUILD_BAN_ADD" | "GUILD_BAN_REMOVE" | "GUILD_CREATE" | "GUILD_FEED_FETCH_SUCCESS" | "GUILD_JOIN_REQUEST_CREATE" | "GUILD_JOIN_REQUEST_UPDATE" | "GUILD_MEMBERS_CHUNK_BATCH" | "GUILD_MEMBER_ADD" | "GUILD_MEMBER_LIST_UPDATE" | "GUILD_MEMBER_UPDATE" | "GUILD_SCHEDULED_EVENT_USERS_FETCH_SUCCESS" | "GUILD_SETTINGS_LOADED_BANS" | "GUILD_SETTINGS_LOADED_BANS_BATCH" | "LOAD_ARCHIVED_THREADS_SUCCESS" | "LOAD_FORUM_POSTS" | "LOAD_FRIEND_SUGGESTIONS_SUCCESS" | "LOAD_MESSAGES_AROUND_SUCCESS" | "LOAD_MESSAGES_SUCCESS" | "LOAD_MESSAGE_REQUESTS_SUPPLEMENTAL_DATA_SUCCESS" | "LOAD_NOTIFICATION_CENTER_ITEMS_SUCCESS" | "LOAD_PINNED_MESSAGES_SUCCESS" | "LOAD_RECENT_MENTIONS_SUCCESS" | "LOAD_RELATIONSHIPS_SUCCESS" | "LOAD_THREADS_SUCCESS" | "LOCAL_MESSAGES_LOADED" | "MEMBER_SAFETY_GUILD_MEMBER_SEARCH_SUCCESS" | "MESSAGE_CREATE" | "MESSAGE_UPDATE" | "MOD_VIEW_SEARCH_FINISH" | "NOTIFICATION_CENTER_ITEM_CREATE" | "OVERLAY_INITIALIZE" | "PASSIVE_UPDATE_V1" | "PRESENCE_UPDATES" | "PRIVATE_CHANNEL_INTEGRATION_CREATE" | "PRIVATE_CHANNEL_INTEGRATION_UPDATE" | "RELATIONSHIP_ADD" | "SEARCH_FINISH" | "THREAD_LIST_SYNC" | "THREAD_MEMBERS_UPDATE" | "THREAD_MEMBER_LIST_UPDATE" | "UPDATE_CLIENT_PREMIUM_TYPE" | "USER_UPDATE">;
|
||||
|
||||
export class UserStore extends FluxSnapshotStore<typeof UserStore, UserStoreSnapshotData, UserStoreAction> {
|
||||
constructor();
|
||||
|
||||
static displayName: "UserStore";
|
||||
static LATEST_SNAPSHOT_VERSION: number;
|
||||
|
||||
|
|
164
src/webpack/common/types/utils.d.ts
vendored
164
src/webpack/common/types/utils.d.ts
vendored
|
@ -19,20 +19,20 @@
|
|||
import type { Guild, GuildMember } from "discord-types/general"; // TODO
|
||||
import type { EventEmitter } from "events"; // Discord uses a polyfill for Node's EventEmitter
|
||||
import type { ReactNode } from "react";
|
||||
import type { OmitIndexSignature } from "type-fest";
|
||||
|
||||
import type { ExtractAction, FluxAction, FluxActionType } from "./fluxActions";
|
||||
// import type { OmitIndexSignature } from "type-fest";
|
||||
import type { ExcludeAction, ExtractAction, FluxAction, FluxActionType } from "./fluxActions";
|
||||
import type { i18nMessages } from "./i18nMessages";
|
||||
|
||||
export { ExtractAction, FluxAction, FluxActionType };
|
||||
export { ExcludeAction, ExtractAction, FluxAction, FluxActionType };
|
||||
|
||||
type Nullish = null | undefined;
|
||||
|
||||
class DepGraph<Data = any> {
|
||||
declare class DepGraph<Data = any> {
|
||||
constructor(options?: { circular?: boolean | undefined; } | undefined);
|
||||
|
||||
addDependency(from: string, to: string): void;
|
||||
addNode(name: string, data?: Data | undefined): void;
|
||||
addNode(name: string, data/* ?*/: Data/* | undefined*/): void;
|
||||
clone(): DepGraph<Data>;
|
||||
dependantsOf(name: string, leavesOnly?: boolean | undefined): string[];
|
||||
dependenciesOf(name: string, leavesOnly?: boolean | undefined): string[];
|
||||
|
@ -41,62 +41,73 @@ class DepGraph<Data = any> {
|
|||
overallOrder(leavesOnly?: boolean | undefined): string[];
|
||||
removeDependency(from: string, to: string): void;
|
||||
removeNode(name: string): void;
|
||||
setNodeData(name: string, data?: Data | undefined): void;
|
||||
setNodeData(name: string, data/* ?*/: Data/* | undefined*/): void;
|
||||
size(): number;
|
||||
|
||||
circular: boolean | undefined;
|
||||
nodes: Record<string, Data | string>;
|
||||
nodes: Record<string, Data/* | string*/>;
|
||||
outgoingEdges: Record<string, string[]>;
|
||||
incomingEdges: Record<string, string[]>;
|
||||
}
|
||||
|
||||
export enum FluxDispatchBand {
|
||||
Early,
|
||||
Database,
|
||||
Default
|
||||
export const enum FluxDispatchBand {
|
||||
Early = 0,
|
||||
Database = 1,
|
||||
Default = 2
|
||||
}
|
||||
|
||||
export type FluxActionHandler<Action = FluxAction, Return = void> = Action extends FluxAction<string>
|
||||
/*
|
||||
export type FluxActionHandler<Action = FluxAction, Return = void> = Action extends FluxAction
|
||||
? Exclude<keyof OmitIndexSignature<Action>, "type"> extends never
|
||||
? (action: any) => Return
|
||||
: (action: Action) => Return
|
||||
: never;
|
||||
*/
|
||||
|
||||
export type FluxActionHandlers<Action extends FluxAction<string> = FluxAction>
|
||||
export type FluxActionHandler<Action extends FluxAction = FluxAction> = (action: Action) => void;
|
||||
|
||||
export type FluxActionHandlerMap<Action extends FluxAction = FluxAction>
|
||||
= { [ActionType in Action["type"]]: FluxActionHandler<ExtractAction<Action, ActionType>>; };
|
||||
|
||||
interface FluxActionHandlersGraphNode<Action extends FluxAction<string> = FluxAction> {
|
||||
name: string;
|
||||
band: number;
|
||||
actionHandler: FluxActionHandler<Action>;
|
||||
storeDidChange: FluxActionHandler<Action>;
|
||||
interface FluxActionHandlersGraphNode {
|
||||
name: string; // storeName
|
||||
band: FluxDispatchBand;
|
||||
actionHandler: FluxActionHandlerMap<FluxAction>;
|
||||
storeDidChange: FluxActionHandler<FluxAction>;
|
||||
}
|
||||
|
||||
type FluxOrderedActionHandlers<Action extends FluxAction<string> = FluxAction>
|
||||
= Omit<FluxActionHandlersGraphNode<Action>, "band">[];
|
||||
type FluxOrderedActionHandlers<Action extends FluxAction = FluxAction> = {
|
||||
name: string; // storeName
|
||||
actionHandler: FluxActionHandler<Action>;
|
||||
storeDidChange: FluxActionHandler<Action>;
|
||||
}[];
|
||||
|
||||
class FluxActionHandlersGraph<Action extends FluxAction<string> = FluxAction> {
|
||||
_addToBand(token: string, band: FluxDispatchBand): void;
|
||||
_bandToken(band: DispatcherBand): string;
|
||||
_computeOrderedActionHandlers(actionType: Action["type"]): FluxOrderedActionHandlers<Action>;
|
||||
declare class FluxActionHandlersGraph {
|
||||
_addToBand(dispatchToken: string, dispatchBand: FluxDispatchBand): void;
|
||||
_bandToken(dispatchBand: FluxDispatchBand): string;
|
||||
_computeOrderedActionHandlers<ActionType extends FluxActionType>(
|
||||
actionType: ActionType
|
||||
): FluxOrderedActionHandlers<ExtractAction<FluxAction, ActionType>>[];
|
||||
_computeOrderedCallbackTokens(): string[];
|
||||
_invalidateCaches(): void;
|
||||
_validateDependencies(fromToken: string, toToken: string): void;
|
||||
addDependencies(fromToken: string, toTokens: string[]): void;
|
||||
_validateDependencies(fromDispatchToken: string, toDispatchToken: string): void;
|
||||
addDependencies(fromDispatchToken: string, toDispatchTokens: string[]): void;
|
||||
createToken(): string;
|
||||
getOrderedActionHandlers(action: Action): FluxOrderedActionHandlers<Action>;
|
||||
register(
|
||||
name: string,
|
||||
actionHandlers: Partial<FluxActionHandlers<Action>>,
|
||||
getOrderedActionHandlers<ActionType extends FluxActionType>({ type }: {
|
||||
type: ActionType;
|
||||
}): FluxOrderedActionHandlers<ExtractAction<FluxAction, ActionType>>;
|
||||
register<Action extends FluxAction>(
|
||||
storeName: string,
|
||||
actionHandlers: FluxActionHandlerMap<Action>,
|
||||
storeDidChange: FluxActionHandler<Action>,
|
||||
band: FluxDispatchBand,
|
||||
token?: string | undefined
|
||||
dispatchBand: FluxDispatchBand,
|
||||
dispatchToken?: string | undefined
|
||||
): string;
|
||||
|
||||
_dependencyGraph: DepGraph<FluxActionHandlersGraphNode<Action>>;
|
||||
_dependencyGraph: DepGraph<FluxActionHandlersGraphNode>;
|
||||
_lastID: number;
|
||||
_orderedActionHandlers: {
|
||||
[ActionType in Action["type"]]?: FluxOrderedActionHandlers<ExtractAction<Action, ActionType>> | Nullish;
|
||||
[ActionType in FluxActionType]?: FluxOrderedActionHandlers<ExtractAction<FluxAction, ActionType>> | Nullish;
|
||||
};
|
||||
_orderedCallbackTokens: string[] | Nullish;
|
||||
}
|
||||
|
@ -111,14 +122,14 @@ interface SentryUtils {
|
|||
}) => void;
|
||||
}
|
||||
|
||||
type ActionMetric<ActionType extends string = FluxActionType>
|
||||
type FluxActionMetric<ActionType extends FluxActionType = FluxActionType>
|
||||
= [storeName: string, actionType: ActionType, totalTime: number];
|
||||
|
||||
class FluxActionLog<Action extends FluxAction<string> = FluxAction> {
|
||||
declare class FluxActionLog<Action extends FluxAction = FluxAction> {
|
||||
constructor(actionType: Action["type"]);
|
||||
|
||||
get name(): Action["type"];
|
||||
toJSON(): Pick<FluxActionLog<Action["type"]>, "action" | "createdAt" | "traces"> & {
|
||||
toJSON(): Pick<FluxActionLog<Action>, "action" | "createdAt" | "traces"> & {
|
||||
created_at: FluxActionLog["createdAt"];
|
||||
};
|
||||
|
||||
|
@ -134,74 +145,84 @@ class FluxActionLog<Action extends FluxAction<string> = FluxAction> {
|
|||
}[];
|
||||
}
|
||||
|
||||
class FluxActionLogger<Action extends FluxAction<string> = FluxAction> extends EventEmitter {
|
||||
declare class FluxActionLogger extends EventEmitter {
|
||||
constructor(options?: { persist?: boolean | undefined; } | undefined);
|
||||
|
||||
getLastActionMetrics(
|
||||
title: string,
|
||||
limit?: number | undefined /* = 20 */
|
||||
): ActionMetric<Action["type"]>[];
|
||||
getSlowestActions(
|
||||
actionType?: Action["type"] | Nullish,
|
||||
): FluxActionMetric[];
|
||||
getSlowestActions<ActionType extends FluxActionType = FluxActionType>(
|
||||
actionType?: ActionType | Nullish,
|
||||
limit?: number | undefined /* = 20 */
|
||||
): ActionMetric<ActionType>[];
|
||||
log<A extends Action>(
|
||||
action: A,
|
||||
callback: (func: <U extends () => any>(storeName: string, func: U) => ReturnType<U>) => void
|
||||
): FluxActionLog<A>;
|
||||
): FluxActionMetric<ActionType>[];
|
||||
log<Action extends FluxAction>(
|
||||
action: Action,
|
||||
callback: (func: <T extends () => any>(storeName: string, func: T) => ReturnType<T>) => void
|
||||
): FluxActionLog<Action>;
|
||||
|
||||
logs: FluxActionLog<Action>[];
|
||||
logs: FluxActionLog[];
|
||||
persist: boolean;
|
||||
}
|
||||
|
||||
export class FluxDispatcher<Action extends FluxAction<string> = FluxAction> {
|
||||
/*
|
||||
* The only reason to make Dispatcher generic with a type parameter for the actions it handles would be to allow plugins
|
||||
* to create their own Flux stores with their own actions. However, this would require removing all contravariant properties
|
||||
* from Dispatcher so that plugins could create stores with their own Dispatcher instances. This would be required, since
|
||||
* the alternative option, allowing plugins to use the main Dispatcher instance, would require removing type information for
|
||||
* Discord's actions from Dispatcher, and would introduce the potential for action type name conflicts. Both of these
|
||||
* options would harm the main use case of these types. Furthermore, there are other state management libraries bundled with
|
||||
* Discord that plugins can use (e.g., Redux, Zustand), and Discord seems to only use one Dispatcher instance (all ~388
|
||||
* stores use the same instance), implying that their type for Dispatcher is also not generic.
|
||||
*/
|
||||
export class FluxDispatcher {
|
||||
constructor(
|
||||
defaultBand?: FluxDispatchBand | undefined /* = 0 */,
|
||||
actionLogger?: FluxActionLogger<Action> | Nullish,
|
||||
defaultBand?: FluxDispatchBand | undefined /* = FluxDispatchBand.Early */,
|
||||
actionLogger?: FluxActionLogger | Nullish,
|
||||
sentryUtils?: SentryUtils | Nullish
|
||||
);
|
||||
|
||||
_dispatch(
|
||||
action: Action,
|
||||
action: FluxAction,
|
||||
func: <U extends () => any>(storeName: string, func: U) => ReturnType<U>
|
||||
): false | void;
|
||||
_dispatchWithDevtools(action: Action): void;
|
||||
_dispatchWithLogging(action: Action): void;
|
||||
addDependencies(fromToken: string, toTokens: string[]): void;
|
||||
addInterceptor(interceptor: FluxActionHandler<Action>): void;
|
||||
_dispatchWithDevtools(action: FluxAction): void;
|
||||
_dispatchWithLogging(action: FluxAction): void;
|
||||
addDependencies(fromDispatchToken: string, toDispatchTokens: string[]): void;
|
||||
addInterceptor(interceptor: FluxActionHandler): void;
|
||||
createToken(): string;
|
||||
dispatch(action: Action): Promise<void>;
|
||||
dispatch(action: FluxAction): Promise<void>;
|
||||
flushWaitQueue(): void;
|
||||
isDispatching(): boolean;
|
||||
register(
|
||||
name: string,
|
||||
actionHandlers: Partial<FluxActionHandlers<Action>>,
|
||||
register<Action extends FluxAction>(
|
||||
storeName: string,
|
||||
actionHandlers: FluxActionHandlerMap<Action>,
|
||||
storeDidChange: FluxActionHandler<Action>,
|
||||
band?: FluxDispatchBand | Nullish,
|
||||
token?: string | undefined
|
||||
dispatchBand?: FluxDispatchBand | Nullish,
|
||||
dispatchToken?: string | undefined
|
||||
): string;
|
||||
subscribe<ActionType extends Action["type"]>(
|
||||
subscribe<ActionType extends FluxActionType>(
|
||||
actionType: ActionType,
|
||||
listener: FluxActionHandler<ExtractAction<Action, ActionType>>
|
||||
listener: FluxActionHandler<ExtractAction<FluxAction, ActionType>>
|
||||
): void;
|
||||
unsubscribe<ActionType extends Action["type"]>(
|
||||
unsubscribe<ActionType extends FluxActionType>(
|
||||
actionType: ActionType,
|
||||
listener: FluxActionHandler<ExtractAction<Action, ActionType>>
|
||||
listener: FluxActionHandler<ExtractAction<FluxAction, ActionType>>
|
||||
): void;
|
||||
wait(callback: () => void): void;
|
||||
|
||||
_actionHandlers: FluxActionHandlersGraph<Action>;
|
||||
_currentDispatchActionType: Action["type"] | Nullish;
|
||||
_actionHandlers: FluxActionHandlersGraph;
|
||||
_currentDispatchActionType: FluxActionType | Nullish;
|
||||
_defaultBand: FluxDispatchBand;
|
||||
_interceptors: ((action: Action) => boolean)[];
|
||||
_interceptors: ((action: FluxAction) => boolean)[];
|
||||
_processingWaitQueue: boolean;
|
||||
_sentryUtils: SentryUtils | Nullish;
|
||||
_subscriptions: {
|
||||
[ActionType in Action["type"]]?: Set<FluxActionHandler<ExtractAction<Action, ActionType>>> | Nullish;
|
||||
[ActionType in FluxActionType]?: Set<FluxActionHandler<ExtractAction<FluxAction, ActionType>>> | Nullish;
|
||||
};
|
||||
_waitQueue: (() => void)[];
|
||||
actionLogger: FluxActionLogger<Action>;
|
||||
functionCache: FluxActionHandlers<Action>;
|
||||
actionLogger: FluxActionLogger;
|
||||
functionCache: FluxActionHandlerMap<FluxAction>;
|
||||
}
|
||||
|
||||
export type Parser = Record<
|
||||
|
@ -352,6 +373,7 @@ export interface NavigationRouter {
|
|||
}
|
||||
|
||||
export interface IconUtils {
|
||||
// @ts-expect-error: TODO
|
||||
getUserAvatarURL(user: User, canAnimate?: boolean, size?: number, format?: string): string;
|
||||
getDefaultAvatarURL(id: string, discriminator?: string): string;
|
||||
getUserBannerURL(data: { id: string, banner: string, canAnimate?: boolean, size: number; }): string | undefined;
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
"resolveJsonModule": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"lib": [
|
||||
"DOM",
|
||||
"DOM.Iterable",
|
||||
|
|
Loading…
Reference in a new issue