diff options
author | V <vendicated@riseup.net> | 2023-04-18 18:52:46 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-18 16:52:46 +0000 |
commit | 7e96b5dcfbf29dfa0fe6c61e861d8441967289d0 (patch) | |
tree | 32e38e0e1b1301e3c97a327a719ef129bad22d9b | |
parent | 99a7d78e9b90642d6098f6b52a3f0e53a08749f5 (diff) | |
download | Vencord-7e96b5dcfbf29dfa0fe6c61e861d8441967289d0.tar.gz Vencord-7e96b5dcfbf29dfa0fe6c61e861d8441967289d0.tar.bz2 Vencord-7e96b5dcfbf29dfa0fe6c61e861d8441967289d0.zip |
RelationShipNotifier: Support multiple users (#944)
-rw-r--r-- | src/plugins/relationshipNotifier/events.ts | 5 | ||||
-rw-r--r-- | src/plugins/relationshipNotifier/utils.ts | 23 |
2 files changed, 19 insertions, 9 deletions
diff --git a/src/plugins/relationshipNotifier/events.ts b/src/plugins/relationshipNotifier/events.ts index 1600484..0c6914d 100644 --- a/src/plugins/relationshipNotifier/events.ts +++ b/src/plugins/relationshipNotifier/events.ts @@ -19,7 +19,7 @@ import { FluxEvents } from "@webpack/types"; import { onChannelDelete, onGuildDelete, onRelationshipRemove } from "./functions"; -import { syncFriends, syncGroups, syncGuilds } from "./utils"; +import { syncAndRunChecks, syncFriends, syncGroups, syncGuilds } from "./utils"; export const FluxHandlers: Partial<Record<FluxEvents, Array<(data: any) => void>>> = { GUILD_CREATE: [syncGuilds], @@ -28,7 +28,8 @@ export const FluxHandlers: Partial<Record<FluxEvents, Array<(data: any) => void> CHANNEL_DELETE: [onChannelDelete], RELATIONSHIP_ADD: [syncFriends], RELATIONSHIP_UPDATE: [syncFriends], - RELATIONSHIP_REMOVE: [syncFriends, onRelationshipRemove] + RELATIONSHIP_REMOVE: [syncFriends, onRelationshipRemove], + CONNECTION_OPEN: [syncAndRunChecks] }; export function forEachEvent(fn: (event: FluxEvents, handler: (data: any) => void) => void) { diff --git a/src/plugins/relationshipNotifier/utils.ts b/src/plugins/relationshipNotifier/utils.ts index 09a329a..39b7fce 100644 --- a/src/plugins/relationshipNotifier/utils.ts +++ b/src/plugins/relationshipNotifier/utils.ts @@ -18,7 +18,7 @@ import { DataStore, Notices } from "@api/index"; import { showNotification } from "@api/Notifications"; -import { ChannelStore, GuildStore, RelationshipStore, UserUtils } from "@webpack/common"; +import { ChannelStore, GuildStore, RelationshipStore, UserStore, UserUtils } from "@webpack/common"; import settings from "./settings"; import { ChannelType, RelationshipType, SimpleGroupChannel, SimpleGuild } from "./types"; @@ -30,11 +30,20 @@ const friends = { requests: [] as string[] }; +const guildsKey = () => `relationship-notifier-guilds-${UserStore.getCurrentUser().id}`; +const groupsKey = () => `relationship-notifier-groups-${UserStore.getCurrentUser().id}`; +const friendsKey = () => `relationship-notifier-friends-${UserStore.getCurrentUser().id}`; + +async function runMigrations() { + DataStore.delMany(["relationship-notifier-guilds", "relationship-notifier-groups", "relationship-notifier-friends"]); +} + export async function syncAndRunChecks() { + await runMigrations(); const [oldGuilds, oldGroups, oldFriends] = await DataStore.getMany([ - "relationship-notifier-guilds", - "relationship-notifier-groups", - "relationship-notifier-friends" + guildsKey(), + groupsKey(), + friendsKey() ]) as [Map<string, SimpleGuild> | undefined, Map<string, SimpleGroupChannel> | undefined, Record<"friends" | "requests", string[]> | undefined]; await Promise.all([syncGuilds(), syncGroups(), syncFriends()]); @@ -104,7 +113,7 @@ export async function syncGuilds() { iconURL: icon && `https://cdn.discordapp.com/icons/${id}/${icon}.png` }); } - await DataStore.set("relationship-notifier-guilds", guilds); + await DataStore.set(guildsKey(), guilds); } export function getGroup(id: string) { @@ -126,7 +135,7 @@ export async function syncGroups() { }); } - await DataStore.set("relationship-notifier-groups", groups); + await DataStore.set(groupsKey(), groups); } export async function syncFriends() { @@ -145,5 +154,5 @@ export async function syncFriends() { } } - await DataStore.set("relationship-notifier-friends", friends); + await DataStore.set(friendsKey(), friends); } |