From 154ddc5dcc26e1cbafff3d4f5614654ce19420d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9lian=20Riboulet?= Date: Wed, 7 Sep 2022 21:41:06 +0200 Subject: [PATCH] Fix #138 chat push notifications (#140) --- src/notification.ts | 4 ++++ src/services/socket/services/chat.socket.service.ts | 7 ++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/notification.ts b/src/notification.ts index 218dddd..adfc5e2 100644 --- a/src/notification.ts +++ b/src/notification.ts @@ -43,10 +43,14 @@ export async function sendPushNotification(notification: Notification | BatchedN const batched = notification as BatchedNotification; if (batched.users != undefined) { + if (batched.users.length === 0) return; + batched.users.forEach(user => { tokens.push(user.deviceToken); }); } else if (single.user != undefined) { + if (single.user != undefined) return; + tokens.push(single.user.deviceToken); } diff --git a/src/services/socket/services/chat.socket.service.ts b/src/services/socket/services/chat.socket.service.ts index 854ca43..3c4f553 100644 --- a/src/services/socket/services/chat.socket.service.ts +++ b/src/services/socket/services/chat.socket.service.ts @@ -66,8 +66,9 @@ export async function addMessage(user: User, connectedUsers: User[], content: st return !connectedUsers.some(connectedUser => connectedUser.id === user.id); }); - const filteredDisconnectedUsers = disconnectedUsers.filter(userToFilter => { - return userWithBlockedUsers.blockedUsers.some(blockedUser => blockedUser.id === userToFilter.id); + const blockedUsersIds = userWithBlockedUsers.blockedUsers.map(user => user.id); + const notBlockedDisconnectedUsers = disconnectedUsers.filter(disconnectedUser => { + return blockedUsersIds.every(id => id !== disconnectedUser.id); }); const message = await client.chatMessage.create({ @@ -80,7 +81,7 @@ export async function addMessage(user: User, connectedUsers: User[], content: st }); sendPushNotification({ - users: filteredDisconnectedUsers, + users: notBlockedDisconnectedUsers, title: user.displayName, body: decryptMessage(content), sound: 'message_sound.mp3',