ESLint: Add js/notifications
This commit is contained in:
parent
b510916ef5
commit
06e3f09732
2 changed files with 42 additions and 26 deletions
|
@ -36,6 +36,7 @@ ts/**/*.js
|
||||||
!js/logging.js
|
!js/logging.js
|
||||||
!js/models/conversations.js
|
!js/models/conversations.js
|
||||||
!js/models/messages.js
|
!js/models/messages.js
|
||||||
|
!js/notifications.js
|
||||||
!js/views/attachment_view.js
|
!js/views/attachment_view.js
|
||||||
!js/views/backbone_wrapper_view.js
|
!js/views/backbone_wrapper_view.js
|
||||||
!js/views/conversation_search_view.js
|
!js/views/conversation_search_view.js
|
||||||
|
|
|
@ -1,9 +1,21 @@
|
||||||
|
/* global Backbone: false */
|
||||||
|
/* global nodeNotifier: false */
|
||||||
|
|
||||||
|
/* global config: false */
|
||||||
|
/* global ConversationController: false */
|
||||||
|
/* global i18n: false */
|
||||||
|
/* global Signal: false */
|
||||||
|
/* global storage: false */
|
||||||
|
/* global Whisper: false */
|
||||||
|
|
||||||
|
// eslint-disable-next-line func-names
|
||||||
(function() {
|
(function() {
|
||||||
'use strict';
|
'use strict';
|
||||||
window.Whisper = window.Whisper || {};
|
|
||||||
const { Settings } = window.Signal.Types;
|
|
||||||
|
|
||||||
var SETTINGS = {
|
window.Whisper = window.Whisper || {};
|
||||||
|
const { Settings } = Signal.Types;
|
||||||
|
|
||||||
|
const SETTINGS = {
|
||||||
OFF: 'off',
|
OFF: 'off',
|
||||||
COUNT: 'count',
|
COUNT: 'count',
|
||||||
NAME: 'name',
|
NAME: 'name',
|
||||||
|
@ -11,16 +23,16 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
Whisper.Notifications = new (Backbone.Collection.extend({
|
Whisper.Notifications = new (Backbone.Collection.extend({
|
||||||
initialize: function() {
|
initialize() {
|
||||||
this.isEnabled = false;
|
this.isEnabled = false;
|
||||||
this.on('add', this.update);
|
this.on('add', this.update);
|
||||||
this.on('remove', this.onRemove);
|
this.on('remove', this.onRemove);
|
||||||
},
|
},
|
||||||
onClick: function(conversationId) {
|
onClick(conversationId) {
|
||||||
var conversation = ConversationController.get(conversationId);
|
const conversation = ConversationController.get(conversationId);
|
||||||
this.trigger('click', conversation);
|
this.trigger('click', conversation);
|
||||||
},
|
},
|
||||||
update: function() {
|
update() {
|
||||||
const { isEnabled } = this;
|
const { isEnabled } = this;
|
||||||
const isFocused = window.isFocused();
|
const isFocused = window.isFocused();
|
||||||
const isAudioNotificationEnabled =
|
const isAudioNotificationEnabled =
|
||||||
|
@ -51,35 +63,35 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var setting = storage.get('notification-setting') || 'message';
|
const setting = this.getSetting();
|
||||||
if (setting === SETTINGS.OFF) {
|
if (setting === SETTINGS.OFF) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
window.drawAttention();
|
window.drawAttention();
|
||||||
|
|
||||||
var title;
|
let title;
|
||||||
var message;
|
let message;
|
||||||
var iconUrl;
|
let iconUrl;
|
||||||
|
|
||||||
// NOTE: i18n has more complex rules for pluralization than just
|
// NOTE: i18n has more complex rules for pluralization than just
|
||||||
// distinguishing between zero (0) and other (non-zero),
|
// distinguishing between zero (0) and other (non-zero),
|
||||||
// e.g. Russian:
|
// e.g. Russian:
|
||||||
// http://docs.translatehouse.org/projects/localization-guide/en/latest/l10n/pluralforms.html
|
// http://docs.translatehouse.org/projects/localization-guide/en/latest/l10n/pluralforms.html
|
||||||
var newMessageCount = [
|
const newMessageCount = [
|
||||||
numNotifications,
|
numNotifications,
|
||||||
numNotifications === 1 ? i18n('newMessage') : i18n('newMessages'),
|
numNotifications === 1 ? i18n('newMessage') : i18n('newMessages'),
|
||||||
].join(' ');
|
].join(' ');
|
||||||
|
|
||||||
var last = this.last();
|
const last = this.last();
|
||||||
switch (this.getSetting()) {
|
switch (setting) {
|
||||||
case SETTINGS.COUNT:
|
case SETTINGS.COUNT:
|
||||||
title = 'Signal';
|
title = 'Signal';
|
||||||
message = newMessageCount;
|
message = newMessageCount;
|
||||||
break;
|
break;
|
||||||
case SETTINGS.NAME:
|
case SETTINGS.NAME:
|
||||||
title = newMessageCount;
|
title = newMessageCount;
|
||||||
message = 'Most recent from ' + last.get('title');
|
message = `Most recent from ${last.get('title')}`;
|
||||||
iconUrl = last.get('iconUrl');
|
iconUrl = last.get('iconUrl');
|
||||||
break;
|
break;
|
||||||
case SETTINGS.MESSAGE:
|
case SETTINGS.MESSAGE:
|
||||||
|
@ -91,19 +103,22 @@
|
||||||
message = last.get('message');
|
message = last.get('message');
|
||||||
iconUrl = last.get('iconUrl');
|
iconUrl = last.get('iconUrl');
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
console.log(`Error: Unknown setting: '${setting}'`);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (window.config.polyfillNotifications) {
|
if (config.polyfillNotifications) {
|
||||||
window.nodeNotifier.notify({
|
nodeNotifier.notify({
|
||||||
title: title,
|
title,
|
||||||
message: message,
|
message,
|
||||||
sound: false,
|
sound: false,
|
||||||
});
|
});
|
||||||
window.nodeNotifier.on('click', function(notifierObject, options) {
|
nodeNotifier.on('click', () => {
|
||||||
last.get('conversationId');
|
last.get('conversationId');
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
var notification = new Notification(title, {
|
const notification = new Notification(title, {
|
||||||
body: message,
|
body: message,
|
||||||
icon: iconUrl,
|
icon: iconUrl,
|
||||||
tag: 'signal',
|
tag: 'signal',
|
||||||
|
@ -119,24 +134,24 @@
|
||||||
// We don't want to notify the user about these same messages again
|
// We don't want to notify the user about these same messages again
|
||||||
this.clear();
|
this.clear();
|
||||||
},
|
},
|
||||||
getSetting: function() {
|
getSetting() {
|
||||||
return storage.get('notification-setting') || SETTINGS.MESSAGE;
|
return storage.get('notification-setting') || SETTINGS.MESSAGE;
|
||||||
},
|
},
|
||||||
onRemove: function() {
|
onRemove() {
|
||||||
console.log('remove notification');
|
console.log('remove notification');
|
||||||
},
|
},
|
||||||
clear: function() {
|
clear() {
|
||||||
console.log('remove all notifications');
|
console.log('remove all notifications');
|
||||||
this.reset([]);
|
this.reset([]);
|
||||||
},
|
},
|
||||||
enable: function() {
|
enable() {
|
||||||
const needUpdate = !this.isEnabled;
|
const needUpdate = !this.isEnabled;
|
||||||
this.isEnabled = true;
|
this.isEnabled = true;
|
||||||
if (needUpdate) {
|
if (needUpdate) {
|
||||||
this.update();
|
this.update();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
disable: function() {
|
disable() {
|
||||||
this.isEnabled = false;
|
this.isEnabled = false;
|
||||||
},
|
},
|
||||||
}))();
|
}))();
|
||||||
|
|
Loading…
Reference in a new issue