Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 28 additions & 18 deletions app/push-notifications/client/views/pushNotificationsFlexTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ const notificationLabels = {
nothing: 'Nothing',
};

const getAudioAssetsArray = () => CustomSounds.getList().map((audio) => ({
id: `audioNotificationValue${ audio.name }`,
name: 'audioNotificationValue',
label: audio.name,
value: `${ audio._id } ${ audio.name }`,
}));

const getAudioAssetValue = (value) => {
const asset = CustomSounds.getList().find((audio) => audio._id === value);
return asset ? `${ asset._id } ${ asset.name }` : '0 Default';
};

const call = (method, ...params) => new Promise((resolve, reject) => {
Meteor.call(method, ...params, (err, result) => {
if (err) {
Expand Down Expand Up @@ -133,10 +145,11 @@ Template.pushNotificationsFlexTab.onCreated(function() {
mobilePushNotifications = 'default',
emailNotifications = 'default',
desktopNotificationDuration = 0,
audioNotificationValue = null,
muteGroupMentions = false,
} = sub;

const audioNotificationValue = sub.audioNotificationValue && getAudioAssetValue(sub.audioNotificationValue);

this.original = {
disableNotifications: new ReactiveVar(disableNotifications),
hideUnreadStatus: new ReactiveVar(hideUnreadStatus),
Expand Down Expand Up @@ -199,19 +212,22 @@ Template.pushNotificationsFlexTab.events({

'click [data-play]'(e) {
e.preventDefault();
const user = Meteor.userId();

const value = Template.instance().form.audioNotificationValue.get().split(' ');
if (value[0] === '0') {
value[0] = getUserPreference(user, 'newMessageNotification');
}
const uid = Meteor.userId();
const formValue = Template.instance().form.audioNotificationValue.get();

const value = formValue && formValue.split(' ')[0] && formValue.split(' ')[0] !== '0'
? formValue.split(' ')[0]
: getUserPreference(uid, 'newMessageNotification');

if (value && value[0] !== 'none') {
const audioVolume = getUserPreference(user, 'notificationsSoundVolume');
CustomSounds.play(value[0], {
volume: Number((audioVolume / 100).toPrecision(2)),
});
if (!value || value === 'none') {
return;
}

const audioVolume = getUserPreference(uid, 'notificationsSoundVolume');
CustomSounds.play(value, {
volume: Number((audioVolume / 100).toPrecision(2)),
});
},

'change input[type=checkbox]'(e, instance) {
Expand All @@ -229,13 +245,7 @@ Template.pushNotificationsFlexTab.events({

switch (key) {
case 'audioNotificationValue':
const audioAssets = (CustomSounds && CustomSounds.getList && CustomSounds.getList()) || [];
const audioAssetsArray = audioAssets.map((audio) => ({
id: `audioNotificationValue${ audio.name }`,
name: 'audioNotificationValue',
label: audio.name,
value: `${ audio._id } ${ audio.name }`,
}));
const audioAssetsArray = getAudioAssetsArray();
options = [
{
id: 'audioNotificationValueNone',
Expand Down