"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "js/notifications.js" between
Signal-Desktop-1.35.2.tar.gz and Signal-Desktop-1.36.1.tar.gz

About: Signal-Desktop is a cross-platform encrypted messaging service (also available for mobile devices).

notifications.js  (Signal-Desktop-1.35.2):notifications.js  (Signal-Desktop-1.36.1)
skipping to change at line 12 skipping to change at line 12
/* global Backbone: false */ /* global Backbone: false */
/* global drawAttention: false */ /* global drawAttention: false */
/* global i18n: false */ /* global i18n: false */
/* global storage: false */ /* global storage: false */
/* global Whisper: false */ /* global Whisper: false */
/* global _: false */ /* global _: false */
// eslint-disable-next-line func-names // eslint-disable-next-line func-names
(function() { (function() {
'use strict';
window.Whisper = window.Whisper || {}; window.Whisper = window.Whisper || {};
const { Settings } = Signal.Types; const { Settings } = Signal.Types;
// The keys and values don't match here. This is because the values correspond
to old
// setting names. In the future, we may wish to migrate these to match.
const SettingNames = { const SettingNames = {
COUNT: 'count', NO_NAME_OR_MESSAGE: 'count',
NAME: 'name', NAME_ONLY: 'name',
MESSAGE: 'message', NAME_AND_MESSAGE: 'message',
}; };
Whisper.Notifications = new (Backbone.Collection.extend({ // Electron, at least on Windows and macOS, only shows one notification at a t
initialize() { ime (see
this.isEnabled = false; // issues [#15364][0] and [#21646][1], among others). Because of that, we ha
this.on('add', this.update); ve a
this.on('remove', this.onRemove); // single slot for notifications, and once a notification is dismissed, all
of
// Signal's notifications are dismissed.
// [0]: https://github.com/electron/electron/issues/15364
// [1]: https://github.com/electron/electron/issues/21646
Whisper.Notifications = {
...Backbone.Events,
isEnabled: false,
// This is either a standard `Notification` or null.
lastNotification: null,
// This is either null or an object of this shape:
//
// {
// conversationId: string;
// messageId: string;
// senderTitle: string;
// message: string;
// notificationIconUrl: string | void;
// isExpiringMessage: boolean;
// reaction: {
// emoji: string;
// };
// }
notificationData: null,
this.lastNotification = null; add(notificationData) {
this.notificationData = notificationData;
this.update();
},
// Testing indicated that trying to create/destroy notifications too quick removeBy({ conversationId, messageId }) {
ly const shouldClear =
// resulted in notifications that stuck around forever, requiring the us Boolean(this.notificationData) &&
er ((conversationId &&
// to manually close them. This introduces a minimum amount of time betw this.notificationData.conversationId === conversationId) ||
een calls, (messageId && this.notificationData.messageId === messageId));
// and batches up the quick successive update() calls we get from an inc if (shouldClear) {
oming this.clear();
// read sync, which might have a number of messages referenced inside of this.update();
it. }
this.fastUpdate = this.update;
this.update = _.debounce(this.update, 1000);
}, },
update() {
fastUpdate() {
if (this.lastNotification) { if (this.lastNotification) {
this.lastNotification.close(); this.lastNotification.close();
this.lastNotification = null; this.lastNotification = null;
} }
const { isEnabled } = this; const { isEnabled } = this;
const isAppFocused = window.isActive(); const isAppFocused = window.isActive();
const isAudioNotificationEnabled = const isAudioNotificationEnabled =
storage.get('audio-notification') || false; storage.get('audio-notification') || false;
const isAudioNotificationSupported = Settings.isAudioNotificationSupported (); const isAudioNotificationSupported = Settings.isAudioNotificationSupported ();
const numNotifications = this.length;
const userSetting = this.getUserSetting(); const userSetting = this.getUserSetting();
const status = Signal.Notifications.getStatus({ const status = Signal.Notifications.getStatus({
isAppFocused, isAppFocused,
isAudioNotificationEnabled, isAudioNotificationEnabled,
isAudioNotificationSupported, isAudioNotificationSupported,
isEnabled, isEnabled,
numNotifications, hasNotifications: Boolean(this.notificationData),
userSetting, userSetting,
}); });
if (status.type !== 'ok') { if (status.type !== 'ok') {
if (status.shouldClearNotifications) { if (status.shouldClearNotifications) {
this.reset([]); this.notificationData = null;
} }
return; return;
} }
let title; let notificationTitle;
let message; let notificationMessage;
let iconUrl; let notificationIconUrl;
// NOTE: i18n has more complex rules for pluralization than just const {
// distinguishing between zero (0) and other (non-zero), conversationId,
// e.g. Russian: messageId,
// http://docs.translatehouse.org/projects/localization-guide/en/latest/l1 senderTitle,
0n/pluralforms.html message,
const newMessageCountLabel = `${numNotifications} ${ isExpiringMessage,
numNotifications === 1 ? i18n('newMessage') : i18n('newMessages') reaction,
}`; } = this.notificationData;
const last = this.last().toJSON(); if (
switch (userSetting) { userSetting === SettingNames.NAME_ONLY ||
case SettingNames.COUNT: userSetting === SettingNames.NAME_AND_MESSAGE
title = 'Signal'; ) {
message = newMessageCountLabel; notificationTitle = senderTitle;
break; ({ notificationIconUrl } = this.notificationData);
case SettingNames.NAME: {
const lastMessageTitle = last.title; const shouldHideExpiringMessageBody =
title = newMessageCountLabel; isExpiringMessage && Signal.OS.isMacOS();
// eslint-disable-next-line prefer-destructuring if (shouldHideExpiringMessageBody) {
iconUrl = last.iconUrl; notificationMessage = i18n('newMessage');
if (numNotifications === 1) { } else if (userSetting === SettingNames.NAME_ONLY) {
if (last.reaction) { if (reaction) {
message = i18n('notificationReaction', { notificationMessage = i18n('notificationReaction', {
sender: lastMessageTitle, sender: senderTitle,
emoji: last.reaction.emoji, emoji: reaction.emoji,
});
} else {
message = `${i18n('notificationFrom')} ${lastMessageTitle}`;
}
} else if (last.reaction) {
message = i18n('notificationReactionMostRecent', {
sender: lastMessageTitle,
emoji: last.reaction.emoji,
}); });
} else { } else {
message = `${i18n( notificationMessage = i18n('newMessage');
'notificationMostRecentFrom'
)} ${lastMessageTitle}`;
} }
break; } else if (reaction) {
notificationMessage = i18n('notificationReactionMessage', {
sender: senderTitle,
emoji: reaction.emoji,
message,
});
} else {
notificationMessage = message;
} }
case SettingNames.MESSAGE: } else {
if (numNotifications === 1) { if (userSetting !== SettingNames.NO_NAME_OR_MESSAGE) {
// eslint-disable-next-line prefer-destructuring
title = last.title;
if (last.reaction) {
message = i18n('notificationReactionMessage', {
sender: last.title,
emoji: last.reaction.emoji,
message: last.message,
});
} else {
// eslint-disable-next-line prefer-destructuring
message = last.message;
}
} else if (last.reaction) {
title = newMessageCountLabel;
message = i18n('notificationReactionMessageMostRecent', {
sender: last.title,
emoji: last.reaction.emoji,
message: last.message,
});
} else {
title = newMessageCountLabel;
message = `${i18n('notificationMostRecent')} ${last.message}`;
}
// eslint-disable-next-line prefer-destructuring
iconUrl = last.iconUrl;
break;
default:
window.log.error( window.log.error(
`Error: Unknown user notification setting: '${userSetting}'` `Error: Unknown user notification setting: '${userSetting}'`
); );
break; }
} notificationTitle = 'Signal';
notificationMessage = i18n('newMessage');
const shouldHideExpiringMessageBody =
last.isExpiringMessage && Signal.OS.isMacOS();
if (shouldHideExpiringMessageBody) {
message = i18n('newMessage');
} }
const shouldDrawAttention = storage.get( const shouldDrawAttention = storage.get(
'notification-draw-attention', 'notification-draw-attention',
true true
); );
if (shouldDrawAttention) { if (shouldDrawAttention) {
drawAttention(); drawAttention();
} }
this.lastNotification = window.Signal.Services.notify({ this.lastNotification = window.Signal.Services.notify({
platform: window.platform, platform: window.platform,
title, title: notificationTitle,
icon: iconUrl, icon: notificationIconUrl,
message, message: notificationMessage,
silent: !status.shouldPlayNotificationSound, silent: !status.shouldPlayNotificationSound,
onNotificationClick: () => { onNotificationClick: () => {
this.trigger('click', last.conversationId, last.messageId); this.trigger('click', conversationId, messageId);
}, },
}); });
// We continue to build up more and more messages for our notifications
// until the user comes back to our app or closes the app. Then we’ll
// clear everything out. The good news is that we'll have a maximum of
// 1 notification in the Notification area (something like
// ‘10 new messages’) assuming that `Notification::close` does its job.
}, },
getUserSetting() { getUserSetting() {
return storage.get('notification-setting') || SettingNames.MESSAGE; return (
}, storage.get('notification-setting') || SettingNames.NAME_AND_MESSAGE
onRemove() { );
window.log.info('Remove notification');
this.update();
}, },
clear() { clear() {
window.log.info('Remove all notifications'); window.log.info('Removing notification');
this.reset([]); this.notificationData = null;
this.update(); this.update();
}, },
// We don't usually call this, but when the process is shutting down, we sho uld at // We don't usually call this, but when the process is shutting down, we sho uld at
// least try to remove the notification immediately instead of waiting for the // least try to remove the notification immediately instead of waiting for the
// normal debounce. // normal debounce.
fastClear() { fastClear() {
this.reset([]); this.notificationData = null;
this.fastUpdate(); this.fastUpdate();
}, },
enable() { enable() {
const needUpdate = !this.isEnabled; const needUpdate = !this.isEnabled;
this.isEnabled = true; this.isEnabled = true;
if (needUpdate) { if (needUpdate) {
this.update(); this.update();
} }
}, },
disable() { disable() {
this.isEnabled = false; this.isEnabled = false;
}, },
}))(); };
// Testing indicated that trying to create/destroy notifications too quickly
// resulted in notifications that stuck around forever, requiring the user
// to manually close them. This introduces a minimum amount of time between
calls,
// and batches up the quick successive update() calls we get from an incomin
g
// read sync, which might have a number of messages referenced inside of it.
Whisper.Notifications.update = _.debounce(
Whisper.Notifications.fastUpdate.bind(Whisper.Notifications),
1000
);
})(); })();
 End of changes. 23 change blocks. 
123 lines changed or deleted 122 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)