Add push notifications for chat participants
This commit is contained in:
@@ -489,6 +489,26 @@ const Notifications = {
|
||||
// sendWebNotification(requesterProfile.webSubscription, notifBody);
|
||||
DB.addNotification(requesterProfile, notifBody, null, null, groupProfile._id);
|
||||
},
|
||||
async youGotANewChatMessage(senderProfileId, messageText) {
|
||||
const DB = await DBGetter.getDB;
|
||||
const participants = await DB.getChatParticipants();
|
||||
const senderProfile = await DB.getProfileCache(senderProfileId);
|
||||
|
||||
const tokens = [];
|
||||
for (const participantProfileId of participants) {
|
||||
if (participantProfileId.toString() === senderProfileId.toString()) continue;
|
||||
|
||||
const participantProfile = await DB.getProfileCache(participantProfileId);
|
||||
if (participantProfile && Array.isArray(participantProfile.token)) {
|
||||
tokens.push(...participantProfile.token);
|
||||
}
|
||||
}
|
||||
|
||||
if (tokens.length > 0) {
|
||||
const notifBody = `${senderProfile.profile.firstName}: ${messageText.substring(0, 100)}${messageText.length > 100 ? '...' : ''}`;
|
||||
sendPushNotification(tokens, notifBody, { type: 'chat' });
|
||||
}
|
||||
},
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user