Skip to content

Commit

Permalink
Merge pull request #7658 from RocketChat/unread-count-for-direct-mess…
Browse files Browse the repository at this point in the history
…ages

[NEW] Add unread options for direct messages
  • Loading branch information
rodrigok committed Aug 8, 2017
1 parent c995ba2 commit 9407587
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 14 deletions.
4 changes: 3 additions & 1 deletion packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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"
}
}
38 changes: 25 additions & 13 deletions packages/rocketchat-lib/server/lib/notifyUsersOnMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
13 changes: 13 additions & 0 deletions packages/rocketchat-lib/server/startup/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9407587

Please sign in to comment.