Skip to content

Commit

Permalink
refactor: utilize IncomingWebxdcNotify.chatId
Browse files Browse the repository at this point in the history
  • Loading branch information
WofWca committed Dec 17, 2024
1 parent d90e328 commit 5a5aa65
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions packages/frontend/src/system-integration/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ export function initNotifications() {
BackendRemote.on('IncomingMsg', (accountId, { chatId, msgId }) => {
incomingMessageHandler(accountId, chatId, msgId, false)
})
BackendRemote.on('IncomingWebxdcNotify', (accountId, { msgId, text }) => {
// we don't have the chatId yet, but it will be fetched in flushNotifications
incomingMessageHandler(accountId, -1, msgId, true, text)
})
BackendRemote.on(
'IncomingWebxdcNotify',
(accountId, { msgId, text, chatId }) => {
incomingMessageHandler(accountId, chatId, msgId, true, text)
}
)
BackendRemote.on('IncomingMsgBunch', accountId => {
flushNotifications(accountId)
})
Expand Down Expand Up @@ -247,14 +249,6 @@ async function flushNotifications(accountId: number) {
let notifications = [...queuedNotifications[accountId]]
queuedNotifications = []

for await (const n of notifications) {
if (n.chatId === -1) {
// get real chatId of the webxdc message
const message = await BackendRemote.rpc.getMessage(accountId, n.messageId)
n.chatId = message.chatId
}
}

// filter out muted chats:
const uniqueChats = [...new Set(notifications.map(n => n.chatId))]
const mutedChats = (
Expand Down

0 comments on commit 5a5aa65

Please sign in to comment.