Skip to content

Commit

Permalink
[FIX] Notifications are not being filtered (#23487)
Browse files Browse the repository at this point in the history
* Add migration to update push notification setting's value

* Update mobileNotifications preference to pushNotifications
  • Loading branch information
matheusbsilva137 authored Oct 29, 2021
1 parent ac84a41 commit c954c5f
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 16 deletions.
2 changes: 1 addition & 1 deletion app/api/server/v1/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
6 changes: 3 additions & 3 deletions app/utils/lib/getDefaultSubscriptionPref.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export const getDefaultSubscriptionPref = (userPref) => {

const {
desktopNotifications,
mobileNotifications,
pushNotifications,
emailNotificationMode,
highlights,
} = (userPref.settings && userPref.settings.preferences) || {};
Expand All @@ -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';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type UserPreferences = {
unreadAlert: boolean;
notificationsSoundVolume: number;
desktopNotifications: string;
mobileNotifications: string;
pushNotifications: string;
enableAutoAway: boolean;
highlights: string[];
messageViewMode: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const PreferencesNotificationsSection = ({ onChange, commitRef, ...props }) => {
{
desktopNotificationRequireInteraction: userDesktopNotificationRequireInteraction,
desktopNotifications: userDesktopNotifications,
mobileNotifications: userMobileNotifications,
pushNotifications: userMobileNotifications,
emailNotificationMode: userEmailNotificationMode,
},
onChange,
Expand All @@ -59,14 +59,14 @@ const PreferencesNotificationsSection = ({ onChange, commitRef, ...props }) => {
const {
desktopNotificationRequireInteraction,
desktopNotifications,
mobileNotifications,
pushNotifications,
emailNotificationMode,
} = values;

const {
handleDesktopNotificationRequireInteraction,
handleDesktopNotifications,
handleMobileNotifications,
handlePushNotifications,
handleEmailNotificationMode,
} = handlers;

Expand Down Expand Up @@ -171,8 +171,8 @@ const PreferencesNotificationsSection = ({ onChange, commitRef, ...props }) => {
<Field.Label>{t('Notification_Push_Default_For')}</Field.Label>
<Field.Row>
<Select
value={mobileNotifications}
onChange={handleMobileNotifications}
value={pushNotifications}
onChange={handlePushNotifications}
options={mobileNotificationOptions}
/>
</Field.Row>
Expand Down
10 changes: 5 additions & 5 deletions server/methods/saveUserPreferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Meteor.methods({
unreadAlert: Match.Optional(Boolean),
notificationsSoundVolume: Match.Optional(Number),
desktopNotifications: Match.Optional(String),
mobileNotifications: Match.Optional(String),
pushNotifications: Match.Optional(String),
enableAutoAway: Match.Optional(Boolean),
highlights: Match.Optional([String]),
messageViewMode: Match.Optional(Number),
Expand All @@ -46,7 +46,7 @@ Meteor.methods({

const {
desktopNotifications: oldDesktopNotifications,
mobileNotifications: oldMobileNotifications,
pushNotifications: oldMobileNotifications,
emailNotificationMode: oldEmailNotifications,
} = (user.settings && user.settings.preferences) || {};

Expand Down Expand Up @@ -81,11 +81,11 @@ Meteor.methods({
}
}

if (settings.mobileNotifications && oldMobileNotifications !== settings.mobileNotifications) {
if (settings.mobileNotifications === 'default') {
if (settings.pushNotifications && oldMobileNotifications !== settings.pushNotifications) {
if (settings.pushNotifications === 'default') {
Subscriptions.clearNotificationUserPreferences(user._id, 'mobilePushNotifications', 'mobilePrefOrigin');
} else {
Subscriptions.updateNotificationUserPreferences(user._id, settings.mobileNotifications, 'mobilePushNotifications', 'mobilePrefOrigin');
Subscriptions.updateNotificationUserPreferences(user._id, settings.pushNotifications, 'mobilePushNotifications', 'mobilePrefOrigin');
}
}

Expand Down
1 change: 1 addition & 0 deletions server/startup/migrations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,5 @@ import './v239';
import './v240';
import './v241';
import './v242';
import './v243';
import './xrun';
26 changes: 26 additions & 0 deletions server/startup/migrations/v243.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { addMigration } from '../../lib/migrations';
import { Settings, Users } from '../../../app/models/server';

addMigration({
version: 243,
up() {
const mobileNotificationsSetting = Settings.findOneById('Accounts_Default_User_Preferences_mobileNotifications');

Settings.removeById('Accounts_Default_User_Preferences_mobileNotifications');
if (mobileNotificationsSetting && mobileNotificationsSetting.value) {
Settings.upsert({
_id: 'Accounts_Default_User_Preferences_pushNotifications',
}, {
$set: {
value: mobileNotificationsSetting.value,
},
});
}

Users.update(
{ 'settings.preferences.mobileNotifications': { $exists: 1 } },
{ $rename: { 'settings.preferences.mobileNotifications': 'settings.preferences.pushNotifications' } },
{ multi: true },
);
},
});
2 changes: 1 addition & 1 deletion tests/data/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const preferences = {
unreadAlert: true,
notificationsSoundVolume: 100,
desktopNotifications: 'default',
mobileNotifications: 'default',
pushNotifications: 'default',
enableAutoAway: true,
highlights: [],
desktopNotificationRequireInteraction: false,
Expand Down

0 comments on commit c954c5f

Please sign in to comment.