mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2025-12-20 10:19:08 +00:00
Selectively run ESLint on js/background.js
Enabling ESLint on a per function basis allows us to incrementally improve the codebase without requiring large and potentially risky refactorings.
This commit is contained in:
@@ -15,5 +15,6 @@ test/views/*.js
|
|||||||
/*.js
|
/*.js
|
||||||
|
|
||||||
# ES2015+ files
|
# ES2015+ files
|
||||||
|
!js/background.js
|
||||||
!main.js
|
!main.js
|
||||||
!prepare_build.js
|
!prepare_build.js
|
||||||
|
|||||||
100
js/background.js
100
js/background.js
@@ -1,3 +1,17 @@
|
|||||||
|
/* eslint-disable */
|
||||||
|
|
||||||
|
/* eslint-env browser */
|
||||||
|
|
||||||
|
/* global Backbone: false */
|
||||||
|
/* global $: false */
|
||||||
|
|
||||||
|
/* global ConversationController: false */
|
||||||
|
/* global getAccountManager: false */
|
||||||
|
/* global storage: false */
|
||||||
|
/* global textsecure: false */
|
||||||
|
/* global Whisper: false */
|
||||||
|
/* global wrapDeferred: false */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* vim: ts=4:sw=4:expandtab
|
* vim: ts=4:sw=4:expandtab
|
||||||
*/
|
*/
|
||||||
@@ -482,49 +496,55 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function onMessageReceived(ev) {
|
/* eslint-enable */
|
||||||
const { data } = ev;
|
/* jshint ignore:start */
|
||||||
|
async function onMessageReceived(ev) {
|
||||||
|
const { data } = ev;
|
||||||
|
|
||||||
if (data.message.flags & textsecure.protobuf.DataMessage.Flags.PROFILE_KEY_UPDATE) {
|
// eslint-disable-next-line no-bitwise
|
||||||
const profileKey = data.message.profileKey.toArrayBuffer();
|
if (data.message.flags & textsecure.protobuf.DataMessage.Flags.PROFILE_KEY_UPDATE) {
|
||||||
const sender = ConversationController.getOrCreateAndWait(data.source, 'private');
|
const profileKey = data.message.profileKey.toArrayBuffer();
|
||||||
await sender.setProfileKey(profileKey);
|
const sender = ConversationController.getOrCreateAndWait(data.source, 'private');
|
||||||
// TODO: Is `ev.confirm` a `Promise`? Original code returned it:
|
await sender.setProfileKey(profileKey);
|
||||||
return ev.confirm();
|
// TODO: Is `ev.confirm` a `Promise`? Original code returned it:
|
||||||
}
|
return ev.confirm();
|
||||||
|
|
||||||
const message = initIncomingMessage(data);
|
|
||||||
const isDuplicate = await isMessageDuplicate(message);
|
|
||||||
if (isDuplicate) {
|
|
||||||
console.log('Received duplicate message', message.idForLogging());
|
|
||||||
// TODO: Is `ev.confirm` a `Promise`? Original code didn’t return it:
|
|
||||||
return ev.confirm();
|
|
||||||
}
|
|
||||||
|
|
||||||
const { type, id } = data.message.group ?
|
|
||||||
{ type: 'group', id: data.message.group.id } :
|
|
||||||
{ type: 'private', id: data.source };
|
|
||||||
|
|
||||||
const processedData = Object.assign({}, data, {
|
|
||||||
message: Object.assign(
|
|
||||||
{},
|
|
||||||
data.message,
|
|
||||||
{
|
|
||||||
attachments: await Promise.all(
|
|
||||||
data.message.attachments.map(Attachment.process)
|
|
||||||
),
|
|
||||||
}
|
|
||||||
),
|
|
||||||
});
|
|
||||||
|
|
||||||
await ConversationController.getOrCreateAndWait(id, type);
|
|
||||||
return message.handleDataMessage(
|
|
||||||
processedData.message,
|
|
||||||
ev.confirm,
|
|
||||||
{ initialLoadComplete }
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const message = initIncomingMessage(data);
|
||||||
|
const isDuplicate = await isMessageDuplicate(message);
|
||||||
|
|
||||||
|
if (isDuplicate) {
|
||||||
|
console.log('Received duplicate message', message.idForLogging());
|
||||||
|
// TODO: Is `ev.confirm` a `Promise`? Original code didn’t return it:
|
||||||
|
return ev.confirm();
|
||||||
|
}
|
||||||
|
|
||||||
|
const { type, id } = data.message.group ?
|
||||||
|
{ type: 'group', id: data.message.group.id } :
|
||||||
|
{ type: 'private', id: data.source };
|
||||||
|
|
||||||
|
const processedData = Object.assign({}, data, {
|
||||||
|
message: Object.assign(
|
||||||
|
{},
|
||||||
|
data.message,
|
||||||
|
{
|
||||||
|
attachments: await Promise.all(
|
||||||
|
data.message.attachments.map(Attachment.process)
|
||||||
|
),
|
||||||
|
}
|
||||||
|
),
|
||||||
|
});
|
||||||
|
|
||||||
|
await ConversationController.getOrCreateAndWait(id, type);
|
||||||
|
return message.handleDataMessage(
|
||||||
|
processedData.message,
|
||||||
|
ev.confirm,
|
||||||
|
{ initialLoadComplete }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
/* jshint ignore:end */
|
||||||
|
/* eslint-disable */
|
||||||
|
|
||||||
function onSentMessage(ev) {
|
function onSentMessage(ev) {
|
||||||
var now = new Date().getTime();
|
var now = new Date().getTime();
|
||||||
var data = ev.data;
|
var data = ev.data;
|
||||||
|
|||||||
Reference in New Issue
Block a user