2023-01-25 03:25:29 +01: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/>.
* /
2024-08-03 00:24:47 -04:00
import { findByCodeLazy , findByPropsLazy } from "@webpack" ;
2023-01-25 03:25:29 +01:00
import type * as Stores from "discord-types/stores" ;
2023-02-10 22:33:34 +01:00
import { waitForStore } from "./internal" ;
import * as t from "./types/stores" ;
2023-01-25 03:25:29 +01:00
2023-02-10 22:33:34 +01:00
export const Flux : t.Flux = findByPropsLazy ( "connectStores" ) ;
2023-05-23 03:32:27 +02:00
export type GenericStore = t . FluxStore & Record < string , any > ;
2023-02-10 22:33:34 +01:00
2024-06-19 03:04:15 +02:00
export const DraftType = findByPropsLazy ( "ChannelMessage" , "SlashCommand" ) ;
2023-08-19 09:19:10 +10:00
2025-02-16 22:57:05 -03:00
export let MessageStore : Omit < Stores.MessageStore , "getMessages" > & GenericStore & {
2023-01-25 03:25:29 +01:00
getMessages ( chanId : string ) : any ;
} ;
2023-02-10 22:33:34 +01:00
2025-05-14 17:08:56 -03:00
// TODO: The correct name for this is ChannelActionCreators and it has already been exported again from utils. Remove this export once enough time has passed
2023-01-25 03:25:29 +01:00
export const PrivateChannelsStore = findByPropsLazy ( "openPrivateChannel" ) ;
2023-02-10 22:33:34 +01:00
export let PermissionStore : GenericStore ;
export let GuildChannelStore : GenericStore ;
export let ReadStateStore : GenericStore ;
export let PresenceStore : GenericStore ;
2025-06-28 16:04:15 -04:00
export let VoiceStateStore : GenericStore ;
2023-02-10 22:33:34 +01:00
2024-03-12 20:18:44 -03:00
export let GuildStore : t.GuildStore ;
2023-02-10 22:33:34 +01:00
export let UserStore : Stores.UserStore & t . FluxStore ;
2023-09-08 03:42:20 +02:00
export let UserProfileStore : GenericStore ;
2023-02-10 22:33:34 +01:00
export let SelectedChannelStore : Stores.SelectedChannelStore & t . FluxStore ;
export let SelectedGuildStore : t.FluxStore & Record < string , any > ;
export let ChannelStore : Stores.ChannelStore & t . FluxStore ;
2024-07-27 23:51:47 -04:00
export let TypingStore : GenericStore ;
2023-02-10 22:33:34 +01:00
export let GuildMemberStore : Stores.GuildMemberStore & t . FluxStore ;
2025-06-17 00:25:03 -04:00
export let RelationshipStore : t.RelationshipStore ;
2023-01-25 03:25:29 +01:00
2023-05-17 12:38:15 +10:00
export let EmojiStore : t.EmojiStore ;
2025-06-24 21:48:47 -04:00
export let StickerStore : t.StickerStore ;
2024-09-02 06:51:29 +02:00
export let ThemeStore : t.ThemeStore ;
2023-02-10 22:33:34 +01:00
export let WindowStore : t.WindowStore ;
2023-08-19 09:19:10 +10:00
export let DraftStore : t.DraftStore ;
2023-02-10 22:33:34 +01:00
/ * *
* React hook that returns stateful data for one or more stores
* You might need a custom comparator ( 4 th 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
2024-05-07 16:32:19 +02:00
* @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
2023-02-10 22:33:34 +01:00
* @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 ) ;
* /
2024-06-19 03:04:15 +02:00
export const useStateFromStores : t.useStateFromStores = findByCodeLazy ( "useStateFromStores" ) ;
2023-02-10 22:33:34 +01:00
2023-08-19 09:19:10 +10:00
waitForStore ( "DraftStore" , s = > DraftStore = s ) ;
2023-02-10 22:33:34 +01:00
waitForStore ( "UserStore" , s = > UserStore = s ) ;
2023-09-08 03:42:20 +02:00
waitForStore ( "UserProfileStore" , m = > UserProfileStore = m ) ;
2023-02-10 22:33:34 +01:00
waitForStore ( "ChannelStore" , m = > ChannelStore = m ) ;
waitForStore ( "SelectedChannelStore" , m = > SelectedChannelStore = m ) ;
waitForStore ( "SelectedGuildStore" , m = > SelectedGuildStore = m ) ;
waitForStore ( "GuildStore" , m = > GuildStore = m ) ;
waitForStore ( "GuildMemberStore" , m = > GuildMemberStore = m ) ;
waitForStore ( "RelationshipStore" , m = > RelationshipStore = 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 ( "WindowStore" , m = > WindowStore = m ) ;
2023-05-17 12:38:15 +10:00
waitForStore ( "EmojiStore" , m = > EmojiStore = m ) ;
2025-06-24 21:48:47 -04:00
waitForStore ( "StickersStore" , m = > StickerStore = m ) ;
2024-07-27 23:51:47 -04:00
waitForStore ( "TypingStore" , m = > TypingStore = m ) ;
2025-05-14 17:08:56 -03:00
waitForStore ( "ThemeStore" , m = > {
ThemeStore = m ;
// Importing this directly can easily cause circular imports. For this reason, use a non import access here.
Vencord . QuickCss . initQuickCssThemeStore ( ) ;
} ) ;
2025-06-28 16:04:15 -04:00
waitForStore ( "VoiceStateStore" , m = > VoiceStateStore = m ) ;