1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-11-22 05:19:22 +00:00

Send event when sending a new message

This commit is contained in:
Pierre HUBERT 2020-03-31 10:57:52 +02:00
parent ce1398dcb8
commit 288d5bdc09

View File

@ -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 // Mark all the user of the conversations as unread, except current user
await DatabaseHelper.UpdateRows({ await DatabaseHelper.UpdateRows({
table: USERS_TABLE, table: USERS_TABLE,
where: { where: {
conv_id: message.convID conv_id: message.convID,
saw_last_message: 1
}, },
customWhere: "user_id != ?", customWhere: "user_id != ?",
customWhereArgs: [message.userID.toString()], 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
})
} }
/** /**