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

Fix: Skip thread notifications on message edit #14100

Merged
merged 1 commit into from
Apr 12, 2019
Merged
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
74 changes: 6 additions & 68 deletions app/threads/server/hooks/aftersavemessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,82 +7,15 @@ import { reply } from '../functions';
import { updateUsersSubscriptions } from '../../../lib/server/lib/notifyUsersOnMessage';
import { sendMessageNotifications } from '../../../lib/server/lib/sendNotificationsOnMessage';


// messages in a thread will have normal behavior as sent to the room it belongs;


function notifyUsersOnReply(message, replies, room) {
// // skips this callback if the message was edited and increments it if the edit was way in the past (aka imported)
// if (message.editedAt && Math.abs(moment(message.editedAt).diff()) > 60000) {
// return message;
// }

// skips this callback if the message was edited and increments it if the edit was way in the past (aka imported)
// skips this callback if the message was edited
if (message.editedAt) {
return message;
}

updateUsersSubscriptions(message, room, replies);

// let toAll = false;
// let toHere = false;
// const mentionIds = [];
// const highlightsIds = [];
// const highlights = Subscriptions.findByRoomAndUsersWithUserHighlights(room._id, replies, { fields: { userHighlights: 1, 'u._id': 1 } }).fetch();

// if (message.mentions != null) {
// message.mentions.forEach(function(mention) {
// if (!toAll && mention._id === 'all') {
// toAll = true;
// }
// if (!toHere && mention._id === 'here') {
// toHere = true;
// }
// if (mention._id !== message.u._id) {
// mentionIds.push(mention._id);
// }
// });
// }

// highlights.forEach(function(subscription) {
// if (messageContainsHighlight(message, subscription.userHighlights)) {
// if (subscription.u._id !== message.u._id) {
// highlightsIds.push(subscription.u._id);
// }
// }
// });

// if (room.t === 'd') {
// const unreadCountDM = settings.get('Unread_Count_DM');

// if (unreadCountDM === 'all_messages') {
// Subscriptions.incUnreadForRoomIdExcludingUserId(room._id, message.u._id);
// } else if (toAll || toHere) {
// Subscriptions.incGroupMentionsAndUnreadForRoomIdExcludingUserId(room._id, message.u._id, 1, 1);
// } else if ((mentionIds && mentionIds.length > 0) || (highlightsIds && highlightsIds.length > 0)) {
// Subscriptions.incUserMentionsAndUnreadForRoomIdAndUserIds(room._id, _.compact(_.unique(mentionIds.concat(highlightsIds))), 1, 1);
// }
// } else {
// const unreadCount = 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;
// }
// 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;
// }
// Subscriptions.incUserMentionsAndUnreadForRoomIdAndUserIds(room._id, _.compact(_.unique(mentionIds.concat(highlightsIds))), 1, incUnread);
// } else if (unreadCount === 'all_messages') {
// Subscriptions.incUnreadForRoomIdExcludingUserId(room._id, message.u._id);
// }
// }

return message;
}

Expand All @@ -94,6 +27,11 @@ const metaData = (message, parentMessage) => {

const notification = (message, room, replies) => {

// skips this callback if the message was edited
if (message.editedAt) {
return message;
}

// will send a notification to everyone who replied/followed the thread except the owner of the message
sendMessageNotifications(message, room, replies);

Expand Down