Skip to content

Commit

Permalink
Merge branch 'develop' into new/omnichannel-source-fields
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagoevanp authored Sep 13, 2021
2 parents aeb56d1 + 6ab8225 commit c259591
Show file tree
Hide file tree
Showing 33 changed files with 190 additions and 301 deletions.
49 changes: 0 additions & 49 deletions app/lib/server/functions/notifications/audio.js

This file was deleted.

20 changes: 0 additions & 20 deletions app/lib/server/lib/sendNotificationsOnMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { callJoinRoom, messageContainsHighlight, parseMessageTextPerUser, replac
import { getEmailData, shouldNotifyEmail } from '../functions/notifications/email';
import { getPushData, shouldNotifyMobile } from '../functions/notifications/mobile';
import { notifyDesktopUser, shouldNotifyDesktop } from '../functions/notifications/desktop';
import { notifyAudioUser, shouldNotifyAudio } from '../functions/notifications/audio';
import { Notification } from '../../../notification-queue/server/NotificationQueue';
import { getMentions } from './notifyUsersOnMessage';

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

const {
audioNotifications,
desktopNotifications,
mobilePushNotifications,
emailNotifications,
} = subscription;

// busy users don't receive audio notification
if (shouldNotifyAudio({
disableAllMessageNotifications,
status: receiver.status,
statusConnection: receiver.statusConnection,
audioNotifications,
hasMentionToAll,
hasMentionToHere,
isHighlighted,
hasMentionToUser,
hasReplyToThread,
roomType,
isThread,
})) {
notifyAudioUser(subscription.u._id, message, room);
}

// busy users don't receive desktop notification
if (shouldNotifyDesktop({
disableAllMessageNotifications,
Expand Down Expand Up @@ -191,7 +172,6 @@ export const sendNotification = async ({

const project = {
$project: {
audioNotifications: 1,
desktopNotifications: 1,
emailNotifications: 1,
mobilePushNotifications: 1,
Expand Down
18 changes: 0 additions & 18 deletions app/lib/server/startup/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,24 +259,6 @@ settings.addGroup('Accounts', function() {
i18nLabel: 'Notification_RequireInteraction',
i18nDescription: 'Notification_RequireInteraction_Description',
});
this.add('Accounts_Default_User_Preferences_audioNotifications', 'mentions', {
type: 'select',
values: [
{
key: 'all',
i18nLabel: 'All_messages',
},
{
key: 'mentions',
i18nLabel: 'Mentions',
},
{
key: 'nothing',
i18nLabel: 'Nothing',
},
],
public: true,
});
this.add('Accounts_Default_User_Preferences_desktopNotifications', 'all', {
type: 'select',
values: [
Expand Down
3 changes: 1 addition & 2 deletions app/livechat/client/lib/stream/queueManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ const newInquirySound = () => {
const userId = Meteor.userId();
const audioVolume = getUserPreference(userId, 'notificationsSoundVolume');
const newRoomNotification = getUserPreference(userId, 'newRoomNotification');
const audioNotificationValue = getUserPreference(userId, 'audioNotifications');

if (audioNotificationValue !== 'none') {
if (newRoomNotification !== 'none') {
CustomSounds.play(newRoomNotification, {
volume: Number((audioVolume / 100).toPrecision(2)),
});
Expand Down
75 changes: 14 additions & 61 deletions app/models/server/models/Subscriptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export class Subscriptions extends Base {
this.tryEnsureIndex({ alert: 1 });
this.tryEnsureIndex({ ts: 1 });
this.tryEnsureIndex({ ls: 1 });
this.tryEnsureIndex({ audioNotifications: 1 }, { sparse: 1 });
this.tryEnsureIndex({ desktopNotifications: 1 }, { sparse: 1 });
this.tryEnsureIndex({ mobilePushNotifications: 1 }, { sparse: 1 });
this.tryEnsureIndex({ emailNotifications: 1 }, { sparse: 1 });
Expand Down Expand Up @@ -146,6 +145,20 @@ export class Subscriptions extends Base {
return this.update(query, update);
}

clearAudioNotificationValueById(_id) {
const query = {
_id,
};

const update = {
$unset: {
audioNotificationValue: 1,
},
};

return this.update(query, update);
}

updateNotificationsPrefById(_id, notificationPref, notificationField, notificationPrefOrigin) {
const query = {
_id,
Expand Down Expand Up @@ -237,15 +250,6 @@ export class Subscriptions extends Base {
this.update(query, update);
}

findAlwaysNotifyAudioUsersByRoomId(roomId) {
const query = {
rid: roomId,
audioNotifications: 'all',
};

return this.find(query);
}

findAlwaysNotifyDesktopUsersByRoomId(roomId) {
const query = {
rid: roomId,
Expand Down Expand Up @@ -293,57 +297,6 @@ export class Subscriptions extends Base {
return this.find(query, { fields: { emailNotifications: 1, u: 1 } });
}

findNotificationPreferencesByRoom(query/* { roomId: rid, desktopFilter: desktopNotifications, mobileFilter: mobilePushNotifications, emailFilter: emailNotifications }*/) {
return this._db.find(query, {
fields: {

// fields needed for notifications
rid: 1,
t: 1,
u: 1,
name: 1,
fname: 1,
code: 1,

// fields to define if should send a notification
ignored: 1,
audioNotifications: 1,
audioNotificationValue: 1,
desktopNotifications: 1,
mobilePushNotifications: 1,
emailNotifications: 1,
disableNotifications: 1,
muteGroupMentions: 1,
userHighlights: 1,
},
});
}

findAllMessagesNotificationPreferencesByRoom(roomId) {
const query = {
rid: roomId,
'u._id': { $exists: true },
$or: [
{ desktopNotifications: { $in: ['all', 'mentions'] } },
{ mobilePushNotifications: { $in: ['all', 'mentions'] } },
{ emailNotifications: { $in: ['all', 'mentions'] } },
],
};

return this._db.find(query, {
fields: {
'u._id': 1,
audioNotifications: 1,
audioNotificationValue: 1,
desktopNotifications: 1,
mobilePushNotifications: 1,
emailNotifications: 1,
disableNotifications: 1,
muteGroupMentions: 1,
},
});
}

resetUserE2EKey(userId) {
this.update({ 'u._id': userId }, {
$unset: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';

import { Subscriptions } from '../../../models/server';
import { getUserNotificationPreference } from '../../../utils';
import { getUserNotificationPreference } from '../../../utils/server';

const saveAudioNotificationValue = (subId, value) => (value === 'default'
? Subscriptions.clearAudioNotificationValueById(subId)
: Subscriptions.updateAudioNotificationValueById(subId, value));

Meteor.methods({
saveNotificationSettings(roomId, field, value) {
Expand All @@ -22,9 +26,6 @@ Meteor.methods({
};

const notifications = {
audioNotifications: {
updateMethod: (subscription, value) => Subscriptions.updateNotificationsPrefById(subscription._id, getNotificationPrefValue('audio', value), 'audioNotifications', 'audioPrefOrigin'),
},
desktopNotifications: {
updateMethod: (subscription, value) => Subscriptions.updateNotificationsPrefById(subscription._id, getNotificationPrefValue('desktop', value), 'desktopNotifications', 'desktopPrefOrigin'),
},
Expand All @@ -47,12 +48,12 @@ Meteor.methods({
updateMethod: (subscription, value) => Subscriptions.updateMuteGroupMentions(subscription._id, value === '1'),
},
audioNotificationValue: {
updateMethod: (subscription, value) => Subscriptions.updateAudioNotificationValueById(subscription._id, value),
updateMethod: (subscription, value) => saveAudioNotificationValue(subscription._id, value),
},
};
const isInvalidNotification = !Object.keys(notifications).includes(field);
const basicValuesForNotifications = ['all', 'mentions', 'nothing', 'default'];
const fieldsMustHaveBasicValues = ['emailNotifications', 'audioNotifications', 'mobilePushNotifications', 'desktopNotifications'];
const fieldsMustHaveBasicValues = ['emailNotifications', 'mobilePushNotifications', 'desktopNotifications'];

if (isInvalidNotification) {
throw new Meteor.Error('error-invalid-settings', 'Invalid settings field', { method: 'saveNotificationSettings' });
Expand All @@ -77,7 +78,7 @@ Meteor.methods({
if (!subscription) {
throw new Meteor.Error('error-invalid-subscription', 'Invalid subscription', { method: 'saveAudioNotificationValue' });
}
Subscriptions.updateAudioNotificationValueById(subscription._id, value);
saveAudioNotificationValue(subscription._id, value);
return true;
},
});
41 changes: 26 additions & 15 deletions app/ui/client/lib/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,24 +101,35 @@ export const KonchatNotification = {
},

newMessage(rid) {
if (!Session.equals(`user_${ Meteor.user().username }_status`, 'busy')) {
const userId = Meteor.userId();
const newMessageNotification = getUserPreference(userId, 'newMessageNotification');
const audioVolume = getUserPreference(userId, 'notificationsSoundVolume');
if (Session.equals(`user_${ Meteor.user().username }_status`, 'busy')) {
return;
}

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

if (sub && sub.audioNotificationValue !== 'none') {
if (sub && sub.audioNotificationValue && sub.audioNotificationValue !== '0') {
CustomSounds.play(sub.audioNotificationValue, {
volume: Number((audioVolume / 100).toPrecision(2)),
});
} else if (newMessageNotification !== 'none') {
CustomSounds.play(newMessageNotification, {
volume: Number((audioVolume / 100).toPrecision(2)),
});
}
const sub = ChatSubscription.findOne({ rid }, { fields: { audioNotificationValue: 1 } });

if (!sub || sub.audioNotificationValue === 'none') {
return;
}

try {
if (sub.audioNotificationValue && sub.audioNotificationValue !== '0') {
CustomSounds.play(sub.audioNotificationValue, {
volume: Number((audioVolume / 100).toPrecision(2)),
});
return;
}

if (newMessageNotification !== 'none') {
CustomSounds.play(newMessageNotification, {
volume: Number((audioVolume / 100).toPrecision(2)),
});
}
} catch (e) {
// do nothing
}
},

Expand Down
6 changes: 0 additions & 6 deletions app/utils/lib/getDefaultSubscriptionPref.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export const getDefaultSubscriptionPref = (userPref) => {
desktopNotifications,
mobileNotifications,
emailNotificationMode,
audioNotifications,
highlights,
} = (userPref.settings && userPref.settings.preferences) || {};

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

if (audioNotifications && audioNotifications !== 'default') {
subscription.audioNotifications = audioNotifications;
subscription.audioPrefOrigin = 'user';
}

return subscription;
};
1 change: 0 additions & 1 deletion app/utils/lib/getUserNotificationPreference.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export const getUserNotificationPreference = (user, pref) => {

let preferenceKey;
switch (pref) {
case 'audio': preferenceKey = 'audioNotifications'; break;
case 'desktop': preferenceKey = 'desktopNotifications'; break;
case 'mobile': preferenceKey = 'pushNotifications'; break;
case 'email': preferenceKey = 'emailNotificationMode'; break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ type UserPreferences = {
unreadAlert: boolean;
notificationsSoundVolume: number;
desktopNotifications: string;
audioNotifications: string;
mobileNotifications: string;
enableAutoAway: boolean;
highlights: string[];
Expand Down
Loading

0 comments on commit c259591

Please sign in to comment.