From c954c5ffece8111bf924bec91e6666b25a66749f Mon Sep 17 00:00:00 2001 From: Matheus Barbosa Silva <36537004+matheusbsilva137@users.noreply.github.com> Date: Fri, 29 Oct 2021 14:40:04 -0300 Subject: [PATCH] [FIX] Notifications are not being filtered (#23487) * Add migration to update push notification setting's value * Update mobileNotifications preference to pushNotifications --- app/api/server/v1/users.js | 2 +- app/utils/lib/getDefaultSubscriptionPref.js | 6 ++--- .../methods/saveUserPreferences.ts | 2 +- .../PreferencesNotificationsSection.js | 10 +++---- server/methods/saveUserPreferences.js | 10 +++---- server/startup/migrations/index.ts | 1 + server/startup/migrations/v243.ts | 26 +++++++++++++++++++ tests/data/user.js | 2 +- 8 files changed, 43 insertions(+), 16 deletions(-) create mode 100644 server/startup/migrations/v243.ts diff --git a/app/api/server/v1/users.js b/app/api/server/v1/users.js index 714fc5e9265f..1f3f22e38e6c 100644 --- a/app/api/server/v1/users.js +++ b/app/api/server/v1/users.js @@ -593,7 +593,7 @@ API.v1.addRoute('users.setPreferences', { authRequired: true }, { unreadAlert: Match.Maybe(Boolean), notificationsSoundVolume: Match.Maybe(Number), desktopNotifications: Match.Maybe(String), - mobileNotifications: Match.Maybe(String), + pushNotifications: Match.Maybe(String), enableAutoAway: Match.Maybe(Boolean), highlights: Match.Maybe(Array), desktopNotificationRequireInteraction: Match.Maybe(Boolean), diff --git a/app/utils/lib/getDefaultSubscriptionPref.js b/app/utils/lib/getDefaultSubscriptionPref.js index 294a7d50a734..0200cb128e33 100644 --- a/app/utils/lib/getDefaultSubscriptionPref.js +++ b/app/utils/lib/getDefaultSubscriptionPref.js @@ -3,7 +3,7 @@ export const getDefaultSubscriptionPref = (userPref) => { const { desktopNotifications, - mobileNotifications, + pushNotifications, emailNotificationMode, highlights, } = (userPref.settings && userPref.settings.preferences) || {}; @@ -17,8 +17,8 @@ export const getDefaultSubscriptionPref = (userPref) => { subscription.desktopPrefOrigin = 'user'; } - if (mobileNotifications && mobileNotifications !== 'default') { - subscription.mobilePushNotifications = mobileNotifications; + if (pushNotifications && pushNotifications !== 'default') { + subscription.mobilePushNotifications = pushNotifications; subscription.mobilePrefOrigin = 'user'; } diff --git a/client/contexts/ServerContext/methods/saveUserPreferences.ts b/client/contexts/ServerContext/methods/saveUserPreferences.ts index 1f5f67100c97..7e6b20ad0bf6 100644 --- a/client/contexts/ServerContext/methods/saveUserPreferences.ts +++ b/client/contexts/ServerContext/methods/saveUserPreferences.ts @@ -12,7 +12,7 @@ type UserPreferences = { unreadAlert: boolean; notificationsSoundVolume: number; desktopNotifications: string; - mobileNotifications: string; + pushNotifications: string; enableAutoAway: boolean; highlights: string[]; messageViewMode: number; diff --git a/client/views/account/preferences/PreferencesNotificationsSection.js b/client/views/account/preferences/PreferencesNotificationsSection.js index 615b063d8e3e..6419f8df5ffe 100644 --- a/client/views/account/preferences/PreferencesNotificationsSection.js +++ b/client/views/account/preferences/PreferencesNotificationsSection.js @@ -50,7 +50,7 @@ const PreferencesNotificationsSection = ({ onChange, commitRef, ...props }) => { { desktopNotificationRequireInteraction: userDesktopNotificationRequireInteraction, desktopNotifications: userDesktopNotifications, - mobileNotifications: userMobileNotifications, + pushNotifications: userMobileNotifications, emailNotificationMode: userEmailNotificationMode, }, onChange, @@ -59,14 +59,14 @@ const PreferencesNotificationsSection = ({ onChange, commitRef, ...props }) => { const { desktopNotificationRequireInteraction, desktopNotifications, - mobileNotifications, + pushNotifications, emailNotificationMode, } = values; const { handleDesktopNotificationRequireInteraction, handleDesktopNotifications, - handleMobileNotifications, + handlePushNotifications, handleEmailNotificationMode, } = handlers; @@ -171,8 +171,8 @@ const PreferencesNotificationsSection = ({ onChange, commitRef, ...props }) => { {t('Notification_Push_Default_For')}