[FIX] Unread count for all messages when mentioning an user (#16884)

Co-authored-by: Diego Sampaio <chinello@gmail.com>
pull/19467/head^2
Subham Sahoo 5 years ago committed by GitHub
parent 2ab1a10f25
commit 89562e5f7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 24
      app/lib/server/lib/notifyUsersOnMessage.js
  2. 4
      app/models/server/models/Subscriptions.js

@ -35,7 +35,7 @@ export function getMentions({ mentions, u: { _id: senderId } }) {
const toAll = mentions.some(({ _id }) => _id === 'all');
const toHere = mentions.some(({ _id }) => _id === 'here');
const mentionIds = mentions
.filter(({ _id }) => _id !== senderId)
.filter(({ _id }) => _id !== senderId && !['all', 'here'].includes(_id))
.map(({ _id }) => _id);
return {
@ -81,17 +81,19 @@ export function updateUsersSubscriptions(message, room) {
const unreadSetting = room.t === 'd' ? 'Unread_Count_DM' : 'Unread_Count';
const unreadCount = settings.get(unreadSetting);
if (toAll || toHere) {
getUserIdsFromHighlights(room._id, message)
.forEach((uid) => userIds.add(uid));
// give priority to user mentions over group mentions
if (userIds.size > 0) {
incUserMentions(room._id, room.t, [...userIds], unreadCount);
} else if (toAll || toHere) {
incGroupMentions(room._id, room.t, message.u._id, unreadCount);
} else {
getUserIdsFromHighlights(room._id, message)
.forEach((uid) => userIds.add(uid));
if (userIds.size > 0) {
incUserMentions(room._id, room.t, [...userIds], unreadCount);
} else if (unreadCount === 'all_messages') {
Subscriptions.incUnreadForRoomIdExcludingUserId(room._id, message.u._id);
}
}
// this shouldn't run only if has group mentions because it will already exclude mentioned users from the query
if (!toAll && !toHere && unreadCount === 'all_messages') {
Subscriptions.incUnreadForRoomIdExcludingUserIds(room._id, [...userIds, message.u._id]);
}
}

@ -871,14 +871,14 @@ export class Subscriptions extends Base {
return this.update(query, update, { multi: true });
}
incUnreadForRoomIdExcludingUserId(roomId, userId, inc) {
incUnreadForRoomIdExcludingUserIds(roomId, userIds, inc) {
if (inc == null) {
inc = 1;
}
const query = {
rid: roomId,
'u._id': {
$ne: userId,
$nin: userIds,
},
};

Loading…
Cancel
Save