From 70bdbbeeeaf5c2e574c313c78b5e1f2df3c3048d Mon Sep 17 00:00:00 2001 From: Sean Boult <996134+Hacksore@users.noreply.github.com> Date: Sun, 28 Jul 2024 18:31:06 -0500 Subject: [PATCH] Notifications work --- apps/desktop/src/rpc/event.ts | 2 ++ apps/desktop/src/rpc/manager.ts | 24 +++++++++++++++++------- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/apps/desktop/src/rpc/event.ts b/apps/desktop/src/rpc/event.ts index 3094836c..74dd6bfe 100644 --- a/apps/desktop/src/rpc/event.ts +++ b/apps/desktop/src/rpc/event.ts @@ -21,6 +21,8 @@ export enum RPCEvent { VIDEO_STATE_UPDATE = "VIDEO_STATE_UPDATE", /** not quite sure */ SCREENSHARE_STATE_UPDATE = "SCREENSHARE_STATE_UPDATE", + /** sent when the you get a message that tags your or a dm */ + NOTIFICATION_CREATE = "NOTIFICATION_CREATE", } // TODO: move this somewhere diff --git a/apps/desktop/src/rpc/manager.ts b/apps/desktop/src/rpc/manager.ts index b1f7cf4d..ce106d68 100644 --- a/apps/desktop/src/rpc/manager.ts +++ b/apps/desktop/src/rpc/manager.ts @@ -63,9 +63,6 @@ const SUBSCRIBABLE_EVENTS = [ RPCEvent.VOICE_STATE_CREATE, RPCEvent.VOICE_STATE_DELETE, RPCEvent.VOICE_STATE_UPDATE, - // NOTE: these dont work or im using them wrong? - // RPCEvent.SCREENSHARE_STATE_UPDATE, - // RPCEvent.VIDEO_STATE_UPDATE, ]; export const APP_ID = "905987126099836938"; @@ -156,7 +153,20 @@ class SocketManager { this.send({ args: { client_id: APP_ID, - scopes: ["identify", "rpc", "rpc.voice.read", "rpc.video.read", "rpc.screenshare.read", "guilds"], + scopes: [ + "identify", + "rpc", + "guilds", + "rpc.notifications.read", + // TODO: how do you use other scopes + // "rpc.activities.write", + // "rpc.voice.read", + // "rpc.voice.write", + // "rpc.video.read", + // "rpc.video.write", + // "rpc.screenshare.read", + // "rpc.screenshare.write", + ], }, cmd: RPCCommand.AUTHORIZE, }); @@ -198,6 +208,7 @@ class SocketManager { } const payload: DiscordPayload = JSON.parse(event.data); + console.log(payload); // either the token is good and valid and we can login otherwise prompt them approve if (payload.evt === RPCEvent.READY) { @@ -347,10 +358,10 @@ class SocketManager { // try to find the user this.requestUserChannel(); - // subscribe to get notified when the user changes channels + // sub to any otifs this.send({ cmd: RPCCommand.SUBSCRIBE, - evt: RPCEvent.VOICE_CHANNEL_SELECT, + evt: RPCEvent.NOTIFICATION_CREATE, }); this.userdataStore.setAccessTokenExpiry(payload.data.expires); @@ -419,7 +430,6 @@ class SocketManager { cmd, args: { channel_id: channelId }, evt: eventName, - nonce: uuid.v4(), }) ); }