Skip to content

Commit c954c5f

Browse files
[FIX] Notifications are not being filtered (#23487)
* Add migration to update push notification setting's value * Update mobileNotifications preference to pushNotifications
1 parent ac84a41 commit c954c5f

File tree

8 files changed

+43
-16
lines changed

8 files changed

+43
-16
lines changed

app/api/server/v1/users.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ API.v1.addRoute('users.setPreferences', { authRequired: true }, {
593593
unreadAlert: Match.Maybe(Boolean),
594594
notificationsSoundVolume: Match.Maybe(Number),
595595
desktopNotifications: Match.Maybe(String),
596-
mobileNotifications: Match.Maybe(String),
596+
pushNotifications: Match.Maybe(String),
597597
enableAutoAway: Match.Maybe(Boolean),
598598
highlights: Match.Maybe(Array),
599599
desktopNotificationRequireInteraction: Match.Maybe(Boolean),

app/utils/lib/getDefaultSubscriptionPref.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export const getDefaultSubscriptionPref = (userPref) => {
33

44
const {
55
desktopNotifications,
6-
mobileNotifications,
6+
pushNotifications,
77
emailNotificationMode,
88
highlights,
99
} = (userPref.settings && userPref.settings.preferences) || {};
@@ -17,8 +17,8 @@ export const getDefaultSubscriptionPref = (userPref) => {
1717
subscription.desktopPrefOrigin = 'user';
1818
}
1919

20-
if (mobileNotifications && mobileNotifications !== 'default') {
21-
subscription.mobilePushNotifications = mobileNotifications;
20+
if (pushNotifications && pushNotifications !== 'default') {
21+
subscription.mobilePushNotifications = pushNotifications;
2222
subscription.mobilePrefOrigin = 'user';
2323
}
2424

client/contexts/ServerContext/methods/saveUserPreferences.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ type UserPreferences = {
1212
unreadAlert: boolean;
1313
notificationsSoundVolume: number;
1414
desktopNotifications: string;
15-
mobileNotifications: string;
15+
pushNotifications: string;
1616
enableAutoAway: boolean;
1717
highlights: string[];
1818
messageViewMode: number;

client/views/account/preferences/PreferencesNotificationsSection.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const PreferencesNotificationsSection = ({ onChange, commitRef, ...props }) => {
5050
{
5151
desktopNotificationRequireInteraction: userDesktopNotificationRequireInteraction,
5252
desktopNotifications: userDesktopNotifications,
53-
mobileNotifications: userMobileNotifications,
53+
pushNotifications: userMobileNotifications,
5454
emailNotificationMode: userEmailNotificationMode,
5555
},
5656
onChange,
@@ -59,14 +59,14 @@ const PreferencesNotificationsSection = ({ onChange, commitRef, ...props }) => {
5959
const {
6060
desktopNotificationRequireInteraction,
6161
desktopNotifications,
62-
mobileNotifications,
62+
pushNotifications,
6363
emailNotificationMode,
6464
} = values;
6565

6666
const {
6767
handleDesktopNotificationRequireInteraction,
6868
handleDesktopNotifications,
69-
handleMobileNotifications,
69+
handlePushNotifications,
7070
handleEmailNotificationMode,
7171
} = handlers;
7272

@@ -171,8 +171,8 @@ const PreferencesNotificationsSection = ({ onChange, commitRef, ...props }) => {
171171
<Field.Label>{t('Notification_Push_Default_For')}</Field.Label>
172172
<Field.Row>
173173
<Select
174-
value={mobileNotifications}
175-
onChange={handleMobileNotifications}
174+
value={pushNotifications}
175+
onChange={handlePushNotifications}
176176
options={mobileNotificationOptions}
177177
/>
178178
</Field.Row>

server/methods/saveUserPreferences.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Meteor.methods({
1919
unreadAlert: Match.Optional(Boolean),
2020
notificationsSoundVolume: Match.Optional(Number),
2121
desktopNotifications: Match.Optional(String),
22-
mobileNotifications: Match.Optional(String),
22+
pushNotifications: Match.Optional(String),
2323
enableAutoAway: Match.Optional(Boolean),
2424
highlights: Match.Optional([String]),
2525
messageViewMode: Match.Optional(Number),
@@ -46,7 +46,7 @@ Meteor.methods({
4646

4747
const {
4848
desktopNotifications: oldDesktopNotifications,
49-
mobileNotifications: oldMobileNotifications,
49+
pushNotifications: oldMobileNotifications,
5050
emailNotificationMode: oldEmailNotifications,
5151
} = (user.settings && user.settings.preferences) || {};
5252

@@ -81,11 +81,11 @@ Meteor.methods({
8181
}
8282
}
8383

84-
if (settings.mobileNotifications && oldMobileNotifications !== settings.mobileNotifications) {
85-
if (settings.mobileNotifications === 'default') {
84+
if (settings.pushNotifications && oldMobileNotifications !== settings.pushNotifications) {
85+
if (settings.pushNotifications === 'default') {
8686
Subscriptions.clearNotificationUserPreferences(user._id, 'mobilePushNotifications', 'mobilePrefOrigin');
8787
} else {
88-
Subscriptions.updateNotificationUserPreferences(user._id, settings.mobileNotifications, 'mobilePushNotifications', 'mobilePrefOrigin');
88+
Subscriptions.updateNotificationUserPreferences(user._id, settings.pushNotifications, 'mobilePushNotifications', 'mobilePrefOrigin');
8989
}
9090
}
9191

server/startup/migrations/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,5 @@ import './v239';
6666
import './v240';
6767
import './v241';
6868
import './v242';
69+
import './v243';
6970
import './xrun';

server/startup/migrations/v243.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { addMigration } from '../../lib/migrations';
2+
import { Settings, Users } from '../../../app/models/server';
3+
4+
addMigration({
5+
version: 243,
6+
up() {
7+
const mobileNotificationsSetting = Settings.findOneById('Accounts_Default_User_Preferences_mobileNotifications');
8+
9+
Settings.removeById('Accounts_Default_User_Preferences_mobileNotifications');
10+
if (mobileNotificationsSetting && mobileNotificationsSetting.value) {
11+
Settings.upsert({
12+
_id: 'Accounts_Default_User_Preferences_pushNotifications',
13+
}, {
14+
$set: {
15+
value: mobileNotificationsSetting.value,
16+
},
17+
});
18+
}
19+
20+
Users.update(
21+
{ 'settings.preferences.mobileNotifications': { $exists: 1 } },
22+
{ $rename: { 'settings.preferences.mobileNotifications': 'settings.preferences.pushNotifications' } },
23+
{ multi: true },
24+
);
25+
},
26+
});

tests/data/user.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const preferences = {
2020
unreadAlert: true,
2121
notificationsSoundVolume: 100,
2222
desktopNotifications: 'default',
23-
mobileNotifications: 'default',
23+
pushNotifications: 'default',
2424
enableAutoAway: true,
2525
highlights: [],
2626
desktopNotificationRequireInteraction: false,

0 commit comments

Comments
 (0)