aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/plugins/relationshipNotifier/events.ts5
-rw-r--r--src/plugins/relationshipNotifier/utils.ts23
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);
}