Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression: Fix notifications for direct messages #10760

Merged
merged 1 commit into from
May 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/rocketchat-lib/lib/roomTypes/direct.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ export class DirectMessageRoomType extends RoomTypeConfig {
name: identifier
};

const subscription = ChatSubscription.findOne(query);
const subscription = RocketChat.models.Subscriptions.findOne(query);
if (subscription && subscription.rid) {
return ChatRoom.findOne(subscription.rid);
}
}

roomName(roomData) {
const subscription = ChatSubscription.findOne({rid: roomData._id}, {fields: {name: 1, fname: 1}});
const subscription = RocketChat.models.Subscriptions.findOne({rid: roomData._id}, {fields: {name: 1, fname: 1}});
if (!subscription) {
return '';
}
Expand All @@ -55,7 +55,7 @@ export class DirectMessageRoomType extends RoomTypeConfig {

secondaryRoomName(roomData) {
if (RocketChat.settings.get('UI_Use_Real_Name')) {
const subscription = ChatSubscription.findOne({rid: roomData._id}, {fields: {name: 1}});
const subscription = RocketChat.models.Subscriptions.findOne({rid: roomData._id}, {fields: {name: 1}});
return subscription && subscription.name;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ export function shouldNotifyAudio({
hasMentionToAll,
hasMentionToHere,
isHighlighted,
hasMentionToUser
hasMentionToUser,
roomType
}) {
if (disableAllMessageNotifications && audioNotifications == null) {
return false;
Expand All @@ -19,7 +20,7 @@ export function shouldNotifyAudio({
return true;
}

return (!disableAllMessageNotifications && (hasMentionToAll || hasMentionToHere)) || isHighlighted || audioNotifications === 'all' || hasMentionToUser;
return roomType === 'd' || (!disableAllMessageNotifications && (hasMentionToAll || hasMentionToHere)) || isHighlighted || audioNotifications === 'all' || hasMentionToUser;
}

export function notifyAudioUser(userId, message, room) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ export function shouldNotifyDesktop({
hasMentionToAll,
hasMentionToHere,
isHighlighted,
hasMentionToUser
hasMentionToUser,
roomType
}) {
if (disableAllMessageNotifications && desktopNotifications == null) {
return false;
Expand All @@ -70,5 +71,5 @@ export function shouldNotifyDesktop({
}
}

return (!disableAllMessageNotifications && (hasMentionToAll || hasMentionToHere)) || isHighlighted || desktopNotifications === 'all' || hasMentionToUser;
return roomType === 'd' || (!disableAllMessageNotifications && (hasMentionToAll || hasMentionToHere)) || isHighlighted || desktopNotifications === 'all' || hasMentionToUser;
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ export function shouldNotifyEmail({
emailNotifications,
isHighlighted,
hasMentionToUser,
hasMentionToAll
hasMentionToAll,
roomType
}) {

// use connected (don't need to send him an email)
Expand All @@ -172,5 +173,5 @@ export function shouldNotifyEmail({
}
}

return isHighlighted || emailNotifications === 'all' || hasMentionToUser || (!disableAllMessageNotifications && hasMentionToAll);
return roomType === 'd' || isHighlighted || emailNotifications === 'all' || hasMentionToUser || (!disableAllMessageNotifications && hasMentionToAll);
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function sendSinglePush({ room, message, userId, receiverUsername, sender
type: room.t,
name: room.name
},
roomName: RocketChat.settings.get('Push_show_username_room') ? `#${ RocketChat.roomTypes.getRoomName(room.t, room) }` : '',
roomName: RocketChat.settings.get('Push_show_username_room') ? `${ room.t === 'd' ? '' : '#' }${ RocketChat.roomTypes.getRoomName(room.t, room) }` : '',
username: RocketChat.settings.get('Push_show_username_room') ? senderUsername : '',
message: RocketChat.settings.get('Push_show_message') ? notificationMessage : ' ',
// badge: getBadgeCount(userIdToNotify),
Expand All @@ -45,7 +45,8 @@ export function shouldNotifyMobile({
hasMentionToAll,
isHighlighted,
hasMentionToUser,
statusConnection
statusConnection,
roomType
}) {
if (disableAllMessageNotifications && mobilePushNotifications == null) {
return false;
Expand All @@ -68,5 +69,5 @@ export function shouldNotifyMobile({
}
}

return (!disableAllMessageNotifications && hasMentionToAll) || isHighlighted || mobilePushNotifications === 'all' || hasMentionToUser;
return roomType === 'd' || (!disableAllMessageNotifications && hasMentionToAll) || isHighlighted || mobilePushNotifications === 'all' || hasMentionToUser;
}
20 changes: 14 additions & 6 deletions packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ const sendNotification = ({

const isHighlighted = messageContainsHighlight(message, subscription.userHighlights);

const roomType = room.t;

const {
audioNotifications,
desktopNotifications,
Expand All @@ -67,7 +69,8 @@ const sendNotification = ({
hasMentionToAll,
hasMentionToHere,
isHighlighted,
hasMentionToUser
hasMentionToUser,
roomType
})) {
notifyAudioUser(subscription.u._id, message, room);
}
Expand All @@ -80,7 +83,8 @@ const sendNotification = ({
hasMentionToAll,
hasMentionToHere,
isHighlighted,
hasMentionToUser
hasMentionToUser,
roomType
})) {
notificationSent = true;
notifyDesktopUser({
Expand All @@ -99,7 +103,8 @@ const sendNotification = ({
hasMentionToAll,
isHighlighted,
hasMentionToUser,
statusConnection: receiver.statusConnection
statusConnection: receiver.statusConnection,
roomType
})) {
notificationSent = true;

Expand All @@ -119,7 +124,8 @@ const sendNotification = ({
emailNotifications,
isHighlighted,
hasMentionToUser,
hasMentionToAll
hasMentionToAll,
roomType
})) {
receiver.emails.some((email) => {
if (email.verified) {
Expand Down Expand Up @@ -194,11 +200,13 @@ function sendAllNotifications(message, room) {
});
}

if (RocketChat.settings.get(`Accounts_Default_User_Preferences_${ notificationField }`) === 'all' && !disableAllMessageNotifications) {
const serverField = kind === 'email' ? 'emailNotificationMode' : `${ kind }Notifications`;
const serverPreference = RocketChat.settings.get(`Accounts_Default_User_Preferences_${ serverField }`);
if ((room.t === 'd' && serverPreference === 'mentions') || (serverPreference === 'all' && !disableAllMessageNotifications)) {
query.$or.push({
[notificationField]: { $exists: false }
});
} else if (RocketChat.settings.get(`Accounts_Default_User_Preferences_${ notificationField }`) === 'mentions' && mentionIdsWithoutGroups.length) {
} else if (serverPreference === 'mentions' && mentionIdsWithoutGroups.length) {
query.$or.push({
[notificationField]: { $exists: false },
'u._id': { $in: mentionIdsWithoutGroups }
Expand Down