More improvements on send notifications logic (#10736)
* Denormalize the User’s Highlights * Find subscriptions for each type of notification * Change email preference values * General improvements * Use just one query to get all subscriptions to notify * Get hightlights from subscriptions on method notifyUsersOnMessage * Keep compatibility of emailNotifications preference in subscription save * Prevent group mentions on large roomspull/10760/head
parent
b995ed69f4
commit
1b8e8a5bf9
@ -1,6 +1,6 @@ |
||||
/* globals emojione */ |
||||
Meteor.startup(function() { |
||||
RocketChat.callbacks.add('beforeNotifyUser', (message) => { |
||||
RocketChat.callbacks.add('beforeSendMessageNotifications', (message) => { |
||||
return emojione.shortnameToUnicode(message); |
||||
}); |
||||
}); |
||||
|
||||
@ -0,0 +1,72 @@ |
||||
RocketChat.Migrations.add({ |
||||
version: 118, |
||||
up() { |
||||
RocketChat.models.Subscriptions.update({ |
||||
emailNotifications: 'all', |
||||
emailPrefOrigin: 'user' |
||||
}, { |
||||
$set: { |
||||
emailNotifications: 'mentions' |
||||
} |
||||
}, { |
||||
multi:true |
||||
}); |
||||
|
||||
RocketChat.models.Users.update({ |
||||
'settings.preferences.emailNotificationMode': 'disabled' |
||||
}, { |
||||
$set: { |
||||
'settings.preferences.emailNotificationMode': 'nothing' |
||||
} |
||||
}, { |
||||
multi:true |
||||
}); |
||||
|
||||
RocketChat.models.Users.update({ |
||||
'settings.preferences.emailNotificationMode': 'all' |
||||
}, { |
||||
$set: { |
||||
'settings.preferences.emailNotificationMode': 'mentions' |
||||
} |
||||
}, { |
||||
multi:true |
||||
}); |
||||
|
||||
RocketChat.models.Settings.update({ |
||||
_id: 'Accounts_Default_User_Preferences_emailNotificationMode', |
||||
value: 'disabled' |
||||
}, { |
||||
$set: { |
||||
value: 'nothing' |
||||
} |
||||
}); |
||||
|
||||
RocketChat.models.Settings.update({ |
||||
_id: 'Accounts_Default_User_Preferences_emailNotificationMode', |
||||
value: 'all' |
||||
}, { |
||||
$set: { |
||||
value: 'mentions' |
||||
} |
||||
}); |
||||
|
||||
// set user highlights on subscriptions
|
||||
RocketChat.models.Users.find({ |
||||
'settings.preferences.highlights.0': {$exists: true} |
||||
}, { |
||||
fields: { |
||||
'settings.preferences.highlights': 1 |
||||
} |
||||
}).forEach(user => { |
||||
RocketChat.models.Subscriptions.update({ |
||||
'u._id': user._id |
||||
}, { |
||||
$set: { |
||||
userHighlights: user.settings.preferences.highlights |
||||
} |
||||
}, { |
||||
multi: true |
||||
}); |
||||
}); |
||||
} |
||||
}); |
||||
Loading…
Reference in new issue