From 288d5bdc099c0672bedda26c1609fad40d3f0906 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Tue, 31 Mar 2020 10:57:52 +0200 Subject: [PATCH] Send event when sending a new message --- src/helpers/ConversationsHelper.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/helpers/ConversationsHelper.ts b/src/helpers/ConversationsHelper.ts index 2499f45..fc66bcd 100644 --- a/src/helpers/ConversationsHelper.ts +++ b/src/helpers/ConversationsHelper.ts @@ -459,11 +459,24 @@ export class ConversationsHelper { } }); + // Get the list of users to notify after the update + const listToNotify = (await DatabaseHelper.Query({ + table: USERS_TABLE, + where: { + conv_id: message.convID, + saw_last_message: 1, + following: 1 + }, + customWhere: "user_id != ?", + customWhereArgs: [message.userID.toString()] + })).map((f) => f.user_id); + // Mark all the user of the conversations as unread, except current user await DatabaseHelper.UpdateRows({ table: USERS_TABLE, where: { - conv_id: message.convID + conv_id: message.convID, + saw_last_message: 1 }, customWhere: "user_id != ?", customWhereArgs: [message.userID.toString()], @@ -472,6 +485,10 @@ export class ConversationsHelper { } }); + // Send the notification to all the other users + await EventsHelper.Emit("updated_number_unread_conversations", { + usersID: listToNotify + }) } /**