RelationShipNotifier: try to fix false positives for unavailable guilds
This commit is contained in:
parent
ca810250d1
commit
e79430ca84
|
@ -21,7 +21,7 @@ import { UserUtils } from "@webpack/common";
|
||||||
|
|
||||||
import settings from "./settings";
|
import settings from "./settings";
|
||||||
import { ChannelDelete, ChannelType, GuildDelete, RelationshipRemove, RelationshipType } from "./types";
|
import { ChannelDelete, ChannelType, GuildDelete, RelationshipRemove, RelationshipType } from "./types";
|
||||||
import { deleteGroup, deleteGuild, getGroup, getGuild, notify } from "./utils";
|
import { deleteGroup, deleteGuild, getGroup, getGuild, GuildAvailabilityStore, notify } from "./utils";
|
||||||
|
|
||||||
let manuallyRemovedFriend: string | undefined;
|
let manuallyRemovedFriend: string | undefined;
|
||||||
let manuallyRemovedGuild: string | undefined;
|
let manuallyRemovedGuild: string | undefined;
|
||||||
|
@ -63,7 +63,7 @@ export async function onRelationshipRemove({ relationship: { type, id } }: Relat
|
||||||
|
|
||||||
export function onGuildDelete({ guild: { id, unavailable } }: GuildDelete) {
|
export function onGuildDelete({ guild: { id, unavailable } }: GuildDelete) {
|
||||||
if (!settings.store.servers) return;
|
if (!settings.store.servers) return;
|
||||||
if (unavailable) return;
|
if (unavailable || GuildAvailabilityStore.isUnavailable(id)) return;
|
||||||
|
|
||||||
if (manuallyRemovedGuild === id) {
|
if (manuallyRemovedGuild === id) {
|
||||||
deleteGuild(id);
|
deleteGuild(id);
|
||||||
|
|
|
@ -19,11 +19,20 @@
|
||||||
import { DataStore, Notices } from "@api/index";
|
import { DataStore, Notices } from "@api/index";
|
||||||
import { showNotification } from "@api/Notifications";
|
import { showNotification } from "@api/Notifications";
|
||||||
import { getUniqueUsername, openUserProfile } from "@utils/discord";
|
import { getUniqueUsername, openUserProfile } from "@utils/discord";
|
||||||
|
import { findStoreLazy } from "@webpack";
|
||||||
import { ChannelStore, GuildMemberStore, GuildStore, RelationshipStore, UserStore, UserUtils } from "@webpack/common";
|
import { ChannelStore, GuildMemberStore, GuildStore, RelationshipStore, UserStore, UserUtils } from "@webpack/common";
|
||||||
|
import { FluxStore } from "@webpack/types";
|
||||||
|
|
||||||
import settings from "./settings";
|
import settings from "./settings";
|
||||||
import { ChannelType, RelationshipType, SimpleGroupChannel, SimpleGuild } from "./types";
|
import { ChannelType, RelationshipType, SimpleGroupChannel, SimpleGuild } from "./types";
|
||||||
|
|
||||||
|
export const GuildAvailabilityStore = findStoreLazy("GuildAvailabilityStore") as FluxStore & {
|
||||||
|
totalGuilds: number;
|
||||||
|
totalUnavailableGuilds: number;
|
||||||
|
unavailableGuilds: string[];
|
||||||
|
isUnavailable(guildId: string): boolean;
|
||||||
|
};
|
||||||
|
|
||||||
const guilds = new Map<string, SimpleGuild>();
|
const guilds = new Map<string, SimpleGuild>();
|
||||||
const groups = new Map<string, SimpleGroupChannel>();
|
const groups = new Map<string, SimpleGroupChannel>();
|
||||||
const friends = {
|
const friends = {
|
||||||
|
@ -59,7 +68,7 @@ export async function syncAndRunChecks() {
|
||||||
|
|
||||||
if (settings.store.servers && oldGuilds?.size) {
|
if (settings.store.servers && oldGuilds?.size) {
|
||||||
for (const [id, guild] of oldGuilds) {
|
for (const [id, guild] of oldGuilds) {
|
||||||
if (!guilds.has(id))
|
if (!guilds.has(id) && !GuildAvailabilityStore.isUnavailable(id))
|
||||||
notify(`You are no longer in the server ${guild.name}.`, guild.iconURL);
|
notify(`You are no longer in the server ${guild.name}.`, guild.iconURL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue