[NEW] Option to select unread count behavior

pull/7477/head
Rodrigo Nascimento 9 years ago
parent 5cb30b479f
commit a78bb69f78
  1. 4
      packages/rocketchat-cas/cas_server.js
  2. 6
      packages/rocketchat-i18n/i18n/en.i18n.json
  3. 2
      packages/rocketchat-irc/server/server.js
  4. 4
      packages/rocketchat-lib/server/functions/addUserToDefaultChannels.js
  5. 4
      packages/rocketchat-lib/server/functions/addUserToRoom.js
  6. 21
      packages/rocketchat-lib/server/lib/notifyUsersOnMessage.js
  7. 19
      packages/rocketchat-lib/server/models/Subscriptions.js
  8. 19
      packages/rocketchat-lib/server/startup/settings.js
  9. 2
      packages/rocketchat-livechat/server/lib/Livechat.js
  10. 2
      packages/rocketchat-livechat/server/lib/QueueMethods.js
  11. 2
      packages/rocketchat-livechat/server/methods/takeInquiry.js
  12. 4
      server/methods/addAllUserToRoom.js
  13. 4
      server/methods/createDirectMessage.js
  14. 2
      server/publications/subscription.js

@ -249,7 +249,9 @@ Accounts.registerLoginHandler(function(options) {
ts: new Date(),
open: true,
alert: true,
unread: 1
unread: 1,
userMentions: 1,
grouMentions: 0
});
}
});

@ -635,6 +635,7 @@
"GoogleCloudStorage": "Google Cloud Storage",
"GoogleNaturalLanguage_ServiceAccount_Description": "Service account key JSON file. More information can be found [here](https://cloud.google.com/natural-language/docs/common/auth#set_up_a_service_account)",
"GoogleTagManager_id": "Google Tag Manager Id",
"Group_mentions_only": "Group mentions only",
"Guest_Pool": "Guest Pool",
"Hash": "Hash",
"Header": "Header",
@ -1712,6 +1713,7 @@
"Unmute_user": "Unmute user",
"Unnamed": "Unnamed",
"Unpin_Message": "Unpin Message",
"Unread_Count": "Unread Count",
"Unread_Tray_Icon_Alert": "Unread Tray Icon Alert",
"Unread_Messages": "Unread Messages",
"Unread_Rooms": "Unread Rooms",
@ -1741,6 +1743,7 @@
"User_added": "User added",
"User_added_by": "User <em>__user_added__</em> added by <em>__user_by__</em>.",
"User_added_successfully": "User added successfully",
"User_and_group_mentions_only": "User and group mentions only",
"User_doesnt_exist": "No user exists by the name of `@%s`.",
"User_has_been_activated": "User has been activated",
"User_has_been_deactivated": "User has been deactivated",
@ -1761,6 +1764,7 @@
"User_left_male": "Has left the channel.",
"User_logged_out": "User is logged out",
"User_management": "User Management",
"User_mentions_only": "User mentions only",
"User_muted": "User Muted",
"User_muted_by": "User <em>__user_muted__</em> muted by <em>__user_by__</em>.",
"User_not_found": "User not found",
@ -1877,4 +1881,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"
}
}

@ -359,6 +359,8 @@ class IrcClient {
open: false,
alert: false,
unread: 0,
userMentions: 0,
grouMentions: 0,
u: { _id: target._id, username: target.username }}
});
return { t: 'd', _id: rid };

@ -14,7 +14,9 @@ RocketChat.addUserToDefaultChannels = function(user, silenced) {
ts: new Date(),
open: true,
alert: true,
unread: 1
unread: 1,
userMentions: 1,
grouMentions: 0
});
// Insert user joined message

@ -18,7 +18,9 @@ RocketChat.addUserToRoom = function(rid, user, inviter, silenced) {
ts: now,
open: true,
alert: true,
unread: 1
unread: 1,
userMentions: 1,
grouMentions: 0
});
if (!silenced) {

@ -39,10 +39,7 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
return has;
}
if (room.t != null && room.t === 'd') {
// Update the other subscriptions
RocketChat.models.Subscriptions.incUnreadOfDirectForRoomIdExcludingUserId(message.rid, message.u._id, 1);
} else {
if (room != null) {
let toAll = false;
let toHere = false;
const mentionIds = [];
@ -71,10 +68,22 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
}
});
const unreadCount = RocketChat.settings.get('Unread_Count');
if (toAll || toHere) {
RocketChat.models.Subscriptions.incUnreadForRoomIdExcludingUserId(room._id, message.u._id);
let incUnread = 0;
if (['all', '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)) {
RocketChat.models.Subscriptions.incUnreadForRoomIdAndUserIds(room._id, _.compact(_.unique(mentionIds.concat(highlightsIds))));
let incUnread = 0;
if (['all', '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') {
RocketChat.models.Subscriptions.incUnreadForRoomIdExcludingUserId(room._id, message.u._id);
}
}

@ -241,6 +241,8 @@ class ModelSubscriptions extends RocketChat.models._Base {
open: true,
alert: false,
unread: 0,
userMentions: 0,
grouMentions: 0,
ls: new Date
}
};
@ -336,11 +338,10 @@ class ModelSubscriptions extends RocketChat.models._Base {
return this.update(query, update, { multi: true });
}
incUnreadOfDirectForRoomIdExcludingUserId(roomId, userId, inc) {
incUnreadForRoomIdExcludingUserId(roomId, userId, inc) {
if (inc == null) { inc = 1; }
const query = {
rid: roomId,
t: 'd',
'u._id': {
$ne: userId
}
@ -359,8 +360,7 @@ class ModelSubscriptions extends RocketChat.models._Base {
return this.update(query, update, { multi: true });
}
incUnreadForRoomIdExcludingUserId(roomId, userId, inc) {
if (inc == null) { inc = 1; }
incGroupMentionsAndUnreadForRoomIdExcludingUserId(roomId, userId, incGroup = 1, incUnread = 1) {
const query = {
rid: roomId,
'u._id': {
@ -374,15 +374,15 @@ class ModelSubscriptions extends RocketChat.models._Base {
open: true
},
$inc: {
unread: inc
unread: incUnread,
groupMentions: incGroup
}
};
return this.update(query, update, { multi: true });
}
incUnreadForRoomIdAndUserIds(roomId, userIds, inc) {
if (inc == null) { inc = 1; }
incUserMentionsAndUnreadForRoomIdAndUserIds(roomId, userIds, incUser = 1, incUnread = 1) {
const query = {
rid: roomId,
'u._id': {
@ -396,7 +396,8 @@ class ModelSubscriptions extends RocketChat.models._Base {
open: true
},
$inc: {
unread: inc
unread: incUnread,
userMentions: incUser
}
};
@ -537,6 +538,8 @@ class ModelSubscriptions extends RocketChat.models._Base {
open: false,
alert: false,
unread: 0,
userMentions: 0,
grouMentions: 0,
ts: room.ts,
rid: room._id,
name: room.name,

@ -354,6 +354,25 @@ RocketChat.settings.addGroup('General', function() {
type: 'boolean',
'public': true
});
this.add('Unread_Count', 'user_and_group_mentions_only', {
type: 'select',
values: [
{
key: 'all',
i18nLabel: 'All'
}, {
key: 'user_mentions_only',
i18nLabel: 'User_mentions_only'
}, {
key: 'group_mentions_only',
i18nLabel: 'Group_mentions_only'
}, {
key: 'user_and_group_mentions_only',
i18nLabel: 'User_and_group_mentions_only'
}
],
'public': true
});
this.add('CDN_PREFIX', '', {
type: 'string',
'public': true

@ -317,6 +317,8 @@ RocketChat.Livechat = {
alert: true,
open: true,
unread: 1,
userMentions: 1,
grouMentions: 0,
code: room.code,
u: {
_id: agent.agentId,

@ -40,6 +40,8 @@ RocketChat.QueueMethods = {
alert: true,
open: true,
unread: 1,
userMentions: 1,
grouMentions: 0,
code: roomCode,
u: {
_id: agent.agentId,

@ -24,6 +24,8 @@ Meteor.methods({
alert: true,
open: true,
unread: 1,
userMentions: 1,
grouMentions: 0,
code: inquiry.code,
u: {
_id: agent.agentId,

@ -37,7 +37,9 @@ Meteor.methods({
ts: now,
open: true,
alert: true,
unread: 1
unread: 1,
userMentions: 1,
groupMentions: 0
});
RocketChat.models.Messages.createUserJoinWithRoomIdAndUser(rid, user, {
ts: now

@ -66,6 +66,8 @@ Meteor.methods({
t: 'd',
alert: false,
unread: 0,
userMentions: 0,
groupMentions: 0,
u: {
_id: me._id,
username: me.username
@ -92,6 +94,8 @@ Meteor.methods({
open: false,
alert: false,
unread: 0,
userMentions: 0,
groupMentions: 0,
u: {
_id: to._id,
username: to.username

@ -12,6 +12,8 @@ const fields = {
alert: 1,
roles: 1,
unread: 1,
userMentions: 1,
groupMentions: 1,
archived: 1,
audioNotification: 1,
desktopNotifications: 1,

Loading…
Cancel
Save