Add push notifications for chat participants

This commit is contained in:
Adolfo Reyna
2026-02-22 23:31:13 -05:00
parent 93d5b6b5f3
commit fd82643477
3 changed files with 30 additions and 0 deletions

View File

@@ -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' });
}
},
}