-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathstore.ts
More file actions
96 lines (80 loc) · 2.85 KB
/
store.ts
File metadata and controls
96 lines (80 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
* Vencord, a Discord client mod
* Copyright (c) 2024 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import { definePluginSettings } from "@api/Settings";
import { proxyLazy } from "@utils/lazy";
import { OptionType } from "@utils/types";
import { Flux as TFlux } from "@vencord/discord-types";
import { ChannelActionCreators, ChannelStore, Flux as FluxWP, FluxDispatcher } from "@webpack/common";
interface IFlux extends TFlux {
PersistedStore: TFlux["Store"];
}
export const settings = definePluginSettings({
persistSidebar: {
type: OptionType.BOOLEAN,
description: "Keep the sidebar chat open across Discord restarts",
default: true,
},
patchCommunity: {
type: OptionType.BOOLEAN,
description: "Patch things like the Channel Browser or Members tab that community servers have. Might have some styling issues.",
default: true,
restartNeeded: true,
}
});
export const SidebarStore = proxyLazy(() => {
const current = {
guildId: "",
channelId: "",
width: 0
};
let previous = { ...current };
class SidebarStore extends (FluxWP as IFlux).PersistedStore {
static persistKey = "SidebarStore";
// @ts-ignore
initialize(previousState: { guildId?: string; channelId?: string; width?: number; } | undefined) {
if (!settings.store.persistSidebar || !previousState) return;
const { guildId, channelId, width } = previousState;
current.guildId = guildId || "";
current.channelId = channelId || "";
current.width = width || 0;
}
getState() {
return current;
}
}
const store = new SidebarStore(FluxDispatcher, {
// @ts-ignore
async VC_SIDEBAR_CHAT_NEW({ guildId: newGId, id }: { guildId: string | null; id: string; }) {
previous = { ...current };
current.guildId = newGId || "";
if (current.guildId) {
current.channelId = id;
store.emitChange();
return;
}
current.channelId = ChannelStore.getChannel(id)?.id ?? await ChannelActionCreators.getOrEnsurePrivateChannel(id);
store.emitChange();
},
VC_SIDEBAR_CHAT_PREVIOUS() {
if (previous.channelId) {
current.guildId = previous.guildId;
current.channelId = previous.channelId;
}
store.emitChange();
},
VC_SIDEBAR_CHAT_CLOSE() {
previous = { ...current };
current.guildId = "";
current.channelId = "";
store.emitChange();
},
/* SIDEBAR_CHAT_WIDTH({ newWidth }: { newWidth: number; }) {
width = newWidth;
store.emitChange();
}*/
});
return store;
});