eslintify expiring_messages.js
This commit is contained in:
parent
12b5547e72
commit
67464774c3
3 changed files with 36 additions and 30 deletions
|
@ -37,6 +37,7 @@ ts/**/*.js
|
|||
!js/models/conversations.js
|
||||
!js/models/messages.js
|
||||
!js/notifications.js
|
||||
!js/expiring_messages.js
|
||||
!js/views/attachment_view.js
|
||||
!js/views/backbone_wrapper_view.js
|
||||
!js/views/conversation_search_view.js
|
||||
|
|
|
@ -102,6 +102,7 @@ module.exports = function(grunt) {
|
|||
'!js/libsignal-protocol-worker.js',
|
||||
'!js/libtextsecure.js',
|
||||
'!js/logging.js',
|
||||
'!js/expiring_messages.js',
|
||||
'!js/modules/**/*.js',
|
||||
'!js/Mp3LameEncoder.min.js',
|
||||
'!js/signal_protocol_store.js',
|
||||
|
|
|
@ -1,15 +1,24 @@
|
|||
/* global _: false */
|
||||
/* global Backbone: false */
|
||||
/* global i18n: false */
|
||||
/* global moment: false */
|
||||
/* global Whisper: false */
|
||||
/* global wrapDeferred: false */
|
||||
|
||||
// eslint-disable-next-line func-names
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
window.Whisper = window.Whisper || {};
|
||||
|
||||
function destroyExpiredMessages() {
|
||||
// Load messages that have expired and destroy them
|
||||
var expired = new Whisper.MessageCollection();
|
||||
expired.on('add', async function(message) {
|
||||
const expired = new Whisper.MessageCollection();
|
||||
expired.on('add', async message => {
|
||||
console.log('Message expired', {
|
||||
sentAt: message.get('sent_at'),
|
||||
});
|
||||
var conversation = message.getConversation();
|
||||
const conversation = message.getConversation();
|
||||
if (conversation) {
|
||||
conversation.trigger('expired', message);
|
||||
}
|
||||
|
@ -26,15 +35,15 @@
|
|||
expired.fetchExpired();
|
||||
}
|
||||
|
||||
var timeout;
|
||||
let timeout;
|
||||
function checkExpiringMessages() {
|
||||
// Look up the next expiring message and set a timer to destroy it
|
||||
var expiring = new Whisper.MessageCollection();
|
||||
expiring.once('add', function(next) {
|
||||
var expires_at = next.get('expires_at');
|
||||
console.log('next message expires', new Date(expires_at).toISOString());
|
||||
const expiring = new Whisper.MessageCollection();
|
||||
expiring.once('add', next => {
|
||||
const expiresAt = next.get('expires_at');
|
||||
console.log('next message expires', new Date(expiresAt).toISOString());
|
||||
|
||||
var wait = expires_at - Date.now();
|
||||
let wait = expiresAt - Date.now();
|
||||
|
||||
// In the past
|
||||
if (wait < 0) {
|
||||
|
@ -51,24 +60,27 @@
|
|||
});
|
||||
expiring.fetchNextExpiring();
|
||||
}
|
||||
var throttledCheckExpiringMessages = _.throttle(checkExpiringMessages, 1000);
|
||||
const throttledCheckExpiringMessages = _.throttle(
|
||||
checkExpiringMessages,
|
||||
1000
|
||||
);
|
||||
|
||||
Whisper.ExpiringMessagesListener = {
|
||||
init: function(events) {
|
||||
init(events) {
|
||||
checkExpiringMessages();
|
||||
events.on('timetravel', throttledCheckExpiringMessages);
|
||||
},
|
||||
update: throttledCheckExpiringMessages,
|
||||
};
|
||||
|
||||
var TimerOption = Backbone.Model.extend({
|
||||
getName: function() {
|
||||
const TimerOption = Backbone.Model.extend({
|
||||
getName() {
|
||||
return (
|
||||
i18n(['timerOption', this.get('time'), this.get('unit')].join('_')) ||
|
||||
moment.duration(this.get('time'), this.get('unit')).humanize()
|
||||
);
|
||||
},
|
||||
getAbbreviated: function() {
|
||||
getAbbreviated() {
|
||||
return i18n(
|
||||
['timerOption', this.get('time'), this.get('unit'), 'abbreviated'].join(
|
||||
'_'
|
||||
|
@ -78,27 +90,19 @@
|
|||
});
|
||||
Whisper.ExpirationTimerOptions = new (Backbone.Collection.extend({
|
||||
model: TimerOption,
|
||||
getName: function(seconds) {
|
||||
if (!seconds) {
|
||||
seconds = 0;
|
||||
}
|
||||
var o = this.findWhere({ seconds: seconds });
|
||||
getName(seconds = 0) {
|
||||
const o = this.findWhere({ seconds });
|
||||
if (o) {
|
||||
return o.getName();
|
||||
} else {
|
||||
return [seconds, 'seconds'].join(' ');
|
||||
}
|
||||
return [seconds, 'seconds'].join(' ');
|
||||
},
|
||||
getAbbreviated: function(seconds) {
|
||||
if (!seconds) {
|
||||
seconds = 0;
|
||||
}
|
||||
var o = this.findWhere({ seconds: seconds });
|
||||
getAbbreviated(seconds = 0) {
|
||||
const o = this.findWhere({ seconds });
|
||||
if (o) {
|
||||
return o.getAbbreviated();
|
||||
} else {
|
||||
return [seconds, 's'].join('');
|
||||
}
|
||||
return [seconds, 's'].join('');
|
||||
},
|
||||
}))(
|
||||
[
|
||||
|
@ -114,8 +118,8 @@
|
|||
[12, 'hours'],
|
||||
[1, 'day'],
|
||||
[1, 'week'],
|
||||
].map(function(o) {
|
||||
var duration = moment.duration(o[0], o[1]); // 5, 'seconds'
|
||||
].map(o => {
|
||||
const duration = moment.duration(o[0], o[1]); // 5, 'seconds'
|
||||
return {
|
||||
time: o[0],
|
||||
unit: o[1],
|
||||
|
|
Loading…
Reference in a new issue