Apply new ESLint rules to legacy code
This commit is contained in:
parent
91cf075697
commit
8a2c17f65f
70 changed files with 376 additions and 516 deletions
|
@ -7,17 +7,13 @@ const DEFAULT_JPEG_QUALITY = 0.85;
|
|||
// Documentation for `options` (`LoadImageOptions`):
|
||||
// https://github.com/blueimp/JavaScript-Load-Image/tree/v2.18.0#options
|
||||
exports.autoOrientImage = (fileOrBlobOrURL, options = {}) => {
|
||||
const optionsWithDefaults = Object.assign(
|
||||
{
|
||||
type: 'image/jpeg',
|
||||
quality: DEFAULT_JPEG_QUALITY,
|
||||
},
|
||||
options,
|
||||
{
|
||||
canvas: true,
|
||||
orientation: true,
|
||||
}
|
||||
);
|
||||
const optionsWithDefaults = {
|
||||
type: 'image/jpeg',
|
||||
quality: DEFAULT_JPEG_QUALITY,
|
||||
...options,
|
||||
canvas: true,
|
||||
orientation: true,
|
||||
};
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
loadImage(
|
||||
|
|
|
@ -459,12 +459,7 @@ async function writeQuoteThumbnails(quotedAttachments, options) {
|
|||
try {
|
||||
await Promise.all(
|
||||
_.map(quotedAttachments, (attachment, index) =>
|
||||
writeQuoteThumbnail(
|
||||
attachment,
|
||||
Object.assign({}, options, {
|
||||
index,
|
||||
})
|
||||
)
|
||||
writeQuoteThumbnail(attachment, { ...options, index })
|
||||
)
|
||||
);
|
||||
} catch (error) {
|
||||
|
@ -531,12 +526,7 @@ async function writeAttachments(attachments, options) {
|
|||
const { name } = options;
|
||||
|
||||
const promises = _.map(attachments, (attachment, index) =>
|
||||
writeAttachment(
|
||||
attachment,
|
||||
Object.assign({}, options, {
|
||||
index,
|
||||
})
|
||||
)
|
||||
writeAttachment(attachment, { ...options, index })
|
||||
);
|
||||
try {
|
||||
await Promise.all(promises);
|
||||
|
@ -575,14 +565,7 @@ async function writeContactAvatars(contact, options) {
|
|||
|
||||
try {
|
||||
await Promise.all(
|
||||
_.map(contact, (item, index) =>
|
||||
writeAvatar(
|
||||
item,
|
||||
Object.assign({}, options, {
|
||||
index,
|
||||
})
|
||||
)
|
||||
)
|
||||
_.map(contact, (item, index) => writeAvatar(item, { ...options, index }))
|
||||
);
|
||||
} catch (error) {
|
||||
window.log.error(
|
||||
|
@ -620,12 +603,7 @@ async function writePreviews(preview, options) {
|
|||
try {
|
||||
await Promise.all(
|
||||
_.map(preview, (item, index) =>
|
||||
writePreviewImage(
|
||||
item,
|
||||
Object.assign({}, options, {
|
||||
index,
|
||||
})
|
||||
)
|
||||
writePreviewImage(item, { ...options, index })
|
||||
)
|
||||
);
|
||||
} catch (error) {
|
||||
|
@ -1236,12 +1214,11 @@ async function exportToDirectory(directory, options) {
|
|||
const attachmentsDir = await createDirectory(directory, 'attachments');
|
||||
|
||||
await exportConversationListToFile(stagingDir);
|
||||
await exportConversations(
|
||||
Object.assign({}, options, {
|
||||
messagesDir: stagingDir,
|
||||
attachmentsDir,
|
||||
})
|
||||
);
|
||||
await exportConversations({
|
||||
...options,
|
||||
messagesDir: stagingDir,
|
||||
attachmentsDir,
|
||||
});
|
||||
|
||||
const archivePath = path.join(directory, ARCHIVE_NAME);
|
||||
await compressArchive(archivePath, stagingDir);
|
||||
|
@ -1281,10 +1258,7 @@ async function importFromDirectory(directory, options) {
|
|||
loadConversationLookup(),
|
||||
]);
|
||||
const [messageLookup, conversationLookup] = lookups;
|
||||
options = Object.assign({}, options, {
|
||||
messageLookup,
|
||||
conversationLookup,
|
||||
});
|
||||
options = { ...options, messageLookup, conversationLookup };
|
||||
|
||||
const archivePath = path.join(directory, ARCHIVE_NAME);
|
||||
if (fs.existsSync(archivePath)) {
|
||||
|
@ -1312,11 +1286,9 @@ async function importFromDirectory(directory, options) {
|
|||
await decryptFile(archivePath, decryptedArchivePath, options);
|
||||
await decompressArchive(decryptedArchivePath, stagingDir);
|
||||
|
||||
options = Object.assign({}, options, {
|
||||
attachmentsDir,
|
||||
});
|
||||
options = { ...options, attachmentsDir };
|
||||
const result = await importNonMessages(stagingDir, options);
|
||||
await importConversations(stagingDir, Object.assign({}, options));
|
||||
await importConversations(stagingDir, { ...options });
|
||||
|
||||
window.log.info('Done importing from backup!');
|
||||
return result;
|
||||
|
|
|
@ -111,20 +111,22 @@ const createRandomMessage = async ({ conversationId } = {}) => {
|
|||
const _createMessage = ({ commonProperties, conversationId, type } = {}) => {
|
||||
switch (type) {
|
||||
case 'incoming':
|
||||
return Object.assign({}, commonProperties, {
|
||||
return {
|
||||
...commonProperties,
|
||||
flags: 0,
|
||||
source: conversationId,
|
||||
sourceDevice: 1,
|
||||
});
|
||||
};
|
||||
case 'outgoing':
|
||||
return Object.assign({}, commonProperties, {
|
||||
return {
|
||||
...commonProperties,
|
||||
delivered: 1,
|
||||
delivered_to: [conversationId],
|
||||
expireTimer: 0,
|
||||
recipients: [conversationId],
|
||||
sent_to: [conversationId],
|
||||
synced: true,
|
||||
});
|
||||
};
|
||||
default:
|
||||
throw new TypeError(`Unknown message type: '${type}'`);
|
||||
}
|
||||
|
|
|
@ -34,7 +34,8 @@ exports.setup = (locale, messages) => {
|
|||
const { message } = entry;
|
||||
if (!substitutions) {
|
||||
return message;
|
||||
} else if (Array.isArray(substitutions)) {
|
||||
}
|
||||
if (Array.isArray(substitutions)) {
|
||||
return substitutions.reduce(
|
||||
(result, substitution) => result.replace(/\$.+?\$/, substitution),
|
||||
message
|
||||
|
|
|
@ -175,15 +175,20 @@ const KB = 1024;
|
|||
function getChunkPattern(size, initialOffset) {
|
||||
if (size > MB) {
|
||||
return _getRequestPattern(size, MB, initialOffset);
|
||||
} else if (size > 500 * KB) {
|
||||
}
|
||||
if (size > 500 * KB) {
|
||||
return _getRequestPattern(size, 500 * KB, initialOffset);
|
||||
} else if (size > 100 * KB) {
|
||||
}
|
||||
if (size > 100 * KB) {
|
||||
return _getRequestPattern(size, 100 * KB, initialOffset);
|
||||
} else if (size > 50 * KB) {
|
||||
}
|
||||
if (size > 50 * KB) {
|
||||
return _getRequestPattern(size, 50 * KB, initialOffset);
|
||||
} else if (size > 10 * KB) {
|
||||
}
|
||||
if (size > 10 * KB) {
|
||||
return _getRequestPattern(size, 10 * KB, initialOffset);
|
||||
} else if (size > KB) {
|
||||
}
|
||||
if (size > KB) {
|
||||
return _getRequestPattern(size, KB, initialOffset);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
const is = require('@sindresorhus/is');
|
||||
|
||||
const AttachmentTS = require('../../../ts/types/Attachment');
|
||||
const GoogleChrome = require('../../../ts/util/GoogleChrome');
|
||||
const MIME = require('../../../ts/types/MIME');
|
||||
const { toLogFormat } = require('./errors');
|
||||
const {
|
||||
arrayBufferToBlob,
|
||||
blobToArrayBuffer,
|
||||
dataURLToBlob,
|
||||
} = require('blob-util');
|
||||
const AttachmentTS = require('../../../ts/types/Attachment');
|
||||
const GoogleChrome = require('../../../ts/util/GoogleChrome');
|
||||
const MIME = require('../../../ts/types/MIME');
|
||||
const { toLogFormat } = require('./errors');
|
||||
const { autoOrientImage } = require('../auto_orient_image');
|
||||
const {
|
||||
migrateDataToFileSystem,
|
||||
|
@ -73,10 +73,11 @@ exports.autoOrientJPEG = async attachment => {
|
|||
// retain it but due to reports of data loss, we don’t want to overburden IndexedDB
|
||||
// by potentially doubling stored image data.
|
||||
// See: https://github.com/signalapp/Signal-Desktop/issues/1589
|
||||
const newAttachment = Object.assign({}, attachment, {
|
||||
const newAttachment = {
|
||||
...attachment,
|
||||
data: newDataArrayBuffer,
|
||||
size: newDataArrayBuffer.byteLength,
|
||||
});
|
||||
};
|
||||
|
||||
// `digest` is no longer valid for auto-oriented image data, so we discard it:
|
||||
delete newAttachment.digest;
|
||||
|
@ -103,9 +104,7 @@ exports._replaceUnicodeOrderOverridesSync = attachment => {
|
|||
INVALID_CHARACTERS_PATTERN,
|
||||
UNICODE_REPLACEMENT_CHARACTER
|
||||
);
|
||||
const newAttachment = Object.assign({}, attachment, {
|
||||
fileName: normalizedFilename,
|
||||
});
|
||||
const newAttachment = { ...attachment, fileName: normalizedFilename };
|
||||
|
||||
return newAttachment;
|
||||
};
|
||||
|
@ -145,7 +144,7 @@ exports.removeSchemaVersion = ({ attachment, logger }) => {
|
|||
return attachment;
|
||||
}
|
||||
|
||||
const attachmentWithoutSchemaVersion = Object.assign({}, attachment);
|
||||
const attachmentWithoutSchemaVersion = { ...attachment };
|
||||
delete attachmentWithoutSchemaVersion.schemaVersion;
|
||||
return attachmentWithoutSchemaVersion;
|
||||
};
|
||||
|
@ -179,7 +178,7 @@ exports.loadData = readAttachmentData => {
|
|||
}
|
||||
|
||||
const data = await readAttachmentData(attachment.path);
|
||||
return Object.assign({}, attachment, { data, size: data.byteLength });
|
||||
return { ...attachment, data, size: data.byteLength };
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -32,8 +32,6 @@ exports.migrateDataToFileSystem = async (
|
|||
|
||||
const path = await writeNewAttachmentData(data);
|
||||
|
||||
const attachmentWithoutData = omit(Object.assign({}, attachment, { path }), [
|
||||
'data',
|
||||
]);
|
||||
const attachmentWithoutData = omit({ ...attachment, path }, ['data']);
|
||||
return attachmentWithoutData;
|
||||
};
|
||||
|
|
|
@ -17,15 +17,17 @@ exports.parseAndWriteAvatar = upgradeAttachment => async (
|
|||
const { avatar } = contact;
|
||||
|
||||
// This is to ensure that an omit() call doesn't pull in prototype props/methods
|
||||
const contactShallowCopy = Object.assign({}, contact);
|
||||
const contactShallowCopy = { ...contact };
|
||||
|
||||
const contactWithUpdatedAvatar =
|
||||
avatar && avatar.avatar
|
||||
? Object.assign({}, contactShallowCopy, {
|
||||
avatar: Object.assign({}, avatar, {
|
||||
? {
|
||||
...contactShallowCopy,
|
||||
avatar: {
|
||||
...avatar,
|
||||
avatar: await upgradeAttachment(avatar.avatar, context),
|
||||
}),
|
||||
})
|
||||
},
|
||||
}
|
||||
: omit(contactShallowCopy, ['avatar']);
|
||||
|
||||
// eliminates empty numbers, emails, and addresses; adds type if not provided
|
||||
|
@ -50,14 +52,13 @@ function parseContact(contact, options = {}) {
|
|||
const boundParsePhone = phoneNumber =>
|
||||
parsePhoneItem(phoneNumber, { regionCode });
|
||||
|
||||
return Object.assign(
|
||||
{},
|
||||
omit(contact, ['avatar', 'number', 'email', 'address']),
|
||||
parseAvatar(contact.avatar),
|
||||
createArrayKey('number', compact(map(contact.number, boundParsePhone))),
|
||||
createArrayKey('email', compact(map(contact.email, parseEmailItem))),
|
||||
createArrayKey('address', compact(map(contact.address, parseAddress)))
|
||||
);
|
||||
return {
|
||||
...omit(contact, ['avatar', 'number', 'email', 'address']),
|
||||
...parseAvatar(contact.avatar),
|
||||
...createArrayKey('number', compact(map(contact.number, boundParsePhone))),
|
||||
...createArrayKey('email', compact(map(contact.email, parseEmailItem))),
|
||||
...createArrayKey('address', compact(map(contact.address, parseAddress))),
|
||||
};
|
||||
}
|
||||
|
||||
function idForLogging(message) {
|
||||
|
@ -94,10 +95,11 @@ function parsePhoneItem(item, options = {}) {
|
|||
return null;
|
||||
}
|
||||
|
||||
return Object.assign({}, item, {
|
||||
return {
|
||||
...item,
|
||||
type: item.type || DEFAULT_PHONE_TYPE,
|
||||
value: parsePhoneNumber(item.value, { regionCode }),
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
function parseEmailItem(item) {
|
||||
|
@ -105,9 +107,7 @@ function parseEmailItem(item) {
|
|||
return null;
|
||||
}
|
||||
|
||||
return Object.assign({}, item, {
|
||||
type: item.type || DEFAULT_EMAIL_TYPE,
|
||||
});
|
||||
return { ...item, type: item.type || DEFAULT_EMAIL_TYPE };
|
||||
}
|
||||
|
||||
function parseAddress(address) {
|
||||
|
@ -127,9 +127,7 @@ function parseAddress(address) {
|
|||
return null;
|
||||
}
|
||||
|
||||
return Object.assign({}, address, {
|
||||
type: address.type || DEFAULT_ADDRESS_TYPE,
|
||||
});
|
||||
return { ...address, type: address.type || DEFAULT_ADDRESS_TYPE };
|
||||
}
|
||||
|
||||
function parseAvatar(avatar) {
|
||||
|
@ -138,9 +136,7 @@ function parseAvatar(avatar) {
|
|||
}
|
||||
|
||||
return {
|
||||
avatar: Object.assign({}, avatar, {
|
||||
isProfile: avatar.isProfile || false,
|
||||
}),
|
||||
avatar: { ...avatar, isProfile: avatar.isProfile || false },
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -72,9 +72,7 @@ exports.initializeSchemaVersion = ({ message, logger }) => {
|
|||
: 0;
|
||||
const hasAttachments = numAttachments > 0;
|
||||
if (!hasAttachments) {
|
||||
return Object.assign({}, message, {
|
||||
schemaVersion: INITIAL_SCHEMA_VERSION,
|
||||
});
|
||||
return { ...message, schemaVersion: INITIAL_SCHEMA_VERSION };
|
||||
}
|
||||
|
||||
// All attachments should have the same schema version, so we just pick
|
||||
|
@ -85,12 +83,13 @@ exports.initializeSchemaVersion = ({ message, logger }) => {
|
|||
)
|
||||
? firstAttachment.schemaVersion
|
||||
: INITIAL_SCHEMA_VERSION;
|
||||
const messageWithInitialSchema = Object.assign({}, message, {
|
||||
const messageWithInitialSchema = {
|
||||
...message,
|
||||
schemaVersion: inheritedSchemaVersion,
|
||||
attachments: message.attachments.map(attachment =>
|
||||
Attachment.removeSchemaVersion({ attachment, logger })
|
||||
),
|
||||
});
|
||||
};
|
||||
|
||||
return messageWithInitialSchema;
|
||||
};
|
||||
|
@ -158,7 +157,7 @@ exports._withSchemaVersion = ({ schemaVersion, upgrade }) => {
|
|||
return message;
|
||||
}
|
||||
|
||||
return Object.assign({}, upgradedMessage, { schemaVersion });
|
||||
return { ...upgradedMessage, schemaVersion };
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -172,7 +171,7 @@ exports._mapAttachments = upgradeAttachment => async (message, context) => {
|
|||
const attachments = await Promise.all(
|
||||
(message.attachments || []).map(upgradeWithContext)
|
||||
);
|
||||
return Object.assign({}, message, { attachments });
|
||||
return { ...message, attachments };
|
||||
};
|
||||
|
||||
// Public API
|
||||
|
@ -180,13 +179,13 @@ exports._mapAttachments = upgradeAttachment => async (message, context) => {
|
|||
// (Message, Context) ->
|
||||
// Promise Message
|
||||
exports._mapContact = upgradeContact => async (message, context) => {
|
||||
const contextWithMessage = Object.assign({}, context, { message });
|
||||
const contextWithMessage = { ...context, message };
|
||||
const upgradeWithContext = contact =>
|
||||
upgradeContact(contact, contextWithMessage);
|
||||
const contact = await Promise.all(
|
||||
(message.contact || []).map(upgradeWithContext)
|
||||
);
|
||||
return Object.assign({}, message, { contact });
|
||||
return { ...message, contact };
|
||||
};
|
||||
|
||||
// _mapQuotedAttachments :: (QuotedAttachment -> Promise QuotedAttachment) ->
|
||||
|
@ -210,9 +209,7 @@ exports._mapQuotedAttachments = upgradeAttachment => async (
|
|||
}
|
||||
|
||||
const upgradedThumbnail = await upgradeAttachment(thumbnail, context);
|
||||
return Object.assign({}, attachment, {
|
||||
thumbnail: upgradedThumbnail,
|
||||
});
|
||||
return { ...attachment, thumbnail: upgradedThumbnail };
|
||||
};
|
||||
|
||||
const quotedAttachments = (message.quote && message.quote.attachments) || [];
|
||||
|
@ -220,11 +217,7 @@ exports._mapQuotedAttachments = upgradeAttachment => async (
|
|||
const attachments = await Promise.all(
|
||||
quotedAttachments.map(upgradeWithContext)
|
||||
);
|
||||
return Object.assign({}, message, {
|
||||
quote: Object.assign({}, message.quote, {
|
||||
attachments,
|
||||
}),
|
||||
});
|
||||
return { ...message, quote: { ...message.quote, attachments } };
|
||||
};
|
||||
|
||||
// _mapPreviewAttachments :: (PreviewAttachment -> Promise PreviewAttachment) ->
|
||||
|
@ -248,17 +241,13 @@ exports._mapPreviewAttachments = upgradeAttachment => async (
|
|||
}
|
||||
|
||||
const upgradedImage = await upgradeAttachment(image, context);
|
||||
return Object.assign({}, preview, {
|
||||
image: upgradedImage,
|
||||
});
|
||||
return { ...preview, image: upgradedImage };
|
||||
};
|
||||
|
||||
const preview = await Promise.all(
|
||||
(message.preview || []).map(upgradeWithContext)
|
||||
);
|
||||
return Object.assign({}, message, {
|
||||
preview,
|
||||
});
|
||||
return { ...message, preview };
|
||||
};
|
||||
|
||||
const toVersion0 = async (message, context) =>
|
||||
|
@ -533,12 +522,10 @@ exports.createAttachmentLoader = loadAttachmentData => {
|
|||
);
|
||||
}
|
||||
|
||||
return async message =>
|
||||
Object.assign({}, message, {
|
||||
attachments: await Promise.all(
|
||||
message.attachments.map(loadAttachmentData)
|
||||
),
|
||||
});
|
||||
return async message => ({
|
||||
...message,
|
||||
attachments: await Promise.all(message.attachments.map(loadAttachmentData)),
|
||||
});
|
||||
};
|
||||
|
||||
exports.loadQuoteData = loadAttachmentData => {
|
||||
|
@ -767,11 +754,10 @@ exports.createAttachmentDataWriter = ({
|
|||
|
||||
await writeExistingAttachmentData(avatar.avatar);
|
||||
|
||||
return Object.assign({}, messageContact, {
|
||||
avatar: Object.assign({}, avatar, {
|
||||
avatar: omit(avatar.avatar, ['data']),
|
||||
}),
|
||||
});
|
||||
return {
|
||||
...messageContact,
|
||||
avatar: { ...avatar, avatar: omit(avatar.avatar, ['data']) },
|
||||
};
|
||||
};
|
||||
|
||||
const writePreviewImage = async item => {
|
||||
|
@ -782,41 +768,36 @@ exports.createAttachmentDataWriter = ({
|
|||
|
||||
await writeExistingAttachmentData(image);
|
||||
|
||||
return Object.assign({}, item, {
|
||||
image: omit(image, ['data']),
|
||||
});
|
||||
return { ...item, image: omit(image, ['data']) };
|
||||
};
|
||||
|
||||
const messageWithoutAttachmentData = Object.assign(
|
||||
{},
|
||||
await writeThumbnails(message, { logger }),
|
||||
{
|
||||
contact: await Promise.all((contact || []).map(writeContactAvatar)),
|
||||
preview: await Promise.all((preview || []).map(writePreviewImage)),
|
||||
attachments: await Promise.all(
|
||||
(attachments || []).map(async attachment => {
|
||||
await writeExistingAttachmentData(attachment);
|
||||
const messageWithoutAttachmentData = {
|
||||
...(await writeThumbnails(message, { logger })),
|
||||
contact: await Promise.all((contact || []).map(writeContactAvatar)),
|
||||
preview: await Promise.all((preview || []).map(writePreviewImage)),
|
||||
attachments: await Promise.all(
|
||||
(attachments || []).map(async attachment => {
|
||||
await writeExistingAttachmentData(attachment);
|
||||
|
||||
if (attachment.screenshot && attachment.screenshot.data) {
|
||||
await writeExistingAttachmentData(attachment.screenshot);
|
||||
}
|
||||
if (attachment.thumbnail && attachment.thumbnail.data) {
|
||||
await writeExistingAttachmentData(attachment.thumbnail);
|
||||
}
|
||||
if (attachment.screenshot && attachment.screenshot.data) {
|
||||
await writeExistingAttachmentData(attachment.screenshot);
|
||||
}
|
||||
if (attachment.thumbnail && attachment.thumbnail.data) {
|
||||
await writeExistingAttachmentData(attachment.thumbnail);
|
||||
}
|
||||
|
||||
return {
|
||||
...omit(attachment, ['data']),
|
||||
...(attachment.thumbnail
|
||||
? { thumbnail: omit(attachment.thumbnail, ['data']) }
|
||||
: null),
|
||||
...(attachment.screenshot
|
||||
? { screenshot: omit(attachment.screenshot, ['data']) }
|
||||
: null),
|
||||
};
|
||||
})
|
||||
),
|
||||
}
|
||||
);
|
||||
return {
|
||||
...omit(attachment, ['data']),
|
||||
...(attachment.thumbnail
|
||||
? { thumbnail: omit(attachment.thumbnail, ['data']) }
|
||||
: null),
|
||||
...(attachment.screenshot
|
||||
? { screenshot: omit(attachment.screenshot, ['data']) }
|
||||
: null),
|
||||
};
|
||||
})
|
||||
),
|
||||
};
|
||||
|
||||
return messageWithoutAttachmentData;
|
||||
};
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
/* global document, URL, Blob */
|
||||
|
||||
const loadImage = require('blueimp-load-image');
|
||||
const { toLogFormat } = require('./errors');
|
||||
const dataURLToBlobSync = require('blueimp-canvas-to-blob');
|
||||
const { blobToArrayBuffer } = require('blob-util');
|
||||
const { toLogFormat } = require('./errors');
|
||||
const {
|
||||
arrayBufferToObjectURL,
|
||||
} = require('../../../ts/util/arrayBufferToObjectURL');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue