Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Commit

Permalink
Fix #138 chat push notifications (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
celian-rib authored Sep 7, 2022
1 parent b4cb972 commit 154ddc5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
7 changes: 4 additions & 3 deletions src/services/socket/services/chat.socket.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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',
Expand Down

0 comments on commit 154ddc5

Please sign in to comment.