2023-01-25 02:25:29 +00:00
|
|
|
/*
|
|
|
|
* Vencord, a modification for Discord's desktop app
|
|
|
|
* Copyright (c) 2023 Vendicated and contributors
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import type * as Stores from "discord-types/stores";
|
|
|
|
|
|
|
|
// eslint-disable-next-line path-alias/no-relative
|
2024-05-03 02:18:12 +00:00
|
|
|
import { findByProps, findStore } from "../webpack";
|
2023-02-10 21:33:34 +00:00
|
|
|
import * as t from "./types/stores";
|
2023-01-25 02:25:29 +00:00
|
|
|
|
2024-05-03 04:50:50 +00:00
|
|
|
export const Flux = findByProps<t.Flux>("connectStores");
|
2023-02-10 21:33:34 +00:00
|
|
|
|
2023-05-23 01:32:27 +00:00
|
|
|
export type GenericStore = t.FluxStore & Record<string, any>;
|
2023-02-10 21:33:34 +00:00
|
|
|
|
2023-08-18 23:19:10 +00:00
|
|
|
export enum DraftType {
|
|
|
|
ChannelMessage = 0,
|
|
|
|
ThreadSettings = 1,
|
|
|
|
FirstThreadMessage = 2,
|
|
|
|
ApplicationLauncherCommand = 3
|
|
|
|
}
|
|
|
|
|
2024-05-03 02:18:12 +00:00
|
|
|
export const MessageStore = findStore("MessageStore") as Omit<Stores.MessageStore, "getMessages"> & {
|
2023-01-25 02:25:29 +00:00
|
|
|
getMessages(chanId: string): any;
|
|
|
|
};
|
2023-02-10 21:33:34 +00:00
|
|
|
|
|
|
|
// this is not actually a FluxStore
|
2024-05-03 02:18:12 +00:00
|
|
|
export const PrivateChannelsStore = findByProps("openPrivateChannel");
|
2024-05-03 04:50:50 +00:00
|
|
|
export const PermissionStore = findStore<GenericStore>("PermissionStore");
|
|
|
|
export const GuildChannelStore = findStore<GenericStore>("GuildChannelStore");
|
|
|
|
export const ReadStateStore = findStore<GenericStore>("ReadStateStore");
|
|
|
|
export const PresenceStore = findStore<GenericStore>("PresenceStore");
|
2023-02-10 21:33:34 +00:00
|
|
|
|
2024-05-03 04:50:50 +00:00
|
|
|
export const GuildStore = findStore<t.GuildStore>("GuildStore");
|
|
|
|
export const UserStore = findStore<Stores.UserStore & t.FluxStore>("UserStore");
|
|
|
|
export const UserProfileStore = findStore<GenericStore>("UserProfileStore");
|
|
|
|
export const SelectedChannelStore = findStore<Stores.SelectedChannelStore & t.FluxStore>("SelectedChannelStore");
|
|
|
|
export const SelectedGuildStore = findStore<GenericStore>("SelectedGuildStore");
|
|
|
|
export const ChannelStore = findStore<Stores.ChannelStore & t.FluxStore>("ChannelStore");
|
|
|
|
export const GuildMemberStore = findStore<Stores.GuildMemberStore & t.FluxStore>("GuildMemberStore");
|
2024-05-03 02:18:12 +00:00
|
|
|
export const RelationshipStore = findStore("RelationshipStore") as Stores.RelationshipStore & t.FluxStore & {
|
2023-01-25 02:25:29 +00:00
|
|
|
/** Get the date (as a string) that the relationship was created */
|
|
|
|
getSince(userId: string): string;
|
|
|
|
};
|
|
|
|
|
2024-05-03 04:50:50 +00:00
|
|
|
export const EmojiStore = findStore<t.EmojiStore>("EmojiStore");
|
|
|
|
export const WindowStore = findStore<t.WindowStore>("WindowStore");
|
|
|
|
export const DraftStore = findStore<t.DraftStore>("DraftStore");
|
2023-02-10 21:33:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 idk some thing, idk just pass null
|
|
|
|
* @param isEqual A custom comparator for the data returned by mapper
|
|
|
|
*
|
|
|
|
* @example const user = useStateFromStores([UserStore], () => UserStore.getCurrentUser(), null, (old, current) => old.id === current.id);
|
|
|
|
*/
|
2023-11-22 05:48:59 +00:00
|
|
|
export const { useStateFromStores }: {
|
|
|
|
useStateFromStores: <T>(
|
|
|
|
stores: t.FluxStore[],
|
|
|
|
mapper: () => T,
|
|
|
|
idk?: any,
|
|
|
|
isEqual?: (old: T, newer: T) => boolean
|
|
|
|
) => T;
|
|
|
|
}
|
2024-05-03 02:18:12 +00:00
|
|
|
= findByProps("useStateFromStores");
|