Skip to content

Commit

Permalink
[FIX] Notification preferences being lost when switching view mode (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
sampaiodiego authored and rodrigok committed Jul 4, 2018
1 parent 5aa08cb commit 013b351
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 25 deletions.
65 changes: 43 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions server/methods/saveUserPreferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,23 @@ Meteor.methods({

// propagate changed notification preferences
Meteor.defer(() => {
if (oldDesktopNotifications !== settings.desktopNotifications) {
if (settings.desktopNotifications && oldDesktopNotifications !== settings.desktopNotifications) {
if (settings.desktopNotifications === 'default') {
RocketChat.models.Subscriptions.clearDesktopNotificationUserPreferences(user._id);
} else {
RocketChat.models.Subscriptions.updateDesktopNotificationUserPreferences(user._id, settings.desktopNotifications);
}
}

if (oldMobileNotifications !== settings.mobileNotifications) {
if (settings.mobileNotifications && oldMobileNotifications !== settings.mobileNotifications) {
if (settings.mobileNotifications === 'default') {
RocketChat.models.Subscriptions.clearMobileNotificationUserPreferences(user._id);
} else {
RocketChat.models.Subscriptions.updateMobileNotificationUserPreferences(user._id, settings.mobileNotifications);
}
}

if (oldEmailNotifications !== settings.emailNotificationMode) {
if (settings.emailNotificationMode && oldEmailNotifications !== settings.emailNotificationMode) {
if (settings.emailNotificationMode === 'default') {
RocketChat.models.Subscriptions.clearEmailNotificationUserPreferences(user._id);
} else {
Expand Down
60 changes: 60 additions & 0 deletions server/startup/migrations/v129.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
RocketChat.Migrations.add({
version: 129,
up() {
RocketChat.models.Users.find({
$or: [
{ 'settings.preferences.desktopNotifications': { $exists: true, $ne: 'default' } },
{ 'settings.preferences.mobileNotifications': { $exists: true, $ne: 'default' } },
{ 'settings.preferences.emailNotificationMode': { $exists: true, $ne: 'default' } }
]
}, {
fields: {
'settings.preferences.desktopNotifications': 1,
'settings.preferences.mobileNotifications': 1,
'settings.preferences.emailNotificationMode': 1
}
}).forEach(user => {
if (user.settings.preferences.desktopNotifications && user.settings.preferences.desktopNotifications !== 'default') {
RocketChat.models.Subscriptions.update({
'u._id': user._id,
desktopPrefOrigin: 'user',
desktopNotifications: null
}, {
$set: {
desktopNotifications: user.settings.preferences.desktopNotifications
}
}, {
multi: true
});
}

if (user.settings.preferences.mobileNotifications && user.settings.preferences.mobileNotifications !== 'default') {
RocketChat.models.Subscriptions.update({
'u._id': user._id,
mobilePrefOrigin: 'user',
mobilePushNotifications: null
}, {
$set: {
mobilePushNotifications: user.settings.preferences.mobileNotifications
}
}, {
multi: true
});
}

if (user.settings.preferences.emailNotificationMode && user.settings.preferences.emailNotificationMode !== 'default') {
RocketChat.models.Subscriptions.update({
'u._id': user._id,
emailPrefOrigin: 'user',
emailNotifications: null
}, {
$set: {
emailNotifications: user.settings.preferences.emailNotificationMode === 'disabled' || user.settings.preferences.emailNotificationMode === 'nothing' ? 'nothing' : 'mentions'
}
}, {
multi: true
});
}
});
}
});

0 comments on commit 013b351

Please sign in to comment.