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