Skip to content

Commit

Permalink
Notifications work
Browse files Browse the repository at this point in the history
  • Loading branch information
Hacksore committed Jul 28, 2024
1 parent c8a9fc9 commit 70bdbbe
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
2 changes: 2 additions & 0 deletions apps/desktop/src/rpc/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 17 additions & 7 deletions apps/desktop/src/rpc/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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,
});
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -419,7 +430,6 @@ class SocketManager {
cmd,
args: { channel_id: channelId },
evt: eventName,
nonce: uuid.v4(),
})
);
}
Expand Down

0 comments on commit 70bdbbe

Please sign in to comment.