Regression: Fix email notification preference not showing correct selected value (#10847)
* Fix email notification preference not showing correct selected value Closes #10844 * Save email notification preferences correctly Closes #10787 * Create room with user notification preferences * Add back the uploaded file message on push notificationspull/10321/head^2
parent
888e2d9b87
commit
e1ef24b08c
@ -0,0 +1,31 @@ |
||||
RocketChat.getDefaultSubscriptionPref = function _getDefaultSubscriptionPref(userPref) { |
||||
const subscription = {}; |
||||
|
||||
const { |
||||
desktopNotifications, |
||||
mobileNotifications, |
||||
emailNotificationMode, |
||||
highlights |
||||
} = (userPref.settings && userPref.settings.preferences) || {}; |
||||
|
||||
if (Array.isArray(highlights) && highlights.length) { |
||||
subscription.userHighlights = highlights; |
||||
} |
||||
|
||||
if (desktopNotifications && desktopNotifications !== 'default') { |
||||
subscription.desktopNotifications = desktopNotifications; |
||||
subscription.desktopPrefOrigin = 'user'; |
||||
} |
||||
|
||||
if (mobileNotifications && mobileNotifications !== 'default') { |
||||
subscription.mobilePushNotifications = mobileNotifications; |
||||
subscription.mobilePrefOrigin = 'user'; |
||||
} |
||||
|
||||
if (emailNotificationMode && emailNotificationMode !== 'default') { |
||||
subscription.emailNotifications = emailNotificationMode; |
||||
subscription.emailPrefOrigin = 'user'; |
||||
} |
||||
|
||||
return subscription; |
||||
}; |
||||
@ -0,0 +1,56 @@ |
||||
RocketChat.Migrations.add({ |
||||
version: 121, |
||||
up() { |
||||
|
||||
// set user preferences on subscriptions
|
||||
RocketChat.models.Users.find({ |
||||
$or: [ |
||||
{ 'settings.preferences.desktopNotifications': { $exists: true } }, |
||||
{ 'settings.preferences.mobileNotifications': { $exists: true } }, |
||||
{ 'settings.preferences.emailNotificationMode': { $exists: true } } |
||||
] |
||||
}).forEach(user => { |
||||
if (user.settings.preferences.desktopNotifications && user.settings.preferences.desktopNotifications !== 'default') { |
||||
RocketChat.models.Subscriptions.update({ |
||||
'u._id': user._id, |
||||
desktopPrefOrigin: { $exists: false } |
||||
}, { |
||||
$set: { |
||||
desktopNotifications: user.settings.preferences.desktopNotifications, |
||||
desktopPrefOrigin: 'user' |
||||
} |
||||
}, { |
||||
multi: true |
||||
}); |
||||
} |
||||
|
||||
if (user.settings.preferences.mobileNotifications && user.settings.preferences.mobileNotifications !== 'default') { |
||||
RocketChat.models.Subscriptions.update({ |
||||
'u._id': user._id, |
||||
mobilePrefOrigin: { $exists: false } |
||||
}, { |
||||
$set: { |
||||
mobileNotifications: user.settings.preferences.mobileNotifications, |
||||
mobilePrefOrigin: 'user' |
||||
} |
||||
}, { |
||||
multi: true |
||||
}); |
||||
} |
||||
|
||||
if (user.settings.preferences.emailNotificationMode && user.settings.preferences.emailNotificationMode !== 'default') { |
||||
RocketChat.models.Subscriptions.update({ |
||||
'u._id': user._id, |
||||
emailPrefOrigin: { $exists: false } |
||||
}, { |
||||
$set: { |
||||
emailNotifications: user.settings.preferences.emailNotificationMode === 'disabled' || user.settings.preferences.emailNotificationMode === 'nothing' ? 'nothing' : 'mentions', |
||||
emailPrefOrigin: 'user' |
||||
} |
||||
}, { |
||||
multi: true |
||||
}); |
||||
} |
||||
}); |
||||
} |
||||
}); |
||||
Loading…
Reference in new issue