diff --git a/packages/rocketchat-i18n/i18n/en.i18n.json b/packages/rocketchat-i18n/i18n/en.i18n.json index 87eba5102aaa..40b470db31ee 100644 --- a/packages/rocketchat-i18n/i18n/en.i18n.json +++ b/packages/rocketchat-i18n/i18n/en.i18n.json @@ -986,6 +986,7 @@ "Members_List": "Members List", "Mentions": "Mentions", "Mentions_default": "Mentions (default)", + "Mentions_only": "Mentions only", "Message": "Message", "Message_AllowBadWordsFilter": "Allow Message bad words filtering", "Message_AllowDeleting": "Allow Message Deleting", @@ -1745,6 +1746,7 @@ "Unnamed": "Unnamed", "Unpin_Message": "Unpin Message", "Unread_Count": "Unread Count", + "Unread_Count_DM": "Unread Count for Direct Messages", "Unread_Tray_Icon_Alert": "Unread Tray Icon Alert", "Unread_Messages": "Unread Messages", "Unread_Rooms": "Unread Rooms", @@ -1916,4 +1918,4 @@ "your_message_optional": "your message (optional)", "Your_password_is_wrong": "Your password is wrong!", "Your_push_was_sent_to_s_devices": "Your push was sent to %s devices" -} \ No newline at end of file +} diff --git a/packages/rocketchat-lib/server/lib/notifyUsersOnMessage.js b/packages/rocketchat-lib/server/lib/notifyUsersOnMessage.js index b14089ad6cb3..efe67344d3ca 100644 --- a/packages/rocketchat-lib/server/lib/notifyUsersOnMessage.js +++ b/packages/rocketchat-lib/server/lib/notifyUsersOnMessage.js @@ -68,22 +68,34 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) { } }); - const unreadCount = RocketChat.settings.get('Unread_Count'); + if (room.t === 'd') { + const unreadCountDM = RocketChat.settings.get('Unread_Count_DM'); - if (toAll || toHere) { - let incUnread = 0; - if (['all_messages', 'group_mentions_only', 'user_and_group_mentions_only'].includes(unreadCount)) { - incUnread = 1; + if (unreadCountDM === 'all_messages') { + RocketChat.models.Subscriptions.incUnreadForRoomIdExcludingUserId(room._id, message.u._id); + } else if (toAll || toHere) { + RocketChat.models.Subscriptions.incGroupMentionsAndUnreadForRoomIdExcludingUserId(room._id, message.u._id, 1, 1); + } else if ((mentionIds && mentionIds.length > 0) || (highlightsIds && highlightsIds.length > 0)) { + RocketChat.models.Subscriptions.incUserMentionsAndUnreadForRoomIdAndUserIds(room._id, _.compact(_.unique(mentionIds.concat(highlightsIds))), 1, 1); } - RocketChat.models.Subscriptions.incGroupMentionsAndUnreadForRoomIdExcludingUserId(room._id, message.u._id, 1, incUnread); - } else if ((mentionIds && mentionIds.length > 0) || (highlightsIds && highlightsIds.length > 0)) { - let incUnread = 0; - if (['all_messages', 'user_mentions_only', 'user_and_group_mentions_only'].includes(unreadCount)) { - incUnread = 1; + } else { + const unreadCount = RocketChat.settings.get('Unread_Count'); + + if (toAll || toHere) { + let incUnread = 0; + if (['all_messages', 'group_mentions_only', 'user_and_group_mentions_only'].includes(unreadCount)) { + incUnread = 1; + } + RocketChat.models.Subscriptions.incGroupMentionsAndUnreadForRoomIdExcludingUserId(room._id, message.u._id, 1, incUnread); + } else if ((mentionIds && mentionIds.length > 0) || (highlightsIds && highlightsIds.length > 0)) { + let incUnread = 0; + if (['all_messages', 'user_mentions_only', 'user_and_group_mentions_only'].includes(unreadCount)) { + incUnread = 1; + } + RocketChat.models.Subscriptions.incUserMentionsAndUnreadForRoomIdAndUserIds(room._id, _.compact(_.unique(mentionIds.concat(highlightsIds))), 1, incUnread); + } else if (unreadCount === 'all_messages') { + RocketChat.models.Subscriptions.incUnreadForRoomIdExcludingUserId(room._id, message.u._id); } - RocketChat.models.Subscriptions.incUserMentionsAndUnreadForRoomIdAndUserIds(room._id, _.compact(_.unique(mentionIds.concat(highlightsIds))), 1, incUnread); - } else if (unreadCount === 'all_messages') { - RocketChat.models.Subscriptions.incUnreadForRoomIdExcludingUserId(room._id, message.u._id); } } diff --git a/packages/rocketchat-lib/server/startup/settings.js b/packages/rocketchat-lib/server/startup/settings.js index 420c1db656c2..325ff3d7e747 100644 --- a/packages/rocketchat-lib/server/startup/settings.js +++ b/packages/rocketchat-lib/server/startup/settings.js @@ -373,6 +373,19 @@ RocketChat.settings.addGroup('General', function() { ], 'public': true }); + this.add('Unread_Count_DM', 'all_messages', { + type: 'select', + values: [ + { + key: 'all_messages', + i18nLabel: 'All_messages' + }, { + key: 'mentions_only', + i18nLabel: 'Mentions_only' + } + ], + 'public': true + }); this.add('CDN_PREFIX', '', { type: 'string', 'public': true