From 22d692112de75f2e09832c61a84f8beceb2e7f9b Mon Sep 17 00:00:00 2001 From: Inbestigator Date: Wed, 6 Mar 2024 16:10:26 -0800 Subject: [PATCH] Combined notification functions --- src/plugins/bypassDND/index.tsx | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/plugins/bypassDND/index.tsx b/src/plugins/bypassDND/index.tsx index 75a0b1b60..7ff671cef 100644 --- a/src/plugins/bypassDND/index.tsx +++ b/src/plugins/bypassDND/index.tsx @@ -9,7 +9,7 @@ import { DataStore, Notifications } from "@api/index"; import { definePluginSettings } from "@api/Settings"; import { Devs } from "@utils/constants"; import definePlugin, { OptionType } from "@utils/types"; -import { ChannelStore, Menu, PresenceStore, PrivateChannelsStore, UserStore } from "@webpack/common"; +import { ChannelStore, Menu, NavigationRouter, PresenceStore, PrivateChannelsStore, UserStore } from "@webpack/common"; import { type Channel, type Guild, type Message, type User } from "discord-types/general"; interface ContextProps { @@ -142,19 +142,14 @@ const settings = definePluginSettings({ } }); -async function showUserNotification(message: Message): Promise { +async function showNotification(message: Message, guildId?: string): Promise { await Notifications.showNotification({ - title: `${message.author.globalName ?? message.author.username} sent a message in a DM`, + title: `${message.author.globalName ?? message.author.username} ${guildId ? `sent a message in ${ChannelStore.getChannel(message.channel_id)?.name}` : "sent a message in a DM"}`, body: message.content, - icon: UserStore.getUser(message.author.id).getAvatarURL(undefined, undefined, false) - }); -} - -async function showChannelNotification(message: Message): Promise { - await Notifications.showNotification({ - title: `${message.author.globalName ?? message.author.username} sent a message in ${ChannelStore.getChannel(message.channel_id)?.name}`, - body: message.content, - icon: UserStore.getUser(message.author.id).getAvatarURL(undefined, undefined, false) + icon: UserStore.getUser(message.author.id).getAvatarURL(undefined, undefined, false), + onClick: function () { + NavigationRouter.transitionTo(`/channels/${guildId ?? "@me"}/${message.channel_id}/${message.id}`); + } }); } @@ -172,14 +167,14 @@ export default definePlugin({ if (message.author.id === currentUser.id) return; if (await PresenceStore.getStatus(currentUser.id) !== "dnd") return; if ((bypasses.guilds.includes(guildId) || bypasses.channels.includes(channelId)) && (message.content.includes(`<@${currentUser.id}>`) || message.mentions.some(mention => mention.id === currentUser.id))) { - await showChannelNotification(message); + await showNotification(message, guildId); return; } if (bypasses.users.includes(message.author.id)) { if (channelId === await PrivateChannelsStore.getOrEnsurePrivateChannel(message.author.id)) { - await showUserNotification(message); + await showNotification(message); } else if ((message.content.includes(`<@${currentUser.id}>`) || message.mentions.some(mention => mention.id === currentUser.id)) && (settings.store.allowOutsideOfDms === true)) { - await showChannelNotification(message); + await showNotification(message, guildId); } } } catch (error) {