Skip to content

Commit c259591

Browse files
authored
Merge branch 'develop' into new/omnichannel-source-fields
2 parents aeb56d1 + 6ab8225 commit c259591

File tree

33 files changed

+190
-301
lines changed

33 files changed

+190
-301
lines changed

app/lib/server/functions/notifications/audio.js

Lines changed: 0 additions & 49 deletions
This file was deleted.

app/lib/server/lib/sendNotificationsOnMessage.js

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { callJoinRoom, messageContainsHighlight, parseMessageTextPerUser, replac
1010
import { getEmailData, shouldNotifyEmail } from '../functions/notifications/email';
1111
import { getPushData, shouldNotifyMobile } from '../functions/notifications/mobile';
1212
import { notifyDesktopUser, shouldNotifyDesktop } from '../functions/notifications/desktop';
13-
import { notifyAudioUser, shouldNotifyAudio } from '../functions/notifications/audio';
1413
import { Notification } from '../../../notification-queue/server/NotificationQueue';
1514
import { getMentions } from './notifyUsersOnMessage';
1615

@@ -74,29 +73,11 @@ export const sendNotification = async ({
7473
const isHighlighted = messageContainsHighlight(message, subscription.userHighlights);
7574

7675
const {
77-
audioNotifications,
7876
desktopNotifications,
7977
mobilePushNotifications,
8078
emailNotifications,
8179
} = subscription;
8280

83-
// busy users don't receive audio notification
84-
if (shouldNotifyAudio({
85-
disableAllMessageNotifications,
86-
status: receiver.status,
87-
statusConnection: receiver.statusConnection,
88-
audioNotifications,
89-
hasMentionToAll,
90-
hasMentionToHere,
91-
isHighlighted,
92-
hasMentionToUser,
93-
hasReplyToThread,
94-
roomType,
95-
isThread,
96-
})) {
97-
notifyAudioUser(subscription.u._id, message, room);
98-
}
99-
10081
// busy users don't receive desktop notification
10182
if (shouldNotifyDesktop({
10283
disableAllMessageNotifications,
@@ -191,7 +172,6 @@ export const sendNotification = async ({
191172

192173
const project = {
193174
$project: {
194-
audioNotifications: 1,
195175
desktopNotifications: 1,
196176
emailNotifications: 1,
197177
mobilePushNotifications: 1,

app/lib/server/startup/settings.js

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -259,24 +259,6 @@ settings.addGroup('Accounts', function() {
259259
i18nLabel: 'Notification_RequireInteraction',
260260
i18nDescription: 'Notification_RequireInteraction_Description',
261261
});
262-
this.add('Accounts_Default_User_Preferences_audioNotifications', 'mentions', {
263-
type: 'select',
264-
values: [
265-
{
266-
key: 'all',
267-
i18nLabel: 'All_messages',
268-
},
269-
{
270-
key: 'mentions',
271-
i18nLabel: 'Mentions',
272-
},
273-
{
274-
key: 'nothing',
275-
i18nLabel: 'Nothing',
276-
},
277-
],
278-
public: true,
279-
});
280262
this.add('Accounts_Default_User_Preferences_desktopNotifications', 'all', {
281263
type: 'select',
282264
values: [

app/livechat/client/lib/stream/queueManager.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ const newInquirySound = () => {
1313
const userId = Meteor.userId();
1414
const audioVolume = getUserPreference(userId, 'notificationsSoundVolume');
1515
const newRoomNotification = getUserPreference(userId, 'newRoomNotification');
16-
const audioNotificationValue = getUserPreference(userId, 'audioNotifications');
1716

18-
if (audioNotificationValue !== 'none') {
17+
if (newRoomNotification !== 'none') {
1918
CustomSounds.play(newRoomNotification, {
2019
volume: Number((audioVolume / 100).toPrecision(2)),
2120
});

app/models/server/models/Subscriptions.js

Lines changed: 14 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ export class Subscriptions extends Base {
2525
this.tryEnsureIndex({ alert: 1 });
2626
this.tryEnsureIndex({ ts: 1 });
2727
this.tryEnsureIndex({ ls: 1 });
28-
this.tryEnsureIndex({ audioNotifications: 1 }, { sparse: 1 });
2928
this.tryEnsureIndex({ desktopNotifications: 1 }, { sparse: 1 });
3029
this.tryEnsureIndex({ mobilePushNotifications: 1 }, { sparse: 1 });
3130
this.tryEnsureIndex({ emailNotifications: 1 }, { sparse: 1 });
@@ -146,6 +145,20 @@ export class Subscriptions extends Base {
146145
return this.update(query, update);
147146
}
148147

148+
clearAudioNotificationValueById(_id) {
149+
const query = {
150+
_id,
151+
};
152+
153+
const update = {
154+
$unset: {
155+
audioNotificationValue: 1,
156+
},
157+
};
158+
159+
return this.update(query, update);
160+
}
161+
149162
updateNotificationsPrefById(_id, notificationPref, notificationField, notificationPrefOrigin) {
150163
const query = {
151164
_id,
@@ -237,15 +250,6 @@ export class Subscriptions extends Base {
237250
this.update(query, update);
238251
}
239252

240-
findAlwaysNotifyAudioUsersByRoomId(roomId) {
241-
const query = {
242-
rid: roomId,
243-
audioNotifications: 'all',
244-
};
245-
246-
return this.find(query);
247-
}
248-
249253
findAlwaysNotifyDesktopUsersByRoomId(roomId) {
250254
const query = {
251255
rid: roomId,
@@ -293,57 +297,6 @@ export class Subscriptions extends Base {
293297
return this.find(query, { fields: { emailNotifications: 1, u: 1 } });
294298
}
295299

296-
findNotificationPreferencesByRoom(query/* { roomId: rid, desktopFilter: desktopNotifications, mobileFilter: mobilePushNotifications, emailFilter: emailNotifications }*/) {
297-
return this._db.find(query, {
298-
fields: {
299-
300-
// fields needed for notifications
301-
rid: 1,
302-
t: 1,
303-
u: 1,
304-
name: 1,
305-
fname: 1,
306-
code: 1,
307-
308-
// fields to define if should send a notification
309-
ignored: 1,
310-
audioNotifications: 1,
311-
audioNotificationValue: 1,
312-
desktopNotifications: 1,
313-
mobilePushNotifications: 1,
314-
emailNotifications: 1,
315-
disableNotifications: 1,
316-
muteGroupMentions: 1,
317-
userHighlights: 1,
318-
},
319-
});
320-
}
321-
322-
findAllMessagesNotificationPreferencesByRoom(roomId) {
323-
const query = {
324-
rid: roomId,
325-
'u._id': { $exists: true },
326-
$or: [
327-
{ desktopNotifications: { $in: ['all', 'mentions'] } },
328-
{ mobilePushNotifications: { $in: ['all', 'mentions'] } },
329-
{ emailNotifications: { $in: ['all', 'mentions'] } },
330-
],
331-
};
332-
333-
return this._db.find(query, {
334-
fields: {
335-
'u._id': 1,
336-
audioNotifications: 1,
337-
audioNotificationValue: 1,
338-
desktopNotifications: 1,
339-
mobilePushNotifications: 1,
340-
emailNotifications: 1,
341-
disableNotifications: 1,
342-
muteGroupMentions: 1,
343-
},
344-
});
345-
}
346-
347300
resetUserE2EKey(userId) {
348301
this.update({ 'u._id': userId }, {
349302
$unset: {

app/push-notifications/server/methods/saveNotificationSettings.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ import { Meteor } from 'meteor/meteor';
22
import { check } from 'meteor/check';
33

44
import { Subscriptions } from '../../../models/server';
5-
import { getUserNotificationPreference } from '../../../utils';
5+
import { getUserNotificationPreference } from '../../../utils/server';
6+
7+
const saveAudioNotificationValue = (subId, value) => (value === 'default'
8+
? Subscriptions.clearAudioNotificationValueById(subId)
9+
: Subscriptions.updateAudioNotificationValueById(subId, value));
610

711
Meteor.methods({
812
saveNotificationSettings(roomId, field, value) {
@@ -22,9 +26,6 @@ Meteor.methods({
2226
};
2327

2428
const notifications = {
25-
audioNotifications: {
26-
updateMethod: (subscription, value) => Subscriptions.updateNotificationsPrefById(subscription._id, getNotificationPrefValue('audio', value), 'audioNotifications', 'audioPrefOrigin'),
27-
},
2829
desktopNotifications: {
2930
updateMethod: (subscription, value) => Subscriptions.updateNotificationsPrefById(subscription._id, getNotificationPrefValue('desktop', value), 'desktopNotifications', 'desktopPrefOrigin'),
3031
},
@@ -47,12 +48,12 @@ Meteor.methods({
4748
updateMethod: (subscription, value) => Subscriptions.updateMuteGroupMentions(subscription._id, value === '1'),
4849
},
4950
audioNotificationValue: {
50-
updateMethod: (subscription, value) => Subscriptions.updateAudioNotificationValueById(subscription._id, value),
51+
updateMethod: (subscription, value) => saveAudioNotificationValue(subscription._id, value),
5152
},
5253
};
5354
const isInvalidNotification = !Object.keys(notifications).includes(field);
5455
const basicValuesForNotifications = ['all', 'mentions', 'nothing', 'default'];
55-
const fieldsMustHaveBasicValues = ['emailNotifications', 'audioNotifications', 'mobilePushNotifications', 'desktopNotifications'];
56+
const fieldsMustHaveBasicValues = ['emailNotifications', 'mobilePushNotifications', 'desktopNotifications'];
5657

5758
if (isInvalidNotification) {
5859
throw new Meteor.Error('error-invalid-settings', 'Invalid settings field', { method: 'saveNotificationSettings' });
@@ -77,7 +78,7 @@ Meteor.methods({
7778
if (!subscription) {
7879
throw new Meteor.Error('error-invalid-subscription', 'Invalid subscription', { method: 'saveAudioNotificationValue' });
7980
}
80-
Subscriptions.updateAudioNotificationValueById(subscription._id, value);
81+
saveAudioNotificationValue(subscription._id, value);
8182
return true;
8283
},
8384
});

app/ui/client/lib/notification.js

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -101,24 +101,35 @@ export const KonchatNotification = {
101101
},
102102

103103
newMessage(rid) {
104-
if (!Session.equals(`user_${ Meteor.user().username }_status`, 'busy')) {
105-
const userId = Meteor.userId();
106-
const newMessageNotification = getUserPreference(userId, 'newMessageNotification');
107-
const audioVolume = getUserPreference(userId, 'notificationsSoundVolume');
104+
if (Session.equals(`user_${ Meteor.user().username }_status`, 'busy')) {
105+
return;
106+
}
108107

109-
const sub = ChatSubscription.findOne({ rid }, { fields: { audioNotificationValue: 1 } });
108+
const userId = Meteor.userId();
109+
const newMessageNotification = getUserPreference(userId, 'newMessageNotification');
110+
const audioVolume = getUserPreference(userId, 'notificationsSoundVolume');
110111

111-
if (sub && sub.audioNotificationValue !== 'none') {
112-
if (sub && sub.audioNotificationValue && sub.audioNotificationValue !== '0') {
113-
CustomSounds.play(sub.audioNotificationValue, {
114-
volume: Number((audioVolume / 100).toPrecision(2)),
115-
});
116-
} else if (newMessageNotification !== 'none') {
117-
CustomSounds.play(newMessageNotification, {
118-
volume: Number((audioVolume / 100).toPrecision(2)),
119-
});
120-
}
112+
const sub = ChatSubscription.findOne({ rid }, { fields: { audioNotificationValue: 1 } });
113+
114+
if (!sub || sub.audioNotificationValue === 'none') {
115+
return;
116+
}
117+
118+
try {
119+
if (sub.audioNotificationValue && sub.audioNotificationValue !== '0') {
120+
CustomSounds.play(sub.audioNotificationValue, {
121+
volume: Number((audioVolume / 100).toPrecision(2)),
122+
});
123+
return;
124+
}
125+
126+
if (newMessageNotification !== 'none') {
127+
CustomSounds.play(newMessageNotification, {
128+
volume: Number((audioVolume / 100).toPrecision(2)),
129+
});
121130
}
131+
} catch (e) {
132+
// do nothing
122133
}
123134
},
124135

app/utils/lib/getDefaultSubscriptionPref.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ export const getDefaultSubscriptionPref = (userPref) => {
55
desktopNotifications,
66
mobileNotifications,
77
emailNotificationMode,
8-
audioNotifications,
98
highlights,
109
} = (userPref.settings && userPref.settings.preferences) || {};
1110

@@ -28,10 +27,5 @@ export const getDefaultSubscriptionPref = (userPref) => {
2827
subscription.emailPrefOrigin = 'user';
2928
}
3029

31-
if (audioNotifications && audioNotifications !== 'default') {
32-
subscription.audioNotifications = audioNotifications;
33-
subscription.audioPrefOrigin = 'user';
34-
}
35-
3630
return subscription;
3731
};

app/utils/lib/getUserNotificationPreference.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ export const getUserNotificationPreference = (user, pref) => {
88

99
let preferenceKey;
1010
switch (pref) {
11-
case 'audio': preferenceKey = 'audioNotifications'; break;
1211
case 'desktop': preferenceKey = 'desktopNotifications'; break;
1312
case 'mobile': preferenceKey = 'pushNotifications'; break;
1413
case 'email': preferenceKey = 'emailNotificationMode'; break;

client/contexts/ServerContext/methods/saveUserPreferences.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ type UserPreferences = {
1212
unreadAlert: boolean;
1313
notificationsSoundVolume: number;
1414
desktopNotifications: string;
15-
audioNotifications: string;
1615
mobileNotifications: string;
1716
enableAutoAway: boolean;
1817
highlights: string[];

0 commit comments

Comments
 (0)