Signal-Desktop/ts/background.ts

3340 lines
99 KiB
TypeScript
Raw Normal View History

2020-10-30 20:34:04 +00:00
// Copyright 2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
type WhatIsThis = typeof window.WhatIsThis;
2018-05-25 01:50:49 +00:00
// eslint-disable-next-line func-names
(async function () {
const eventHandlerQueue = new window.PQueue({
concurrency: 1,
timeout: 1000 * 60 * 2,
});
window.Whisper.deliveryReceiptQueue = new window.PQueue({
concurrency: 1,
timeout: 1000 * 60 * 2,
});
window.Whisper.deliveryReceiptQueue.pause();
window.Whisper.deliveryReceiptBatcher = window.Signal.Util.createBatcher({
2019-09-26 19:56:31 +00:00
wait: 500,
maxSize: 500,
processBatch: async (items: WhatIsThis) => {
const byConversationId = _.groupBy(items, item =>
window.ConversationController.ensureContactIds({
e164: item.source,
uuid: item.sourceUuid,
})
);
const ids = Object.keys(byConversationId);
for (let i = 0, max = ids.length; i < max; i += 1) {
const conversationId = ids[i];
const timestamps = byConversationId[conversationId].map(
item => item.timestamp
);
2019-09-26 19:56:31 +00:00
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const c = window.ConversationController.get(conversationId)!;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const uuid = c.get('uuid')!;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const e164 = c.get('e164')!;
2019-09-26 19:56:31 +00:00
c.queueJob(async () => {
try {
const {
wrap,
sendOptions,
} = window.ConversationController.prepareForSend(c.get('id'));
// eslint-disable-next-line no-await-in-loop
await wrap(
window.textsecure.messaging.sendDeliveryReceipt(
e164,
uuid,
timestamps,
sendOptions
)
);
} catch (error) {
window.log.error(
`Failed to send delivery receipt to ${e164}/${uuid} for timestamps ${timestamps}:`,
error && error.stack ? error.stack : error
);
}
});
2019-09-26 19:56:31 +00:00
}
},
});
// Globally disable drag and drop
document.body.addEventListener(
'dragover',
e => {
e.preventDefault();
e.stopPropagation();
},
false
);
document.body.addEventListener(
'drop',
e => {
e.preventDefault();
e.stopPropagation();
},
false
);
// Idle timer - you're active for ACTIVE_TIMEOUT after one of these events
const ACTIVE_TIMEOUT = 15 * 1000;
const ACTIVE_EVENTS = [
'click',
'keydown',
'mousedown',
'mousemove',
// 'scroll', // this is triggered by Timeline re-renders, can't use
'touchstart',
'wheel',
];
const LISTENER_DEBOUNCE = 5 * 1000;
let activeHandlers: Array<WhatIsThis> = [];
let activeTimestamp = Date.now();
window.addEventListener('blur', () => {
// Force inactivity
activeTimestamp = Date.now() - ACTIVE_TIMEOUT;
});
window.resetActiveTimer = _.throttle(() => {
const previouslyActive = window.isActive();
activeTimestamp = Date.now();
if (!previouslyActive) {
activeHandlers.forEach(handler => handler());
}
}, LISTENER_DEBOUNCE);
ACTIVE_EVENTS.forEach(name => {
document.addEventListener(name, window.resetActiveTimer, true);
});
window.isActive = () => {
const now = Date.now();
return now <= activeTimestamp + ACTIVE_TIMEOUT;
};
window.registerForActive = handler => activeHandlers.push(handler);
window.unregisterForActive = handler => {
activeHandlers = activeHandlers.filter(item => item !== handler);
};
// Keyboard/mouse mode
2020-10-30 17:52:21 +00:00
let interactionMode: 'mouse' | 'keyboard' = 'mouse';
$(document.body).addClass('mouse-mode');
window.enterKeyboardMode = () => {
if (interactionMode === 'keyboard') {
return;
}
interactionMode = 'keyboard';
$(document.body).addClass('keyboard-mode').removeClass('mouse-mode');
const { userChanged } = window.reduxActions.user;
const { clearSelectedMessage } = window.reduxActions.conversations;
if (clearSelectedMessage) {
clearSelectedMessage();
}
if (userChanged) {
userChanged({
interactionMode,
} as WhatIsThis);
}
};
window.enterMouseMode = () => {
if (interactionMode === 'mouse') {
return;
}
interactionMode = 'mouse';
$(document.body).addClass('mouse-mode').removeClass('keyboard-mode');
const { userChanged } = window.reduxActions.user;
const { clearSelectedMessage } = window.reduxActions.conversations;
if (clearSelectedMessage) {
clearSelectedMessage();
}
if (userChanged) {
userChanged({ interactionMode } as WhatIsThis);
}
};
document.addEventListener(
'keydown',
event => {
if (event.key === 'Tab') {
window.enterKeyboardMode();
}
},
true
);
document.addEventListener('wheel', window.enterMouseMode, true);
document.addEventListener('mousedown', window.enterMouseMode, true);
window.getInteractionMode = () => interactionMode;
// Load these images now to ensure that they don't flicker on first use
2019-10-04 18:06:17 +00:00
window.preloadedImages = [];
function preload(list: Array<WhatIsThis>) {
for (let index = 0, max = list.length; index < max; index += 1) {
const image = new Image();
image.src = `./images/${list[index]}`;
2019-10-04 18:06:17 +00:00
window.preloadedImages.push(image);
}
}
2019-10-04 18:06:17 +00:00
const builtInImages = await window.getBuiltInImages();
preload(builtInImages);
// We add this to window here because the default Node context is erased at the end
// of preload.js processing
window.setImmediate = window.nodeSetImmediate;
const { IdleDetector, MessageDataMigrator } = window.Signal.Workflow;
2018-10-18 01:01:21 +00:00
const {
2020-04-28 21:18:41 +00:00
removeDatabase: removeIndexedDB,
2018-10-18 01:01:21 +00:00
doesDatabaseExist,
} = window.Signal.IndexedDB;
2018-04-27 21:25:04 +00:00
const { Errors, Message } = window.Signal.Types;
2018-09-21 01:47:19 +00:00
const {
upgradeMessageSchema,
writeNewAttachmentData,
deleteAttachmentData,
doesAttachmentExist,
} = window.Signal.Migrations;
2018-04-27 21:25:04 +00:00
const { Views } = window.Signal;
window.log.info('background page reloaded');
window.log.info('environment:', window.getEnvironment());
2018-04-27 21:25:04 +00:00
let idleDetector: WhatIsThis;
2018-05-25 01:50:49 +00:00
let initialLoadComplete = false;
let newVersion = false;
2018-04-27 21:25:04 +00:00
window.owsDesktopApp = {};
window.document.title = window.getTitle();
2015-09-25 18:10:25 +00:00
window.Whisper.KeyChangeListener.init(window.textsecure.storage.protocol);
window.textsecure.storage.protocol.on('removePreKey', () => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
window.getAccountManager()!.refreshPreKeys();
2018-04-27 21:25:04 +00:00
});
let messageReceiver: WhatIsThis;
let preMessageReceiverStatus: WhatIsThis;
2018-05-25 01:50:49 +00:00
window.getSocketStatus = () => {
2018-04-27 21:25:04 +00:00
if (messageReceiver) {
return messageReceiver.getStatus();
Beta versions support: SxS support, in-app env/instance display (#1606) * Script for beta config; unique data dir, in-app env/type display To release a beta build, increment the version and add -beta-N to the end, then go through all the standard release activities. The prepare-build npm script then updates key bits of the package.json to ensure that the beta build can be installed alongside a production build. This includes a new name ('Signal Beta') and a different location for application data. Note: Beta builds can be installed alongside production builds. As part of this, a couple new bits of data are shown across the app: - Environment (development or test, not shown if production) - App Instance (disabled in production; used for multiple accounts) These are shown in: - The window title - both environment and app instance. You can tell beta builds because the app name, preceding these data bits, is different. - The about window - both environment and app instance. You can tell beta builds from the version number. - The header added to the debug log - just environment. The version number will tell us if it's a beta build, and app instance isn't helpful. * Turn on single-window mode in non-production modes Because it's really frightening when you see 'unable to read from db' errors in the console. * aply.sh: More instructions for initial setup and testing * Gruntfile: Get consistent with use of package.json datas * Linux: manually update desktop keys, since macros not available
2017-10-30 20:57:13 +00:00
}
2020-09-04 01:25:19 +00:00
if (_.isNumber(preMessageReceiverStatus)) {
return preMessageReceiverStatus;
}
2018-05-25 01:50:49 +00:00
return -1;
2018-04-27 21:25:04 +00:00
};
window.Whisper.events = _.clone(window.Backbone.Events);
let accountManager: typeof window.textsecure.AccountManager;
2018-05-25 01:50:49 +00:00
window.getAccountManager = () => {
2018-04-27 21:25:04 +00:00
if (!accountManager) {
const OLD_USERNAME = window.storage.get('number_id');
const USERNAME = window.storage.get('uuid_id');
const PASSWORD = window.storage.get('password');
accountManager = new window.textsecure.AccountManager(
USERNAME || OLD_USERNAME,
PASSWORD
);
2018-05-25 01:50:49 +00:00
accountManager.addEventListener('registration', () => {
const ourNumber = window.textsecure.storage.user.getNumber();
const ourUuid = window.textsecure.storage.user.getUuid();
2019-01-14 21:49:58 +00:00
const user = {
regionCode: window.storage.get('regionCode'),
ourNumber,
ourUuid,
ourConversationId: window.ConversationController.getOurConversationId(),
2019-01-14 21:49:58 +00:00
};
window.Whisper.events.trigger('userChanged', user);
2019-01-14 21:49:58 +00:00
window.Signal.Util.Registration.markDone();
window.log.info('dispatching registration event');
window.Whisper.events.trigger('registration_done');
2018-04-27 21:25:04 +00:00
});
Beta versions support: SxS support, in-app env/instance display (#1606) * Script for beta config; unique data dir, in-app env/type display To release a beta build, increment the version and add -beta-N to the end, then go through all the standard release activities. The prepare-build npm script then updates key bits of the package.json to ensure that the beta build can be installed alongside a production build. This includes a new name ('Signal Beta') and a different location for application data. Note: Beta builds can be installed alongside production builds. As part of this, a couple new bits of data are shown across the app: - Environment (development or test, not shown if production) - App Instance (disabled in production; used for multiple accounts) These are shown in: - The window title - both environment and app instance. You can tell beta builds because the app name, preceding these data bits, is different. - The about window - both environment and app instance. You can tell beta builds from the version number. - The header added to the debug log - just environment. The version number will tell us if it's a beta build, and app instance isn't helpful. * Turn on single-window mode in non-production modes Because it's really frightening when you see 'unable to read from db' errors in the console. * aply.sh: More instructions for initial setup and testing * Gruntfile: Get consistent with use of package.json datas * Linux: manually update desktop keys, since macros not available
2017-10-30 20:57:13 +00:00
}
2018-04-27 21:25:04 +00:00
return accountManager;
};
const cancelInitializationMessage = Views.Initialization.setMessage();
const version = await window.Signal.Data.getItemById('version');
if (!version) {
2020-04-28 21:18:41 +00:00
const isIndexedDBPresent = await doesDatabaseExist();
if (isIndexedDBPresent) {
2020-04-28 21:18:41 +00:00
window.log.info('Found IndexedDB database.');
try {
window.log.info('Confirming deletion of old data with user...');
try {
await new Promise((resolve, reject) => {
const dialog = new window.Whisper.ConfirmationDialogView({
2020-04-28 21:18:41 +00:00
message: window.i18n('deleteOldIndexedDBData'),
okText: window.i18n('deleteOldData'),
cancelText: window.i18n('quit'),
resolve,
reject,
});
document.body.append(dialog.el);
dialog.focusCancel();
});
} catch (error) {
window.log.info(
'User chose not to delete old data. Shutting down.',
error && error.stack ? error.stack : error
);
window.shutdown();
return;
}
window.log.info('Deleting all previously-migrated data in SQL...');
window.log.info('Deleting IndexedDB file...');
await Promise.all([
removeIndexedDB(),
window.Signal.Data.removeAll(),
window.Signal.Data.removeIndexedDBFiles(),
]);
window.log.info('Done with SQL deletion and IndexedDB file deletion.');
} catch (error) {
window.log.error(
'Failed to remove IndexedDB file or remove SQL data:',
error && error.stack ? error.stack : error
);
}
// Set a flag to delete IndexedDB on next startup if it wasn't deleted just now.
// We need to use direct data calls, since window.storage isn't ready yet.
2020-04-28 21:18:41 +00:00
await window.Signal.Data.createOrUpdateItem({
id: 'indexeddb-delete-needed',
value: true,
});
}
2018-10-18 01:01:21 +00:00
}
2018-09-21 01:47:19 +00:00
window.log.info('Storage fetch');
window.storage.fetch();
function mapOldThemeToNew(theme: WhatIsThis) {
switch (theme) {
case 'dark':
case 'light':
2019-05-16 22:32:38 +00:00
case 'system':
return theme;
case 'android-dark':
return 'dark';
case 'android':
case 'ios':
default:
return 'light';
}
}
2018-04-27 21:25:04 +00:00
// We need this 'first' check because we don't want to start the app up any other time
// than the first time. And window.storage.fetch() will cause onready() to fire.
2018-05-25 01:50:49 +00:00
let first = true;
window.storage.onready(async () => {
2018-04-27 21:25:04 +00:00
if (!first) {
return;
}
first = false;
// These make key operations available to IPC handlers created in preload.js
window.Events = {
getDeviceName: () => window.textsecure.storage.user.getDeviceName(),
2019-05-16 22:32:38 +00:00
getThemeSetting: () =>
window.storage.get(
2019-05-16 22:32:38 +00:00
'theme-setting',
window.platform === 'darwin' ? 'system' : 'light'
),
setThemeSetting: (value: WhatIsThis) => {
window.storage.put('theme-setting', value);
onChangeTheme();
},
getHideMenuBar: () => window.storage.get('hide-menu-bar'),
setHideMenuBar: (value: WhatIsThis) => {
window.storage.put('hide-menu-bar', value);
window.setAutoHideMenuBar(value);
window.setMenuBarVisibility(!value);
},
getNotificationSetting: () =>
window.storage.get('notification-setting', 'message'),
setNotificationSetting: (value: WhatIsThis) =>
window.storage.put('notification-setting', value),
getNotificationDrawAttention: () =>
window.storage.get('notification-draw-attention', true),
setNotificationDrawAttention: (value: WhatIsThis) =>
window.storage.put('notification-draw-attention', value),
getAudioNotification: () => window.storage.get('audio-notification'),
setAudioNotification: (value: WhatIsThis) =>
window.storage.put('audio-notification', value),
getCountMutedConversations: () =>
window.storage.get('badge-count-muted-conversations', false),
setCountMutedConversations: (value: WhatIsThis) => {
window.storage.put('badge-count-muted-conversations', value);
window.Whisper.events.trigger('updateUnreadCount');
},
2020-06-04 18:16:19 +00:00
getCallRingtoneNotification: () =>
window.storage.get('call-ringtone-notification', true),
setCallRingtoneNotification: (value: WhatIsThis) =>
window.storage.put('call-ringtone-notification', value),
2020-06-04 18:16:19 +00:00
getCallSystemNotification: () =>
window.storage.get('call-system-notification', true),
setCallSystemNotification: (value: WhatIsThis) =>
window.storage.put('call-system-notification', value),
2020-06-04 18:16:19 +00:00
getIncomingCallNotification: () =>
window.storage.get('incoming-call-notification', true),
setIncomingCallNotification: (value: WhatIsThis) =>
window.storage.put('incoming-call-notification', value),
getSpellCheck: () => window.storage.get('spell-check', true),
setSpellCheck: (value: WhatIsThis) => {
window.storage.put('spell-check', value);
},
getAlwaysRelayCalls: () => window.storage.get('always-relay-calls'),
setAlwaysRelayCalls: (value: WhatIsThis) =>
window.storage.put('always-relay-calls', value),
2020-06-04 18:16:19 +00:00
// eslint-disable-next-line eqeqeq
isPrimary: () => window.textsecure.storage.user.getDeviceId() == '1',
getSyncRequest: () =>
new Promise((resolve, reject) => {
const syncRequest = window.getSyncRequest();
syncRequest.addEventListener('success', resolve);
syncRequest.addEventListener('timeout', reject);
}),
getLastSyncTime: () => window.storage.get('synced_at'),
setLastSyncTime: (value: WhatIsThis) =>
window.storage.put('synced_at', value),
addDarkOverlay: () => {
if ($('.dark-overlay').length) {
return;
}
$(document.body).prepend('<div class="dark-overlay"></div>');
$('.dark-overlay').on('click', () => $('.dark-overlay').remove());
},
removeDarkOverlay: () => $('.dark-overlay').remove(),
2019-11-07 21:36:16 +00:00
showKeyboardShortcuts: () => window.showKeyboardShortcuts(),
deleteAllData: () => {
const clearDataView = new window.Whisper.ClearDataView().render();
$('body').append(clearDataView.el);
},
shutdown: async () => {
window.log.info('background/shutdown');
// Stop background processing
window.Signal.AttachmentDownloads.stop();
if (idleDetector) {
idleDetector.stop();
}
// Stop processing incoming messages
if (messageReceiver) {
await messageReceiver.stopProcessing();
2019-09-26 19:56:31 +00:00
await window.waitForAllBatchers();
}
2019-09-26 19:56:31 +00:00
if (messageReceiver) {
messageReceiver.unregisterBatchers();
messageReceiver = null;
}
2019-09-26 19:56:31 +00:00
// A number of still-to-queue database queries might be waiting inside batchers.
// We wait for these to empty first, and then shut down the data interface.
await Promise.all([
window.waitForAllBatchers(),
window.waitForAllWaitBatchers(),
]);
// Shut down the data interface cleanly
await window.Signal.Data.shutdown();
},
showStickerPack: async (packId: string, key: string) => {
// We can get these events even if the user has never linked this instance.
2020-03-04 02:47:01 +00:00
if (!window.Signal.Util.Registration.everDone()) {
return;
}
// Kick off the download
window.Signal.Stickers.downloadEphemeralPack(packId, key);
const props = {
packId,
onClose: async () => {
stickerPreviewModalView.remove();
await window.Signal.Stickers.removeEphemeralPack(packId);
},
};
const stickerPreviewModalView = new window.Whisper.ReactWrapperView({
className: 'sticker-preview-modal-wrapper',
JSX: window.Signal.State.Roots.createStickerPreviewModal(
window.reduxStore,
props
),
});
},
2019-12-17 20:25:57 +00:00
installStickerPack: async (packId: string, key: string) => {
2019-12-17 20:25:57 +00:00
window.Signal.Stickers.downloadStickerPack(packId, key, {
finalStatus: 'installed',
});
},
};
// How long since we were last running?
const now = Date.now();
const lastHeartbeat = window.storage.get('lastHeartbeat');
await window.storage.put('lastStartup', Date.now());
const THIRTY_DAYS = 30 * 24 * 60 * 60 * 1000;
if (lastHeartbeat > 0 && now - lastHeartbeat > THIRTY_DAYS) {
await unlinkAndDisconnect();
}
// Start heartbeat timer
window.storage.put('lastHeartbeat', Date.now());
const TWELVE_HOURS = 12 * 60 * 60 * 1000;
setInterval(
() => window.storage.put('lastHeartbeat', Date.now()),
TWELVE_HOURS
);
const currentVersion = window.getVersion();
const lastVersion = window.storage.get('version');
newVersion = !lastVersion || currentVersion !== lastVersion;
await window.storage.put('version', currentVersion);
if (newVersion && lastVersion) {
window.log.info(
`New version detected: ${currentVersion}; previous: ${lastVersion}`
);
2019-05-16 22:32:38 +00:00
const themeSetting = window.Events.getThemeSetting();
const newThemeSetting = mapOldThemeToNew(themeSetting);
if (window.isBeforeVersion(lastVersion, 'v1.29.2-beta.1')) {
// Stickers flags
await Promise.all([
window.storage.put('showStickersIntroduction', true),
window.storage.put('showStickerPickerHint', true),
]);
}
if (window.isBeforeVersion(lastVersion, 'v1.26.0')) {
// Ensure that we re-register our support for sealed sender
await window.storage.put(
'hasRegisterSupportForUnauthenticatedDelivery',
false
);
}
if (
window.isBeforeVersion(lastVersion, 'v1.25.0') &&
window.platform === 'darwin' &&
newThemeSetting === window.systemTheme
) {
window.Events.setThemeSetting('system');
} else {
window.Events.setThemeSetting(newThemeSetting);
}
if (
2020-09-09 02:25:05 +00:00
window.isBeforeVersion(lastVersion, 'v1.36.0-beta.1') &&
window.isAfterVersion(lastVersion, 'v1.35.0-beta.1')
) {
2020-09-09 00:56:23 +00:00
await window.Signal.Services.eraseAllStorageServiceState();
}
2019-05-16 22:32:38 +00:00
// This one should always be last - it could restart the app
if (window.isBeforeVersion(lastVersion, 'v1.15.0-beta.5')) {
await window.Signal.Logs.deleteAll();
window.restart();
return;
}
}
Views.Initialization.setMessage(window.i18n('optimizingApplication'));
2018-08-08 17:00:33 +00:00
if (newVersion) {
await window.Signal.Data.cleanupOrphanedAttachments();
// Don't block on the following operation
window.Signal.Data.ensureFilePermissions();
2018-08-08 17:00:33 +00:00
}
Views.Initialization.setMessage(window.i18n('loading'));
idleDetector = new IdleDetector();
let isMigrationWithIndexComplete = false;
window.log.info(
2020-01-08 17:44:54 +00:00
`Starting background data migration. Target version: ${Message.CURRENT_SCHEMA_VERSION}`
);
idleDetector.on('idle', async () => {
const NUM_MESSAGES_PER_BATCH = 1;
if (!isMigrationWithIndexComplete) {
const batchWithIndex = await MessageDataMigrator.processNext({
BackboneMessage: window.Whisper.Message,
BackboneMessageCollection: window.Whisper.MessageCollection,
numMessagesPerBatch: NUM_MESSAGES_PER_BATCH,
upgradeMessageSchema,
getMessagesNeedingUpgrade:
window.Signal.Data.getMessagesNeedingUpgrade,
saveMessage: window.Signal.Data.saveMessage,
});
window.log.info('Upgrade message schema (with index):', batchWithIndex);
isMigrationWithIndexComplete = batchWithIndex.done;
}
if (isMigrationWithIndexComplete) {
window.log.info(
'Background migration complete. Stopping idle detector.'
);
idleDetector.stop();
}
});
window.Signal.conversationControllerStart();
2020-08-05 01:13:19 +00:00
// We start this up before window.ConversationController.load() to
// ensure that our feature flags are represented in the cached props
// we generate on load of each convo.
2020-08-05 01:13:19 +00:00
window.Signal.RemoteConfig.initRemoteConfig();
2018-05-25 01:50:49 +00:00
try {
await Promise.all([
window.ConversationController.load(),
window.Signal.Stickers.load(),
window.Signal.Emojis.load(),
window.textsecure.storage.protocol.hydrateCaches(),
]);
await window.ConversationController.checkForConflicts();
} catch (error) {
window.log.error(
'background.js: ConversationController failed to load:',
error && error.stack ? error.stack : error
);
2018-05-25 01:50:49 +00:00
} finally {
initializeRedux();
2018-05-25 01:50:49 +00:00
start();
window.Signal.Services.initializeNetworkObserver(
window.reduxActions.network
);
window.Signal.Services.initializeUpdateListener(
2020-02-21 00:09:50 +00:00
window.reduxActions.updates,
window.Whisper.events
);
2020-06-04 18:16:19 +00:00
window.Signal.Services.calling.initialize(window.reduxActions.calling);
window.reduxActions.expiration.hydrateExpirationStatus(
window.Signal.Util.hasExpired()
);
2018-05-25 01:50:49 +00:00
}
2018-04-27 21:25:04 +00:00
});
function initializeRedux() {
// Here we set up a full redux store with initial state for our LeftPane Root
const convoCollection = window.getConversations();
const conversations = convoCollection.map(conversation =>
conversation.format()
);
const ourNumber = window.textsecure.storage.user.getNumber();
const ourUuid = window.textsecure.storage.user.getUuid();
const ourConversationId = window.ConversationController.getOurConversationId();
const initialState = {
conversations: {
conversationLookup: window.Signal.Util.makeLookup(conversations, 'id'),
messagesByConversation: {},
messagesLookup: {},
2020-10-30 17:52:21 +00:00
selectedConversation: undefined,
selectedMessage: undefined,
selectedMessageCounter: 0,
showArchived: false,
},
emojis: window.Signal.Emojis.getInitialState(),
items: window.storage.getItemsState(),
stickers: window.Signal.Stickers.getInitialState(),
user: {
attachmentsPath: window.baseAttachmentsPath,
stickersPath: window.baseStickersPath,
tempPath: window.baseTempPath,
regionCode: window.storage.get('regionCode'),
ourConversationId,
ourNumber,
ourUuid,
2019-11-07 21:36:16 +00:00
platform: window.platform,
i18n: window.i18n,
interactionMode: window.getInteractionMode(),
},
};
const store = window.Signal.State.createStore(initialState);
window.reduxStore = store;
const actions: WhatIsThis = {};
window.reduxActions = actions;
// Binding these actions to our redux store and exposing them allows us to update
// redux when things change in the backbone world.
actions.calling = window.Signal.State.bindActionCreators(
window.Signal.State.Ducks.calling.actions,
2020-06-04 18:16:19 +00:00
store.dispatch
);
actions.conversations = window.Signal.State.bindActionCreators(
window.Signal.State.Ducks.conversations.actions,
store.dispatch
);
actions.emojis = window.Signal.State.bindActionCreators(
window.Signal.State.Ducks.emojis.actions,
2019-05-24 23:58:27 +00:00
store.dispatch
);
actions.expiration = window.Signal.State.bindActionCreators(
window.Signal.State.Ducks.expiration.actions,
store.dispatch
);
actions.items = window.Signal.State.bindActionCreators(
window.Signal.State.Ducks.items.actions,
store.dispatch
);
actions.network = window.Signal.State.bindActionCreators(
window.Signal.State.Ducks.network.actions,
store.dispatch
);
actions.updates = window.Signal.State.bindActionCreators(
window.Signal.State.Ducks.updates.actions,
store.dispatch
);
actions.user = window.Signal.State.bindActionCreators(
window.Signal.State.Ducks.user.actions,
store.dispatch
);
actions.search = window.Signal.State.bindActionCreators(
window.Signal.State.Ducks.search.actions,
2019-08-09 23:12:29 +00:00
store.dispatch
);
actions.stickers = window.Signal.State.bindActionCreators(
window.Signal.State.Ducks.stickers.actions,
store.dispatch
);
const {
conversationAdded,
conversationChanged,
conversationRemoved,
removeAllConversations,
messageExpired,
} = actions.conversations;
const { userChanged } = actions.user;
convoCollection.on('remove', conversation => {
const { id } = conversation || {};
conversationRemoved(id);
});
convoCollection.on('add', conversation => {
if (!conversation) {
return;
}
conversationAdded(conversation.id, conversation.format());
});
convoCollection.on('change', conversation => {
if (!conversation) {
return;
}
conversationChanged(conversation.id, conversation.format());
});
convoCollection.on('reset', removeAllConversations);
window.Whisper.events.on('messageExpired', messageExpired);
window.Whisper.events.on('userChanged', userChanged);
let shortcutGuideView: WhatIsThis | null = null;
2019-11-07 21:36:16 +00:00
window.showKeyboardShortcuts = () => {
if (!shortcutGuideView) {
shortcutGuideView = new window.Whisper.ReactWrapperView({
2019-11-07 21:36:16 +00:00
className: 'shortcut-guide-wrapper',
JSX: window.Signal.State.Roots.createShortcutGuideModal(
window.reduxStore,
{
close: () => {
if (shortcutGuideView) {
shortcutGuideView.remove();
shortcutGuideView = null;
}
},
}
),
2019-11-07 21:36:16 +00:00
onClose: () => {
shortcutGuideView = null;
},
});
}
};
2020-10-09 21:53:20 +00:00
function getConversationsToSearch() {
const state = store.getState();
2020-10-09 21:53:20 +00:00
const {
archivedConversations,
conversations: unpinnedConversations,
pinnedConversations,
} = window.Signal.State.Selectors.conversations.getLeftPaneLists(state);
return state.conversations.showArchived
? archivedConversations
: [...pinnedConversations, ...unpinnedConversations];
}
2020-10-09 21:53:20 +00:00
function getConversationByIndex(index: WhatIsThis) {
const conversationsToSearch = getConversationsToSearch();
const target = conversationsToSearch[index];
if (target) {
return target.id;
}
return null;
}
function findConversation(
conversationId: WhatIsThis,
direction: WhatIsThis,
unreadOnly: WhatIsThis
) {
2020-10-09 21:53:20 +00:00
const conversationsToSearch = getConversationsToSearch();
2019-11-07 21:36:16 +00:00
const increment = direction === 'up' ? -1 : 1;
2020-10-30 17:52:21 +00:00
let startIndex: WhatIsThis;
2019-11-07 21:36:16 +00:00
if (conversationId) {
2020-10-09 21:53:20 +00:00
const index = conversationsToSearch.findIndex(
(item: WhatIsThis) => item.id === conversationId
);
2019-11-07 21:36:16 +00:00
if (index >= 0) {
startIndex = index + increment;
}
} else {
2020-10-09 21:53:20 +00:00
startIndex = direction === 'up' ? conversationsToSearch.length - 1 : 0;
2019-11-07 21:36:16 +00:00
}
for (
2020-10-09 21:53:20 +00:00
let i = startIndex, max = conversationsToSearch.length;
2019-11-07 21:36:16 +00:00
i >= 0 && i < max;
i += increment
) {
2020-10-09 21:53:20 +00:00
const target = conversationsToSearch[i];
2019-11-07 21:36:16 +00:00
if (!unreadOnly) {
return target.id;
2020-09-09 00:46:29 +00:00
}
2020-10-30 17:52:21 +00:00
if ((target.unreadCount || 0) > 0) {
2019-11-07 21:36:16 +00:00
return target.id;
}
}
return null;
}
const NUMBERS: Record<string, number> = {
'1': 1,
'2': 2,
'3': 3,
'4': 4,
'5': 5,
'6': 6,
'7': 7,
'8': 8,
'9': 9,
};
2019-11-07 21:36:16 +00:00
document.addEventListener('keydown', event => {
const { altKey, ctrlKey, key, metaKey, shiftKey } = event;
const optionOrAlt = altKey;
const commandKey = window.platform === 'darwin' && metaKey;
const controlKey = window.platform !== 'darwin' && ctrlKey;
const commandOrCtrl = commandKey || controlKey;
const commandAndCtrl = commandKey && ctrlKey;
2019-11-07 21:36:16 +00:00
const state = store.getState();
const selectedId = state.conversations.selectedConversation;
const conversation = window.ConversationController.get(selectedId);
const isSearching = window.Signal.State.Selectors.search.isSearching(
state
);
2019-11-07 21:36:16 +00:00
// NAVIGATION
// Show keyboard shortcuts - handled by Electron-managed keyboard shortcuts
// However, on linux Ctrl+/ selects all text, so we prevent that
if (commandOrCtrl && key === '/') {
window.showKeyboardShortcuts();
event.stopPropagation();
event.preventDefault();
return;
}
2019-11-07 21:36:16 +00:00
// Navigate by section
if (commandOrCtrl && !shiftKey && (key === 't' || key === 'T')) {
window.enterKeyboardMode();
2019-11-07 21:36:16 +00:00
const focusedElement = document.activeElement;
const targets: Array<HTMLElement | null> = [
2019-11-07 21:36:16 +00:00
document.querySelector('.module-main-header .module-avatar-button'),
document.querySelector('.module-left-pane__to-inbox-button'),
document.querySelector('.module-main-header__search__input'),
document.querySelector('.module-left-pane__list'),
document.querySelector('.module-search-results'),
document.querySelector(
'.module-composition-area .public-DraftEditor-content'
),
];
const focusedIndex = targets.findIndex(target => {
if (!target || !focusedElement) {
return false;
}
if (target === focusedElement) {
return true;
}
if (target.contains(focusedElement)) {
return true;
}
return false;
});
const lastIndex = targets.length - 1;
let index;
if (focusedIndex < 0 || focusedIndex >= lastIndex) {
index = 0;
} else {
index = focusedIndex + 1;
}
while (!targets[index]) {
index += 1;
if (index > lastIndex) {
index = 0;
}
}
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
targets[index]!.focus();
2019-11-07 21:36:16 +00:00
}
// Cancel out of keyboard shortcut screen - has first precedence
if (shortcutGuideView && key === 'Escape') {
shortcutGuideView.remove();
shortcutGuideView = null;
event.preventDefault();
event.stopPropagation();
return;
}
// Escape is heavily overloaded - here we avoid clashes with other Escape handlers
if (key === 'Escape') {
// Check origin - if within a react component which handles escape, don't handle.
// Why? Because React's synthetic events can cause events to be handled twice.
const target = document.activeElement;
// We might want to use NamedNodeMap.getNamedItem('class')
/* eslint-disable @typescript-eslint/no-explicit-any */
2019-11-07 21:36:16 +00:00
if (
target &&
target.attributes &&
(target.attributes as any).class &&
(target.attributes as any).class.value
2019-11-07 21:36:16 +00:00
) {
const className = (target.attributes as any).class.value;
/* eslint-enable @typescript-eslint/no-explicit-any */
2019-11-07 21:36:16 +00:00
// These want to handle events internally
// CaptionEditor text box
if (className.includes('module-caption-editor__caption-input')) {
return;
}
// MainHeader search box
if (className.includes('module-main-header__search__input')) {
return;
}
if (className.includes('module-contact-modal')) {
return;
}
2019-11-07 21:36:16 +00:00
}
// These add listeners to document, but we'll run first
const confirmationModal = document.querySelector(
'.module-confirmation-dialog__overlay'
);
if (confirmationModal) {
return;
}
const emojiPicker = document.querySelector('.module-emoji-picker');
if (emojiPicker) {
return;
}
const lightBox = document.querySelector('.module-lightbox');
if (lightBox) {
return;
}
const stickerPicker = document.querySelector('.module-sticker-picker');
if (stickerPicker) {
return;
}
const stickerPreview = document.querySelector(
'.module-sticker-manager__preview-modal__overlay'
);
if (stickerPreview) {
return;
}
2020-01-17 22:23:19 +00:00
const reactionViewer = document.querySelector(
'.module-reaction-viewer'
);
if (reactionViewer) {
return;
}
2020-01-23 23:57:37 +00:00
const reactionPicker = document.querySelector('module-reaction-picker');
if (reactionPicker) {
return;
}
2019-11-07 21:36:16 +00:00
}
// Close window.Backbone-based confirmation dialog
if (window.Whisper.activeConfirmationView && key === 'Escape') {
window.Whisper.activeConfirmationView.remove();
window.Whisper.activeConfirmationView = null;
2019-11-07 21:36:16 +00:00
event.preventDefault();
event.stopPropagation();
return;
}
// Send Escape to active conversation so it can close panels
if (conversation && key === 'Escape') {
conversation.trigger('escape-pressed');
event.preventDefault();
event.stopPropagation();
return;
}
// Change currently selected conversation by index
if (!isSearching && commandOrCtrl && NUMBERS[key]) {
const targetId = getConversationByIndex(
(NUMBERS[key] as WhatIsThis) - 1
);
if (targetId) {
window.Whisper.events.trigger('showConversation', targetId);
event.preventDefault();
event.stopPropagation();
return;
}
}
// Change currently selected conversation
// up/previous
if (
(!isSearching && optionOrAlt && !shiftKey && key === 'ArrowUp') ||
(!isSearching && ctrlKey && shiftKey && key === 'Tab')
) {
2019-11-07 21:36:16 +00:00
const unreadOnly = false;
const targetId = findConversation(
conversation ? conversation.id : null,
'up',
unreadOnly
);
if (targetId) {
window.Whisper.events.trigger('showConversation', targetId);
event.preventDefault();
event.stopPropagation();
return;
}
}
// down/next
if (
(!isSearching && optionOrAlt && !shiftKey && key === 'ArrowDown') ||
(!isSearching && ctrlKey && key === 'Tab')
) {
2019-11-07 21:36:16 +00:00
const unreadOnly = false;
const targetId = findConversation(
conversation ? conversation.id : null,
'down',
unreadOnly
);
if (targetId) {
window.Whisper.events.trigger('showConversation', targetId);
event.preventDefault();
event.stopPropagation();
return;
}
}
// previous unread
if (!isSearching && optionOrAlt && shiftKey && key === 'ArrowUp') {
2019-11-07 21:36:16 +00:00
const unreadOnly = true;
const targetId = findConversation(
conversation ? conversation.id : null,
'up',
unreadOnly
);
if (targetId) {
window.Whisper.events.trigger('showConversation', targetId);
event.preventDefault();
event.stopPropagation();
return;
}
}
// next unread
if (!isSearching && optionOrAlt && shiftKey && key === 'ArrowDown') {
2019-11-07 21:36:16 +00:00
const unreadOnly = true;
const targetId = findConversation(
conversation ? conversation.id : null,
'down',
unreadOnly
);
if (targetId) {
window.Whisper.events.trigger('showConversation', targetId);
event.preventDefault();
event.stopPropagation();
return;
}
}
// Preferences - handled by Electron-managed keyboard shortcuts
// Open the top-right menu for current conversation
if (
conversation &&
commandOrCtrl &&
shiftKey &&
(key === 'l' || key === 'L')
) {
2019-11-07 21:36:16 +00:00
const button = document.querySelector(
'.module-conversation-header__more-button'
);
if (!button) {
return;
}
// Because the menu is shown at a location based on the initiating click, we need
// to fake up a mouse event to get the menu to show somewhere other than (0,0).
const { x, y, width, height } = button.getBoundingClientRect();
const mouseEvent = document.createEvent('MouseEvents');
// Types do not match signature
/* eslint-disable @typescript-eslint/no-explicit-any */
2019-11-07 21:36:16 +00:00
mouseEvent.initMouseEvent(
'click',
true, // bubbles
false, // cancelable
null as any, // view
null as any, // detail
2019-11-07 21:36:16 +00:00
0, // screenX,
0, // screenY,
x + width / 2,
y + height / 2,
false, // ctrlKey,
false, // altKey,
false, // shiftKey,
false, // metaKey,
false as any, // button,
2019-11-07 21:36:16 +00:00
document.body
);
/* eslint-enable @typescript-eslint/no-explicit-any */
2019-11-07 21:36:16 +00:00
button.dispatchEvent(mouseEvent);
event.preventDefault();
event.stopPropagation();
return;
}
// Search
if (
commandOrCtrl &&
!commandAndCtrl &&
!shiftKey &&
(key === 'f' || key === 'F')
) {
2019-11-07 21:36:16 +00:00
const { startSearch } = actions.search;
startSearch();
event.preventDefault();
event.stopPropagation();
return;
}
// Search in conversation
if (
conversation &&
commandOrCtrl &&
!commandAndCtrl &&
shiftKey &&
(key === 'f' || key === 'F')
) {
2019-11-07 21:36:16 +00:00
const { searchInConversation } = actions.search;
const name = conversation.isMe()
? window.i18n('noteToSelf')
: conversation.getTitle();
searchInConversation(conversation.id, name);
event.preventDefault();
event.stopPropagation();
return;
}
// Focus composer field
if (
conversation &&
commandOrCtrl &&
shiftKey &&
(key === 't' || key === 'T')
) {
2019-11-07 21:36:16 +00:00
conversation.trigger('focus-composer');
event.preventDefault();
event.stopPropagation();
return;
}
// Open all media
if (
conversation &&
commandOrCtrl &&
shiftKey &&
(key === 'm' || key === 'M')
) {
2019-11-07 21:36:16 +00:00
conversation.trigger('open-all-media');
event.preventDefault();
event.stopPropagation();
return;
}
// Open emoji picker - handled by component
// Open sticker picker - handled by component
// Begin recording voice note
if (
conversation &&
commandOrCtrl &&
shiftKey &&
(key === 'v' || key === 'V')
) {
2019-11-07 21:36:16 +00:00
conversation.trigger('begin-recording');
event.preventDefault();
event.stopPropagation();
return;
}
// Archive or unarchive conversation
if (
conversation &&
!conversation.get('isArchived') &&
commandOrCtrl &&
2019-11-07 21:36:16 +00:00
shiftKey &&
(key === 'a' || key === 'A')
2019-11-07 21:36:16 +00:00
) {
conversation.setArchived(true);
conversation.trigger('unload', 'keyboard shortcut archive');
window.Whisper.ToastView.show(
window.Whisper.ConversationArchivedToast,
2019-11-07 21:36:16 +00:00
document.body
);
// It's very likely that the act of archiving a conversation will set focus to
// 'none,' or the top-level body element. This resets it to the left pane,
// whether in the normal conversation list or search results.
if (document.activeElement === document.body) {
const leftPaneEl: HTMLElement | null = document.querySelector(
'.module-left-pane__list'
);
if (leftPaneEl) {
leftPaneEl.focus();
}
const searchResultsEl: HTMLElement | null = document.querySelector(
'.module-search-results'
);
if (searchResultsEl) {
searchResultsEl.focus();
}
}
2019-11-07 21:36:16 +00:00
event.preventDefault();
event.stopPropagation();
return;
}
if (
conversation &&
conversation.get('isArchived') &&
commandOrCtrl &&
2019-11-07 21:36:16 +00:00
shiftKey &&
(key === 'u' || key === 'U')
2019-11-07 21:36:16 +00:00
) {
conversation.setArchived(false);
window.Whisper.ToastView.show(
window.Whisper.ConversationUnarchivedToast,
2019-11-07 21:36:16 +00:00
document.body
);
event.preventDefault();
event.stopPropagation();
return;
}
// Scroll to bottom of list - handled by component
// Scroll to top of list - handled by component
// Close conversation
if (
conversation &&
commandOrCtrl &&
shiftKey &&
(key === 'c' || key === 'C')
) {
2019-11-07 21:36:16 +00:00
conversation.trigger('unload', 'keyboard shortcut close');
event.preventDefault();
event.stopPropagation();
return;
}
// MESSAGES
// Show message details
if (
conversation &&
commandOrCtrl &&
!shiftKey &&
(key === 'd' || key === 'D')
) {
2019-11-07 21:36:16 +00:00
const { selectedMessage } = state.conversations;
if (!selectedMessage) {
return;
}
conversation.trigger('show-message-details', selectedMessage);
event.preventDefault();
event.stopPropagation();
return;
}
// Toggle reply to message
if (
conversation &&
commandOrCtrl &&
shiftKey &&
(key === 'r' || key === 'R')
) {
2019-11-07 21:36:16 +00:00
const { selectedMessage } = state.conversations;
conversation.trigger('toggle-reply', selectedMessage);
event.preventDefault();
event.stopPropagation();
return;
}
// Save attachment
if (
conversation &&
commandOrCtrl &&
!shiftKey &&
(key === 's' || key === 'S')
) {
2019-11-07 21:36:16 +00:00
const { selectedMessage } = state.conversations;
if (selectedMessage) {
conversation.trigger('save-attachment', selectedMessage);
event.preventDefault();
event.stopPropagation();
return;
}
}
if (
conversation &&
commandOrCtrl &&
shiftKey &&
(key === 'd' || key === 'D')
) {
2019-11-07 21:36:16 +00:00
const { selectedMessage } = state.conversations;
if (selectedMessage) {
conversation.trigger('delete-message', selectedMessage);
event.preventDefault();
event.stopPropagation();
return;
}
}
// COMPOSER
// Create a newline in your message - handled by component
// Expand composer - handled by component
// Send in expanded composer - handled by component
// Attach file
if (
conversation &&
commandOrCtrl &&
!shiftKey &&
(key === 'u' || key === 'U')
) {
2019-11-07 21:36:16 +00:00
conversation.trigger('attach-file');
event.preventDefault();
event.stopPropagation();
return;
}
// Remove draft link preview
if (
conversation &&
commandOrCtrl &&
!shiftKey &&
(key === 'p' || key === 'P')
) {
2019-11-07 21:36:16 +00:00
conversation.trigger('remove-link-review');
event.preventDefault();
event.stopPropagation();
return;
}
// Attach file
if (
conversation &&
commandOrCtrl &&
shiftKey &&
(key === 'p' || key === 'P')
) {
2019-11-07 21:36:16 +00:00
conversation.trigger('remove-all-draft-attachments');
event.preventDefault();
event.stopPropagation();
// Commented out because this is the last item
// return;
}
});
}
window.Whisper.events.on('setupAsNewDevice', () => {
2018-05-25 01:50:49 +00:00
const { appView } = window.owsDesktopApp;
2018-04-27 21:25:04 +00:00
if (appView) {
appView.openInstaller();
}
});
window.Whisper.events.on('setupAsStandalone', () => {
2018-05-25 01:50:49 +00:00
const { appView } = window.owsDesktopApp;
2018-04-27 21:25:04 +00:00
if (appView) {
appView.openStandalone();
}
});
function runStorageService() {
window.Signal.Services.enableStorageService();
window.textsecure.messaging.sendRequestKeySyncMessage();
}
async function start() {
2018-04-27 21:25:04 +00:00
window.dispatchEvent(new Event('storage_ready'));
window.log.info('Cleanup: starting...');
const messagesForCleanup = await window.Signal.Data.getOutgoingWithoutExpiresAt(
{
MessageCollection: window.Whisper.MessageCollection,
}
);
window.log.info(
`Cleanup: Found ${messagesForCleanup.length} messages for cleanup`
);
await Promise.all(
messagesForCleanup.map(async message => {
const delivered = message.get('delivered');
const sentAt = message.get('sent_at');
const expirationStartTimestamp = message.get(
'expirationStartTimestamp'
);
if (message.hasErrors()) {
return;
}
if (delivered) {
window.log.info(
`Cleanup: Starting timer for delivered message ${sentAt}`
);
message.set(
'expirationStartTimestamp',
expirationStartTimestamp || sentAt
);
await message.setToExpire();
return;
}
window.log.info(`Cleanup: Deleting unsent message ${sentAt}`);
await window.Signal.Data.removeMessage(message.id, {
Message: window.Whisper.Message,
});
const conversation = message.getConversation();
if (conversation) {
await conversation.updateLastMessage();
}
})
);
window.log.info('Cleanup: complete');
window.log.info('listening for registration events');
window.Whisper.events.on('registration_done', () => {
window.log.info('handling registration event');
2018-04-27 21:25:04 +00:00
connect(true);
});
2018-04-27 21:25:04 +00:00
cancelInitializationMessage();
const appView = new window.Whisper.AppView({
2018-04-27 21:25:04 +00:00
el: $('body'),
2018-05-25 01:50:49 +00:00
});
window.owsDesktopApp.appView = appView;
2018-04-27 21:25:04 +00:00
window.Whisper.WallClockListener.init(window.Whisper.events);
window.Whisper.ExpiringMessagesListener.init(window.Whisper.events);
window.Whisper.TapToViewMessagesListener.init(window.Whisper.events);
2018-04-27 21:25:04 +00:00
2020-03-04 02:47:01 +00:00
if (window.Signal.Util.Registration.everDone()) {
2018-04-27 21:25:04 +00:00
connect();
appView.openInbox({
2018-05-25 01:50:49 +00:00
initialLoadComplete,
2018-04-27 21:25:04 +00:00
});
} else {
appView.openInstaller();
}
window.Whisper.events.on('showDebugLog', () => {
2018-04-27 21:25:04 +00:00
appView.openDebugLog();
});
window.Whisper.events.on('unauthorized', () => {
2018-04-27 21:25:04 +00:00
appView.inboxView.networkStatusView.update();
});
window.Whisper.events.on('contactsync', () => {
2018-04-27 21:25:04 +00:00
if (appView.installView) {
appView.openInbox();
}
});
window.registerForActive(() => window.Whisper.Notifications.clear());
window.addEventListener('unload', () =>
window.Whisper.Notifications.fastClear()
);
window.Whisper.events.on('showConversation', (id, messageId) => {
if (appView) {
2019-01-14 21:49:58 +00:00
appView.openConversation(id, messageId);
}
});
window.Whisper.Notifications.on('click', (id, messageId) => {
2018-05-25 01:50:49 +00:00
window.showWindow();
2019-01-14 21:49:58 +00:00
if (id) {
appView.openConversation(id, messageId);
Full export, migration banner, and full migration workflow - behind flag (#1342) * Add support for backup and restore This first pass works for all stores except messages, pending some scaling improvements. // FREEBIE * Import of messages and attachments Properly sanitize filenames. Logging information that will help with debugging but won't threaten privacy (no contact or group names), where the on-disk directories have this information to make things human-readable FREEBIE * First fully operational single-action export and import! FREEBIE * Add migration export flow A banner alert leads to a blocking ui for the migration. We close the socket and wait for incoming messages to drain before starting the export. FREEBIE * A number of updates for the export flow 1. We don't immediately pop the directory selection dialog box, instead showing an explicit 'choose directory' button after explaining what is about to happen 2. We show a 'submit debug log' button on most steps of the process 3. We handle export errors and encourage the user to double-check their filesystem then submit their log 4. We are resilient to restarts during the process 5. We handle the user cancelling out of the directory selection dialog differently from other errors. 6. The export process is now serialized: non-messages, then messages. 7. After successful export, show where the data is on disk FREEBUE * Put migration behind a flag FREEBIE * Shut down websocket before proceeding with export FREEBIE * Add MigrationView to test/index.html to fix test FREEBIE * Remove 'Submit Debug Log' button when the export process is complete FREEBIE * Create a 'Signal Export' directory below user-chosen dir This cleans things up a bit so we don't litter the user's target directory with lots of stuff. FREEBIE * Clarify MessageReceiver.drain() method comments FREEBIE * A couple updates for clarity - event names, else handling Also the removal of wait(), which wasn't used anywhere. FREEBIE * A number of wording updates for the export flow FREEBIE * Export complete: put dir on its own line, make text selectable FREEBIE
2017-08-28 20:06:10 +00:00
} else {
2018-04-27 21:25:04 +00:00
appView.openInbox({
2018-05-25 01:50:49 +00:00
initialLoadComplete,
2018-04-27 21:25:04 +00:00
});
Full export, migration banner, and full migration workflow - behind flag (#1342) * Add support for backup and restore This first pass works for all stores except messages, pending some scaling improvements. // FREEBIE * Import of messages and attachments Properly sanitize filenames. Logging information that will help with debugging but won't threaten privacy (no contact or group names), where the on-disk directories have this information to make things human-readable FREEBIE * First fully operational single-action export and import! FREEBIE * Add migration export flow A banner alert leads to a blocking ui for the migration. We close the socket and wait for incoming messages to drain before starting the export. FREEBIE * A number of updates for the export flow 1. We don't immediately pop the directory selection dialog box, instead showing an explicit 'choose directory' button after explaining what is about to happen 2. We show a 'submit debug log' button on most steps of the process 3. We handle export errors and encourage the user to double-check their filesystem then submit their log 4. We are resilient to restarts during the process 5. We handle the user cancelling out of the directory selection dialog differently from other errors. 6. The export process is now serialized: non-messages, then messages. 7. After successful export, show where the data is on disk FREEBUE * Put migration behind a flag FREEBIE * Shut down websocket before proceeding with export FREEBIE * Add MigrationView to test/index.html to fix test FREEBIE * Remove 'Submit Debug Log' button when the export process is complete FREEBIE * Create a 'Signal Export' directory below user-chosen dir This cleans things up a bit so we don't litter the user's target directory with lots of stuff. FREEBIE * Clarify MessageReceiver.drain() method comments FREEBIE * A couple updates for clarity - event names, else handling Also the removal of wait(), which wasn't used anywhere. FREEBIE * A number of wording updates for the export flow FREEBIE * Export complete: put dir on its own line, make text selectable FREEBIE
2017-08-28 20:06:10 +00:00
}
});
2020-05-27 21:37:06 +00:00
// Maybe refresh remote configuration when we become active
window.registerForActive(async () => {
await window.Signal.RemoteConfig.maybeRefreshRemoteConfig();
});
// Listen for changes to the `desktop.clientExpiration` remote flag
window.Signal.RemoteConfig.onChange(
'desktop.clientExpiration',
({ value }) => {
const remoteBuildExpirationTimestamp = window.Signal.Util.parseRemoteClientExpiration(
value as string
);
if (remoteBuildExpirationTimestamp) {
window.storage.put(
'remoteBuildExpiration',
remoteBuildExpirationTimestamp
);
window.reduxActions.expiration.hydrateExpirationStatus(
window.Signal.Util.hasExpired()
);
}
}
);
2020-05-27 21:37:06 +00:00
// Listen for changes to the `desktop.messageRequests` remote configuration flag
const removeMessageRequestListener = window.Signal.RemoteConfig.onChange(
'desktop.messageRequests',
({ enabled }) => {
if (!enabled) {
return;
}
const conversations = window.getConversations();
conversations.forEach(conversation => {
conversation.set({
messageCountBeforeMessageRequests:
conversation.get('messageCount') || 0,
});
window.Signal.Data.updateConversation(conversation.attributes);
});
removeMessageRequestListener();
}
);
2020-09-09 02:25:05 +00:00
// Listen for changes to the `desktop.gv2` remote configuration flag
const removeGv2Listener = window.Signal.RemoteConfig.onChange(
'desktop.gv2',
async ({ enabled }) => {
if (!enabled) {
return;
}
// Erase current manifest version so we re-process storage service data
2020-09-09 02:25:05 +00:00
await window.storage.remove('manifestVersion');
// Kick off window.storage service fetch to grab GroupV2 information
2020-09-09 02:25:05 +00:00
await window.Signal.Services.runStorageServiceSyncJob();
// This is a one-time thing
removeGv2Listener();
}
);
window.Signal.RemoteConfig.onChange(
'desktop.storage',
async ({ enabled }) => {
if (!enabled) {
await window.storage.remove('storageKey');
return;
}
await window.storage.remove('manifestVersion');
await window.textsecure.messaging.sendRequestKeySyncMessage();
}
);
2018-04-27 21:25:04 +00:00
}
Full export, migration banner, and full migration workflow - behind flag (#1342) * Add support for backup and restore This first pass works for all stores except messages, pending some scaling improvements. // FREEBIE * Import of messages and attachments Properly sanitize filenames. Logging information that will help with debugging but won't threaten privacy (no contact or group names), where the on-disk directories have this information to make things human-readable FREEBIE * First fully operational single-action export and import! FREEBIE * Add migration export flow A banner alert leads to a blocking ui for the migration. We close the socket and wait for incoming messages to drain before starting the export. FREEBIE * A number of updates for the export flow 1. We don't immediately pop the directory selection dialog box, instead showing an explicit 'choose directory' button after explaining what is about to happen 2. We show a 'submit debug log' button on most steps of the process 3. We handle export errors and encourage the user to double-check their filesystem then submit their log 4. We are resilient to restarts during the process 5. We handle the user cancelling out of the directory selection dialog differently from other errors. 6. The export process is now serialized: non-messages, then messages. 7. After successful export, show where the data is on disk FREEBUE * Put migration behind a flag FREEBIE * Shut down websocket before proceeding with export FREEBIE * Add MigrationView to test/index.html to fix test FREEBIE * Remove 'Submit Debug Log' button when the export process is complete FREEBIE * Create a 'Signal Export' directory below user-chosen dir This cleans things up a bit so we don't litter the user's target directory with lots of stuff. FREEBIE * Clarify MessageReceiver.drain() method comments FREEBIE * A couple updates for clarity - event names, else handling Also the removal of wait(), which wasn't used anywhere. FREEBIE * A number of wording updates for the export flow FREEBIE * Export complete: put dir on its own line, make text selectable FREEBIE
2017-08-28 20:06:10 +00:00
2018-05-25 01:50:49 +00:00
window.getSyncRequest = () =>
new window.textsecure.SyncRequest(
window.textsecure.messaging,
messageReceiver
);
let disconnectTimer: WhatIsThis | null = null;
let reconnectTimer: WhatIsThis | null = null;
2018-04-27 21:25:04 +00:00
function onOffline() {
window.log.info('offline');
2018-04-27 21:25:04 +00:00
window.removeEventListener('offline', onOffline);
window.addEventListener('online', onOnline);
2018-04-27 21:25:04 +00:00
// We've received logs from Linux where we get an 'offline' event, then 30ms later
// we get an online event. This waits a bit after getting an 'offline' event
// before disconnecting the socket manually.
disconnectTimer = setTimeout(disconnect, 1000);
}
2018-04-27 21:25:04 +00:00
function onOnline() {
window.log.info('online');
2018-04-27 21:25:04 +00:00
window.removeEventListener('online', onOnline);
window.addEventListener('offline', onOffline);
2018-04-27 21:25:04 +00:00
if (disconnectTimer && isSocketOnline()) {
window.log.warn('Already online. Had a blip in online/offline status.');
2018-04-27 21:25:04 +00:00
clearTimeout(disconnectTimer);
disconnectTimer = null;
return;
}
2018-04-27 21:25:04 +00:00
if (disconnectTimer) {
clearTimeout(disconnectTimer);
disconnectTimer = null;
}
2018-04-27 21:25:04 +00:00
connect();
}
function isSocketOnline() {
2018-05-25 01:50:49 +00:00
const socketStatus = window.getSocketStatus();
2018-04-27 21:25:04 +00:00
return (
socketStatus === WebSocket.CONNECTING || socketStatus === WebSocket.OPEN
);
}
2018-04-27 21:25:04 +00:00
function disconnect() {
window.log.info('disconnect');
2018-04-27 21:25:04 +00:00
// Clear timer, since we're only called when the timer is expired
disconnectTimer = null;
if (messageReceiver) {
messageReceiver.close();
}
window.Signal.AttachmentDownloads.stop();
2018-04-27 21:25:04 +00:00
}
2018-05-25 01:50:49 +00:00
let connectCount = 0;
let connecting = false;
async function connect(firstRun?: boolean) {
if (connecting) {
window.log.warn('connect already running', { connectCount });
2018-04-27 21:25:04 +00:00
return;
}
try {
connecting = true;
window.log.info('connect', { firstRun, connectCount });
if (reconnectTimer) {
clearTimeout(reconnectTimer);
reconnectTimer = null;
}
2020-09-04 01:25:19 +00:00
// Bootstrap our online/offline detection, only the first time we connect
if (connectCount === 0 && navigator.onLine) {
window.addEventListener('offline', onOffline);
}
if (connectCount === 0 && !navigator.onLine) {
window.log.warn(
'Starting up offline; will connect when we have network access'
);
window.addEventListener('online', onOnline);
onEmpty(); // this ensures that the loading screen is dismissed
return;
}
2019-09-26 19:56:31 +00:00
if (!window.Signal.Util.Registration.everDone()) {
return;
}
2019-09-26 19:56:31 +00:00
preMessageReceiverStatus = WebSocket.CONNECTING;
if (messageReceiver) {
await messageReceiver.stopProcessing();
await window.waitForAllBatchers();
messageReceiver.unregisterBatchers();
2020-09-04 01:25:19 +00:00
messageReceiver = null;
2020-09-09 02:25:05 +00:00
}
2020-09-04 01:25:19 +00:00
const OLD_USERNAME = window.storage.get('number_id');
const USERNAME = window.storage.get('uuid_id');
const PASSWORD = window.storage.get('password');
const mySignalingKey = window.storage.get('signaling_key');
2020-09-09 02:25:05 +00:00
window.textsecure.messaging = new window.textsecure.MessageSender(
USERNAME || OLD_USERNAME,
PASSWORD
);
if (connectCount === 0) {
try {
// Force a re-fetch before we process our queue. We may want to turn on
// something which changes how we process incoming messages!
await window.Signal.RemoteConfig.refreshRemoteConfig();
} catch (error) {
window.log.error(
'connect: Error refreshing remote config:',
error && error.stack ? error.stack : error
);
}
try {
if (window.Signal.RemoteConfig.isEnabled('desktop.cds')) {
const lonelyE164s = window
.getConversations()
.filter(c =>
Boolean(
c.isPrivate() &&
c.get('e164') &&
!c.get('uuid') &&
!c.isEverUnregistered()
)
)
.map(c => c.get('e164'));
if (lonelyE164s.length > 0) {
const lookup = await window.textsecure.messaging.getUuidsForE164s(
lonelyE164s as WhatIsThis
);
const e164s = Object.keys(lookup);
e164s.forEach(e164 => {
const uuid = lookup[e164];
if (!uuid) {
const byE164 = window.ConversationController.get(e164);
if (byE164) {
byE164.setUnregistered();
}
2020-09-09 02:25:05 +00:00
}
window.ConversationController.ensureContactIds({
e164,
uuid,
highTrust: true,
});
2020-09-09 02:25:05 +00:00
});
}
2020-09-09 02:25:05 +00:00
}
} catch (error) {
window.log.error(
'connect: Error fetching UUIDs for lonely e164s:',
error && error.stack ? error.stack : error
);
2020-09-04 01:25:19 +00:00
}
}
connectCount += 1;
window.Whisper.deliveryReceiptQueue.pause(); // avoid flood of delivery receipts until we catch up
window.Whisper.Notifications.disable(); // avoid notification flood until empty
// initialize the socket and start listening for messages
window.log.info('Initializing socket and listening for messages');
const messageReceiverOptions = {
serverTrustRoot: window.getServerTrustRoot(),
};
messageReceiver = new window.textsecure.MessageReceiver(
OLD_USERNAME,
USERNAME,
PASSWORD,
mySignalingKey,
messageReceiverOptions as WhatIsThis
);
window.textsecure.messageReceiver = messageReceiver;
window.Signal.Services.initializeGroupCredentialFetcher();
preMessageReceiverStatus = null;
// eslint-disable-next-line no-inner-declarations
function addQueuedEventListener(name: WhatIsThis, handler: WhatIsThis) {
messageReceiver.addEventListener(name, (...args: Array<WhatIsThis>) =>
eventHandlerQueue.add(async () => {
try {
await handler(...args);
} finally {
// message/sent: Message.handleDataMessage has its own queue and will
// trigger this event itself when complete.
// error: Error processing (below) also has its own queue and self-trigger.
if (name !== 'message' && name !== 'sent' && name !== 'error') {
window.Whisper.events.trigger('incrementProgress');
}
}
})
);
}
addQueuedEventListener('message', onMessageReceived);
addQueuedEventListener('delivery', onDeliveryReceipt);
addQueuedEventListener('contact', onContactReceived);
addQueuedEventListener('group', onGroupReceived);
addQueuedEventListener('sent', onSentMessage);
addQueuedEventListener('readSync', onReadSync);
addQueuedEventListener('read', onReadReceipt);
addQueuedEventListener('verified', onVerified);
addQueuedEventListener('error', onError);
addQueuedEventListener('empty', onEmpty);
addQueuedEventListener('reconnect', onReconnect);
addQueuedEventListener('configuration', onConfiguration);
addQueuedEventListener('typing', onTyping);
addQueuedEventListener('sticker-pack', onStickerPack);
addQueuedEventListener('viewSync', onViewSync);
addQueuedEventListener(
'messageRequestResponse',
onMessageRequestResponse
);
addQueuedEventListener('profileKeyUpdate', onProfileKeyUpdate);
addQueuedEventListener('fetchLatest', onFetchLatestSync);
addQueuedEventListener('keys', onKeysSync);
window.Signal.AttachmentDownloads.start({
getMessageReceiver: () => messageReceiver,
logger: window.log,
});
if (connectCount === 1) {
window.Signal.Stickers.downloadQueuedPacks();
if (!newVersion) {
runStorageService();
}
}
// On startup after upgrading to a new version, request a contact sync
// (but only if we're not the primary device)
if (
!firstRun &&
connectCount === 1 &&
newVersion &&
// eslint-disable-next-line eqeqeq
window.textsecure.storage.user.getDeviceId() != '1'
) {
window.log.info('Boot after upgrading. Requesting contact sync');
window.getSyncRequest();
runStorageService();
try {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const manager = window.getAccountManager()!;
await Promise.all([
manager.maybeUpdateDeviceName(),
manager.maybeDeleteSignalingKey(),
]);
} catch (e) {
window.log.error(
'Problem with account manager updates after starting new version: ',
e && e.stack ? e.stack : e
);
}
}
const udSupportKey = 'hasRegisterSupportForUnauthenticatedDelivery';
if (!window.storage.get(udSupportKey)) {
const server = window.WebAPI.connect({
username: USERNAME || OLD_USERNAME,
password: PASSWORD,
});
try {
await server.registerSupportForUnauthenticatedDelivery();
window.storage.put(udSupportKey, true);
} catch (error) {
window.log.error(
'Error: Unable to register for unauthenticated delivery support.',
error && error.stack ? error.stack : error
);
}
}
const deviceId = window.textsecure.storage.user.getDeviceId();
// If we didn't capture a UUID on registration, go get it from the server
if (!window.textsecure.storage.user.getUuid()) {
const server = window.WebAPI.connect({
username: OLD_USERNAME,
password: PASSWORD,
});
try {
const { uuid } = await server.whoami();
window.textsecure.storage.user.setUuidAndDeviceId(
uuid,
deviceId as WhatIsThis
);
const ourNumber = window.textsecure.storage.user.getNumber();
const me = await window.ConversationController.getOrCreateAndWait(
ourNumber,
'private'
);
me.updateUuid(uuid);
} catch (error) {
window.log.error(
'Error: Unable to retrieve UUID from service.',
error && error.stack ? error.stack : error
);
}
2020-10-30 17:56:03 +00:00
}
// We need to do this after fetching our UUID
const hasRegisteredGV23Support = 'hasRegisteredGV23Support';
if (
!window.storage.get(hasRegisteredGV23Support) &&
window.textsecure.storage.user.getUuid()
) {
const server = window.WebAPI.connect({
username: USERNAME || OLD_USERNAME,
password: PASSWORD,
});
try {
await server.registerCapabilities({ 'gv2-3': true });
window.storage.put(hasRegisteredGV23Support, true);
} catch (error) {
window.log.error(
'Error: Unable to register support for GV2.',
error && error.stack ? error.stack : error
);
}
}
if (firstRun === true && deviceId !== '1') {
const hasThemeSetting = Boolean(window.storage.get('theme-setting'));
if (
!hasThemeSetting &&
window.textsecure.storage.get('userAgent') === 'OWI'
) {
window.storage.put('theme-setting', 'ios');
onChangeTheme();
}
const syncRequest = new window.textsecure.SyncRequest(
window.textsecure.messaging,
messageReceiver
);
window.Whisper.events.trigger('contactsync:begin');
syncRequest.addEventListener('success', () => {
window.log.info('sync successful');
window.storage.put('synced_at', Date.now());
window.Whisper.events.trigger('contactsync');
runStorageService();
});
syncRequest.addEventListener('timeout', () => {
window.log.error('sync timed out');
window.Whisper.events.trigger('contactsync');
runStorageService();
});
const ourId = window.ConversationController.getOurConversationId();
const {
wrap,
sendOptions,
} = window.ConversationController.prepareForSend(ourId, {
syncMessage: true,
});
const installedStickerPacks = window.Signal.Stickers.getInstalledStickerPacks();
if (installedStickerPacks.length) {
const operations = installedStickerPacks.map((pack: WhatIsThis) => ({
packId: pack.id,
packKey: pack.key,
installed: true,
}));
wrap(
window.textsecure.messaging.sendStickerPackSync(
operations,
sendOptions
)
).catch(error => {
window.log.error(
'Failed to send installed sticker packs via sync message',
error && error.stack ? error.stack : error
);
});
}
}
window.storage.onready(async () => {
idleDetector.start();
});
} finally {
connecting = false;
}
2018-04-30 17:53:07 +00:00
}
2018-04-27 21:25:04 +00:00
function onChangeTheme() {
2018-05-25 01:50:49 +00:00
const view = window.owsDesktopApp.appView;
2018-04-27 21:25:04 +00:00
if (view) {
view.applyTheme();
2018-04-25 01:32:47 +00:00
}
2018-04-27 21:25:04 +00:00
}
2020-09-09 02:25:05 +00:00
const FIVE_MINUTES = 5 * 60 * 1000;
// Note: once this function returns, there still might be messages being processed on
// a given conversation's queue. But we have processed all events from the websocket.
async function waitForEmptyEventQueue() {
if (!messageReceiver) {
window.log.info(
'waitForEmptyEventQueue: No messageReceiver available, returning early'
);
return;
}
if (!messageReceiver.hasEmptied()) {
window.log.info(
'waitForEmptyEventQueue: Waiting for MessageReceiver empty event...'
);
let resolve: WhatIsThis;
let reject: WhatIsThis;
2020-09-09 02:25:05 +00:00
const promise = new Promise((innerResolve, innerReject) => {
resolve = innerResolve;
reject = innerReject;
});
const timeout = setTimeout(reject, FIVE_MINUTES);
const onEmptyOnce = () => {
messageReceiver.removeEventListener('empty', onEmptyOnce);
clearTimeout(timeout);
resolve();
};
messageReceiver.addEventListener('empty', onEmptyOnce);
await promise;
}
window.log.info(
'waitForEmptyEventQueue: Waiting for event handler queue idle...'
);
await eventHandlerQueue.onIdle();
}
window.waitForEmptyEventQueue = waitForEmptyEventQueue;
2019-09-26 19:56:31 +00:00
async function onEmpty() {
await Promise.all([
window.waitForAllBatchers(),
window.waitForAllWaitBatchers(),
]);
window.log.info('onEmpty: All outstanding database requests complete');
2018-04-27 21:25:04 +00:00
initialLoadComplete = true;
window.readyForUpdates();
// Start listeners here, after we get through our queue.
window.Whisper.RotateSignedPreKeyListener.init(
window.Whisper.events,
newVersion
);
window.Signal.RefreshSenderCertificate.initialize({
events: window.Whisper.events,
storage: window.storage,
navigator,
logger: window.log,
});
let interval: NodeJS.Timer | null = setInterval(() => {
2018-05-25 01:50:49 +00:00
const view = window.owsDesktopApp.appView;
2018-04-27 21:25:04 +00:00
if (view) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
clearInterval(interval!);
2018-04-27 21:25:04 +00:00
interval = null;
view.onEmpty();
}
}, 500);
window.Whisper.deliveryReceiptQueue.start();
window.Whisper.Notifications.enable();
2018-04-27 21:25:04 +00:00
}
function onReconnect() {
// We disable notifications on first connect, but the same applies to reconnect. In
// scenarios where we're coming back from sleep, we can get offline/online events
// very fast, and it looks like a network blip. But we need to suppress
// notifications in these scenarios too. So we listen for 'reconnect' events.
window.Whisper.deliveryReceiptQueue.pause();
window.Whisper.Notifications.disable();
}
let initialStartupCount = 0;
window.Whisper.events.on('incrementProgress', incrementProgress);
function incrementProgress() {
initialStartupCount += 1;
// Only update progress every 10 items
if (initialStartupCount % 10 !== 0) {
return;
}
window.log.info(
`incrementProgress: Message count is ${initialStartupCount}`
);
2018-05-25 01:50:49 +00:00
const view = window.owsDesktopApp.appView;
2018-04-27 21:25:04 +00:00
if (view) {
view.onProgress(initialStartupCount);
}
2018-04-27 21:25:04 +00:00
}
window.Whisper.events.on('manualConnect', manualConnect);
function manualConnect() {
if (isSocketOnline()) {
window.log.info('manualConnect: already online; not connecting again');
return;
}
window.log.info('manualConnect: calling connect()');
connect();
}
function onConfiguration(ev: WhatIsThis) {
2019-09-26 19:56:31 +00:00
ev.confirm();
const { configuration } = ev;
2018-11-14 19:10:32 +00:00
const {
readReceipts,
typingIndicators,
unidentifiedDeliveryIndicators,
2019-01-16 03:03:56 +00:00
linkPreviews,
2018-11-14 19:10:32 +00:00
} = configuration;
window.storage.put('read-receipt-setting', readReceipts);
if (
unidentifiedDeliveryIndicators === true ||
unidentifiedDeliveryIndicators === false
) {
window.storage.put(
'unidentifiedDeliveryIndicators',
unidentifiedDeliveryIndicators
);
}
2018-11-14 19:10:32 +00:00
if (typingIndicators === true || typingIndicators === false) {
window.storage.put('typingIndicators', typingIndicators);
2018-11-14 19:10:32 +00:00
}
2019-01-16 03:03:56 +00:00
if (linkPreviews === true || linkPreviews === false) {
window.storage.put('linkPreviews', linkPreviews);
2019-01-16 03:03:56 +00:00
}
2018-04-27 21:25:04 +00:00
}
function onTyping(ev: WhatIsThis) {
2019-09-26 19:56:31 +00:00
// Note: this type of message is automatically removed from cache in MessageReceiver
const { typing, sender, senderUuid, senderDevice } = ev;
2020-09-09 02:25:05 +00:00
const { groupId, groupV2Id, started } = typing || {};
2018-11-14 19:10:32 +00:00
// We don't do anything with incoming typing messages if the setting is disabled
if (!window.storage.get('typingIndicators')) {
2018-11-14 19:10:32 +00:00
return;
}
const senderId = window.ConversationController.ensureContactIds({
2020-06-12 22:36:32 +00:00
e164: sender,
uuid: senderUuid,
highTrust: true,
2020-06-12 22:36:32 +00:00
});
const conversation = window.ConversationController.get(
2020-09-09 02:25:05 +00:00
groupV2Id || groupId || senderId
);
const ourId = window.ConversationController.getOurConversationId();
2018-11-14 19:10:32 +00:00
2020-09-09 02:25:05 +00:00
if (!conversation) {
window.log.warn(
`onTyping: Did not find conversation for typing indicator (groupv2(${groupV2Id}), group(${groupId}), ${sender}, ${senderUuid})`
);
return;
}
2019-05-13 22:00:41 +00:00
2020-09-09 02:25:05 +00:00
// We drop typing notifications in groups we're not a part of
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
if (!conversation.isPrivate() && !conversation.hasMember(ourId!)) {
2020-09-09 02:25:05 +00:00
window.log.warn(
`Received typing indicator for group ${conversation.idForLogging()}, which we're not a part of. Dropping.`
);
return;
2018-11-14 19:10:32 +00:00
}
2020-09-09 02:25:05 +00:00
conversation.notifyTyping({
isTyping: started,
isMe: ourId === senderId,
sender,
senderUuid,
senderId,
senderDevice,
} as WhatIsThis);
2018-11-14 19:10:32 +00:00
}
async function onStickerPack(ev: WhatIsThis) {
2019-09-26 19:56:31 +00:00
ev.confirm();
const packs = ev.stickerPacks || [];
packs.forEach((pack: WhatIsThis) => {
const { id, key, isInstall, isRemove } = pack || {};
if (!id || !key || (!isInstall && !isRemove)) {
window.log.warn(
'Received malformed sticker pack operation sync message'
);
return;
}
const status = window.Signal.Stickers.getStickerPackStatus(id);
if (status === 'installed' && isRemove) {
window.reduxActions.stickers.uninstallStickerPack(id, key, {
fromSync: true,
});
} else if (isInstall) {
if (status === 'downloaded') {
window.reduxActions.stickers.installStickerPack(id, key, {
fromSync: true,
});
} else {
window.Signal.Stickers.downloadStickerPack(id, key, {
finalStatus: 'installed',
fromSync: true,
});
}
}
});
}
async function onContactReceived(ev: WhatIsThis) {
2018-05-25 01:50:49 +00:00
const details = ev.contactDetails;
2018-04-27 21:25:04 +00:00
if (
(details.number &&
details.number === window.textsecure.storage.user.getNumber()) ||
(details.uuid &&
details.uuid === window.textsecure.storage.user.getUuid())
) {
2018-04-27 21:25:04 +00:00
// special case for syncing details about ourselves
if (details.profileKey) {
window.log.info('Got sync message with our own profile key');
window.storage.put('profileKey', details.profileKey);
2018-04-27 21:25:04 +00:00
}
}
2018-04-27 21:25:04 +00:00
const c = new window.Whisper.Conversation({
e164: details.number,
uuid: details.uuid,
type: 'private',
} as WhatIsThis);
const validationError = c.validate();
2018-05-25 01:50:49 +00:00
if (validationError) {
window.log.error(
2018-05-25 01:50:49 +00:00
'Invalid contact received:',
Errors.toLogFormat(validationError as WhatIsThis)
2018-05-25 01:50:49 +00:00
);
2018-04-27 21:25:04 +00:00
return;
Feature: Blue check marks for read messages if opted in (#1489) * Refactor delivery receipt event handler * Rename the delivery receipt event For less ambiguity with read receipts. * Rename synced read event For less ambiguity with read receipts from other Signal users. * Add support for incoming receipt messages Handle ReceiptMessages, which may include encrypted delivery receipts or read receipts from recipients of our sent messages. // FREEBIE * Rename ReadReceipts to ReadSyncs * Render read messages with blue double checks * Send read receipts to senders of incoming messages // FREEBIE * Move ReadSyncs to their own file // FREEBIE * Fixup old comments on read receipts (now read syncs) And some variable renaming for extra clarity. // FREEBIE * Add global setting for read receipts Don't send read receipt messages unless the setting is enabled. Don't process read receipts if the setting is disabled. // FREEBIE * Sync read receipt setting from mobile Toggling this setting on your mobile device should sync it to Desktop. When linking, use the setting in the provisioning message. // FREEBIE * Send receipt messages silently Avoid generating phantom messages on ios // FREEBIE * Save recipients on the outgoing message models For accurate tracking and display of sent/delivered/read state, even if group membership changes later. // FREEBIE * Fix conversation type in profile key update handling // FREEBIE * Set recipients on synced sent messages * Render saved recipients in message detail if available For older messages, where we did not save the intended set of recipients at the time of sending, fall back to the current group membership. // FREEBIE * Record who has been successfully sent to // FREEBIE * Record who a message has been delivered to * Invert the not-clickable class * Fix readReceipt setting sync when linking * Render per recipient sent/delivered/read status In the message detail view for outgoing messages, render each recipient's individual sent/delivered/read status with respect to this message, as long as there are no errors associated with the recipient (ie, safety number changes, user not registered, etc...) since the error icon is displayed in that case. *Messages sent before this change may not have per-recipient status lists and will simply show no status icon. // FREEBIE * Add configuration sync request Send these requests in a one-off fashion when: 1. We have just setup from a chrome app import 2. We have just upgraded to read-receipt support // FREEBIE * Expose sendRequestConfigurationSyncMessage // FREEBIE * Fix handling of incoming delivery receipts - union with array FREEBIE
2017-10-04 22:28:43 +00:00
}
2018-05-25 01:50:49 +00:00
try {
const detailsId = window.ConversationController.ensureContactIds({
2020-06-12 22:36:32 +00:00
e164: details.number,
uuid: details.uuid,
highTrust: true,
2020-06-12 22:36:32 +00:00
});
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const conversation = window.ConversationController.get(detailsId)!;
2018-05-25 01:50:49 +00:00
let activeAt = conversation.get('active_at');
2018-04-27 21:25:04 +00:00
2018-05-25 01:50:49 +00:00
// The idea is to make any new contact show up in the left pane. If
// activeAt is null, then this contact has been purposefully hidden.
if (activeAt !== null) {
activeAt = activeAt || Date.now();
}
2018-05-25 01:50:49 +00:00
if (details.profileKey) {
const profileKey = window.Signal.Crypto.arrayBufferToBase64(
details.profileKey
2018-09-21 01:47:19 +00:00
);
conversation.setProfileKey(profileKey);
} else {
conversation.dropProfileKey();
2018-05-25 01:50:49 +00:00
}
Profiles (#1453) * Add AES-GCM encryption for profiles With tests. * Add profileKey to DataMessage protobuf // FREEBIE * Decrypt and save profile names // FREEBIE * Save incoming profile keys * Move pad/unpad to crypto module // FREEBIE * Support fetching avatars from the cdn // FREEBIE * Translate failed authentication errors When AES-GCM authentication fails, webcrypto returns a very generic error. The same error is thrown for invalid length inputs, but our earlier checks in decryptProfile should rule out those failure modes and leave us safe to assume that we either had bad ciphertext or the wrong key. // FREEBIE * Handle profile avatars (wip) and log decrypt errors // FREEBIE * Display profile avatars Synced contact avatars will still override profile avatars. * Display profile names in convo list Only if we don't have a synced contact name. // FREEBIE * Make cdn url an environment config Use different ones for staging and production // FREEBIE * Display profile name in conversation header * Display profile name in group messages * Update conversation header if profile avatar changes // FREEBIE * Style profile names small with ~ * Save profileKeys from contact sync messages // FREEBIE * Save profile keys from provisioning messages For standalone accounts, generate a random profile key. // FREEBIE * Special case for one-time sync of our profile key Android will use a contact sync message to sync a profile key from Android clients who have just upgraded and generated their profile key. Normally we should receive this data in a provisioning message. // FREEBIE * Infer profile sharing from synced data messages * Populate profile keys on outgoing messages Requires that `profileSharing` be set on the conversation. // FREEBIE * Support for the profile key update flag When receiving a message with this flag, don't init a message record, just process the profile key and move on. // FREEBIE * Display profile names in group member list * Refresh contact's profile on profile key changes // FREEBIE * Catch errors on profile save // FREEBIE * Save our own synced contact info Don't return early if we get a contact sync for our own number // FREEBIE
2017-09-11 16:50:35 +00:00
2018-05-25 01:50:49 +00:00
if (typeof details.blocked !== 'undefined') {
if (details.blocked) {
conversation.block();
2018-05-25 01:50:49 +00:00
} else {
conversation.unblock();
Profiles (#1453) * Add AES-GCM encryption for profiles With tests. * Add profileKey to DataMessage protobuf // FREEBIE * Decrypt and save profile names // FREEBIE * Save incoming profile keys * Move pad/unpad to crypto module // FREEBIE * Support fetching avatars from the cdn // FREEBIE * Translate failed authentication errors When AES-GCM authentication fails, webcrypto returns a very generic error. The same error is thrown for invalid length inputs, but our earlier checks in decryptProfile should rule out those failure modes and leave us safe to assume that we either had bad ciphertext or the wrong key. // FREEBIE * Handle profile avatars (wip) and log decrypt errors // FREEBIE * Display profile avatars Synced contact avatars will still override profile avatars. * Display profile names in convo list Only if we don't have a synced contact name. // FREEBIE * Make cdn url an environment config Use different ones for staging and production // FREEBIE * Display profile name in conversation header * Display profile name in group messages * Update conversation header if profile avatar changes // FREEBIE * Style profile names small with ~ * Save profileKeys from contact sync messages // FREEBIE * Save profile keys from provisioning messages For standalone accounts, generate a random profile key. // FREEBIE * Special case for one-time sync of our profile key Android will use a contact sync message to sync a profile key from Android clients who have just upgraded and generated their profile key. Normally we should receive this data in a provisioning message. // FREEBIE * Infer profile sharing from synced data messages * Populate profile keys on outgoing messages Requires that `profileSharing` be set on the conversation. // FREEBIE * Support for the profile key update flag When receiving a message with this flag, don't init a message record, just process the profile key and move on. // FREEBIE * Display profile names in group member list * Refresh contact's profile on profile key changes // FREEBIE * Catch errors on profile save // FREEBIE * Save our own synced contact info Don't return early if we get a contact sync for our own number // FREEBIE
2017-09-11 16:50:35 +00:00
}
2018-05-25 01:50:49 +00:00
}
Profiles (#1453) * Add AES-GCM encryption for profiles With tests. * Add profileKey to DataMessage protobuf // FREEBIE * Decrypt and save profile names // FREEBIE * Save incoming profile keys * Move pad/unpad to crypto module // FREEBIE * Support fetching avatars from the cdn // FREEBIE * Translate failed authentication errors When AES-GCM authentication fails, webcrypto returns a very generic error. The same error is thrown for invalid length inputs, but our earlier checks in decryptProfile should rule out those failure modes and leave us safe to assume that we either had bad ciphertext or the wrong key. // FREEBIE * Handle profile avatars (wip) and log decrypt errors // FREEBIE * Display profile avatars Synced contact avatars will still override profile avatars. * Display profile names in convo list Only if we don't have a synced contact name. // FREEBIE * Make cdn url an environment config Use different ones for staging and production // FREEBIE * Display profile name in conversation header * Display profile name in group messages * Update conversation header if profile avatar changes // FREEBIE * Style profile names small with ~ * Save profileKeys from contact sync messages // FREEBIE * Save profile keys from provisioning messages For standalone accounts, generate a random profile key. // FREEBIE * Special case for one-time sync of our profile key Android will use a contact sync message to sync a profile key from Android clients who have just upgraded and generated their profile key. Normally we should receive this data in a provisioning message. // FREEBIE * Infer profile sharing from synced data messages * Populate profile keys on outgoing messages Requires that `profileSharing` be set on the conversation. // FREEBIE * Support for the profile key update flag When receiving a message with this flag, don't init a message record, just process the profile key and move on. // FREEBIE * Display profile names in group member list * Refresh contact's profile on profile key changes // FREEBIE * Catch errors on profile save // FREEBIE * Save our own synced contact info Don't return early if we get a contact sync for our own number // FREEBIE
2017-09-11 16:50:35 +00:00
2018-09-21 01:47:19 +00:00
conversation.set({
name: details.name,
color: details.color,
active_at: activeAt,
inbox_position: details.inboxPosition,
2018-09-21 01:47:19 +00:00
});
// Update the conversation avatar only if new avatar exists and hash differs
const { avatar } = details;
if (avatar && avatar.data) {
const newAttributes = await window.Signal.Types.Conversation.maybeUpdateAvatar(
conversation.attributes,
avatar.data,
{
writeNewAttachmentData,
deleteAttachmentData,
doesAttachmentExist,
2018-09-21 01:47:19 +00:00
}
);
conversation.set(newAttributes);
} else {
const { attributes } = conversation;
if (attributes.avatar && attributes.avatar.path) {
await deleteAttachmentData(attributes.avatar.path);
}
conversation.set({ avatar: null });
2018-09-21 01:47:19 +00:00
}
window.Signal.Data.updateConversation(conversation.attributes);
2018-05-25 01:50:49 +00:00
const { expireTimer } = details;
const isValidExpireTimer = typeof expireTimer === 'number';
if (isValidExpireTimer) {
const ourId = window.ConversationController.getOurConversationId();
const receivedAt = Date.now();
await conversation.updateExpirationTimer(
expireTimer,
2020-06-12 22:36:32 +00:00
ourId,
receivedAt,
2020-06-12 22:36:32 +00:00
{
fromSync: true,
}
);
2018-05-25 01:50:49 +00:00
}
if (details.verified) {
const { verified } = details;
const verifiedEvent = new Event('verified');
verifiedEvent.verified = {
state: verified.state,
destination: verified.destination,
destinationUuid: verified.destinationUuid,
2018-05-25 01:50:49 +00:00
identityKey: verified.identityKey.toArrayBuffer(),
};
(verifiedEvent as WhatIsThis).viaContactSync = true;
2018-05-25 01:50:49 +00:00
await onVerified(verifiedEvent);
}
const { appView } = window.owsDesktopApp;
if (appView && appView.installView && appView.installView.didLink) {
window.log.info(
'onContactReceived: Adding the message history disclaimer on link'
);
await conversation.addMessageHistoryDisclaimer();
}
2018-05-25 01:50:49 +00:00
} catch (error) {
window.log.error('onContactReceived error:', Errors.toLogFormat(error));
2018-05-25 01:50:49 +00:00
}
2018-04-27 21:25:04 +00:00
}
2020-09-09 02:25:05 +00:00
// Note: this handler is only for v1 groups received via 'group sync' messages
async function onGroupReceived(ev: WhatIsThis) {
2018-05-25 01:50:49 +00:00
const details = ev.groupDetails;
const { id } = details;
2018-04-27 21:25:04 +00:00
const idBuffer = window.Signal.Crypto.fromEncodedBinaryToArrayBuffer(id);
const idBytes = idBuffer.byteLength;
if (idBytes !== 16) {
window.log.error(
`onGroupReceived: Id was ${idBytes} bytes, expected 16 bytes. Dropping group.`
);
return;
}
const conversation = await window.ConversationController.getOrCreateAndWait(
2018-05-25 01:50:49 +00:00
id,
'group'
);
2020-10-02 22:19:52 +00:00
if (conversation.isGroupV2()) {
2020-09-09 02:25:05 +00:00
window.log.warn(
'Got group sync for v2 group: ',
conversation.idForLogging()
2020-09-09 02:25:05 +00:00
);
return;
}
2018-09-21 01:47:19 +00:00
const memberConversations = details.membersE164.map((e164: WhatIsThis) =>
window.ConversationController.getOrCreate(e164, 'private')
);
const members = memberConversations.map((c: WhatIsThis) => c.get('id'));
2018-05-25 01:50:49 +00:00
const updates = {
name: details.name,
members,
color: details.color,
2018-05-25 01:50:49 +00:00
type: 'group',
inbox_position: details.inboxPosition,
} as WhatIsThis;
2018-09-21 01:47:19 +00:00
2018-05-25 01:50:49 +00:00
if (details.active) {
const activeAt = conversation.get('active_at');
2018-04-27 21:25:04 +00:00
2018-05-25 01:50:49 +00:00
// The idea is to make any new group show up in the left pane. If
// activeAt is null, then this group has been purposefully hidden.
if (activeAt !== null) {
updates.active_at = activeAt || Date.now();
2018-04-27 21:25:04 +00:00
}
2018-05-25 01:50:49 +00:00
updates.left = false;
} else {
updates.left = true;
}
if (details.blocked) {
conversation.block();
} else {
conversation.unblock();
}
2018-09-21 01:47:19 +00:00
conversation.set(updates);
// Update the conversation avatar only if new avatar exists and hash differs
const { avatar } = details;
if (avatar && avatar.data) {
const newAttributes = await window.Signal.Types.Conversation.maybeUpdateAvatar(
conversation.attributes,
avatar.data,
{
writeNewAttachmentData,
deleteAttachmentData,
doesAttachmentExist,
2018-09-21 01:47:19 +00:00
}
);
conversation.set(newAttributes);
}
window.Signal.Data.updateConversation(conversation.attributes);
const { appView } = window.owsDesktopApp;
if (appView && appView.installView && appView.installView.didLink) {
window.log.info(
'onGroupReceived: Adding the message history disclaimer on link'
);
await conversation.addMessageHistoryDisclaimer();
}
2018-05-25 01:50:49 +00:00
const { expireTimer } = details;
const isValidExpireTimer = typeof expireTimer === 'number';
if (!isValidExpireTimer) {
return;
}
const receivedAt = Date.now();
await conversation.updateExpirationTimer(
expireTimer,
window.ConversationController.getOurConversationId(),
receivedAt,
{
fromSync: true,
}
);
2018-05-25 01:50:49 +00:00
}
Auto-orient image attachments based on EXIF metadata As described in #998, images are sometimes displayed with an incorrect orientation. This is because cameras often write files in the native sensor byte order and attach the `Orientation` EXIF metadata to tell end-user devices how to display the images based on the original author’s capture orientation. Electron/Chromium (and therefore Signal Desktop) currently doesn’t support applying this metadata for `<img>` tags, e.g. CSS `image-orientation: from- image`. As a workaround, this change uses the `loadImage` library with the `orientation: true` flag to auto-orient images ~~before display~~ upon receipt and before sending. **Changes** - [x] ~~Auto-orient images during display in message list view~~ - [x] Ensure image is not displayed until loaded (to prevent layout reflow) . - [x] Auto-orient images upon receipt and before storing in IndexedDB (~~or preserve original data until Chromium offers native fix?~~) - [x] Auto-orient images in compose area preview. - [x] ~~Auto-orient images in lightbox view~~ - [x] Auto-orient images before sending / storage. - [x] Add EditorConfig for sharing code styles across editors. - [x] Fix ESLint ignore file. - [x] Change `function-paren-newline` ESLint rule from `consistent` to `multiline`. - [x] Add `operator-linebreak` ESLint rule for consistency. - [x] Added `blob-util` dependency for converting between array buffers, blobs, etc. - [x] Extracted `createMessageHandler` to consolidate logic for `onMessageReceived` and `onSentMessage`. - [x] Introduce `async` / `await` to simplify async coding (restore control flow for branching, loops, and exceptions). - [x] Introduce `window.Signal` namespace for exposing ES2015+ CommonJS modules. - [x] Introduce rudimentary `Message` and `Attachment` types to begin defining a schema and versioning. This will allow us to track which changes, e.g. auto-orient JPEGs, per message / attachment as well as which fields are stored. - [x] Renamed `window.dataURLtoBlob` to `window.dataURLToBlobSync` to both fix the strange `camelCase` as well as to highlight that this operation is synchronous and therefore blocks the user thread. - [x] Normalize all JPEG MIME types to `image/jpeg`, eliminating the invalid `image/jpg`. - [x] Add `npm run test-modules` command for testing non-browser specific CommonJS modules. - **Stretch Goals** - [ ] ~~Restrict `autoOrientImage` to `Blob` to narrow API interface.~~ Do this once we use PureScript. - [ ] ~~Return non-JPEGs as no-op from `autoOrientImage`.~~ Skipping `autoOrientImage` for non-JPEGs altogether. - [ ] Retroactively auto-orient existing JPEG image attachments in the background. --- Fixes #998 --- - **Blog:** EXIF Orientation Handling Is a Ghetto: https://www.daveperrett.com/articles/2012/07/28/exif-orientation-handling-is-a-ghetto/ - **Chromium Bug:** EXIF orientation is ignored: https://bugs.chromium.org/p/chromium/issues/detail?id=56845 - **Chromium Bug:** Support for the CSS image-orientation CSS property: https://bugs.chromium.org/p/chromium/issues/detail?id=158753 --- commit ce5090b473a2448229dc38e4c3f15d7ad0137714 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 16 10:35:36 2018 -0500 Inline message descriptors commit 329036e59c138c1e950ec7c654eebd7d87076de5 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Thu Feb 15 17:34:40 2018 -0500 Clarify order of operations Semantically, it makes more sense to do `getFile` before `clearForm` even though it seems to work either way. commit f9d4cfb2ba0d8aa308b0923bbe6066ea34cb97bd Author: Daniel Gasienica <daniel@gasienica.ch> Date: Thu Feb 15 17:18:26 2018 -0500 Simplify `operator-linebreak` configuration Enabling `before` caused more code changes and it turns out our previous configuration is already the default. commit db588997acdd90ed2ad829174ecbba744383c78b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Thu Feb 15 17:15:59 2018 -0500 Remove obsolete TODO commit 799c8817633f6afa0b731fc3b5434e463bd850e3 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Thu Feb 15 17:12:18 2018 -0500 Enable ESLint `function-paren-newline` `multiline` Per discussion. commit b660b6bc8ef41df7601a411213d6cda80821df87 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Thu Feb 15 17:10:48 2018 -0500 Use `messageDescriptor.id` not `source` commit 5e7309d176f4a7e97d3dc4c738e6b0ccd4792871 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 16:29:01 2018 -0500 Remove unnecessary `eslint-env` commit 393b3da55eabd7413596c86cc3971b063a0efe31 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 16:19:17 2018 -0500 Refactor `onSentMessage` and `onMessageReceived` Since they are so similar, we create the handlers using new `createMessageHandler` function. This allows us to ensure both synced and received messages go through schema upgrade pipeline. commit b3db0bf179c9a5bea96480cde28c6fa7193ac117 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 16:18:21 2018 -0500 Add `Message` descriptor functions commit 8febf125b1b42fe4ae1888dd50fcee2749dc1ff0 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 14:46:56 2018 -0500 Fix typo commit 98d951ef77bd578b313a4ff4b496b793e82e88d5 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 12:22:39 2018 -0500 Remove `promises` reference commit a0e9559ed5bed947dabf28cb672e63d39948d854 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 12:22:13 2018 -0500 Fix `AttachmentView::mediaType` fall-through commit 67be916a83951b8a1f9b22efe78a6da6b1825f38 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 12:03:41 2018 -0500 Remove minor TODOs commit 0af186e118256b62905de38487ffacc41693ff47 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 11:44:41 2018 -0500 Enable ESLint for `js/views/attachment_view.js` commit 28a2dc5b8a28e1a087924fdc7275bf7d9a577b92 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 11:44:12 2018 -0500 Remove dynamic type checks commit f4ce36fcfc2737de32d911cd6103f889097813f6 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 11:27:56 2018 -0500 Rename `process` to `upgradeSchema` - `Message.process` -> `Message.upgradeSchema` - `Attachment.process` -> `Attachment.upgradeSchema` - `Attachment::processVersion` -> `Attachment::schemaVersion` Document version history. commit 41b92c0a31050ba05ddb1c43171d651f3568b9ac Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 11:11:50 2018 -0500 Add `operator-linebreak` ESLint rule Based on the following discussion: https://github.com/signalapp/Signal-Desktop/pull/2040#discussion_r168029106 commit 462defbe55879060fe25bc69103d4429bae2b2f6 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 11:01:30 2018 -0500 Add missing `await` for `ConversationController.getOrCreateAndWait` Tested this by setting `if` condition to `true` and confirming it works. It turns rotating a profile key is more involved and might require registering a new account according to Matthew. commit c08058ee4b883b3e23a40683de802ac81ed74874 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 16:32:24 2018 -0500 Convert `FileList` to `Array` commit 70a6c4201925f57be1f94d9da3547fdefc7bbb53 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 15:46:34 2018 -0500 :art: Fix lint errors commit 2ca7cdbc31d4120d6c6a838a6dcf43bc209d9788 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 15:07:09 2018 -0500 Skip `autoOrientImage` for non-JPEG images commit 58eac383013c16ca363a4ed33dca5c7ba61284e5 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 14:55:35 2018 -0500 Move new-style modules to `window.Signal` namespace commit 02c9328877dce289d6116a18b1c223891bd3cd0b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 14:35:23 2018 -0500 Extract `npm run test-modules` command commit 2c708eb94fba468b81ea9427734896114f5a7807 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 13:25:51 2018 -0500 Extract `Message.process` commit 4a2e52f68a77536a0fa04aa3c29ad3e541a8fa7e Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 13:25:12 2018 -0500 Fix EditorConfig commit a346bab5db082720f5d47363f06301380e870425 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 13:13:02 2018 -0500 Remove `vim` directives on ESLint-ed files commit 7ec885c6359e495b407d5bc3eac9431d47c37fc6 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 13:08:24 2018 -0500 Remove CSP whitelisting of `blob:` We no longer use `autoOrientImage` using blob URLs. Bring this back if we decide to auto-orient legacy attachments. commit 879b6f58f4a3f4a9ed6915af6b1be46c1e90e0ca Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:57:05 2018 -0500 Use `Message` type to determine send function Throws on invalid message type. commit 5203d945c98fd2562ae4e22c5c9838d27dec305b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:56:48 2018 -0500 Whitelist `Whisper` global commit 8ad0b066a3690d3382b86bf6ac00c03df7d1e20b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:56:32 2018 -0500 Add `Whisper.Types` namespace This avoids namespace collision for `Whisper.Message`. commit 785a949fce2656ca7dcaf0869d6b9e0648114e80 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:55:43 2018 -0500 Add `Message` type commit 674a7357abf0dcc365455695d56c0479998ebf27 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:35:23 2018 -0500 Run ESLint on `Conversation::sendMessage` commit cd985aa700caa80946245b17ea1b856449f152a0 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:34:38 2018 -0500 Document type signature of `FileInputView::readFile` commit d70d70e52c49588a1dc9833dfe5dd7128e13607f Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:31:16 2018 -0500 Move attachment processing closer to sending This helps ensure processing happens uniformly, regardless of which code paths are taken to send an attachment. commit 532ac3e273a26b97f831247f9ee3412621b5c112 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:22:29 2018 -0500 Process attachment before it’s sent Picked this place since it already had various async steps, similar to `onMessageReceived` for the incoming `Attachment.process`. Could we try have this live closer to where we store it in IndexedDB, e.g. `Conversation::sendMessage`? commit a4582ae2fb6e1d3487131ba1f8fa6a00170cb32c Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:21:42 2018 -0500 Refactor `getFile` and `getFiles` Lint them using ESLint. commit 07e9114e65046d791fc4f6ed90d6e2e938ad559d Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:37:31 2018 -0500 Document incoming and outgoing attachments fields Note how outgoing message attachments only have 4 fields. This presumably means the others are not used in our code and could be discarded for simplicity. commit fdc3ef289d6ec1be344a12d496839d5ba747bb6a Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:36:21 2018 -0500 Highlight that `dataURLToBlob` is synchronous commit b9c6bf600fcecedfd649ef2ae3c8629cced4e45a Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:35:49 2018 -0500 Add EditorConfig configuration commit e56101e229d56810c8e31ad7289043a152c6c449 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:34:23 2018 -0500 Replace custom with `blob-util` functions IMPORTANT: All of them are async so we need to use `await`, otherwise we get strange or silent errors. commit f95150f6a9569fabcb31f3acd9f6b7bf50b5d145 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:17:30 2018 -0500 Revert "Replace custom functions with `blob-util`" This reverts commit 8a81e9c01bfe80c0e1bf76737092206c06949512. commit 33860d93f3d30ec55c32f3f4a58729df2eb43f0d Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:13:02 2018 -0500 Revert "Replace `blueimp-canvas-to-blob` with `blob-util`" This reverts commit 31b3e853e4afc78fe80995921aa4152d9f6e4783. commit 7a0ba6fed622d76a3c39c7f03de541a7edb5b8dd Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:12:58 2018 -0500 Replace `blueimp-canvas-to-blob` with `blob-util` commit 47a5f2bfd8b3f546e27e8d2b7e1969755d825a66 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 10:55:34 2018 -0500 Replace custom functions with `blob-util` commit 1cfa0efdb4fb1265369e2bf243c21f04f044fa01 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 10:47:02 2018 -0500 Add `blob-util` dependency commit 9ac26be1bd783cd5070d886de107dd3ad9c91ad1 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 10:46:44 2018 -0500 Document why we drop original image data during auto-orient commit 4136d6c382b99f41760a4da519d0db537fa7de8d Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 10:46:27 2018 -0500 Extract `DEFAULT_JPEG_QUALITY` commit 4a7156327eb5f94dba80cb300b344ac591226b0e Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 10:37:11 2018 -0500 Drop support for invalid `image/jpg` MIME type commit 69fe96581f25413194032232f1bf704312e4754c Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:54:30 2018 -0500 Document `window.onInvalidStateError` global commit a48ba1c77458da38583ee9cd488f70a59f6ee0fd Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:54:04 2018 -0500 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. commit e6d1cf826befc17ad4ec72fda8e761701665635e Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:16:23 2018 -0500 Move async attachment processing to `onMessageReceived` We previously processed attachments in `handleDataMessage` which is mostly a synchronous function, except for the saving of the model. Moving the processing into the already async `onMessageReceived` improves code clarity. commit be6ca2a9aae5b59c360817deb1e18d39d705755e Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:14:49 2018 -0500 Document import of ES2015+ modules commit eaaf7c41608fb988b8f4bbaa933cff110115610e Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:14:29 2018 -0500 :art: Fix lint error commit a25b0e2e3d0f72c6a7bf0a15683f02450d5209ee Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:13:57 2018 -0500 :art: Organize `require`s commit e0cc3d8fab6529d01b388acddf8605908c3d236b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:07:17 2018 -0500 Implement attachment process version Instead of keeping track of last normalization (processing) date, we now keep track of an internal processing version that will help us understand what kind of processing has already been completed for a given attachment. This will let us retroactively upgrade existing attachments. As we add more processing steps, we can build a processing pipeline that can convert any attachment processing version into a higher one, e.g. 4 -> 5 -> 6 -> 7. commit ad9083d0fdb880bc518e02251e51a39f7e1c585f Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:50:31 2018 -0500 Ignore ES2015+ files during JSCS linting commit 96641205f734927aaebc2342d977c555799c3e3b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:48:07 2018 -0500 Improve ESLint ignore rules Apparently, using unqualified `/**` patterns prevents `!` include patterns. Using qualified glob patterns, e.g. `js/models/**/*.js`, lets us work around this. commit 255e0ab15bd1a0ca8ca5746e42d23977c8765d01 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:44:59 2018 -0500 :abc: ESLint ignored files commit ebcb70258a26f234bd602072ac7c0a1913128132 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:35:47 2018 -0500 Whitelist `browser` environment for ESLint commit 3eaace6f3a21421c5aaaaf01592408c7ed83ecd3 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:35:05 2018 -0500 Use `MIME` module commit ba2cf7770e614415733414a2dcc48f110b929892 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:32:54 2018 -0500 :art: Fix lint errors commit 65acc86e8580e88f7a6611eb4b8fa5d7291f7a3f Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:30:42 2018 -0500 Add ES2015+ files to JSHint ignored list commit 8b6494ae6c9247acdfa059a9b361ec5ffcdb39f0 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:29:20 2018 -0500 Document potentially unexpected `autoScale` behavior commit 8b4c69b2002d1777d3621be10f92cbf432f9d4d6 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:26:47 2018 -0500 Test CommonJS modules separately Not sure how to test them as part of Grunt `unit-tests` task as `test/index.html` doesn’t allow for inclusion of CommonJS modules that use `require`. The tests are silently skipped. commit 213400e4b2bba3efee856a25b40e269221c3c39d Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:24:27 2018 -0500 Add `MIME` type module commit 37a726e4fb4b3ed65914463122a5662847b5adee Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 20:18:05 2018 -0500 Return proper `Error` from `blobArrayToBuffer` commit 164752db5612220e4dcf58d57bcd682cb489a399 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 20:15:41 2018 -0500 :art: Fix ESLint errors commit d498dd79a067c75098dd3179814c914780e5cb4f Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 20:14:33 2018 -0500 Update `Attachment` type field definitions commit 141155a1533ff8fb616b70ea313432781bbebffd Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 20:12:50 2018 -0500 Move `blueimp-canvas-to-blob` from Bower to npm commit 7ccb833e5d286ddd6235d3e491c62ac1e4544510 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:33:50 2018 -0500 :art: Clarify data flow commit e7da41591fde5a830467bebf1b6f51c1f7293e74 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:31:21 2018 -0500 Use `blobUrl` for consistency commit 523a80eefe0e2858aa1fb2bb9539ec44da502963 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:28:06 2018 -0500 Remove just-in-time image auto-orient for lightbox We can bring this back if our users would like auto-orient for old attachments. commit 0739feae9c47dd523c10740d6cdf746d539f270c Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:27:21 2018 -0500 Remove just-in-time auto-orient of message attachments We can bring this back if our users would like auto-orient for old attachments. But better yet, we might implement this as database migration. commit ed43c66f92830ee233d5a94d0545eea4da43894d Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:26:24 2018 -0500 Auto-orient JPEG attachments upon receipt commit e2eb8e36b017b048d57602fca14e45d657e0e1a1 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:25:26 2018 -0500 Expose `Attachment` type through `Whisper.Attachment` commit 9638fbc987b84f143ca34211dc4666d96248ea2f Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:23:39 2018 -0500 Use `contentType` from `model` commit 032c0ced46c3876cb9474b26f9d53d6f1c6b16a0 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:23:04 2018 -0500 Return `Error` object for `autoOrientImage` failures commit ff04bad8510c4b21aef350bed2b1887d0e055b98 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:22:32 2018 -0500 Add `options` for `autoOrientImage` output type / quality commit 87745b5586d1e182b51c9f9bc5e4eaf6dbc16722 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:18:46 2018 -0500 Add `Attachment` type Defines various functions on attachments, e.g. normalization (auto-orient JPEGs, etc.) commit de27fdc10a53bc8882a9c978e82265db9ac6d6f5 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:16:34 2018 -0500 Add `yarn grunt` shortcut This allows us to use local `grunt-cli` for `grunt dev`. commit 59974db5a5da0d8f4cdc8ce5c4e3c974ecd5e754 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 10:10:11 2018 -0500 Improve readability commit b5ba96f1e6f40f2e1fa77490c583217768e1f412 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 10:08:12 2018 -0500 Use `snake_case` for module names Prevents problems across case-sensitive and case-insensitive file systems. We can work around this in the future using a lint rule such as `eslint-plugin-require-path-exists`. See discussion: https://github.com/signalapp/Signal-Desktop/pull/2040#discussion_r167365931 commit 48c5d3155c96ef628b00d99b52975e580d1d5501 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 10:05:44 2018 -0500 :art: Use destructuring commit 4822f49f22382a99ebf142b337375f7c25251d76 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 17:41:40 2018 -0500 Auto-orient images in lightbox view commit 7317110809677dddbbef3fadbf912cdba1c010bf Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 17:40:14 2018 -0500 Document magic number for escape key commit c790d07389a7d0bbf5298de83dbcfa8be1e7696b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 17:38:35 2018 -0500 Make second `View` argument an `options` object commit fbe010bb63d0088af9dfe11f153437fab34247e0 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 17:27:40 2018 -0500 Allow `loadImage` to fetch `blob://` URLs commit ec35710d002b019a273eeb48f94dcaf2babe5d96 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:57:48 2018 -0500 :art: Shorten `autoOrientImage` import commit d07433e3cf316c6a143a0c9393ba26df9e3af17b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:57:19 2018 -0500 Make `autoOrientImage` module standalone commit c285bf5e33cdf10e0ef71e72cd6f55aef0df96ef Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:55:44 2018 -0500 Replace `loadImage` with `autoOrientImage` commit 44318549235af01fd061c25f557c93fd21cebb7a Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:53:23 2018 -0500 Add `autoOrientImage` module This module exposes `loadImage` with a `Promise` based interface and pre- populates `orientation: true` option to auto-orient input. Returns data URL as string. The module uses a named export as refactoring references of modules with `default` (`module.exports`) export references can be error-prone. See: https://basarat.gitbooks.io/typescript/docs/tips/defaultIsBad.html commit c77063afc6366fe49615052796fe46f9b369de39 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:44:30 2018 -0500 Auto-orient preview images See: #998 commit 06dba5eb8f662c11af3a9ba8395bb453ab2e5f8d Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:43:23 2018 -0500 TODO: Use native `Canvas::toBlob` One challenge is that `Canvas::toBlob` is async whereas `dataURLtoBlob` is sync. commit b15c304a3125dd023fd90990e6225a7303f3596f Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:42:45 2018 -0500 Make `null` check strict Appeases JSHint. ESLint has a nice `smart` option for `eqeqeq` rule: https://eslint.org/docs/rules/eqeqeq#smart commit ea70b92d9b18201758e11fdc25b09afc97b50055 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 15:23:58 2018 -0500 Use `Canvas::toDataURL` to preserve `ImageView` logic This way, all the other code paths remain untouched in case we want to remove the auto-orient code once Chrome supports the `image-orientation` CSS property. See: - #998 - https://developer.mozilla.org/en-US/docs/Web/CSS/image-orientation commit 62fd744f9f27d951573a68d2cdfe7ba2a3784b41 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 14:38:04 2018 -0500 Use CSS to constrain auto-oriented images commit f4d3392687168c237441b29140c7968b49dbef9e Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 14:35:02 2018 -0500 Replace `ImageView` `el` with auto-oriented `canvas` See: #998 commit 1602d7f610e4993ad1291f88197f9ead1e25e776 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 14:25:48 2018 -0500 Pass `Blob` to `View` (for `ImageView`) This allows us to do JPEG auto-orientation based on EXIF metadata. commit e6a414f2b2a80da1137b839b348a38510efd04bb Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 14:25:12 2018 -0500 :hocho: Remove newline commit 5f0d9570d7862fc428ff89c2ecfd332a744537e5 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 11:17:02 2018 -0500 Expose `blueimp-load-image` as `window.loadImage` commit 1e1c62fe2f6a76dbcf1998dd468c26187c9871dc Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 11:16:46 2018 -0500 Add `blueimp-load-image` npm dependency commit ad17fa8a68a21ca5ddec336801b8568009bef3d4 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 11:14:40 2018 -0500 Remove `blueimp-load-image` Bower dependency
2018-02-21 15:26:59 +00:00
// Received:
async function handleMessageReceivedProfileUpdate({
data,
confirm,
messageDescriptor,
}: WhatIsThis) {
2018-09-21 01:47:19 +00:00
const profileKey = data.message.profileKey.toString('base64');
const sender = window.ConversationController.get(messageDescriptor.id);
2018-09-21 01:47:19 +00:00
if (sender) {
// Will do the save for us
await sender.setProfileKey(profileKey);
}
2018-09-21 01:47:19 +00:00
Auto-orient image attachments based on EXIF metadata As described in #998, images are sometimes displayed with an incorrect orientation. This is because cameras often write files in the native sensor byte order and attach the `Orientation` EXIF metadata to tell end-user devices how to display the images based on the original author’s capture orientation. Electron/Chromium (and therefore Signal Desktop) currently doesn’t support applying this metadata for `<img>` tags, e.g. CSS `image-orientation: from- image`. As a workaround, this change uses the `loadImage` library with the `orientation: true` flag to auto-orient images ~~before display~~ upon receipt and before sending. **Changes** - [x] ~~Auto-orient images during display in message list view~~ - [x] Ensure image is not displayed until loaded (to prevent layout reflow) . - [x] Auto-orient images upon receipt and before storing in IndexedDB (~~or preserve original data until Chromium offers native fix?~~) - [x] Auto-orient images in compose area preview. - [x] ~~Auto-orient images in lightbox view~~ - [x] Auto-orient images before sending / storage. - [x] Add EditorConfig for sharing code styles across editors. - [x] Fix ESLint ignore file. - [x] Change `function-paren-newline` ESLint rule from `consistent` to `multiline`. - [x] Add `operator-linebreak` ESLint rule for consistency. - [x] Added `blob-util` dependency for converting between array buffers, blobs, etc. - [x] Extracted `createMessageHandler` to consolidate logic for `onMessageReceived` and `onSentMessage`. - [x] Introduce `async` / `await` to simplify async coding (restore control flow for branching, loops, and exceptions). - [x] Introduce `window.Signal` namespace for exposing ES2015+ CommonJS modules. - [x] Introduce rudimentary `Message` and `Attachment` types to begin defining a schema and versioning. This will allow us to track which changes, e.g. auto-orient JPEGs, per message / attachment as well as which fields are stored. - [x] Renamed `window.dataURLtoBlob` to `window.dataURLToBlobSync` to both fix the strange `camelCase` as well as to highlight that this operation is synchronous and therefore blocks the user thread. - [x] Normalize all JPEG MIME types to `image/jpeg`, eliminating the invalid `image/jpg`. - [x] Add `npm run test-modules` command for testing non-browser specific CommonJS modules. - **Stretch Goals** - [ ] ~~Restrict `autoOrientImage` to `Blob` to narrow API interface.~~ Do this once we use PureScript. - [ ] ~~Return non-JPEGs as no-op from `autoOrientImage`.~~ Skipping `autoOrientImage` for non-JPEGs altogether. - [ ] Retroactively auto-orient existing JPEG image attachments in the background. --- Fixes #998 --- - **Blog:** EXIF Orientation Handling Is a Ghetto: https://www.daveperrett.com/articles/2012/07/28/exif-orientation-handling-is-a-ghetto/ - **Chromium Bug:** EXIF orientation is ignored: https://bugs.chromium.org/p/chromium/issues/detail?id=56845 - **Chromium Bug:** Support for the CSS image-orientation CSS property: https://bugs.chromium.org/p/chromium/issues/detail?id=158753 --- commit ce5090b473a2448229dc38e4c3f15d7ad0137714 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 16 10:35:36 2018 -0500 Inline message descriptors commit 329036e59c138c1e950ec7c654eebd7d87076de5 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Thu Feb 15 17:34:40 2018 -0500 Clarify order of operations Semantically, it makes more sense to do `getFile` before `clearForm` even though it seems to work either way. commit f9d4cfb2ba0d8aa308b0923bbe6066ea34cb97bd Author: Daniel Gasienica <daniel@gasienica.ch> Date: Thu Feb 15 17:18:26 2018 -0500 Simplify `operator-linebreak` configuration Enabling `before` caused more code changes and it turns out our previous configuration is already the default. commit db588997acdd90ed2ad829174ecbba744383c78b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Thu Feb 15 17:15:59 2018 -0500 Remove obsolete TODO commit 799c8817633f6afa0b731fc3b5434e463bd850e3 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Thu Feb 15 17:12:18 2018 -0500 Enable ESLint `function-paren-newline` `multiline` Per discussion. commit b660b6bc8ef41df7601a411213d6cda80821df87 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Thu Feb 15 17:10:48 2018 -0500 Use `messageDescriptor.id` not `source` commit 5e7309d176f4a7e97d3dc4c738e6b0ccd4792871 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 16:29:01 2018 -0500 Remove unnecessary `eslint-env` commit 393b3da55eabd7413596c86cc3971b063a0efe31 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 16:19:17 2018 -0500 Refactor `onSentMessage` and `onMessageReceived` Since they are so similar, we create the handlers using new `createMessageHandler` function. This allows us to ensure both synced and received messages go through schema upgrade pipeline. commit b3db0bf179c9a5bea96480cde28c6fa7193ac117 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 16:18:21 2018 -0500 Add `Message` descriptor functions commit 8febf125b1b42fe4ae1888dd50fcee2749dc1ff0 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 14:46:56 2018 -0500 Fix typo commit 98d951ef77bd578b313a4ff4b496b793e82e88d5 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 12:22:39 2018 -0500 Remove `promises` reference commit a0e9559ed5bed947dabf28cb672e63d39948d854 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 12:22:13 2018 -0500 Fix `AttachmentView::mediaType` fall-through commit 67be916a83951b8a1f9b22efe78a6da6b1825f38 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 12:03:41 2018 -0500 Remove minor TODOs commit 0af186e118256b62905de38487ffacc41693ff47 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 11:44:41 2018 -0500 Enable ESLint for `js/views/attachment_view.js` commit 28a2dc5b8a28e1a087924fdc7275bf7d9a577b92 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 11:44:12 2018 -0500 Remove dynamic type checks commit f4ce36fcfc2737de32d911cd6103f889097813f6 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 11:27:56 2018 -0500 Rename `process` to `upgradeSchema` - `Message.process` -> `Message.upgradeSchema` - `Attachment.process` -> `Attachment.upgradeSchema` - `Attachment::processVersion` -> `Attachment::schemaVersion` Document version history. commit 41b92c0a31050ba05ddb1c43171d651f3568b9ac Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 11:11:50 2018 -0500 Add `operator-linebreak` ESLint rule Based on the following discussion: https://github.com/signalapp/Signal-Desktop/pull/2040#discussion_r168029106 commit 462defbe55879060fe25bc69103d4429bae2b2f6 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 11:01:30 2018 -0500 Add missing `await` for `ConversationController.getOrCreateAndWait` Tested this by setting `if` condition to `true` and confirming it works. It turns rotating a profile key is more involved and might require registering a new account according to Matthew. commit c08058ee4b883b3e23a40683de802ac81ed74874 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 16:32:24 2018 -0500 Convert `FileList` to `Array` commit 70a6c4201925f57be1f94d9da3547fdefc7bbb53 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 15:46:34 2018 -0500 :art: Fix lint errors commit 2ca7cdbc31d4120d6c6a838a6dcf43bc209d9788 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 15:07:09 2018 -0500 Skip `autoOrientImage` for non-JPEG images commit 58eac383013c16ca363a4ed33dca5c7ba61284e5 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 14:55:35 2018 -0500 Move new-style modules to `window.Signal` namespace commit 02c9328877dce289d6116a18b1c223891bd3cd0b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 14:35:23 2018 -0500 Extract `npm run test-modules` command commit 2c708eb94fba468b81ea9427734896114f5a7807 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 13:25:51 2018 -0500 Extract `Message.process` commit 4a2e52f68a77536a0fa04aa3c29ad3e541a8fa7e Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 13:25:12 2018 -0500 Fix EditorConfig commit a346bab5db082720f5d47363f06301380e870425 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 13:13:02 2018 -0500 Remove `vim` directives on ESLint-ed files commit 7ec885c6359e495b407d5bc3eac9431d47c37fc6 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 13:08:24 2018 -0500 Remove CSP whitelisting of `blob:` We no longer use `autoOrientImage` using blob URLs. Bring this back if we decide to auto-orient legacy attachments. commit 879b6f58f4a3f4a9ed6915af6b1be46c1e90e0ca Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:57:05 2018 -0500 Use `Message` type to determine send function Throws on invalid message type. commit 5203d945c98fd2562ae4e22c5c9838d27dec305b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:56:48 2018 -0500 Whitelist `Whisper` global commit 8ad0b066a3690d3382b86bf6ac00c03df7d1e20b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:56:32 2018 -0500 Add `Whisper.Types` namespace This avoids namespace collision for `Whisper.Message`. commit 785a949fce2656ca7dcaf0869d6b9e0648114e80 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:55:43 2018 -0500 Add `Message` type commit 674a7357abf0dcc365455695d56c0479998ebf27 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:35:23 2018 -0500 Run ESLint on `Conversation::sendMessage` commit cd985aa700caa80946245b17ea1b856449f152a0 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:34:38 2018 -0500 Document type signature of `FileInputView::readFile` commit d70d70e52c49588a1dc9833dfe5dd7128e13607f Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:31:16 2018 -0500 Move attachment processing closer to sending This helps ensure processing happens uniformly, regardless of which code paths are taken to send an attachment. commit 532ac3e273a26b97f831247f9ee3412621b5c112 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:22:29 2018 -0500 Process attachment before it’s sent Picked this place since it already had various async steps, similar to `onMessageReceived` for the incoming `Attachment.process`. Could we try have this live closer to where we store it in IndexedDB, e.g. `Conversation::sendMessage`? commit a4582ae2fb6e1d3487131ba1f8fa6a00170cb32c Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:21:42 2018 -0500 Refactor `getFile` and `getFiles` Lint them using ESLint. commit 07e9114e65046d791fc4f6ed90d6e2e938ad559d Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:37:31 2018 -0500 Document incoming and outgoing attachments fields Note how outgoing message attachments only have 4 fields. This presumably means the others are not used in our code and could be discarded for simplicity. commit fdc3ef289d6ec1be344a12d496839d5ba747bb6a Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:36:21 2018 -0500 Highlight that `dataURLToBlob` is synchronous commit b9c6bf600fcecedfd649ef2ae3c8629cced4e45a Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:35:49 2018 -0500 Add EditorConfig configuration commit e56101e229d56810c8e31ad7289043a152c6c449 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:34:23 2018 -0500 Replace custom with `blob-util` functions IMPORTANT: All of them are async so we need to use `await`, otherwise we get strange or silent errors. commit f95150f6a9569fabcb31f3acd9f6b7bf50b5d145 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:17:30 2018 -0500 Revert "Replace custom functions with `blob-util`" This reverts commit 8a81e9c01bfe80c0e1bf76737092206c06949512. commit 33860d93f3d30ec55c32f3f4a58729df2eb43f0d Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:13:02 2018 -0500 Revert "Replace `blueimp-canvas-to-blob` with `blob-util`" This reverts commit 31b3e853e4afc78fe80995921aa4152d9f6e4783. commit 7a0ba6fed622d76a3c39c7f03de541a7edb5b8dd Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:12:58 2018 -0500 Replace `blueimp-canvas-to-blob` with `blob-util` commit 47a5f2bfd8b3f546e27e8d2b7e1969755d825a66 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 10:55:34 2018 -0500 Replace custom functions with `blob-util` commit 1cfa0efdb4fb1265369e2bf243c21f04f044fa01 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 10:47:02 2018 -0500 Add `blob-util` dependency commit 9ac26be1bd783cd5070d886de107dd3ad9c91ad1 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 10:46:44 2018 -0500 Document why we drop original image data during auto-orient commit 4136d6c382b99f41760a4da519d0db537fa7de8d Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 10:46:27 2018 -0500 Extract `DEFAULT_JPEG_QUALITY` commit 4a7156327eb5f94dba80cb300b344ac591226b0e Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 10:37:11 2018 -0500 Drop support for invalid `image/jpg` MIME type commit 69fe96581f25413194032232f1bf704312e4754c Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:54:30 2018 -0500 Document `window.onInvalidStateError` global commit a48ba1c77458da38583ee9cd488f70a59f6ee0fd Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:54:04 2018 -0500 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. commit e6d1cf826befc17ad4ec72fda8e761701665635e Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:16:23 2018 -0500 Move async attachment processing to `onMessageReceived` We previously processed attachments in `handleDataMessage` which is mostly a synchronous function, except for the saving of the model. Moving the processing into the already async `onMessageReceived` improves code clarity. commit be6ca2a9aae5b59c360817deb1e18d39d705755e Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:14:49 2018 -0500 Document import of ES2015+ modules commit eaaf7c41608fb988b8f4bbaa933cff110115610e Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:14:29 2018 -0500 :art: Fix lint error commit a25b0e2e3d0f72c6a7bf0a15683f02450d5209ee Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:13:57 2018 -0500 :art: Organize `require`s commit e0cc3d8fab6529d01b388acddf8605908c3d236b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:07:17 2018 -0500 Implement attachment process version Instead of keeping track of last normalization (processing) date, we now keep track of an internal processing version that will help us understand what kind of processing has already been completed for a given attachment. This will let us retroactively upgrade existing attachments. As we add more processing steps, we can build a processing pipeline that can convert any attachment processing version into a higher one, e.g. 4 -> 5 -> 6 -> 7. commit ad9083d0fdb880bc518e02251e51a39f7e1c585f Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:50:31 2018 -0500 Ignore ES2015+ files during JSCS linting commit 96641205f734927aaebc2342d977c555799c3e3b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:48:07 2018 -0500 Improve ESLint ignore rules Apparently, using unqualified `/**` patterns prevents `!` include patterns. Using qualified glob patterns, e.g. `js/models/**/*.js`, lets us work around this. commit 255e0ab15bd1a0ca8ca5746e42d23977c8765d01 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:44:59 2018 -0500 :abc: ESLint ignored files commit ebcb70258a26f234bd602072ac7c0a1913128132 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:35:47 2018 -0500 Whitelist `browser` environment for ESLint commit 3eaace6f3a21421c5aaaaf01592408c7ed83ecd3 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:35:05 2018 -0500 Use `MIME` module commit ba2cf7770e614415733414a2dcc48f110b929892 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:32:54 2018 -0500 :art: Fix lint errors commit 65acc86e8580e88f7a6611eb4b8fa5d7291f7a3f Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:30:42 2018 -0500 Add ES2015+ files to JSHint ignored list commit 8b6494ae6c9247acdfa059a9b361ec5ffcdb39f0 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:29:20 2018 -0500 Document potentially unexpected `autoScale` behavior commit 8b4c69b2002d1777d3621be10f92cbf432f9d4d6 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:26:47 2018 -0500 Test CommonJS modules separately Not sure how to test them as part of Grunt `unit-tests` task as `test/index.html` doesn’t allow for inclusion of CommonJS modules that use `require`. The tests are silently skipped. commit 213400e4b2bba3efee856a25b40e269221c3c39d Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:24:27 2018 -0500 Add `MIME` type module commit 37a726e4fb4b3ed65914463122a5662847b5adee Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 20:18:05 2018 -0500 Return proper `Error` from `blobArrayToBuffer` commit 164752db5612220e4dcf58d57bcd682cb489a399 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 20:15:41 2018 -0500 :art: Fix ESLint errors commit d498dd79a067c75098dd3179814c914780e5cb4f Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 20:14:33 2018 -0500 Update `Attachment` type field definitions commit 141155a1533ff8fb616b70ea313432781bbebffd Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 20:12:50 2018 -0500 Move `blueimp-canvas-to-blob` from Bower to npm commit 7ccb833e5d286ddd6235d3e491c62ac1e4544510 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:33:50 2018 -0500 :art: Clarify data flow commit e7da41591fde5a830467bebf1b6f51c1f7293e74 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:31:21 2018 -0500 Use `blobUrl` for consistency commit 523a80eefe0e2858aa1fb2bb9539ec44da502963 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:28:06 2018 -0500 Remove just-in-time image auto-orient for lightbox We can bring this back if our users would like auto-orient for old attachments. commit 0739feae9c47dd523c10740d6cdf746d539f270c Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:27:21 2018 -0500 Remove just-in-time auto-orient of message attachments We can bring this back if our users would like auto-orient for old attachments. But better yet, we might implement this as database migration. commit ed43c66f92830ee233d5a94d0545eea4da43894d Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:26:24 2018 -0500 Auto-orient JPEG attachments upon receipt commit e2eb8e36b017b048d57602fca14e45d657e0e1a1 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:25:26 2018 -0500 Expose `Attachment` type through `Whisper.Attachment` commit 9638fbc987b84f143ca34211dc4666d96248ea2f Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:23:39 2018 -0500 Use `contentType` from `model` commit 032c0ced46c3876cb9474b26f9d53d6f1c6b16a0 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:23:04 2018 -0500 Return `Error` object for `autoOrientImage` failures commit ff04bad8510c4b21aef350bed2b1887d0e055b98 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:22:32 2018 -0500 Add `options` for `autoOrientImage` output type / quality commit 87745b5586d1e182b51c9f9bc5e4eaf6dbc16722 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:18:46 2018 -0500 Add `Attachment` type Defines various functions on attachments, e.g. normalization (auto-orient JPEGs, etc.) commit de27fdc10a53bc8882a9c978e82265db9ac6d6f5 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:16:34 2018 -0500 Add `yarn grunt` shortcut This allows us to use local `grunt-cli` for `grunt dev`. commit 59974db5a5da0d8f4cdc8ce5c4e3c974ecd5e754 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 10:10:11 2018 -0500 Improve readability commit b5ba96f1e6f40f2e1fa77490c583217768e1f412 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 10:08:12 2018 -0500 Use `snake_case` for module names Prevents problems across case-sensitive and case-insensitive file systems. We can work around this in the future using a lint rule such as `eslint-plugin-require-path-exists`. See discussion: https://github.com/signalapp/Signal-Desktop/pull/2040#discussion_r167365931 commit 48c5d3155c96ef628b00d99b52975e580d1d5501 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 10:05:44 2018 -0500 :art: Use destructuring commit 4822f49f22382a99ebf142b337375f7c25251d76 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 17:41:40 2018 -0500 Auto-orient images in lightbox view commit 7317110809677dddbbef3fadbf912cdba1c010bf Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 17:40:14 2018 -0500 Document magic number for escape key commit c790d07389a7d0bbf5298de83dbcfa8be1e7696b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 17:38:35 2018 -0500 Make second `View` argument an `options` object commit fbe010bb63d0088af9dfe11f153437fab34247e0 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 17:27:40 2018 -0500 Allow `loadImage` to fetch `blob://` URLs commit ec35710d002b019a273eeb48f94dcaf2babe5d96 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:57:48 2018 -0500 :art: Shorten `autoOrientImage` import commit d07433e3cf316c6a143a0c9393ba26df9e3af17b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:57:19 2018 -0500 Make `autoOrientImage` module standalone commit c285bf5e33cdf10e0ef71e72cd6f55aef0df96ef Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:55:44 2018 -0500 Replace `loadImage` with `autoOrientImage` commit 44318549235af01fd061c25f557c93fd21cebb7a Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:53:23 2018 -0500 Add `autoOrientImage` module This module exposes `loadImage` with a `Promise` based interface and pre- populates `orientation: true` option to auto-orient input. Returns data URL as string. The module uses a named export as refactoring references of modules with `default` (`module.exports`) export references can be error-prone. See: https://basarat.gitbooks.io/typescript/docs/tips/defaultIsBad.html commit c77063afc6366fe49615052796fe46f9b369de39 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:44:30 2018 -0500 Auto-orient preview images See: #998 commit 06dba5eb8f662c11af3a9ba8395bb453ab2e5f8d Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:43:23 2018 -0500 TODO: Use native `Canvas::toBlob` One challenge is that `Canvas::toBlob` is async whereas `dataURLtoBlob` is sync. commit b15c304a3125dd023fd90990e6225a7303f3596f Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:42:45 2018 -0500 Make `null` check strict Appeases JSHint. ESLint has a nice `smart` option for `eqeqeq` rule: https://eslint.org/docs/rules/eqeqeq#smart commit ea70b92d9b18201758e11fdc25b09afc97b50055 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 15:23:58 2018 -0500 Use `Canvas::toDataURL` to preserve `ImageView` logic This way, all the other code paths remain untouched in case we want to remove the auto-orient code once Chrome supports the `image-orientation` CSS property. See: - #998 - https://developer.mozilla.org/en-US/docs/Web/CSS/image-orientation commit 62fd744f9f27d951573a68d2cdfe7ba2a3784b41 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 14:38:04 2018 -0500 Use CSS to constrain auto-oriented images commit f4d3392687168c237441b29140c7968b49dbef9e Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 14:35:02 2018 -0500 Replace `ImageView` `el` with auto-oriented `canvas` See: #998 commit 1602d7f610e4993ad1291f88197f9ead1e25e776 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 14:25:48 2018 -0500 Pass `Blob` to `View` (for `ImageView`) This allows us to do JPEG auto-orientation based on EXIF metadata. commit e6a414f2b2a80da1137b839b348a38510efd04bb Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 14:25:12 2018 -0500 :hocho: Remove newline commit 5f0d9570d7862fc428ff89c2ecfd332a744537e5 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 11:17:02 2018 -0500 Expose `blueimp-load-image` as `window.loadImage` commit 1e1c62fe2f6a76dbcf1998dd468c26187c9871dc Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 11:16:46 2018 -0500 Add `blueimp-load-image` npm dependency commit ad17fa8a68a21ca5ddec336801b8568009bef3d4 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 11:14:40 2018 -0500 Remove `blueimp-load-image` Bower dependency
2018-02-21 15:26:59 +00:00
return confirm();
}
2020-09-09 02:25:05 +00:00
// Matches event data from `libtextsecure` `MessageReceiver::handleDataMessage`:
const getDescriptorForReceived = ({
message,
source,
sourceUuid,
}: WhatIsThis) => {
2020-09-09 02:25:05 +00:00
if (message.groupV2) {
const { id } = message.groupV2;
const conversationId = window.ConversationController.ensureGroup(id, {
2020-10-06 17:06:34 +00:00
// Note: We don't set active_at, because we don't want the group to show until
// we have information about it beyond these initial details.
// see maybeUpdateGroup().
2020-09-09 02:25:05 +00:00
groupVersion: 2,
masterKey: message.groupV2.masterKey,
secretParams: message.groupV2.secretParams,
publicParams: message.groupV2.publicParams,
});
return {
type: Message.GROUP,
id: conversationId,
};
}
if (message.group) {
const { id } = message.group;
const fromContactId = window.ConversationController.ensureContactIds({
2020-09-09 02:25:05 +00:00
e164: source,
uuid: sourceUuid,
highTrust: true,
});
const conversationId = window.ConversationController.ensureGroup(id, {
2020-09-09 02:25:05 +00:00
addedBy: fromContactId,
});
return {
type: Message.GROUP,
id: conversationId,
};
}
return {
type: Message.PRIVATE,
id: window.ConversationController.ensureContactIds({
2020-09-09 02:25:05 +00:00
e164: source,
uuid: sourceUuid,
highTrust: true,
}),
};
};
// Note: We do very little in this function, since everything in handleDataMessage is
// inside a conversation-specific queue(). Any code here might run before an earlier
// message is processed in handleDataMessage().
function onMessageReceived(event: WhatIsThis) {
const { data, confirm } = event;
const messageDescriptor = getDescriptorForReceived(data);
const { PROFILE_KEY_UPDATE } = window.textsecure.protobuf.DataMessage.Flags;
// eslint-disable-next-line no-bitwise
const isProfileUpdate = Boolean(data.message.flags & PROFILE_KEY_UPDATE);
if (isProfileUpdate) {
2020-04-29 21:24:12 +00:00
return handleMessageReceivedProfileUpdate({
data,
confirm,
messageDescriptor,
});
}
2020-06-12 22:36:32 +00:00
const message = initIncomingMessage(data, messageDescriptor);
2020-01-17 22:23:19 +00:00
if (data.message.reaction) {
window.normalizeUuids(
data.message.reaction,
['targetAuthorUuid'],
'background::onMessageReceived'
);
2020-01-17 22:23:19 +00:00
const { reaction } = data.message;
2020-09-09 02:25:05 +00:00
window.log.info(
'Queuing incoming reaction for',
reaction.targetTimestamp
);
const reactionModel = window.Whisper.Reactions.add({
2020-01-17 22:23:19 +00:00
emoji: reaction.emoji,
remove: reaction.remove,
targetAuthorE164: reaction.targetAuthorE164,
targetAuthorUuid: reaction.targetAuthorUuid,
2020-09-09 02:25:05 +00:00
targetTimestamp: reaction.targetTimestamp,
2020-01-17 22:23:19 +00:00
timestamp: Date.now(),
fromId: window.ConversationController.ensureContactIds({
2020-06-12 22:36:32 +00:00
e164: data.source,
uuid: data.sourceUuid,
}),
2020-01-17 22:23:19 +00:00
});
// Note: We do not wait for completion here
window.Whisper.Reactions.onReaction(reactionModel);
2020-01-17 22:23:19 +00:00
confirm();
2020-04-29 21:24:12 +00:00
return Promise.resolve();
}
if (data.message.delete) {
const { delete: del } = data.message;
2020-09-09 02:25:05 +00:00
window.log.info('Queuing incoming DOE for', del.targetSentTimestamp);
const deleteModel = window.Whisper.Deletes.add({
2020-04-29 21:24:12 +00:00
targetSentTimestamp: del.targetSentTimestamp,
serverTimestamp: data.serverTimestamp,
fromId: window.ConversationController.ensureContactIds({
2020-06-12 22:36:32 +00:00
e164: data.source,
uuid: data.sourceUuid,
}),
2020-04-29 21:24:12 +00:00
});
// Note: We do not wait for completion here
window.Whisper.Deletes.onDelete(deleteModel);
2020-04-29 21:24:12 +00:00
confirm();
return Promise.resolve();
2020-01-17 22:23:19 +00:00
}
2019-09-26 19:56:31 +00:00
// Don't wait for handleDataMessage, as it has its own per-conversation queueing
message.handleDataMessage(data.message, event.confirm);
2020-04-29 21:24:12 +00:00
return Promise.resolve();
}
Auto-orient image attachments based on EXIF metadata As described in #998, images are sometimes displayed with an incorrect orientation. This is because cameras often write files in the native sensor byte order and attach the `Orientation` EXIF metadata to tell end-user devices how to display the images based on the original author’s capture orientation. Electron/Chromium (and therefore Signal Desktop) currently doesn’t support applying this metadata for `<img>` tags, e.g. CSS `image-orientation: from- image`. As a workaround, this change uses the `loadImage` library with the `orientation: true` flag to auto-orient images ~~before display~~ upon receipt and before sending. **Changes** - [x] ~~Auto-orient images during display in message list view~~ - [x] Ensure image is not displayed until loaded (to prevent layout reflow) . - [x] Auto-orient images upon receipt and before storing in IndexedDB (~~or preserve original data until Chromium offers native fix?~~) - [x] Auto-orient images in compose area preview. - [x] ~~Auto-orient images in lightbox view~~ - [x] Auto-orient images before sending / storage. - [x] Add EditorConfig for sharing code styles across editors. - [x] Fix ESLint ignore file. - [x] Change `function-paren-newline` ESLint rule from `consistent` to `multiline`. - [x] Add `operator-linebreak` ESLint rule for consistency. - [x] Added `blob-util` dependency for converting between array buffers, blobs, etc. - [x] Extracted `createMessageHandler` to consolidate logic for `onMessageReceived` and `onSentMessage`. - [x] Introduce `async` / `await` to simplify async coding (restore control flow for branching, loops, and exceptions). - [x] Introduce `window.Signal` namespace for exposing ES2015+ CommonJS modules. - [x] Introduce rudimentary `Message` and `Attachment` types to begin defining a schema and versioning. This will allow us to track which changes, e.g. auto-orient JPEGs, per message / attachment as well as which fields are stored. - [x] Renamed `window.dataURLtoBlob` to `window.dataURLToBlobSync` to both fix the strange `camelCase` as well as to highlight that this operation is synchronous and therefore blocks the user thread. - [x] Normalize all JPEG MIME types to `image/jpeg`, eliminating the invalid `image/jpg`. - [x] Add `npm run test-modules` command for testing non-browser specific CommonJS modules. - **Stretch Goals** - [ ] ~~Restrict `autoOrientImage` to `Blob` to narrow API interface.~~ Do this once we use PureScript. - [ ] ~~Return non-JPEGs as no-op from `autoOrientImage`.~~ Skipping `autoOrientImage` for non-JPEGs altogether. - [ ] Retroactively auto-orient existing JPEG image attachments in the background. --- Fixes #998 --- - **Blog:** EXIF Orientation Handling Is a Ghetto: https://www.daveperrett.com/articles/2012/07/28/exif-orientation-handling-is-a-ghetto/ - **Chromium Bug:** EXIF orientation is ignored: https://bugs.chromium.org/p/chromium/issues/detail?id=56845 - **Chromium Bug:** Support for the CSS image-orientation CSS property: https://bugs.chromium.org/p/chromium/issues/detail?id=158753 --- commit ce5090b473a2448229dc38e4c3f15d7ad0137714 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 16 10:35:36 2018 -0500 Inline message descriptors commit 329036e59c138c1e950ec7c654eebd7d87076de5 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Thu Feb 15 17:34:40 2018 -0500 Clarify order of operations Semantically, it makes more sense to do `getFile` before `clearForm` even though it seems to work either way. commit f9d4cfb2ba0d8aa308b0923bbe6066ea34cb97bd Author: Daniel Gasienica <daniel@gasienica.ch> Date: Thu Feb 15 17:18:26 2018 -0500 Simplify `operator-linebreak` configuration Enabling `before` caused more code changes and it turns out our previous configuration is already the default. commit db588997acdd90ed2ad829174ecbba744383c78b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Thu Feb 15 17:15:59 2018 -0500 Remove obsolete TODO commit 799c8817633f6afa0b731fc3b5434e463bd850e3 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Thu Feb 15 17:12:18 2018 -0500 Enable ESLint `function-paren-newline` `multiline` Per discussion. commit b660b6bc8ef41df7601a411213d6cda80821df87 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Thu Feb 15 17:10:48 2018 -0500 Use `messageDescriptor.id` not `source` commit 5e7309d176f4a7e97d3dc4c738e6b0ccd4792871 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 16:29:01 2018 -0500 Remove unnecessary `eslint-env` commit 393b3da55eabd7413596c86cc3971b063a0efe31 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 16:19:17 2018 -0500 Refactor `onSentMessage` and `onMessageReceived` Since they are so similar, we create the handlers using new `createMessageHandler` function. This allows us to ensure both synced and received messages go through schema upgrade pipeline. commit b3db0bf179c9a5bea96480cde28c6fa7193ac117 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 16:18:21 2018 -0500 Add `Message` descriptor functions commit 8febf125b1b42fe4ae1888dd50fcee2749dc1ff0 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 14:46:56 2018 -0500 Fix typo commit 98d951ef77bd578b313a4ff4b496b793e82e88d5 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 12:22:39 2018 -0500 Remove `promises` reference commit a0e9559ed5bed947dabf28cb672e63d39948d854 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 12:22:13 2018 -0500 Fix `AttachmentView::mediaType` fall-through commit 67be916a83951b8a1f9b22efe78a6da6b1825f38 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 12:03:41 2018 -0500 Remove minor TODOs commit 0af186e118256b62905de38487ffacc41693ff47 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 11:44:41 2018 -0500 Enable ESLint for `js/views/attachment_view.js` commit 28a2dc5b8a28e1a087924fdc7275bf7d9a577b92 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 11:44:12 2018 -0500 Remove dynamic type checks commit f4ce36fcfc2737de32d911cd6103f889097813f6 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 11:27:56 2018 -0500 Rename `process` to `upgradeSchema` - `Message.process` -> `Message.upgradeSchema` - `Attachment.process` -> `Attachment.upgradeSchema` - `Attachment::processVersion` -> `Attachment::schemaVersion` Document version history. commit 41b92c0a31050ba05ddb1c43171d651f3568b9ac Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 11:11:50 2018 -0500 Add `operator-linebreak` ESLint rule Based on the following discussion: https://github.com/signalapp/Signal-Desktop/pull/2040#discussion_r168029106 commit 462defbe55879060fe25bc69103d4429bae2b2f6 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 11:01:30 2018 -0500 Add missing `await` for `ConversationController.getOrCreateAndWait` Tested this by setting `if` condition to `true` and confirming it works. It turns rotating a profile key is more involved and might require registering a new account according to Matthew. commit c08058ee4b883b3e23a40683de802ac81ed74874 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 16:32:24 2018 -0500 Convert `FileList` to `Array` commit 70a6c4201925f57be1f94d9da3547fdefc7bbb53 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 15:46:34 2018 -0500 :art: Fix lint errors commit 2ca7cdbc31d4120d6c6a838a6dcf43bc209d9788 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 15:07:09 2018 -0500 Skip `autoOrientImage` for non-JPEG images commit 58eac383013c16ca363a4ed33dca5c7ba61284e5 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 14:55:35 2018 -0500 Move new-style modules to `window.Signal` namespace commit 02c9328877dce289d6116a18b1c223891bd3cd0b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 14:35:23 2018 -0500 Extract `npm run test-modules` command commit 2c708eb94fba468b81ea9427734896114f5a7807 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 13:25:51 2018 -0500 Extract `Message.process` commit 4a2e52f68a77536a0fa04aa3c29ad3e541a8fa7e Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 13:25:12 2018 -0500 Fix EditorConfig commit a346bab5db082720f5d47363f06301380e870425 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 13:13:02 2018 -0500 Remove `vim` directives on ESLint-ed files commit 7ec885c6359e495b407d5bc3eac9431d47c37fc6 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 13:08:24 2018 -0500 Remove CSP whitelisting of `blob:` We no longer use `autoOrientImage` using blob URLs. Bring this back if we decide to auto-orient legacy attachments. commit 879b6f58f4a3f4a9ed6915af6b1be46c1e90e0ca Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:57:05 2018 -0500 Use `Message` type to determine send function Throws on invalid message type. commit 5203d945c98fd2562ae4e22c5c9838d27dec305b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:56:48 2018 -0500 Whitelist `Whisper` global commit 8ad0b066a3690d3382b86bf6ac00c03df7d1e20b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:56:32 2018 -0500 Add `Whisper.Types` namespace This avoids namespace collision for `Whisper.Message`. commit 785a949fce2656ca7dcaf0869d6b9e0648114e80 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:55:43 2018 -0500 Add `Message` type commit 674a7357abf0dcc365455695d56c0479998ebf27 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:35:23 2018 -0500 Run ESLint on `Conversation::sendMessage` commit cd985aa700caa80946245b17ea1b856449f152a0 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:34:38 2018 -0500 Document type signature of `FileInputView::readFile` commit d70d70e52c49588a1dc9833dfe5dd7128e13607f Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:31:16 2018 -0500 Move attachment processing closer to sending This helps ensure processing happens uniformly, regardless of which code paths are taken to send an attachment. commit 532ac3e273a26b97f831247f9ee3412621b5c112 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:22:29 2018 -0500 Process attachment before it’s sent Picked this place since it already had various async steps, similar to `onMessageReceived` for the incoming `Attachment.process`. Could we try have this live closer to where we store it in IndexedDB, e.g. `Conversation::sendMessage`? commit a4582ae2fb6e1d3487131ba1f8fa6a00170cb32c Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:21:42 2018 -0500 Refactor `getFile` and `getFiles` Lint them using ESLint. commit 07e9114e65046d791fc4f6ed90d6e2e938ad559d Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:37:31 2018 -0500 Document incoming and outgoing attachments fields Note how outgoing message attachments only have 4 fields. This presumably means the others are not used in our code and could be discarded for simplicity. commit fdc3ef289d6ec1be344a12d496839d5ba747bb6a Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:36:21 2018 -0500 Highlight that `dataURLToBlob` is synchronous commit b9c6bf600fcecedfd649ef2ae3c8629cced4e45a Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:35:49 2018 -0500 Add EditorConfig configuration commit e56101e229d56810c8e31ad7289043a152c6c449 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:34:23 2018 -0500 Replace custom with `blob-util` functions IMPORTANT: All of them are async so we need to use `await`, otherwise we get strange or silent errors. commit f95150f6a9569fabcb31f3acd9f6b7bf50b5d145 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:17:30 2018 -0500 Revert "Replace custom functions with `blob-util`" This reverts commit 8a81e9c01bfe80c0e1bf76737092206c06949512. commit 33860d93f3d30ec55c32f3f4a58729df2eb43f0d Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:13:02 2018 -0500 Revert "Replace `blueimp-canvas-to-blob` with `blob-util`" This reverts commit 31b3e853e4afc78fe80995921aa4152d9f6e4783. commit 7a0ba6fed622d76a3c39c7f03de541a7edb5b8dd Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:12:58 2018 -0500 Replace `blueimp-canvas-to-blob` with `blob-util` commit 47a5f2bfd8b3f546e27e8d2b7e1969755d825a66 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 10:55:34 2018 -0500 Replace custom functions with `blob-util` commit 1cfa0efdb4fb1265369e2bf243c21f04f044fa01 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 10:47:02 2018 -0500 Add `blob-util` dependency commit 9ac26be1bd783cd5070d886de107dd3ad9c91ad1 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 10:46:44 2018 -0500 Document why we drop original image data during auto-orient commit 4136d6c382b99f41760a4da519d0db537fa7de8d Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 10:46:27 2018 -0500 Extract `DEFAULT_JPEG_QUALITY` commit 4a7156327eb5f94dba80cb300b344ac591226b0e Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 10:37:11 2018 -0500 Drop support for invalid `image/jpg` MIME type commit 69fe96581f25413194032232f1bf704312e4754c Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:54:30 2018 -0500 Document `window.onInvalidStateError` global commit a48ba1c77458da38583ee9cd488f70a59f6ee0fd Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:54:04 2018 -0500 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. commit e6d1cf826befc17ad4ec72fda8e761701665635e Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:16:23 2018 -0500 Move async attachment processing to `onMessageReceived` We previously processed attachments in `handleDataMessage` which is mostly a synchronous function, except for the saving of the model. Moving the processing into the already async `onMessageReceived` improves code clarity. commit be6ca2a9aae5b59c360817deb1e18d39d705755e Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:14:49 2018 -0500 Document import of ES2015+ modules commit eaaf7c41608fb988b8f4bbaa933cff110115610e Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:14:29 2018 -0500 :art: Fix lint error commit a25b0e2e3d0f72c6a7bf0a15683f02450d5209ee Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:13:57 2018 -0500 :art: Organize `require`s commit e0cc3d8fab6529d01b388acddf8605908c3d236b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:07:17 2018 -0500 Implement attachment process version Instead of keeping track of last normalization (processing) date, we now keep track of an internal processing version that will help us understand what kind of processing has already been completed for a given attachment. This will let us retroactively upgrade existing attachments. As we add more processing steps, we can build a processing pipeline that can convert any attachment processing version into a higher one, e.g. 4 -> 5 -> 6 -> 7. commit ad9083d0fdb880bc518e02251e51a39f7e1c585f Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:50:31 2018 -0500 Ignore ES2015+ files during JSCS linting commit 96641205f734927aaebc2342d977c555799c3e3b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:48:07 2018 -0500 Improve ESLint ignore rules Apparently, using unqualified `/**` patterns prevents `!` include patterns. Using qualified glob patterns, e.g. `js/models/**/*.js`, lets us work around this. commit 255e0ab15bd1a0ca8ca5746e42d23977c8765d01 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:44:59 2018 -0500 :abc: ESLint ignored files commit ebcb70258a26f234bd602072ac7c0a1913128132 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:35:47 2018 -0500 Whitelist `browser` environment for ESLint commit 3eaace6f3a21421c5aaaaf01592408c7ed83ecd3 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:35:05 2018 -0500 Use `MIME` module commit ba2cf7770e614415733414a2dcc48f110b929892 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:32:54 2018 -0500 :art: Fix lint errors commit 65acc86e8580e88f7a6611eb4b8fa5d7291f7a3f Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:30:42 2018 -0500 Add ES2015+ files to JSHint ignored list commit 8b6494ae6c9247acdfa059a9b361ec5ffcdb39f0 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:29:20 2018 -0500 Document potentially unexpected `autoScale` behavior commit 8b4c69b2002d1777d3621be10f92cbf432f9d4d6 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:26:47 2018 -0500 Test CommonJS modules separately Not sure how to test them as part of Grunt `unit-tests` task as `test/index.html` doesn’t allow for inclusion of CommonJS modules that use `require`. The tests are silently skipped. commit 213400e4b2bba3efee856a25b40e269221c3c39d Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:24:27 2018 -0500 Add `MIME` type module commit 37a726e4fb4b3ed65914463122a5662847b5adee Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 20:18:05 2018 -0500 Return proper `Error` from `blobArrayToBuffer` commit 164752db5612220e4dcf58d57bcd682cb489a399 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 20:15:41 2018 -0500 :art: Fix ESLint errors commit d498dd79a067c75098dd3179814c914780e5cb4f Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 20:14:33 2018 -0500 Update `Attachment` type field definitions commit 141155a1533ff8fb616b70ea313432781bbebffd Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 20:12:50 2018 -0500 Move `blueimp-canvas-to-blob` from Bower to npm commit 7ccb833e5d286ddd6235d3e491c62ac1e4544510 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:33:50 2018 -0500 :art: Clarify data flow commit e7da41591fde5a830467bebf1b6f51c1f7293e74 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:31:21 2018 -0500 Use `blobUrl` for consistency commit 523a80eefe0e2858aa1fb2bb9539ec44da502963 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:28:06 2018 -0500 Remove just-in-time image auto-orient for lightbox We can bring this back if our users would like auto-orient for old attachments. commit 0739feae9c47dd523c10740d6cdf746d539f270c Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:27:21 2018 -0500 Remove just-in-time auto-orient of message attachments We can bring this back if our users would like auto-orient for old attachments. But better yet, we might implement this as database migration. commit ed43c66f92830ee233d5a94d0545eea4da43894d Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:26:24 2018 -0500 Auto-orient JPEG attachments upon receipt commit e2eb8e36b017b048d57602fca14e45d657e0e1a1 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:25:26 2018 -0500 Expose `Attachment` type through `Whisper.Attachment` commit 9638fbc987b84f143ca34211dc4666d96248ea2f Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:23:39 2018 -0500 Use `contentType` from `model` commit 032c0ced46c3876cb9474b26f9d53d6f1c6b16a0 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:23:04 2018 -0500 Return `Error` object for `autoOrientImage` failures commit ff04bad8510c4b21aef350bed2b1887d0e055b98 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:22:32 2018 -0500 Add `options` for `autoOrientImage` output type / quality commit 87745b5586d1e182b51c9f9bc5e4eaf6dbc16722 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:18:46 2018 -0500 Add `Attachment` type Defines various functions on attachments, e.g. normalization (auto-orient JPEGs, etc.) commit de27fdc10a53bc8882a9c978e82265db9ac6d6f5 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:16:34 2018 -0500 Add `yarn grunt` shortcut This allows us to use local `grunt-cli` for `grunt dev`. commit 59974db5a5da0d8f4cdc8ce5c4e3c974ecd5e754 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 10:10:11 2018 -0500 Improve readability commit b5ba96f1e6f40f2e1fa77490c583217768e1f412 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 10:08:12 2018 -0500 Use `snake_case` for module names Prevents problems across case-sensitive and case-insensitive file systems. We can work around this in the future using a lint rule such as `eslint-plugin-require-path-exists`. See discussion: https://github.com/signalapp/Signal-Desktop/pull/2040#discussion_r167365931 commit 48c5d3155c96ef628b00d99b52975e580d1d5501 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 10:05:44 2018 -0500 :art: Use destructuring commit 4822f49f22382a99ebf142b337375f7c25251d76 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 17:41:40 2018 -0500 Auto-orient images in lightbox view commit 7317110809677dddbbef3fadbf912cdba1c010bf Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 17:40:14 2018 -0500 Document magic number for escape key commit c790d07389a7d0bbf5298de83dbcfa8be1e7696b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 17:38:35 2018 -0500 Make second `View` argument an `options` object commit fbe010bb63d0088af9dfe11f153437fab34247e0 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 17:27:40 2018 -0500 Allow `loadImage` to fetch `blob://` URLs commit ec35710d002b019a273eeb48f94dcaf2babe5d96 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:57:48 2018 -0500 :art: Shorten `autoOrientImage` import commit d07433e3cf316c6a143a0c9393ba26df9e3af17b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:57:19 2018 -0500 Make `autoOrientImage` module standalone commit c285bf5e33cdf10e0ef71e72cd6f55aef0df96ef Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:55:44 2018 -0500 Replace `loadImage` with `autoOrientImage` commit 44318549235af01fd061c25f557c93fd21cebb7a Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:53:23 2018 -0500 Add `autoOrientImage` module This module exposes `loadImage` with a `Promise` based interface and pre- populates `orientation: true` option to auto-orient input. Returns data URL as string. The module uses a named export as refactoring references of modules with `default` (`module.exports`) export references can be error-prone. See: https://basarat.gitbooks.io/typescript/docs/tips/defaultIsBad.html commit c77063afc6366fe49615052796fe46f9b369de39 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:44:30 2018 -0500 Auto-orient preview images See: #998 commit 06dba5eb8f662c11af3a9ba8395bb453ab2e5f8d Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:43:23 2018 -0500 TODO: Use native `Canvas::toBlob` One challenge is that `Canvas::toBlob` is async whereas `dataURLtoBlob` is sync. commit b15c304a3125dd023fd90990e6225a7303f3596f Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:42:45 2018 -0500 Make `null` check strict Appeases JSHint. ESLint has a nice `smart` option for `eqeqeq` rule: https://eslint.org/docs/rules/eqeqeq#smart commit ea70b92d9b18201758e11fdc25b09afc97b50055 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 15:23:58 2018 -0500 Use `Canvas::toDataURL` to preserve `ImageView` logic This way, all the other code paths remain untouched in case we want to remove the auto-orient code once Chrome supports the `image-orientation` CSS property. See: - #998 - https://developer.mozilla.org/en-US/docs/Web/CSS/image-orientation commit 62fd744f9f27d951573a68d2cdfe7ba2a3784b41 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 14:38:04 2018 -0500 Use CSS to constrain auto-oriented images commit f4d3392687168c237441b29140c7968b49dbef9e Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 14:35:02 2018 -0500 Replace `ImageView` `el` with auto-oriented `canvas` See: #998 commit 1602d7f610e4993ad1291f88197f9ead1e25e776 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 14:25:48 2018 -0500 Pass `Blob` to `View` (for `ImageView`) This allows us to do JPEG auto-orientation based on EXIF metadata. commit e6a414f2b2a80da1137b839b348a38510efd04bb Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 14:25:12 2018 -0500 :hocho: Remove newline commit 5f0d9570d7862fc428ff89c2ecfd332a744537e5 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 11:17:02 2018 -0500 Expose `blueimp-load-image` as `window.loadImage` commit 1e1c62fe2f6a76dbcf1998dd468c26187c9871dc Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 11:16:46 2018 -0500 Add `blueimp-load-image` npm dependency commit ad17fa8a68a21ca5ddec336801b8568009bef3d4 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 11:14:40 2018 -0500 Remove `blueimp-load-image` Bower dependency
2018-02-21 15:26:59 +00:00
async function onProfileKeyUpdate({ data, confirm }: WhatIsThis) {
const conversationId = window.ConversationController.ensureContactIds({
e164: data.source,
uuid: data.sourceUuid,
highTrust: true,
});
const conversation = window.ConversationController.get(conversationId);
2020-05-27 21:37:06 +00:00
if (!conversation) {
window.log.error(
'onProfileKeyUpdate: could not find conversation',
data.source,
data.sourceUuid
);
confirm();
return;
}
if (!data.profileKey) {
window.log.error(
'onProfileKeyUpdate: missing profileKey',
data.profileKey
);
confirm();
return;
}
window.log.info(
'onProfileKeyUpdate: updating profileKey',
data.source,
data.sourceUuid
);
await conversation.setProfileKey(data.profileKey);
confirm();
}
2018-04-27 21:25:04 +00:00
async function handleMessageSentProfileUpdate({
2018-10-31 23:58:14 +00:00
data,
2018-04-27 21:25:04 +00:00
confirm,
messageDescriptor,
}: WhatIsThis) {
2018-10-31 23:58:14 +00:00
// First set profileSharing = true for the conversation we sent to
const { id } = messageDescriptor;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const conversation = window.ConversationController.get(id)!;
2018-09-21 01:47:19 +00:00
2020-05-27 21:37:06 +00:00
conversation.enableProfileSharing();
window.Signal.Data.updateConversation(conversation.attributes);
2018-09-21 01:47:19 +00:00
2018-10-31 23:58:14 +00:00
// Then we update our own profileKey if it's different from what we have
const ourId = window.ConversationController.getOurConversationId();
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const me = window.ConversationController.get(ourId)!;
2018-10-31 23:58:14 +00:00
const profileKey = data.message.profileKey.toString('base64');
// Will do the save for us if needed
await me.setProfileKey(profileKey);
Auto-orient image attachments based on EXIF metadata As described in #998, images are sometimes displayed with an incorrect orientation. This is because cameras often write files in the native sensor byte order and attach the `Orientation` EXIF metadata to tell end-user devices how to display the images based on the original author’s capture orientation. Electron/Chromium (and therefore Signal Desktop) currently doesn’t support applying this metadata for `<img>` tags, e.g. CSS `image-orientation: from- image`. As a workaround, this change uses the `loadImage` library with the `orientation: true` flag to auto-orient images ~~before display~~ upon receipt and before sending. **Changes** - [x] ~~Auto-orient images during display in message list view~~ - [x] Ensure image is not displayed until loaded (to prevent layout reflow) . - [x] Auto-orient images upon receipt and before storing in IndexedDB (~~or preserve original data until Chromium offers native fix?~~) - [x] Auto-orient images in compose area preview. - [x] ~~Auto-orient images in lightbox view~~ - [x] Auto-orient images before sending / storage. - [x] Add EditorConfig for sharing code styles across editors. - [x] Fix ESLint ignore file. - [x] Change `function-paren-newline` ESLint rule from `consistent` to `multiline`. - [x] Add `operator-linebreak` ESLint rule for consistency. - [x] Added `blob-util` dependency for converting between array buffers, blobs, etc. - [x] Extracted `createMessageHandler` to consolidate logic for `onMessageReceived` and `onSentMessage`. - [x] Introduce `async` / `await` to simplify async coding (restore control flow for branching, loops, and exceptions). - [x] Introduce `window.Signal` namespace for exposing ES2015+ CommonJS modules. - [x] Introduce rudimentary `Message` and `Attachment` types to begin defining a schema and versioning. This will allow us to track which changes, e.g. auto-orient JPEGs, per message / attachment as well as which fields are stored. - [x] Renamed `window.dataURLtoBlob` to `window.dataURLToBlobSync` to both fix the strange `camelCase` as well as to highlight that this operation is synchronous and therefore blocks the user thread. - [x] Normalize all JPEG MIME types to `image/jpeg`, eliminating the invalid `image/jpg`. - [x] Add `npm run test-modules` command for testing non-browser specific CommonJS modules. - **Stretch Goals** - [ ] ~~Restrict `autoOrientImage` to `Blob` to narrow API interface.~~ Do this once we use PureScript. - [ ] ~~Return non-JPEGs as no-op from `autoOrientImage`.~~ Skipping `autoOrientImage` for non-JPEGs altogether. - [ ] Retroactively auto-orient existing JPEG image attachments in the background. --- Fixes #998 --- - **Blog:** EXIF Orientation Handling Is a Ghetto: https://www.daveperrett.com/articles/2012/07/28/exif-orientation-handling-is-a-ghetto/ - **Chromium Bug:** EXIF orientation is ignored: https://bugs.chromium.org/p/chromium/issues/detail?id=56845 - **Chromium Bug:** Support for the CSS image-orientation CSS property: https://bugs.chromium.org/p/chromium/issues/detail?id=158753 --- commit ce5090b473a2448229dc38e4c3f15d7ad0137714 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 16 10:35:36 2018 -0500 Inline message descriptors commit 329036e59c138c1e950ec7c654eebd7d87076de5 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Thu Feb 15 17:34:40 2018 -0500 Clarify order of operations Semantically, it makes more sense to do `getFile` before `clearForm` even though it seems to work either way. commit f9d4cfb2ba0d8aa308b0923bbe6066ea34cb97bd Author: Daniel Gasienica <daniel@gasienica.ch> Date: Thu Feb 15 17:18:26 2018 -0500 Simplify `operator-linebreak` configuration Enabling `before` caused more code changes and it turns out our previous configuration is already the default. commit db588997acdd90ed2ad829174ecbba744383c78b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Thu Feb 15 17:15:59 2018 -0500 Remove obsolete TODO commit 799c8817633f6afa0b731fc3b5434e463bd850e3 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Thu Feb 15 17:12:18 2018 -0500 Enable ESLint `function-paren-newline` `multiline` Per discussion. commit b660b6bc8ef41df7601a411213d6cda80821df87 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Thu Feb 15 17:10:48 2018 -0500 Use `messageDescriptor.id` not `source` commit 5e7309d176f4a7e97d3dc4c738e6b0ccd4792871 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 16:29:01 2018 -0500 Remove unnecessary `eslint-env` commit 393b3da55eabd7413596c86cc3971b063a0efe31 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 16:19:17 2018 -0500 Refactor `onSentMessage` and `onMessageReceived` Since they are so similar, we create the handlers using new `createMessageHandler` function. This allows us to ensure both synced and received messages go through schema upgrade pipeline. commit b3db0bf179c9a5bea96480cde28c6fa7193ac117 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 16:18:21 2018 -0500 Add `Message` descriptor functions commit 8febf125b1b42fe4ae1888dd50fcee2749dc1ff0 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 14:46:56 2018 -0500 Fix typo commit 98d951ef77bd578b313a4ff4b496b793e82e88d5 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 12:22:39 2018 -0500 Remove `promises` reference commit a0e9559ed5bed947dabf28cb672e63d39948d854 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 12:22:13 2018 -0500 Fix `AttachmentView::mediaType` fall-through commit 67be916a83951b8a1f9b22efe78a6da6b1825f38 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 12:03:41 2018 -0500 Remove minor TODOs commit 0af186e118256b62905de38487ffacc41693ff47 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 11:44:41 2018 -0500 Enable ESLint for `js/views/attachment_view.js` commit 28a2dc5b8a28e1a087924fdc7275bf7d9a577b92 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 11:44:12 2018 -0500 Remove dynamic type checks commit f4ce36fcfc2737de32d911cd6103f889097813f6 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 11:27:56 2018 -0500 Rename `process` to `upgradeSchema` - `Message.process` -> `Message.upgradeSchema` - `Attachment.process` -> `Attachment.upgradeSchema` - `Attachment::processVersion` -> `Attachment::schemaVersion` Document version history. commit 41b92c0a31050ba05ddb1c43171d651f3568b9ac Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 11:11:50 2018 -0500 Add `operator-linebreak` ESLint rule Based on the following discussion: https://github.com/signalapp/Signal-Desktop/pull/2040#discussion_r168029106 commit 462defbe55879060fe25bc69103d4429bae2b2f6 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 11:01:30 2018 -0500 Add missing `await` for `ConversationController.getOrCreateAndWait` Tested this by setting `if` condition to `true` and confirming it works. It turns rotating a profile key is more involved and might require registering a new account according to Matthew. commit c08058ee4b883b3e23a40683de802ac81ed74874 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 16:32:24 2018 -0500 Convert `FileList` to `Array` commit 70a6c4201925f57be1f94d9da3547fdefc7bbb53 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 15:46:34 2018 -0500 :art: Fix lint errors commit 2ca7cdbc31d4120d6c6a838a6dcf43bc209d9788 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 15:07:09 2018 -0500 Skip `autoOrientImage` for non-JPEG images commit 58eac383013c16ca363a4ed33dca5c7ba61284e5 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 14:55:35 2018 -0500 Move new-style modules to `window.Signal` namespace commit 02c9328877dce289d6116a18b1c223891bd3cd0b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 14:35:23 2018 -0500 Extract `npm run test-modules` command commit 2c708eb94fba468b81ea9427734896114f5a7807 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 13:25:51 2018 -0500 Extract `Message.process` commit 4a2e52f68a77536a0fa04aa3c29ad3e541a8fa7e Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 13:25:12 2018 -0500 Fix EditorConfig commit a346bab5db082720f5d47363f06301380e870425 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 13:13:02 2018 -0500 Remove `vim` directives on ESLint-ed files commit 7ec885c6359e495b407d5bc3eac9431d47c37fc6 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 13:08:24 2018 -0500 Remove CSP whitelisting of `blob:` We no longer use `autoOrientImage` using blob URLs. Bring this back if we decide to auto-orient legacy attachments. commit 879b6f58f4a3f4a9ed6915af6b1be46c1e90e0ca Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:57:05 2018 -0500 Use `Message` type to determine send function Throws on invalid message type. commit 5203d945c98fd2562ae4e22c5c9838d27dec305b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:56:48 2018 -0500 Whitelist `Whisper` global commit 8ad0b066a3690d3382b86bf6ac00c03df7d1e20b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:56:32 2018 -0500 Add `Whisper.Types` namespace This avoids namespace collision for `Whisper.Message`. commit 785a949fce2656ca7dcaf0869d6b9e0648114e80 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:55:43 2018 -0500 Add `Message` type commit 674a7357abf0dcc365455695d56c0479998ebf27 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:35:23 2018 -0500 Run ESLint on `Conversation::sendMessage` commit cd985aa700caa80946245b17ea1b856449f152a0 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:34:38 2018 -0500 Document type signature of `FileInputView::readFile` commit d70d70e52c49588a1dc9833dfe5dd7128e13607f Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:31:16 2018 -0500 Move attachment processing closer to sending This helps ensure processing happens uniformly, regardless of which code paths are taken to send an attachment. commit 532ac3e273a26b97f831247f9ee3412621b5c112 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:22:29 2018 -0500 Process attachment before it’s sent Picked this place since it already had various async steps, similar to `onMessageReceived` for the incoming `Attachment.process`. Could we try have this live closer to where we store it in IndexedDB, e.g. `Conversation::sendMessage`? commit a4582ae2fb6e1d3487131ba1f8fa6a00170cb32c Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:21:42 2018 -0500 Refactor `getFile` and `getFiles` Lint them using ESLint. commit 07e9114e65046d791fc4f6ed90d6e2e938ad559d Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:37:31 2018 -0500 Document incoming and outgoing attachments fields Note how outgoing message attachments only have 4 fields. This presumably means the others are not used in our code and could be discarded for simplicity. commit fdc3ef289d6ec1be344a12d496839d5ba747bb6a Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:36:21 2018 -0500 Highlight that `dataURLToBlob` is synchronous commit b9c6bf600fcecedfd649ef2ae3c8629cced4e45a Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:35:49 2018 -0500 Add EditorConfig configuration commit e56101e229d56810c8e31ad7289043a152c6c449 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:34:23 2018 -0500 Replace custom with `blob-util` functions IMPORTANT: All of them are async so we need to use `await`, otherwise we get strange or silent errors. commit f95150f6a9569fabcb31f3acd9f6b7bf50b5d145 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:17:30 2018 -0500 Revert "Replace custom functions with `blob-util`" This reverts commit 8a81e9c01bfe80c0e1bf76737092206c06949512. commit 33860d93f3d30ec55c32f3f4a58729df2eb43f0d Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:13:02 2018 -0500 Revert "Replace `blueimp-canvas-to-blob` with `blob-util`" This reverts commit 31b3e853e4afc78fe80995921aa4152d9f6e4783. commit 7a0ba6fed622d76a3c39c7f03de541a7edb5b8dd Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:12:58 2018 -0500 Replace `blueimp-canvas-to-blob` with `blob-util` commit 47a5f2bfd8b3f546e27e8d2b7e1969755d825a66 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 10:55:34 2018 -0500 Replace custom functions with `blob-util` commit 1cfa0efdb4fb1265369e2bf243c21f04f044fa01 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 10:47:02 2018 -0500 Add `blob-util` dependency commit 9ac26be1bd783cd5070d886de107dd3ad9c91ad1 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 10:46:44 2018 -0500 Document why we drop original image data during auto-orient commit 4136d6c382b99f41760a4da519d0db537fa7de8d Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 10:46:27 2018 -0500 Extract `DEFAULT_JPEG_QUALITY` commit 4a7156327eb5f94dba80cb300b344ac591226b0e Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 10:37:11 2018 -0500 Drop support for invalid `image/jpg` MIME type commit 69fe96581f25413194032232f1bf704312e4754c Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:54:30 2018 -0500 Document `window.onInvalidStateError` global commit a48ba1c77458da38583ee9cd488f70a59f6ee0fd Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:54:04 2018 -0500 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. commit e6d1cf826befc17ad4ec72fda8e761701665635e Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:16:23 2018 -0500 Move async attachment processing to `onMessageReceived` We previously processed attachments in `handleDataMessage` which is mostly a synchronous function, except for the saving of the model. Moving the processing into the already async `onMessageReceived` improves code clarity. commit be6ca2a9aae5b59c360817deb1e18d39d705755e Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:14:49 2018 -0500 Document import of ES2015+ modules commit eaaf7c41608fb988b8f4bbaa933cff110115610e Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:14:29 2018 -0500 :art: Fix lint error commit a25b0e2e3d0f72c6a7bf0a15683f02450d5209ee Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:13:57 2018 -0500 :art: Organize `require`s commit e0cc3d8fab6529d01b388acddf8605908c3d236b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:07:17 2018 -0500 Implement attachment process version Instead of keeping track of last normalization (processing) date, we now keep track of an internal processing version that will help us understand what kind of processing has already been completed for a given attachment. This will let us retroactively upgrade existing attachments. As we add more processing steps, we can build a processing pipeline that can convert any attachment processing version into a higher one, e.g. 4 -> 5 -> 6 -> 7. commit ad9083d0fdb880bc518e02251e51a39f7e1c585f Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:50:31 2018 -0500 Ignore ES2015+ files during JSCS linting commit 96641205f734927aaebc2342d977c555799c3e3b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:48:07 2018 -0500 Improve ESLint ignore rules Apparently, using unqualified `/**` patterns prevents `!` include patterns. Using qualified glob patterns, e.g. `js/models/**/*.js`, lets us work around this. commit 255e0ab15bd1a0ca8ca5746e42d23977c8765d01 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:44:59 2018 -0500 :abc: ESLint ignored files commit ebcb70258a26f234bd602072ac7c0a1913128132 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:35:47 2018 -0500 Whitelist `browser` environment for ESLint commit 3eaace6f3a21421c5aaaaf01592408c7ed83ecd3 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:35:05 2018 -0500 Use `MIME` module commit ba2cf7770e614415733414a2dcc48f110b929892 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:32:54 2018 -0500 :art: Fix lint errors commit 65acc86e8580e88f7a6611eb4b8fa5d7291f7a3f Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:30:42 2018 -0500 Add ES2015+ files to JSHint ignored list commit 8b6494ae6c9247acdfa059a9b361ec5ffcdb39f0 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:29:20 2018 -0500 Document potentially unexpected `autoScale` behavior commit 8b4c69b2002d1777d3621be10f92cbf432f9d4d6 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:26:47 2018 -0500 Test CommonJS modules separately Not sure how to test them as part of Grunt `unit-tests` task as `test/index.html` doesn’t allow for inclusion of CommonJS modules that use `require`. The tests are silently skipped. commit 213400e4b2bba3efee856a25b40e269221c3c39d Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:24:27 2018 -0500 Add `MIME` type module commit 37a726e4fb4b3ed65914463122a5662847b5adee Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 20:18:05 2018 -0500 Return proper `Error` from `blobArrayToBuffer` commit 164752db5612220e4dcf58d57bcd682cb489a399 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 20:15:41 2018 -0500 :art: Fix ESLint errors commit d498dd79a067c75098dd3179814c914780e5cb4f Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 20:14:33 2018 -0500 Update `Attachment` type field definitions commit 141155a1533ff8fb616b70ea313432781bbebffd Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 20:12:50 2018 -0500 Move `blueimp-canvas-to-blob` from Bower to npm commit 7ccb833e5d286ddd6235d3e491c62ac1e4544510 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:33:50 2018 -0500 :art: Clarify data flow commit e7da41591fde5a830467bebf1b6f51c1f7293e74 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:31:21 2018 -0500 Use `blobUrl` for consistency commit 523a80eefe0e2858aa1fb2bb9539ec44da502963 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:28:06 2018 -0500 Remove just-in-time image auto-orient for lightbox We can bring this back if our users would like auto-orient for old attachments. commit 0739feae9c47dd523c10740d6cdf746d539f270c Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:27:21 2018 -0500 Remove just-in-time auto-orient of message attachments We can bring this back if our users would like auto-orient for old attachments. But better yet, we might implement this as database migration. commit ed43c66f92830ee233d5a94d0545eea4da43894d Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:26:24 2018 -0500 Auto-orient JPEG attachments upon receipt commit e2eb8e36b017b048d57602fca14e45d657e0e1a1 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:25:26 2018 -0500 Expose `Attachment` type through `Whisper.Attachment` commit 9638fbc987b84f143ca34211dc4666d96248ea2f Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:23:39 2018 -0500 Use `contentType` from `model` commit 032c0ced46c3876cb9474b26f9d53d6f1c6b16a0 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:23:04 2018 -0500 Return `Error` object for `autoOrientImage` failures commit ff04bad8510c4b21aef350bed2b1887d0e055b98 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:22:32 2018 -0500 Add `options` for `autoOrientImage` output type / quality commit 87745b5586d1e182b51c9f9bc5e4eaf6dbc16722 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:18:46 2018 -0500 Add `Attachment` type Defines various functions on attachments, e.g. normalization (auto-orient JPEGs, etc.) commit de27fdc10a53bc8882a9c978e82265db9ac6d6f5 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:16:34 2018 -0500 Add `yarn grunt` shortcut This allows us to use local `grunt-cli` for `grunt dev`. commit 59974db5a5da0d8f4cdc8ce5c4e3c974ecd5e754 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 10:10:11 2018 -0500 Improve readability commit b5ba96f1e6f40f2e1fa77490c583217768e1f412 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 10:08:12 2018 -0500 Use `snake_case` for module names Prevents problems across case-sensitive and case-insensitive file systems. We can work around this in the future using a lint rule such as `eslint-plugin-require-path-exists`. See discussion: https://github.com/signalapp/Signal-Desktop/pull/2040#discussion_r167365931 commit 48c5d3155c96ef628b00d99b52975e580d1d5501 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 10:05:44 2018 -0500 :art: Use destructuring commit 4822f49f22382a99ebf142b337375f7c25251d76 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 17:41:40 2018 -0500 Auto-orient images in lightbox view commit 7317110809677dddbbef3fadbf912cdba1c010bf Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 17:40:14 2018 -0500 Document magic number for escape key commit c790d07389a7d0bbf5298de83dbcfa8be1e7696b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 17:38:35 2018 -0500 Make second `View` argument an `options` object commit fbe010bb63d0088af9dfe11f153437fab34247e0 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 17:27:40 2018 -0500 Allow `loadImage` to fetch `blob://` URLs commit ec35710d002b019a273eeb48f94dcaf2babe5d96 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:57:48 2018 -0500 :art: Shorten `autoOrientImage` import commit d07433e3cf316c6a143a0c9393ba26df9e3af17b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:57:19 2018 -0500 Make `autoOrientImage` module standalone commit c285bf5e33cdf10e0ef71e72cd6f55aef0df96ef Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:55:44 2018 -0500 Replace `loadImage` with `autoOrientImage` commit 44318549235af01fd061c25f557c93fd21cebb7a Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:53:23 2018 -0500 Add `autoOrientImage` module This module exposes `loadImage` with a `Promise` based interface and pre- populates `orientation: true` option to auto-orient input. Returns data URL as string. The module uses a named export as refactoring references of modules with `default` (`module.exports`) export references can be error-prone. See: https://basarat.gitbooks.io/typescript/docs/tips/defaultIsBad.html commit c77063afc6366fe49615052796fe46f9b369de39 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:44:30 2018 -0500 Auto-orient preview images See: #998 commit 06dba5eb8f662c11af3a9ba8395bb453ab2e5f8d Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:43:23 2018 -0500 TODO: Use native `Canvas::toBlob` One challenge is that `Canvas::toBlob` is async whereas `dataURLtoBlob` is sync. commit b15c304a3125dd023fd90990e6225a7303f3596f Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:42:45 2018 -0500 Make `null` check strict Appeases JSHint. ESLint has a nice `smart` option for `eqeqeq` rule: https://eslint.org/docs/rules/eqeqeq#smart commit ea70b92d9b18201758e11fdc25b09afc97b50055 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 15:23:58 2018 -0500 Use `Canvas::toDataURL` to preserve `ImageView` logic This way, all the other code paths remain untouched in case we want to remove the auto-orient code once Chrome supports the `image-orientation` CSS property. See: - #998 - https://developer.mozilla.org/en-US/docs/Web/CSS/image-orientation commit 62fd744f9f27d951573a68d2cdfe7ba2a3784b41 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 14:38:04 2018 -0500 Use CSS to constrain auto-oriented images commit f4d3392687168c237441b29140c7968b49dbef9e Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 14:35:02 2018 -0500 Replace `ImageView` `el` with auto-oriented `canvas` See: #998 commit 1602d7f610e4993ad1291f88197f9ead1e25e776 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 14:25:48 2018 -0500 Pass `Blob` to `View` (for `ImageView`) This allows us to do JPEG auto-orientation based on EXIF metadata. commit e6a414f2b2a80da1137b839b348a38510efd04bb Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 14:25:12 2018 -0500 :hocho: Remove newline commit 5f0d9570d7862fc428ff89c2ecfd332a744537e5 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 11:17:02 2018 -0500 Expose `blueimp-load-image` as `window.loadImage` commit 1e1c62fe2f6a76dbcf1998dd468c26187c9871dc Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 11:16:46 2018 -0500 Add `blueimp-load-image` npm dependency commit ad17fa8a68a21ca5ddec336801b8568009bef3d4 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 11:14:40 2018 -0500 Remove `blueimp-load-image` Bower dependency
2018-02-21 15:26:59 +00:00
return confirm();
}
function createSentMessage(data: WhatIsThis, descriptor: WhatIsThis) {
Auto-orient image attachments based on EXIF metadata As described in #998, images are sometimes displayed with an incorrect orientation. This is because cameras often write files in the native sensor byte order and attach the `Orientation` EXIF metadata to tell end-user devices how to display the images based on the original author’s capture orientation. Electron/Chromium (and therefore Signal Desktop) currently doesn’t support applying this metadata for `<img>` tags, e.g. CSS `image-orientation: from- image`. As a workaround, this change uses the `loadImage` library with the `orientation: true` flag to auto-orient images ~~before display~~ upon receipt and before sending. **Changes** - [x] ~~Auto-orient images during display in message list view~~ - [x] Ensure image is not displayed until loaded (to prevent layout reflow) . - [x] Auto-orient images upon receipt and before storing in IndexedDB (~~or preserve original data until Chromium offers native fix?~~) - [x] Auto-orient images in compose area preview. - [x] ~~Auto-orient images in lightbox view~~ - [x] Auto-orient images before sending / storage. - [x] Add EditorConfig for sharing code styles across editors. - [x] Fix ESLint ignore file. - [x] Change `function-paren-newline` ESLint rule from `consistent` to `multiline`. - [x] Add `operator-linebreak` ESLint rule for consistency. - [x] Added `blob-util` dependency for converting between array buffers, blobs, etc. - [x] Extracted `createMessageHandler` to consolidate logic for `onMessageReceived` and `onSentMessage`. - [x] Introduce `async` / `await` to simplify async coding (restore control flow for branching, loops, and exceptions). - [x] Introduce `window.Signal` namespace for exposing ES2015+ CommonJS modules. - [x] Introduce rudimentary `Message` and `Attachment` types to begin defining a schema and versioning. This will allow us to track which changes, e.g. auto-orient JPEGs, per message / attachment as well as which fields are stored. - [x] Renamed `window.dataURLtoBlob` to `window.dataURLToBlobSync` to both fix the strange `camelCase` as well as to highlight that this operation is synchronous and therefore blocks the user thread. - [x] Normalize all JPEG MIME types to `image/jpeg`, eliminating the invalid `image/jpg`. - [x] Add `npm run test-modules` command for testing non-browser specific CommonJS modules. - **Stretch Goals** - [ ] ~~Restrict `autoOrientImage` to `Blob` to narrow API interface.~~ Do this once we use PureScript. - [ ] ~~Return non-JPEGs as no-op from `autoOrientImage`.~~ Skipping `autoOrientImage` for non-JPEGs altogether. - [ ] Retroactively auto-orient existing JPEG image attachments in the background. --- Fixes #998 --- - **Blog:** EXIF Orientation Handling Is a Ghetto: https://www.daveperrett.com/articles/2012/07/28/exif-orientation-handling-is-a-ghetto/ - **Chromium Bug:** EXIF orientation is ignored: https://bugs.chromium.org/p/chromium/issues/detail?id=56845 - **Chromium Bug:** Support for the CSS image-orientation CSS property: https://bugs.chromium.org/p/chromium/issues/detail?id=158753 --- commit ce5090b473a2448229dc38e4c3f15d7ad0137714 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 16 10:35:36 2018 -0500 Inline message descriptors commit 329036e59c138c1e950ec7c654eebd7d87076de5 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Thu Feb 15 17:34:40 2018 -0500 Clarify order of operations Semantically, it makes more sense to do `getFile` before `clearForm` even though it seems to work either way. commit f9d4cfb2ba0d8aa308b0923bbe6066ea34cb97bd Author: Daniel Gasienica <daniel@gasienica.ch> Date: Thu Feb 15 17:18:26 2018 -0500 Simplify `operator-linebreak` configuration Enabling `before` caused more code changes and it turns out our previous configuration is already the default. commit db588997acdd90ed2ad829174ecbba744383c78b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Thu Feb 15 17:15:59 2018 -0500 Remove obsolete TODO commit 799c8817633f6afa0b731fc3b5434e463bd850e3 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Thu Feb 15 17:12:18 2018 -0500 Enable ESLint `function-paren-newline` `multiline` Per discussion. commit b660b6bc8ef41df7601a411213d6cda80821df87 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Thu Feb 15 17:10:48 2018 -0500 Use `messageDescriptor.id` not `source` commit 5e7309d176f4a7e97d3dc4c738e6b0ccd4792871 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 16:29:01 2018 -0500 Remove unnecessary `eslint-env` commit 393b3da55eabd7413596c86cc3971b063a0efe31 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 16:19:17 2018 -0500 Refactor `onSentMessage` and `onMessageReceived` Since they are so similar, we create the handlers using new `createMessageHandler` function. This allows us to ensure both synced and received messages go through schema upgrade pipeline. commit b3db0bf179c9a5bea96480cde28c6fa7193ac117 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 16:18:21 2018 -0500 Add `Message` descriptor functions commit 8febf125b1b42fe4ae1888dd50fcee2749dc1ff0 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 14:46:56 2018 -0500 Fix typo commit 98d951ef77bd578b313a4ff4b496b793e82e88d5 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 12:22:39 2018 -0500 Remove `promises` reference commit a0e9559ed5bed947dabf28cb672e63d39948d854 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 12:22:13 2018 -0500 Fix `AttachmentView::mediaType` fall-through commit 67be916a83951b8a1f9b22efe78a6da6b1825f38 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 12:03:41 2018 -0500 Remove minor TODOs commit 0af186e118256b62905de38487ffacc41693ff47 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 11:44:41 2018 -0500 Enable ESLint for `js/views/attachment_view.js` commit 28a2dc5b8a28e1a087924fdc7275bf7d9a577b92 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 11:44:12 2018 -0500 Remove dynamic type checks commit f4ce36fcfc2737de32d911cd6103f889097813f6 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 11:27:56 2018 -0500 Rename `process` to `upgradeSchema` - `Message.process` -> `Message.upgradeSchema` - `Attachment.process` -> `Attachment.upgradeSchema` - `Attachment::processVersion` -> `Attachment::schemaVersion` Document version history. commit 41b92c0a31050ba05ddb1c43171d651f3568b9ac Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 11:11:50 2018 -0500 Add `operator-linebreak` ESLint rule Based on the following discussion: https://github.com/signalapp/Signal-Desktop/pull/2040#discussion_r168029106 commit 462defbe55879060fe25bc69103d4429bae2b2f6 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 11:01:30 2018 -0500 Add missing `await` for `ConversationController.getOrCreateAndWait` Tested this by setting `if` condition to `true` and confirming it works. It turns rotating a profile key is more involved and might require registering a new account according to Matthew. commit c08058ee4b883b3e23a40683de802ac81ed74874 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 16:32:24 2018 -0500 Convert `FileList` to `Array` commit 70a6c4201925f57be1f94d9da3547fdefc7bbb53 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 15:46:34 2018 -0500 :art: Fix lint errors commit 2ca7cdbc31d4120d6c6a838a6dcf43bc209d9788 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 15:07:09 2018 -0500 Skip `autoOrientImage` for non-JPEG images commit 58eac383013c16ca363a4ed33dca5c7ba61284e5 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 14:55:35 2018 -0500 Move new-style modules to `window.Signal` namespace commit 02c9328877dce289d6116a18b1c223891bd3cd0b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 14:35:23 2018 -0500 Extract `npm run test-modules` command commit 2c708eb94fba468b81ea9427734896114f5a7807 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 13:25:51 2018 -0500 Extract `Message.process` commit 4a2e52f68a77536a0fa04aa3c29ad3e541a8fa7e Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 13:25:12 2018 -0500 Fix EditorConfig commit a346bab5db082720f5d47363f06301380e870425 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 13:13:02 2018 -0500 Remove `vim` directives on ESLint-ed files commit 7ec885c6359e495b407d5bc3eac9431d47c37fc6 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 13:08:24 2018 -0500 Remove CSP whitelisting of `blob:` We no longer use `autoOrientImage` using blob URLs. Bring this back if we decide to auto-orient legacy attachments. commit 879b6f58f4a3f4a9ed6915af6b1be46c1e90e0ca Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:57:05 2018 -0500 Use `Message` type to determine send function Throws on invalid message type. commit 5203d945c98fd2562ae4e22c5c9838d27dec305b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:56:48 2018 -0500 Whitelist `Whisper` global commit 8ad0b066a3690d3382b86bf6ac00c03df7d1e20b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:56:32 2018 -0500 Add `Whisper.Types` namespace This avoids namespace collision for `Whisper.Message`. commit 785a949fce2656ca7dcaf0869d6b9e0648114e80 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:55:43 2018 -0500 Add `Message` type commit 674a7357abf0dcc365455695d56c0479998ebf27 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:35:23 2018 -0500 Run ESLint on `Conversation::sendMessage` commit cd985aa700caa80946245b17ea1b856449f152a0 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:34:38 2018 -0500 Document type signature of `FileInputView::readFile` commit d70d70e52c49588a1dc9833dfe5dd7128e13607f Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:31:16 2018 -0500 Move attachment processing closer to sending This helps ensure processing happens uniformly, regardless of which code paths are taken to send an attachment. commit 532ac3e273a26b97f831247f9ee3412621b5c112 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:22:29 2018 -0500 Process attachment before it’s sent Picked this place since it already had various async steps, similar to `onMessageReceived` for the incoming `Attachment.process`. Could we try have this live closer to where we store it in IndexedDB, e.g. `Conversation::sendMessage`? commit a4582ae2fb6e1d3487131ba1f8fa6a00170cb32c Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:21:42 2018 -0500 Refactor `getFile` and `getFiles` Lint them using ESLint. commit 07e9114e65046d791fc4f6ed90d6e2e938ad559d Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:37:31 2018 -0500 Document incoming and outgoing attachments fields Note how outgoing message attachments only have 4 fields. This presumably means the others are not used in our code and could be discarded for simplicity. commit fdc3ef289d6ec1be344a12d496839d5ba747bb6a Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:36:21 2018 -0500 Highlight that `dataURLToBlob` is synchronous commit b9c6bf600fcecedfd649ef2ae3c8629cced4e45a Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:35:49 2018 -0500 Add EditorConfig configuration commit e56101e229d56810c8e31ad7289043a152c6c449 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:34:23 2018 -0500 Replace custom with `blob-util` functions IMPORTANT: All of them are async so we need to use `await`, otherwise we get strange or silent errors. commit f95150f6a9569fabcb31f3acd9f6b7bf50b5d145 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:17:30 2018 -0500 Revert "Replace custom functions with `blob-util`" This reverts commit 8a81e9c01bfe80c0e1bf76737092206c06949512. commit 33860d93f3d30ec55c32f3f4a58729df2eb43f0d Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:13:02 2018 -0500 Revert "Replace `blueimp-canvas-to-blob` with `blob-util`" This reverts commit 31b3e853e4afc78fe80995921aa4152d9f6e4783. commit 7a0ba6fed622d76a3c39c7f03de541a7edb5b8dd Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:12:58 2018 -0500 Replace `blueimp-canvas-to-blob` with `blob-util` commit 47a5f2bfd8b3f546e27e8d2b7e1969755d825a66 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 10:55:34 2018 -0500 Replace custom functions with `blob-util` commit 1cfa0efdb4fb1265369e2bf243c21f04f044fa01 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 10:47:02 2018 -0500 Add `blob-util` dependency commit 9ac26be1bd783cd5070d886de107dd3ad9c91ad1 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 10:46:44 2018 -0500 Document why we drop original image data during auto-orient commit 4136d6c382b99f41760a4da519d0db537fa7de8d Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 10:46:27 2018 -0500 Extract `DEFAULT_JPEG_QUALITY` commit 4a7156327eb5f94dba80cb300b344ac591226b0e Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 10:37:11 2018 -0500 Drop support for invalid `image/jpg` MIME type commit 69fe96581f25413194032232f1bf704312e4754c Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:54:30 2018 -0500 Document `window.onInvalidStateError` global commit a48ba1c77458da38583ee9cd488f70a59f6ee0fd Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:54:04 2018 -0500 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. commit e6d1cf826befc17ad4ec72fda8e761701665635e Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:16:23 2018 -0500 Move async attachment processing to `onMessageReceived` We previously processed attachments in `handleDataMessage` which is mostly a synchronous function, except for the saving of the model. Moving the processing into the already async `onMessageReceived` improves code clarity. commit be6ca2a9aae5b59c360817deb1e18d39d705755e Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:14:49 2018 -0500 Document import of ES2015+ modules commit eaaf7c41608fb988b8f4bbaa933cff110115610e Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:14:29 2018 -0500 :art: Fix lint error commit a25b0e2e3d0f72c6a7bf0a15683f02450d5209ee Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:13:57 2018 -0500 :art: Organize `require`s commit e0cc3d8fab6529d01b388acddf8605908c3d236b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:07:17 2018 -0500 Implement attachment process version Instead of keeping track of last normalization (processing) date, we now keep track of an internal processing version that will help us understand what kind of processing has already been completed for a given attachment. This will let us retroactively upgrade existing attachments. As we add more processing steps, we can build a processing pipeline that can convert any attachment processing version into a higher one, e.g. 4 -> 5 -> 6 -> 7. commit ad9083d0fdb880bc518e02251e51a39f7e1c585f Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:50:31 2018 -0500 Ignore ES2015+ files during JSCS linting commit 96641205f734927aaebc2342d977c555799c3e3b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:48:07 2018 -0500 Improve ESLint ignore rules Apparently, using unqualified `/**` patterns prevents `!` include patterns. Using qualified glob patterns, e.g. `js/models/**/*.js`, lets us work around this. commit 255e0ab15bd1a0ca8ca5746e42d23977c8765d01 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:44:59 2018 -0500 :abc: ESLint ignored files commit ebcb70258a26f234bd602072ac7c0a1913128132 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:35:47 2018 -0500 Whitelist `browser` environment for ESLint commit 3eaace6f3a21421c5aaaaf01592408c7ed83ecd3 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:35:05 2018 -0500 Use `MIME` module commit ba2cf7770e614415733414a2dcc48f110b929892 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:32:54 2018 -0500 :art: Fix lint errors commit 65acc86e8580e88f7a6611eb4b8fa5d7291f7a3f Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:30:42 2018 -0500 Add ES2015+ files to JSHint ignored list commit 8b6494ae6c9247acdfa059a9b361ec5ffcdb39f0 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:29:20 2018 -0500 Document potentially unexpected `autoScale` behavior commit 8b4c69b2002d1777d3621be10f92cbf432f9d4d6 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:26:47 2018 -0500 Test CommonJS modules separately Not sure how to test them as part of Grunt `unit-tests` task as `test/index.html` doesn’t allow for inclusion of CommonJS modules that use `require`. The tests are silently skipped. commit 213400e4b2bba3efee856a25b40e269221c3c39d Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:24:27 2018 -0500 Add `MIME` type module commit 37a726e4fb4b3ed65914463122a5662847b5adee Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 20:18:05 2018 -0500 Return proper `Error` from `blobArrayToBuffer` commit 164752db5612220e4dcf58d57bcd682cb489a399 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 20:15:41 2018 -0500 :art: Fix ESLint errors commit d498dd79a067c75098dd3179814c914780e5cb4f Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 20:14:33 2018 -0500 Update `Attachment` type field definitions commit 141155a1533ff8fb616b70ea313432781bbebffd Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 20:12:50 2018 -0500 Move `blueimp-canvas-to-blob` from Bower to npm commit 7ccb833e5d286ddd6235d3e491c62ac1e4544510 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:33:50 2018 -0500 :art: Clarify data flow commit e7da41591fde5a830467bebf1b6f51c1f7293e74 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:31:21 2018 -0500 Use `blobUrl` for consistency commit 523a80eefe0e2858aa1fb2bb9539ec44da502963 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:28:06 2018 -0500 Remove just-in-time image auto-orient for lightbox We can bring this back if our users would like auto-orient for old attachments. commit 0739feae9c47dd523c10740d6cdf746d539f270c Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:27:21 2018 -0500 Remove just-in-time auto-orient of message attachments We can bring this back if our users would like auto-orient for old attachments. But better yet, we might implement this as database migration. commit ed43c66f92830ee233d5a94d0545eea4da43894d Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:26:24 2018 -0500 Auto-orient JPEG attachments upon receipt commit e2eb8e36b017b048d57602fca14e45d657e0e1a1 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:25:26 2018 -0500 Expose `Attachment` type through `Whisper.Attachment` commit 9638fbc987b84f143ca34211dc4666d96248ea2f Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:23:39 2018 -0500 Use `contentType` from `model` commit 032c0ced46c3876cb9474b26f9d53d6f1c6b16a0 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:23:04 2018 -0500 Return `Error` object for `autoOrientImage` failures commit ff04bad8510c4b21aef350bed2b1887d0e055b98 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:22:32 2018 -0500 Add `options` for `autoOrientImage` output type / quality commit 87745b5586d1e182b51c9f9bc5e4eaf6dbc16722 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:18:46 2018 -0500 Add `Attachment` type Defines various functions on attachments, e.g. normalization (auto-orient JPEGs, etc.) commit de27fdc10a53bc8882a9c978e82265db9ac6d6f5 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:16:34 2018 -0500 Add `yarn grunt` shortcut This allows us to use local `grunt-cli` for `grunt dev`. commit 59974db5a5da0d8f4cdc8ce5c4e3c974ecd5e754 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 10:10:11 2018 -0500 Improve readability commit b5ba96f1e6f40f2e1fa77490c583217768e1f412 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 10:08:12 2018 -0500 Use `snake_case` for module names Prevents problems across case-sensitive and case-insensitive file systems. We can work around this in the future using a lint rule such as `eslint-plugin-require-path-exists`. See discussion: https://github.com/signalapp/Signal-Desktop/pull/2040#discussion_r167365931 commit 48c5d3155c96ef628b00d99b52975e580d1d5501 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 10:05:44 2018 -0500 :art: Use destructuring commit 4822f49f22382a99ebf142b337375f7c25251d76 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 17:41:40 2018 -0500 Auto-orient images in lightbox view commit 7317110809677dddbbef3fadbf912cdba1c010bf Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 17:40:14 2018 -0500 Document magic number for escape key commit c790d07389a7d0bbf5298de83dbcfa8be1e7696b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 17:38:35 2018 -0500 Make second `View` argument an `options` object commit fbe010bb63d0088af9dfe11f153437fab34247e0 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 17:27:40 2018 -0500 Allow `loadImage` to fetch `blob://` URLs commit ec35710d002b019a273eeb48f94dcaf2babe5d96 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:57:48 2018 -0500 :art: Shorten `autoOrientImage` import commit d07433e3cf316c6a143a0c9393ba26df9e3af17b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:57:19 2018 -0500 Make `autoOrientImage` module standalone commit c285bf5e33cdf10e0ef71e72cd6f55aef0df96ef Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:55:44 2018 -0500 Replace `loadImage` with `autoOrientImage` commit 44318549235af01fd061c25f557c93fd21cebb7a Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:53:23 2018 -0500 Add `autoOrientImage` module This module exposes `loadImage` with a `Promise` based interface and pre- populates `orientation: true` option to auto-orient input. Returns data URL as string. The module uses a named export as refactoring references of modules with `default` (`module.exports`) export references can be error-prone. See: https://basarat.gitbooks.io/typescript/docs/tips/defaultIsBad.html commit c77063afc6366fe49615052796fe46f9b369de39 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:44:30 2018 -0500 Auto-orient preview images See: #998 commit 06dba5eb8f662c11af3a9ba8395bb453ab2e5f8d Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:43:23 2018 -0500 TODO: Use native `Canvas::toBlob` One challenge is that `Canvas::toBlob` is async whereas `dataURLtoBlob` is sync. commit b15c304a3125dd023fd90990e6225a7303f3596f Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:42:45 2018 -0500 Make `null` check strict Appeases JSHint. ESLint has a nice `smart` option for `eqeqeq` rule: https://eslint.org/docs/rules/eqeqeq#smart commit ea70b92d9b18201758e11fdc25b09afc97b50055 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 15:23:58 2018 -0500 Use `Canvas::toDataURL` to preserve `ImageView` logic This way, all the other code paths remain untouched in case we want to remove the auto-orient code once Chrome supports the `image-orientation` CSS property. See: - #998 - https://developer.mozilla.org/en-US/docs/Web/CSS/image-orientation commit 62fd744f9f27d951573a68d2cdfe7ba2a3784b41 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 14:38:04 2018 -0500 Use CSS to constrain auto-oriented images commit f4d3392687168c237441b29140c7968b49dbef9e Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 14:35:02 2018 -0500 Replace `ImageView` `el` with auto-oriented `canvas` See: #998 commit 1602d7f610e4993ad1291f88197f9ead1e25e776 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 14:25:48 2018 -0500 Pass `Blob` to `View` (for `ImageView`) This allows us to do JPEG auto-orientation based on EXIF metadata. commit e6a414f2b2a80da1137b839b348a38510efd04bb Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 14:25:12 2018 -0500 :hocho: Remove newline commit 5f0d9570d7862fc428ff89c2ecfd332a744537e5 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 11:17:02 2018 -0500 Expose `blueimp-load-image` as `window.loadImage` commit 1e1c62fe2f6a76dbcf1998dd468c26187c9871dc Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 11:16:46 2018 -0500 Add `blueimp-load-image` npm dependency commit ad17fa8a68a21ca5ddec336801b8568009bef3d4 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 11:14:40 2018 -0500 Remove `blueimp-load-image` Bower dependency
2018-02-21 15:26:59 +00:00
const now = Date.now();
let sentTo = [];
if (data.unidentifiedStatus && data.unidentifiedStatus.length) {
sentTo = data.unidentifiedStatus.map(
(item: WhatIsThis) => item.destinationUuid || item.destination
);
const unidentified = _.filter(data.unidentifiedStatus, item =>
Boolean(item.unidentified)
);
// eslint-disable-next-line no-param-reassign
data.unidentifiedDeliveries = unidentified.map(
item => item.destinationUuid || item.destination
);
}
return new window.Whisper.Message({
source: window.textsecure.storage.user.getNumber(),
sourceUuid: window.textsecure.storage.user.getUuid(),
Auto-orient image attachments based on EXIF metadata As described in #998, images are sometimes displayed with an incorrect orientation. This is because cameras often write files in the native sensor byte order and attach the `Orientation` EXIF metadata to tell end-user devices how to display the images based on the original author’s capture orientation. Electron/Chromium (and therefore Signal Desktop) currently doesn’t support applying this metadata for `<img>` tags, e.g. CSS `image-orientation: from- image`. As a workaround, this change uses the `loadImage` library with the `orientation: true` flag to auto-orient images ~~before display~~ upon receipt and before sending. **Changes** - [x] ~~Auto-orient images during display in message list view~~ - [x] Ensure image is not displayed until loaded (to prevent layout reflow) . - [x] Auto-orient images upon receipt and before storing in IndexedDB (~~or preserve original data until Chromium offers native fix?~~) - [x] Auto-orient images in compose area preview. - [x] ~~Auto-orient images in lightbox view~~ - [x] Auto-orient images before sending / storage. - [x] Add EditorConfig for sharing code styles across editors. - [x] Fix ESLint ignore file. - [x] Change `function-paren-newline` ESLint rule from `consistent` to `multiline`. - [x] Add `operator-linebreak` ESLint rule for consistency. - [x] Added `blob-util` dependency for converting between array buffers, blobs, etc. - [x] Extracted `createMessageHandler` to consolidate logic for `onMessageReceived` and `onSentMessage`. - [x] Introduce `async` / `await` to simplify async coding (restore control flow for branching, loops, and exceptions). - [x] Introduce `window.Signal` namespace for exposing ES2015+ CommonJS modules. - [x] Introduce rudimentary `Message` and `Attachment` types to begin defining a schema and versioning. This will allow us to track which changes, e.g. auto-orient JPEGs, per message / attachment as well as which fields are stored. - [x] Renamed `window.dataURLtoBlob` to `window.dataURLToBlobSync` to both fix the strange `camelCase` as well as to highlight that this operation is synchronous and therefore blocks the user thread. - [x] Normalize all JPEG MIME types to `image/jpeg`, eliminating the invalid `image/jpg`. - [x] Add `npm run test-modules` command for testing non-browser specific CommonJS modules. - **Stretch Goals** - [ ] ~~Restrict `autoOrientImage` to `Blob` to narrow API interface.~~ Do this once we use PureScript. - [ ] ~~Return non-JPEGs as no-op from `autoOrientImage`.~~ Skipping `autoOrientImage` for non-JPEGs altogether. - [ ] Retroactively auto-orient existing JPEG image attachments in the background. --- Fixes #998 --- - **Blog:** EXIF Orientation Handling Is a Ghetto: https://www.daveperrett.com/articles/2012/07/28/exif-orientation-handling-is-a-ghetto/ - **Chromium Bug:** EXIF orientation is ignored: https://bugs.chromium.org/p/chromium/issues/detail?id=56845 - **Chromium Bug:** Support for the CSS image-orientation CSS property: https://bugs.chromium.org/p/chromium/issues/detail?id=158753 --- commit ce5090b473a2448229dc38e4c3f15d7ad0137714 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 16 10:35:36 2018 -0500 Inline message descriptors commit 329036e59c138c1e950ec7c654eebd7d87076de5 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Thu Feb 15 17:34:40 2018 -0500 Clarify order of operations Semantically, it makes more sense to do `getFile` before `clearForm` even though it seems to work either way. commit f9d4cfb2ba0d8aa308b0923bbe6066ea34cb97bd Author: Daniel Gasienica <daniel@gasienica.ch> Date: Thu Feb 15 17:18:26 2018 -0500 Simplify `operator-linebreak` configuration Enabling `before` caused more code changes and it turns out our previous configuration is already the default. commit db588997acdd90ed2ad829174ecbba744383c78b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Thu Feb 15 17:15:59 2018 -0500 Remove obsolete TODO commit 799c8817633f6afa0b731fc3b5434e463bd850e3 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Thu Feb 15 17:12:18 2018 -0500 Enable ESLint `function-paren-newline` `multiline` Per discussion. commit b660b6bc8ef41df7601a411213d6cda80821df87 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Thu Feb 15 17:10:48 2018 -0500 Use `messageDescriptor.id` not `source` commit 5e7309d176f4a7e97d3dc4c738e6b0ccd4792871 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 16:29:01 2018 -0500 Remove unnecessary `eslint-env` commit 393b3da55eabd7413596c86cc3971b063a0efe31 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 16:19:17 2018 -0500 Refactor `onSentMessage` and `onMessageReceived` Since they are so similar, we create the handlers using new `createMessageHandler` function. This allows us to ensure both synced and received messages go through schema upgrade pipeline. commit b3db0bf179c9a5bea96480cde28c6fa7193ac117 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 16:18:21 2018 -0500 Add `Message` descriptor functions commit 8febf125b1b42fe4ae1888dd50fcee2749dc1ff0 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 14:46:56 2018 -0500 Fix typo commit 98d951ef77bd578b313a4ff4b496b793e82e88d5 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 12:22:39 2018 -0500 Remove `promises` reference commit a0e9559ed5bed947dabf28cb672e63d39948d854 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 12:22:13 2018 -0500 Fix `AttachmentView::mediaType` fall-through commit 67be916a83951b8a1f9b22efe78a6da6b1825f38 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 12:03:41 2018 -0500 Remove minor TODOs commit 0af186e118256b62905de38487ffacc41693ff47 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 11:44:41 2018 -0500 Enable ESLint for `js/views/attachment_view.js` commit 28a2dc5b8a28e1a087924fdc7275bf7d9a577b92 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 11:44:12 2018 -0500 Remove dynamic type checks commit f4ce36fcfc2737de32d911cd6103f889097813f6 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 11:27:56 2018 -0500 Rename `process` to `upgradeSchema` - `Message.process` -> `Message.upgradeSchema` - `Attachment.process` -> `Attachment.upgradeSchema` - `Attachment::processVersion` -> `Attachment::schemaVersion` Document version history. commit 41b92c0a31050ba05ddb1c43171d651f3568b9ac Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 11:11:50 2018 -0500 Add `operator-linebreak` ESLint rule Based on the following discussion: https://github.com/signalapp/Signal-Desktop/pull/2040#discussion_r168029106 commit 462defbe55879060fe25bc69103d4429bae2b2f6 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 11:01:30 2018 -0500 Add missing `await` for `ConversationController.getOrCreateAndWait` Tested this by setting `if` condition to `true` and confirming it works. It turns rotating a profile key is more involved and might require registering a new account according to Matthew. commit c08058ee4b883b3e23a40683de802ac81ed74874 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 16:32:24 2018 -0500 Convert `FileList` to `Array` commit 70a6c4201925f57be1f94d9da3547fdefc7bbb53 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 15:46:34 2018 -0500 :art: Fix lint errors commit 2ca7cdbc31d4120d6c6a838a6dcf43bc209d9788 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 15:07:09 2018 -0500 Skip `autoOrientImage` for non-JPEG images commit 58eac383013c16ca363a4ed33dca5c7ba61284e5 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 14:55:35 2018 -0500 Move new-style modules to `window.Signal` namespace commit 02c9328877dce289d6116a18b1c223891bd3cd0b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 14:35:23 2018 -0500 Extract `npm run test-modules` command commit 2c708eb94fba468b81ea9427734896114f5a7807 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 13:25:51 2018 -0500 Extract `Message.process` commit 4a2e52f68a77536a0fa04aa3c29ad3e541a8fa7e Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 13:25:12 2018 -0500 Fix EditorConfig commit a346bab5db082720f5d47363f06301380e870425 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 13:13:02 2018 -0500 Remove `vim` directives on ESLint-ed files commit 7ec885c6359e495b407d5bc3eac9431d47c37fc6 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 13:08:24 2018 -0500 Remove CSP whitelisting of `blob:` We no longer use `autoOrientImage` using blob URLs. Bring this back if we decide to auto-orient legacy attachments. commit 879b6f58f4a3f4a9ed6915af6b1be46c1e90e0ca Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:57:05 2018 -0500 Use `Message` type to determine send function Throws on invalid message type. commit 5203d945c98fd2562ae4e22c5c9838d27dec305b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:56:48 2018 -0500 Whitelist `Whisper` global commit 8ad0b066a3690d3382b86bf6ac00c03df7d1e20b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:56:32 2018 -0500 Add `Whisper.Types` namespace This avoids namespace collision for `Whisper.Message`. commit 785a949fce2656ca7dcaf0869d6b9e0648114e80 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:55:43 2018 -0500 Add `Message` type commit 674a7357abf0dcc365455695d56c0479998ebf27 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:35:23 2018 -0500 Run ESLint on `Conversation::sendMessage` commit cd985aa700caa80946245b17ea1b856449f152a0 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:34:38 2018 -0500 Document type signature of `FileInputView::readFile` commit d70d70e52c49588a1dc9833dfe5dd7128e13607f Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:31:16 2018 -0500 Move attachment processing closer to sending This helps ensure processing happens uniformly, regardless of which code paths are taken to send an attachment. commit 532ac3e273a26b97f831247f9ee3412621b5c112 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:22:29 2018 -0500 Process attachment before it’s sent Picked this place since it already had various async steps, similar to `onMessageReceived` for the incoming `Attachment.process`. Could we try have this live closer to where we store it in IndexedDB, e.g. `Conversation::sendMessage`? commit a4582ae2fb6e1d3487131ba1f8fa6a00170cb32c Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:21:42 2018 -0500 Refactor `getFile` and `getFiles` Lint them using ESLint. commit 07e9114e65046d791fc4f6ed90d6e2e938ad559d Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:37:31 2018 -0500 Document incoming and outgoing attachments fields Note how outgoing message attachments only have 4 fields. This presumably means the others are not used in our code and could be discarded for simplicity. commit fdc3ef289d6ec1be344a12d496839d5ba747bb6a Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:36:21 2018 -0500 Highlight that `dataURLToBlob` is synchronous commit b9c6bf600fcecedfd649ef2ae3c8629cced4e45a Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:35:49 2018 -0500 Add EditorConfig configuration commit e56101e229d56810c8e31ad7289043a152c6c449 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:34:23 2018 -0500 Replace custom with `blob-util` functions IMPORTANT: All of them are async so we need to use `await`, otherwise we get strange or silent errors. commit f95150f6a9569fabcb31f3acd9f6b7bf50b5d145 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:17:30 2018 -0500 Revert "Replace custom functions with `blob-util`" This reverts commit 8a81e9c01bfe80c0e1bf76737092206c06949512. commit 33860d93f3d30ec55c32f3f4a58729df2eb43f0d Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:13:02 2018 -0500 Revert "Replace `blueimp-canvas-to-blob` with `blob-util`" This reverts commit 31b3e853e4afc78fe80995921aa4152d9f6e4783. commit 7a0ba6fed622d76a3c39c7f03de541a7edb5b8dd Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:12:58 2018 -0500 Replace `blueimp-canvas-to-blob` with `blob-util` commit 47a5f2bfd8b3f546e27e8d2b7e1969755d825a66 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 10:55:34 2018 -0500 Replace custom functions with `blob-util` commit 1cfa0efdb4fb1265369e2bf243c21f04f044fa01 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 10:47:02 2018 -0500 Add `blob-util` dependency commit 9ac26be1bd783cd5070d886de107dd3ad9c91ad1 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 10:46:44 2018 -0500 Document why we drop original image data during auto-orient commit 4136d6c382b99f41760a4da519d0db537fa7de8d Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 10:46:27 2018 -0500 Extract `DEFAULT_JPEG_QUALITY` commit 4a7156327eb5f94dba80cb300b344ac591226b0e Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 10:37:11 2018 -0500 Drop support for invalid `image/jpg` MIME type commit 69fe96581f25413194032232f1bf704312e4754c Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:54:30 2018 -0500 Document `window.onInvalidStateError` global commit a48ba1c77458da38583ee9cd488f70a59f6ee0fd Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:54:04 2018 -0500 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. commit e6d1cf826befc17ad4ec72fda8e761701665635e Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:16:23 2018 -0500 Move async attachment processing to `onMessageReceived` We previously processed attachments in `handleDataMessage` which is mostly a synchronous function, except for the saving of the model. Moving the processing into the already async `onMessageReceived` improves code clarity. commit be6ca2a9aae5b59c360817deb1e18d39d705755e Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:14:49 2018 -0500 Document import of ES2015+ modules commit eaaf7c41608fb988b8f4bbaa933cff110115610e Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:14:29 2018 -0500 :art: Fix lint error commit a25b0e2e3d0f72c6a7bf0a15683f02450d5209ee Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:13:57 2018 -0500 :art: Organize `require`s commit e0cc3d8fab6529d01b388acddf8605908c3d236b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:07:17 2018 -0500 Implement attachment process version Instead of keeping track of last normalization (processing) date, we now keep track of an internal processing version that will help us understand what kind of processing has already been completed for a given attachment. This will let us retroactively upgrade existing attachments. As we add more processing steps, we can build a processing pipeline that can convert any attachment processing version into a higher one, e.g. 4 -> 5 -> 6 -> 7. commit ad9083d0fdb880bc518e02251e51a39f7e1c585f Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:50:31 2018 -0500 Ignore ES2015+ files during JSCS linting commit 96641205f734927aaebc2342d977c555799c3e3b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:48:07 2018 -0500 Improve ESLint ignore rules Apparently, using unqualified `/**` patterns prevents `!` include patterns. Using qualified glob patterns, e.g. `js/models/**/*.js`, lets us work around this. commit 255e0ab15bd1a0ca8ca5746e42d23977c8765d01 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:44:59 2018 -0500 :abc: ESLint ignored files commit ebcb70258a26f234bd602072ac7c0a1913128132 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:35:47 2018 -0500 Whitelist `browser` environment for ESLint commit 3eaace6f3a21421c5aaaaf01592408c7ed83ecd3 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:35:05 2018 -0500 Use `MIME` module commit ba2cf7770e614415733414a2dcc48f110b929892 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:32:54 2018 -0500 :art: Fix lint errors commit 65acc86e8580e88f7a6611eb4b8fa5d7291f7a3f Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:30:42 2018 -0500 Add ES2015+ files to JSHint ignored list commit 8b6494ae6c9247acdfa059a9b361ec5ffcdb39f0 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:29:20 2018 -0500 Document potentially unexpected `autoScale` behavior commit 8b4c69b2002d1777d3621be10f92cbf432f9d4d6 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:26:47 2018 -0500 Test CommonJS modules separately Not sure how to test them as part of Grunt `unit-tests` task as `test/index.html` doesn’t allow for inclusion of CommonJS modules that use `require`. The tests are silently skipped. commit 213400e4b2bba3efee856a25b40e269221c3c39d Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:24:27 2018 -0500 Add `MIME` type module commit 37a726e4fb4b3ed65914463122a5662847b5adee Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 20:18:05 2018 -0500 Return proper `Error` from `blobArrayToBuffer` commit 164752db5612220e4dcf58d57bcd682cb489a399 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 20:15:41 2018 -0500 :art: Fix ESLint errors commit d498dd79a067c75098dd3179814c914780e5cb4f Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 20:14:33 2018 -0500 Update `Attachment` type field definitions commit 141155a1533ff8fb616b70ea313432781bbebffd Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 20:12:50 2018 -0500 Move `blueimp-canvas-to-blob` from Bower to npm commit 7ccb833e5d286ddd6235d3e491c62ac1e4544510 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:33:50 2018 -0500 :art: Clarify data flow commit e7da41591fde5a830467bebf1b6f51c1f7293e74 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:31:21 2018 -0500 Use `blobUrl` for consistency commit 523a80eefe0e2858aa1fb2bb9539ec44da502963 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:28:06 2018 -0500 Remove just-in-time image auto-orient for lightbox We can bring this back if our users would like auto-orient for old attachments. commit 0739feae9c47dd523c10740d6cdf746d539f270c Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:27:21 2018 -0500 Remove just-in-time auto-orient of message attachments We can bring this back if our users would like auto-orient for old attachments. But better yet, we might implement this as database migration. commit ed43c66f92830ee233d5a94d0545eea4da43894d Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:26:24 2018 -0500 Auto-orient JPEG attachments upon receipt commit e2eb8e36b017b048d57602fca14e45d657e0e1a1 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:25:26 2018 -0500 Expose `Attachment` type through `Whisper.Attachment` commit 9638fbc987b84f143ca34211dc4666d96248ea2f Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:23:39 2018 -0500 Use `contentType` from `model` commit 032c0ced46c3876cb9474b26f9d53d6f1c6b16a0 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:23:04 2018 -0500 Return `Error` object for `autoOrientImage` failures commit ff04bad8510c4b21aef350bed2b1887d0e055b98 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:22:32 2018 -0500 Add `options` for `autoOrientImage` output type / quality commit 87745b5586d1e182b51c9f9bc5e4eaf6dbc16722 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:18:46 2018 -0500 Add `Attachment` type Defines various functions on attachments, e.g. normalization (auto-orient JPEGs, etc.) commit de27fdc10a53bc8882a9c978e82265db9ac6d6f5 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:16:34 2018 -0500 Add `yarn grunt` shortcut This allows us to use local `grunt-cli` for `grunt dev`. commit 59974db5a5da0d8f4cdc8ce5c4e3c974ecd5e754 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 10:10:11 2018 -0500 Improve readability commit b5ba96f1e6f40f2e1fa77490c583217768e1f412 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 10:08:12 2018 -0500 Use `snake_case` for module names Prevents problems across case-sensitive and case-insensitive file systems. We can work around this in the future using a lint rule such as `eslint-plugin-require-path-exists`. See discussion: https://github.com/signalapp/Signal-Desktop/pull/2040#discussion_r167365931 commit 48c5d3155c96ef628b00d99b52975e580d1d5501 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 10:05:44 2018 -0500 :art: Use destructuring commit 4822f49f22382a99ebf142b337375f7c25251d76 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 17:41:40 2018 -0500 Auto-orient images in lightbox view commit 7317110809677dddbbef3fadbf912cdba1c010bf Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 17:40:14 2018 -0500 Document magic number for escape key commit c790d07389a7d0bbf5298de83dbcfa8be1e7696b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 17:38:35 2018 -0500 Make second `View` argument an `options` object commit fbe010bb63d0088af9dfe11f153437fab34247e0 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 17:27:40 2018 -0500 Allow `loadImage` to fetch `blob://` URLs commit ec35710d002b019a273eeb48f94dcaf2babe5d96 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:57:48 2018 -0500 :art: Shorten `autoOrientImage` import commit d07433e3cf316c6a143a0c9393ba26df9e3af17b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:57:19 2018 -0500 Make `autoOrientImage` module standalone commit c285bf5e33cdf10e0ef71e72cd6f55aef0df96ef Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:55:44 2018 -0500 Replace `loadImage` with `autoOrientImage` commit 44318549235af01fd061c25f557c93fd21cebb7a Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:53:23 2018 -0500 Add `autoOrientImage` module This module exposes `loadImage` with a `Promise` based interface and pre- populates `orientation: true` option to auto-orient input. Returns data URL as string. The module uses a named export as refactoring references of modules with `default` (`module.exports`) export references can be error-prone. See: https://basarat.gitbooks.io/typescript/docs/tips/defaultIsBad.html commit c77063afc6366fe49615052796fe46f9b369de39 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:44:30 2018 -0500 Auto-orient preview images See: #998 commit 06dba5eb8f662c11af3a9ba8395bb453ab2e5f8d Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:43:23 2018 -0500 TODO: Use native `Canvas::toBlob` One challenge is that `Canvas::toBlob` is async whereas `dataURLtoBlob` is sync. commit b15c304a3125dd023fd90990e6225a7303f3596f Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:42:45 2018 -0500 Make `null` check strict Appeases JSHint. ESLint has a nice `smart` option for `eqeqeq` rule: https://eslint.org/docs/rules/eqeqeq#smart commit ea70b92d9b18201758e11fdc25b09afc97b50055 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 15:23:58 2018 -0500 Use `Canvas::toDataURL` to preserve `ImageView` logic This way, all the other code paths remain untouched in case we want to remove the auto-orient code once Chrome supports the `image-orientation` CSS property. See: - #998 - https://developer.mozilla.org/en-US/docs/Web/CSS/image-orientation commit 62fd744f9f27d951573a68d2cdfe7ba2a3784b41 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 14:38:04 2018 -0500 Use CSS to constrain auto-oriented images commit f4d3392687168c237441b29140c7968b49dbef9e Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 14:35:02 2018 -0500 Replace `ImageView` `el` with auto-oriented `canvas` See: #998 commit 1602d7f610e4993ad1291f88197f9ead1e25e776 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 14:25:48 2018 -0500 Pass `Blob` to `View` (for `ImageView`) This allows us to do JPEG auto-orientation based on EXIF metadata. commit e6a414f2b2a80da1137b839b348a38510efd04bb Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 14:25:12 2018 -0500 :hocho: Remove newline commit 5f0d9570d7862fc428ff89c2ecfd332a744537e5 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 11:17:02 2018 -0500 Expose `blueimp-load-image` as `window.loadImage` commit 1e1c62fe2f6a76dbcf1998dd468c26187c9871dc Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 11:16:46 2018 -0500 Add `blueimp-load-image` npm dependency commit ad17fa8a68a21ca5ddec336801b8568009bef3d4 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 11:14:40 2018 -0500 Remove `blueimp-load-image` Bower dependency
2018-02-21 15:26:59 +00:00
sourceDevice: data.device,
sent_at: data.timestamp,
2020-04-29 21:24:12 +00:00
serverTimestamp: data.serverTimestamp,
sent_to: sentTo,
Auto-orient image attachments based on EXIF metadata As described in #998, images are sometimes displayed with an incorrect orientation. This is because cameras often write files in the native sensor byte order and attach the `Orientation` EXIF metadata to tell end-user devices how to display the images based on the original author’s capture orientation. Electron/Chromium (and therefore Signal Desktop) currently doesn’t support applying this metadata for `<img>` tags, e.g. CSS `image-orientation: from- image`. As a workaround, this change uses the `loadImage` library with the `orientation: true` flag to auto-orient images ~~before display~~ upon receipt and before sending. **Changes** - [x] ~~Auto-orient images during display in message list view~~ - [x] Ensure image is not displayed until loaded (to prevent layout reflow) . - [x] Auto-orient images upon receipt and before storing in IndexedDB (~~or preserve original data until Chromium offers native fix?~~) - [x] Auto-orient images in compose area preview. - [x] ~~Auto-orient images in lightbox view~~ - [x] Auto-orient images before sending / storage. - [x] Add EditorConfig for sharing code styles across editors. - [x] Fix ESLint ignore file. - [x] Change `function-paren-newline` ESLint rule from `consistent` to `multiline`. - [x] Add `operator-linebreak` ESLint rule for consistency. - [x] Added `blob-util` dependency for converting between array buffers, blobs, etc. - [x] Extracted `createMessageHandler` to consolidate logic for `onMessageReceived` and `onSentMessage`. - [x] Introduce `async` / `await` to simplify async coding (restore control flow for branching, loops, and exceptions). - [x] Introduce `window.Signal` namespace for exposing ES2015+ CommonJS modules. - [x] Introduce rudimentary `Message` and `Attachment` types to begin defining a schema and versioning. This will allow us to track which changes, e.g. auto-orient JPEGs, per message / attachment as well as which fields are stored. - [x] Renamed `window.dataURLtoBlob` to `window.dataURLToBlobSync` to both fix the strange `camelCase` as well as to highlight that this operation is synchronous and therefore blocks the user thread. - [x] Normalize all JPEG MIME types to `image/jpeg`, eliminating the invalid `image/jpg`. - [x] Add `npm run test-modules` command for testing non-browser specific CommonJS modules. - **Stretch Goals** - [ ] ~~Restrict `autoOrientImage` to `Blob` to narrow API interface.~~ Do this once we use PureScript. - [ ] ~~Return non-JPEGs as no-op from `autoOrientImage`.~~ Skipping `autoOrientImage` for non-JPEGs altogether. - [ ] Retroactively auto-orient existing JPEG image attachments in the background. --- Fixes #998 --- - **Blog:** EXIF Orientation Handling Is a Ghetto: https://www.daveperrett.com/articles/2012/07/28/exif-orientation-handling-is-a-ghetto/ - **Chromium Bug:** EXIF orientation is ignored: https://bugs.chromium.org/p/chromium/issues/detail?id=56845 - **Chromium Bug:** Support for the CSS image-orientation CSS property: https://bugs.chromium.org/p/chromium/issues/detail?id=158753 --- commit ce5090b473a2448229dc38e4c3f15d7ad0137714 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 16 10:35:36 2018 -0500 Inline message descriptors commit 329036e59c138c1e950ec7c654eebd7d87076de5 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Thu Feb 15 17:34:40 2018 -0500 Clarify order of operations Semantically, it makes more sense to do `getFile` before `clearForm` even though it seems to work either way. commit f9d4cfb2ba0d8aa308b0923bbe6066ea34cb97bd Author: Daniel Gasienica <daniel@gasienica.ch> Date: Thu Feb 15 17:18:26 2018 -0500 Simplify `operator-linebreak` configuration Enabling `before` caused more code changes and it turns out our previous configuration is already the default. commit db588997acdd90ed2ad829174ecbba744383c78b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Thu Feb 15 17:15:59 2018 -0500 Remove obsolete TODO commit 799c8817633f6afa0b731fc3b5434e463bd850e3 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Thu Feb 15 17:12:18 2018 -0500 Enable ESLint `function-paren-newline` `multiline` Per discussion. commit b660b6bc8ef41df7601a411213d6cda80821df87 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Thu Feb 15 17:10:48 2018 -0500 Use `messageDescriptor.id` not `source` commit 5e7309d176f4a7e97d3dc4c738e6b0ccd4792871 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 16:29:01 2018 -0500 Remove unnecessary `eslint-env` commit 393b3da55eabd7413596c86cc3971b063a0efe31 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 16:19:17 2018 -0500 Refactor `onSentMessage` and `onMessageReceived` Since they are so similar, we create the handlers using new `createMessageHandler` function. This allows us to ensure both synced and received messages go through schema upgrade pipeline. commit b3db0bf179c9a5bea96480cde28c6fa7193ac117 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 16:18:21 2018 -0500 Add `Message` descriptor functions commit 8febf125b1b42fe4ae1888dd50fcee2749dc1ff0 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 14:46:56 2018 -0500 Fix typo commit 98d951ef77bd578b313a4ff4b496b793e82e88d5 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 12:22:39 2018 -0500 Remove `promises` reference commit a0e9559ed5bed947dabf28cb672e63d39948d854 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 12:22:13 2018 -0500 Fix `AttachmentView::mediaType` fall-through commit 67be916a83951b8a1f9b22efe78a6da6b1825f38 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 12:03:41 2018 -0500 Remove minor TODOs commit 0af186e118256b62905de38487ffacc41693ff47 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 11:44:41 2018 -0500 Enable ESLint for `js/views/attachment_view.js` commit 28a2dc5b8a28e1a087924fdc7275bf7d9a577b92 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 11:44:12 2018 -0500 Remove dynamic type checks commit f4ce36fcfc2737de32d911cd6103f889097813f6 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 11:27:56 2018 -0500 Rename `process` to `upgradeSchema` - `Message.process` -> `Message.upgradeSchema` - `Attachment.process` -> `Attachment.upgradeSchema` - `Attachment::processVersion` -> `Attachment::schemaVersion` Document version history. commit 41b92c0a31050ba05ddb1c43171d651f3568b9ac Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 11:11:50 2018 -0500 Add `operator-linebreak` ESLint rule Based on the following discussion: https://github.com/signalapp/Signal-Desktop/pull/2040#discussion_r168029106 commit 462defbe55879060fe25bc69103d4429bae2b2f6 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 11:01:30 2018 -0500 Add missing `await` for `ConversationController.getOrCreateAndWait` Tested this by setting `if` condition to `true` and confirming it works. It turns rotating a profile key is more involved and might require registering a new account according to Matthew. commit c08058ee4b883b3e23a40683de802ac81ed74874 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 16:32:24 2018 -0500 Convert `FileList` to `Array` commit 70a6c4201925f57be1f94d9da3547fdefc7bbb53 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 15:46:34 2018 -0500 :art: Fix lint errors commit 2ca7cdbc31d4120d6c6a838a6dcf43bc209d9788 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 15:07:09 2018 -0500 Skip `autoOrientImage` for non-JPEG images commit 58eac383013c16ca363a4ed33dca5c7ba61284e5 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 14:55:35 2018 -0500 Move new-style modules to `window.Signal` namespace commit 02c9328877dce289d6116a18b1c223891bd3cd0b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 14:35:23 2018 -0500 Extract `npm run test-modules` command commit 2c708eb94fba468b81ea9427734896114f5a7807 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 13:25:51 2018 -0500 Extract `Message.process` commit 4a2e52f68a77536a0fa04aa3c29ad3e541a8fa7e Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 13:25:12 2018 -0500 Fix EditorConfig commit a346bab5db082720f5d47363f06301380e870425 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 13:13:02 2018 -0500 Remove `vim` directives on ESLint-ed files commit 7ec885c6359e495b407d5bc3eac9431d47c37fc6 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 13:08:24 2018 -0500 Remove CSP whitelisting of `blob:` We no longer use `autoOrientImage` using blob URLs. Bring this back if we decide to auto-orient legacy attachments. commit 879b6f58f4a3f4a9ed6915af6b1be46c1e90e0ca Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:57:05 2018 -0500 Use `Message` type to determine send function Throws on invalid message type. commit 5203d945c98fd2562ae4e22c5c9838d27dec305b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:56:48 2018 -0500 Whitelist `Whisper` global commit 8ad0b066a3690d3382b86bf6ac00c03df7d1e20b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:56:32 2018 -0500 Add `Whisper.Types` namespace This avoids namespace collision for `Whisper.Message`. commit 785a949fce2656ca7dcaf0869d6b9e0648114e80 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:55:43 2018 -0500 Add `Message` type commit 674a7357abf0dcc365455695d56c0479998ebf27 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:35:23 2018 -0500 Run ESLint on `Conversation::sendMessage` commit cd985aa700caa80946245b17ea1b856449f152a0 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:34:38 2018 -0500 Document type signature of `FileInputView::readFile` commit d70d70e52c49588a1dc9833dfe5dd7128e13607f Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:31:16 2018 -0500 Move attachment processing closer to sending This helps ensure processing happens uniformly, regardless of which code paths are taken to send an attachment. commit 532ac3e273a26b97f831247f9ee3412621b5c112 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:22:29 2018 -0500 Process attachment before it’s sent Picked this place since it already had various async steps, similar to `onMessageReceived` for the incoming `Attachment.process`. Could we try have this live closer to where we store it in IndexedDB, e.g. `Conversation::sendMessage`? commit a4582ae2fb6e1d3487131ba1f8fa6a00170cb32c Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:21:42 2018 -0500 Refactor `getFile` and `getFiles` Lint them using ESLint. commit 07e9114e65046d791fc4f6ed90d6e2e938ad559d Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:37:31 2018 -0500 Document incoming and outgoing attachments fields Note how outgoing message attachments only have 4 fields. This presumably means the others are not used in our code and could be discarded for simplicity. commit fdc3ef289d6ec1be344a12d496839d5ba747bb6a Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:36:21 2018 -0500 Highlight that `dataURLToBlob` is synchronous commit b9c6bf600fcecedfd649ef2ae3c8629cced4e45a Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:35:49 2018 -0500 Add EditorConfig configuration commit e56101e229d56810c8e31ad7289043a152c6c449 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:34:23 2018 -0500 Replace custom with `blob-util` functions IMPORTANT: All of them are async so we need to use `await`, otherwise we get strange or silent errors. commit f95150f6a9569fabcb31f3acd9f6b7bf50b5d145 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:17:30 2018 -0500 Revert "Replace custom functions with `blob-util`" This reverts commit 8a81e9c01bfe80c0e1bf76737092206c06949512. commit 33860d93f3d30ec55c32f3f4a58729df2eb43f0d Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:13:02 2018 -0500 Revert "Replace `blueimp-canvas-to-blob` with `blob-util`" This reverts commit 31b3e853e4afc78fe80995921aa4152d9f6e4783. commit 7a0ba6fed622d76a3c39c7f03de541a7edb5b8dd Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:12:58 2018 -0500 Replace `blueimp-canvas-to-blob` with `blob-util` commit 47a5f2bfd8b3f546e27e8d2b7e1969755d825a66 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 10:55:34 2018 -0500 Replace custom functions with `blob-util` commit 1cfa0efdb4fb1265369e2bf243c21f04f044fa01 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 10:47:02 2018 -0500 Add `blob-util` dependency commit 9ac26be1bd783cd5070d886de107dd3ad9c91ad1 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 10:46:44 2018 -0500 Document why we drop original image data during auto-orient commit 4136d6c382b99f41760a4da519d0db537fa7de8d Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 10:46:27 2018 -0500 Extract `DEFAULT_JPEG_QUALITY` commit 4a7156327eb5f94dba80cb300b344ac591226b0e Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 10:37:11 2018 -0500 Drop support for invalid `image/jpg` MIME type commit 69fe96581f25413194032232f1bf704312e4754c Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:54:30 2018 -0500 Document `window.onInvalidStateError` global commit a48ba1c77458da38583ee9cd488f70a59f6ee0fd Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:54:04 2018 -0500 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. commit e6d1cf826befc17ad4ec72fda8e761701665635e Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:16:23 2018 -0500 Move async attachment processing to `onMessageReceived` We previously processed attachments in `handleDataMessage` which is mostly a synchronous function, except for the saving of the model. Moving the processing into the already async `onMessageReceived` improves code clarity. commit be6ca2a9aae5b59c360817deb1e18d39d705755e Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:14:49 2018 -0500 Document import of ES2015+ modules commit eaaf7c41608fb988b8f4bbaa933cff110115610e Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:14:29 2018 -0500 :art: Fix lint error commit a25b0e2e3d0f72c6a7bf0a15683f02450d5209ee Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:13:57 2018 -0500 :art: Organize `require`s commit e0cc3d8fab6529d01b388acddf8605908c3d236b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:07:17 2018 -0500 Implement attachment process version Instead of keeping track of last normalization (processing) date, we now keep track of an internal processing version that will help us understand what kind of processing has already been completed for a given attachment. This will let us retroactively upgrade existing attachments. As we add more processing steps, we can build a processing pipeline that can convert any attachment processing version into a higher one, e.g. 4 -> 5 -> 6 -> 7. commit ad9083d0fdb880bc518e02251e51a39f7e1c585f Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:50:31 2018 -0500 Ignore ES2015+ files during JSCS linting commit 96641205f734927aaebc2342d977c555799c3e3b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:48:07 2018 -0500 Improve ESLint ignore rules Apparently, using unqualified `/**` patterns prevents `!` include patterns. Using qualified glob patterns, e.g. `js/models/**/*.js`, lets us work around this. commit 255e0ab15bd1a0ca8ca5746e42d23977c8765d01 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:44:59 2018 -0500 :abc: ESLint ignored files commit ebcb70258a26f234bd602072ac7c0a1913128132 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:35:47 2018 -0500 Whitelist `browser` environment for ESLint commit 3eaace6f3a21421c5aaaaf01592408c7ed83ecd3 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:35:05 2018 -0500 Use `MIME` module commit ba2cf7770e614415733414a2dcc48f110b929892 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:32:54 2018 -0500 :art: Fix lint errors commit 65acc86e8580e88f7a6611eb4b8fa5d7291f7a3f Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:30:42 2018 -0500 Add ES2015+ files to JSHint ignored list commit 8b6494ae6c9247acdfa059a9b361ec5ffcdb39f0 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:29:20 2018 -0500 Document potentially unexpected `autoScale` behavior commit 8b4c69b2002d1777d3621be10f92cbf432f9d4d6 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:26:47 2018 -0500 Test CommonJS modules separately Not sure how to test them as part of Grunt `unit-tests` task as `test/index.html` doesn’t allow for inclusion of CommonJS modules that use `require`. The tests are silently skipped. commit 213400e4b2bba3efee856a25b40e269221c3c39d Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:24:27 2018 -0500 Add `MIME` type module commit 37a726e4fb4b3ed65914463122a5662847b5adee Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 20:18:05 2018 -0500 Return proper `Error` from `blobArrayToBuffer` commit 164752db5612220e4dcf58d57bcd682cb489a399 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 20:15:41 2018 -0500 :art: Fix ESLint errors commit d498dd79a067c75098dd3179814c914780e5cb4f Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 20:14:33 2018 -0500 Update `Attachment` type field definitions commit 141155a1533ff8fb616b70ea313432781bbebffd Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 20:12:50 2018 -0500 Move `blueimp-canvas-to-blob` from Bower to npm commit 7ccb833e5d286ddd6235d3e491c62ac1e4544510 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:33:50 2018 -0500 :art: Clarify data flow commit e7da41591fde5a830467bebf1b6f51c1f7293e74 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:31:21 2018 -0500 Use `blobUrl` for consistency commit 523a80eefe0e2858aa1fb2bb9539ec44da502963 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:28:06 2018 -0500 Remove just-in-time image auto-orient for lightbox We can bring this back if our users would like auto-orient for old attachments. commit 0739feae9c47dd523c10740d6cdf746d539f270c Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:27:21 2018 -0500 Remove just-in-time auto-orient of message attachments We can bring this back if our users would like auto-orient for old attachments. But better yet, we might implement this as database migration. commit ed43c66f92830ee233d5a94d0545eea4da43894d Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:26:24 2018 -0500 Auto-orient JPEG attachments upon receipt commit e2eb8e36b017b048d57602fca14e45d657e0e1a1 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:25:26 2018 -0500 Expose `Attachment` type through `Whisper.Attachment` commit 9638fbc987b84f143ca34211dc4666d96248ea2f Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:23:39 2018 -0500 Use `contentType` from `model` commit 032c0ced46c3876cb9474b26f9d53d6f1c6b16a0 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:23:04 2018 -0500 Return `Error` object for `autoOrientImage` failures commit ff04bad8510c4b21aef350bed2b1887d0e055b98 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:22:32 2018 -0500 Add `options` for `autoOrientImage` output type / quality commit 87745b5586d1e182b51c9f9bc5e4eaf6dbc16722 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:18:46 2018 -0500 Add `Attachment` type Defines various functions on attachments, e.g. normalization (auto-orient JPEGs, etc.) commit de27fdc10a53bc8882a9c978e82265db9ac6d6f5 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:16:34 2018 -0500 Add `yarn grunt` shortcut This allows us to use local `grunt-cli` for `grunt dev`. commit 59974db5a5da0d8f4cdc8ce5c4e3c974ecd5e754 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 10:10:11 2018 -0500 Improve readability commit b5ba96f1e6f40f2e1fa77490c583217768e1f412 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 10:08:12 2018 -0500 Use `snake_case` for module names Prevents problems across case-sensitive and case-insensitive file systems. We can work around this in the future using a lint rule such as `eslint-plugin-require-path-exists`. See discussion: https://github.com/signalapp/Signal-Desktop/pull/2040#discussion_r167365931 commit 48c5d3155c96ef628b00d99b52975e580d1d5501 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 10:05:44 2018 -0500 :art: Use destructuring commit 4822f49f22382a99ebf142b337375f7c25251d76 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 17:41:40 2018 -0500 Auto-orient images in lightbox view commit 7317110809677dddbbef3fadbf912cdba1c010bf Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 17:40:14 2018 -0500 Document magic number for escape key commit c790d07389a7d0bbf5298de83dbcfa8be1e7696b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 17:38:35 2018 -0500 Make second `View` argument an `options` object commit fbe010bb63d0088af9dfe11f153437fab34247e0 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 17:27:40 2018 -0500 Allow `loadImage` to fetch `blob://` URLs commit ec35710d002b019a273eeb48f94dcaf2babe5d96 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:57:48 2018 -0500 :art: Shorten `autoOrientImage` import commit d07433e3cf316c6a143a0c9393ba26df9e3af17b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:57:19 2018 -0500 Make `autoOrientImage` module standalone commit c285bf5e33cdf10e0ef71e72cd6f55aef0df96ef Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:55:44 2018 -0500 Replace `loadImage` with `autoOrientImage` commit 44318549235af01fd061c25f557c93fd21cebb7a Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:53:23 2018 -0500 Add `autoOrientImage` module This module exposes `loadImage` with a `Promise` based interface and pre- populates `orientation: true` option to auto-orient input. Returns data URL as string. The module uses a named export as refactoring references of modules with `default` (`module.exports`) export references can be error-prone. See: https://basarat.gitbooks.io/typescript/docs/tips/defaultIsBad.html commit c77063afc6366fe49615052796fe46f9b369de39 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:44:30 2018 -0500 Auto-orient preview images See: #998 commit 06dba5eb8f662c11af3a9ba8395bb453ab2e5f8d Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:43:23 2018 -0500 TODO: Use native `Canvas::toBlob` One challenge is that `Canvas::toBlob` is async whereas `dataURLtoBlob` is sync. commit b15c304a3125dd023fd90990e6225a7303f3596f Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:42:45 2018 -0500 Make `null` check strict Appeases JSHint. ESLint has a nice `smart` option for `eqeqeq` rule: https://eslint.org/docs/rules/eqeqeq#smart commit ea70b92d9b18201758e11fdc25b09afc97b50055 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 15:23:58 2018 -0500 Use `Canvas::toDataURL` to preserve `ImageView` logic This way, all the other code paths remain untouched in case we want to remove the auto-orient code once Chrome supports the `image-orientation` CSS property. See: - #998 - https://developer.mozilla.org/en-US/docs/Web/CSS/image-orientation commit 62fd744f9f27d951573a68d2cdfe7ba2a3784b41 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 14:38:04 2018 -0500 Use CSS to constrain auto-oriented images commit f4d3392687168c237441b29140c7968b49dbef9e Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 14:35:02 2018 -0500 Replace `ImageView` `el` with auto-oriented `canvas` See: #998 commit 1602d7f610e4993ad1291f88197f9ead1e25e776 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 14:25:48 2018 -0500 Pass `Blob` to `View` (for `ImageView`) This allows us to do JPEG auto-orientation based on EXIF metadata. commit e6a414f2b2a80da1137b839b348a38510efd04bb Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 14:25:12 2018 -0500 :hocho: Remove newline commit 5f0d9570d7862fc428ff89c2ecfd332a744537e5 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 11:17:02 2018 -0500 Expose `blueimp-load-image` as `window.loadImage` commit 1e1c62fe2f6a76dbcf1998dd468c26187c9871dc Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 11:16:46 2018 -0500 Add `blueimp-load-image` npm dependency commit ad17fa8a68a21ca5ddec336801b8568009bef3d4 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 11:14:40 2018 -0500 Remove `blueimp-load-image` Bower dependency
2018-02-21 15:26:59 +00:00
received_at: now,
2020-09-09 02:25:05 +00:00
conversationId: descriptor.id,
Auto-orient image attachments based on EXIF metadata As described in #998, images are sometimes displayed with an incorrect orientation. This is because cameras often write files in the native sensor byte order and attach the `Orientation` EXIF metadata to tell end-user devices how to display the images based on the original author’s capture orientation. Electron/Chromium (and therefore Signal Desktop) currently doesn’t support applying this metadata for `<img>` tags, e.g. CSS `image-orientation: from- image`. As a workaround, this change uses the `loadImage` library with the `orientation: true` flag to auto-orient images ~~before display~~ upon receipt and before sending. **Changes** - [x] ~~Auto-orient images during display in message list view~~ - [x] Ensure image is not displayed until loaded (to prevent layout reflow) . - [x] Auto-orient images upon receipt and before storing in IndexedDB (~~or preserve original data until Chromium offers native fix?~~) - [x] Auto-orient images in compose area preview. - [x] ~~Auto-orient images in lightbox view~~ - [x] Auto-orient images before sending / storage. - [x] Add EditorConfig for sharing code styles across editors. - [x] Fix ESLint ignore file. - [x] Change `function-paren-newline` ESLint rule from `consistent` to `multiline`. - [x] Add `operator-linebreak` ESLint rule for consistency. - [x] Added `blob-util` dependency for converting between array buffers, blobs, etc. - [x] Extracted `createMessageHandler` to consolidate logic for `onMessageReceived` and `onSentMessage`. - [x] Introduce `async` / `await` to simplify async coding (restore control flow for branching, loops, and exceptions). - [x] Introduce `window.Signal` namespace for exposing ES2015+ CommonJS modules. - [x] Introduce rudimentary `Message` and `Attachment` types to begin defining a schema and versioning. This will allow us to track which changes, e.g. auto-orient JPEGs, per message / attachment as well as which fields are stored. - [x] Renamed `window.dataURLtoBlob` to `window.dataURLToBlobSync` to both fix the strange `camelCase` as well as to highlight that this operation is synchronous and therefore blocks the user thread. - [x] Normalize all JPEG MIME types to `image/jpeg`, eliminating the invalid `image/jpg`. - [x] Add `npm run test-modules` command for testing non-browser specific CommonJS modules. - **Stretch Goals** - [ ] ~~Restrict `autoOrientImage` to `Blob` to narrow API interface.~~ Do this once we use PureScript. - [ ] ~~Return non-JPEGs as no-op from `autoOrientImage`.~~ Skipping `autoOrientImage` for non-JPEGs altogether. - [ ] Retroactively auto-orient existing JPEG image attachments in the background. --- Fixes #998 --- - **Blog:** EXIF Orientation Handling Is a Ghetto: https://www.daveperrett.com/articles/2012/07/28/exif-orientation-handling-is-a-ghetto/ - **Chromium Bug:** EXIF orientation is ignored: https://bugs.chromium.org/p/chromium/issues/detail?id=56845 - **Chromium Bug:** Support for the CSS image-orientation CSS property: https://bugs.chromium.org/p/chromium/issues/detail?id=158753 --- commit ce5090b473a2448229dc38e4c3f15d7ad0137714 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 16 10:35:36 2018 -0500 Inline message descriptors commit 329036e59c138c1e950ec7c654eebd7d87076de5 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Thu Feb 15 17:34:40 2018 -0500 Clarify order of operations Semantically, it makes more sense to do `getFile` before `clearForm` even though it seems to work either way. commit f9d4cfb2ba0d8aa308b0923bbe6066ea34cb97bd Author: Daniel Gasienica <daniel@gasienica.ch> Date: Thu Feb 15 17:18:26 2018 -0500 Simplify `operator-linebreak` configuration Enabling `before` caused more code changes and it turns out our previous configuration is already the default. commit db588997acdd90ed2ad829174ecbba744383c78b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Thu Feb 15 17:15:59 2018 -0500 Remove obsolete TODO commit 799c8817633f6afa0b731fc3b5434e463bd850e3 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Thu Feb 15 17:12:18 2018 -0500 Enable ESLint `function-paren-newline` `multiline` Per discussion. commit b660b6bc8ef41df7601a411213d6cda80821df87 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Thu Feb 15 17:10:48 2018 -0500 Use `messageDescriptor.id` not `source` commit 5e7309d176f4a7e97d3dc4c738e6b0ccd4792871 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 16:29:01 2018 -0500 Remove unnecessary `eslint-env` commit 393b3da55eabd7413596c86cc3971b063a0efe31 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 16:19:17 2018 -0500 Refactor `onSentMessage` and `onMessageReceived` Since they are so similar, we create the handlers using new `createMessageHandler` function. This allows us to ensure both synced and received messages go through schema upgrade pipeline. commit b3db0bf179c9a5bea96480cde28c6fa7193ac117 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 16:18:21 2018 -0500 Add `Message` descriptor functions commit 8febf125b1b42fe4ae1888dd50fcee2749dc1ff0 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 14:46:56 2018 -0500 Fix typo commit 98d951ef77bd578b313a4ff4b496b793e82e88d5 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 12:22:39 2018 -0500 Remove `promises` reference commit a0e9559ed5bed947dabf28cb672e63d39948d854 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 12:22:13 2018 -0500 Fix `AttachmentView::mediaType` fall-through commit 67be916a83951b8a1f9b22efe78a6da6b1825f38 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 12:03:41 2018 -0500 Remove minor TODOs commit 0af186e118256b62905de38487ffacc41693ff47 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 11:44:41 2018 -0500 Enable ESLint for `js/views/attachment_view.js` commit 28a2dc5b8a28e1a087924fdc7275bf7d9a577b92 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 11:44:12 2018 -0500 Remove dynamic type checks commit f4ce36fcfc2737de32d911cd6103f889097813f6 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 11:27:56 2018 -0500 Rename `process` to `upgradeSchema` - `Message.process` -> `Message.upgradeSchema` - `Attachment.process` -> `Attachment.upgradeSchema` - `Attachment::processVersion` -> `Attachment::schemaVersion` Document version history. commit 41b92c0a31050ba05ddb1c43171d651f3568b9ac Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 11:11:50 2018 -0500 Add `operator-linebreak` ESLint rule Based on the following discussion: https://github.com/signalapp/Signal-Desktop/pull/2040#discussion_r168029106 commit 462defbe55879060fe25bc69103d4429bae2b2f6 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 11:01:30 2018 -0500 Add missing `await` for `ConversationController.getOrCreateAndWait` Tested this by setting `if` condition to `true` and confirming it works. It turns rotating a profile key is more involved and might require registering a new account according to Matthew. commit c08058ee4b883b3e23a40683de802ac81ed74874 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 16:32:24 2018 -0500 Convert `FileList` to `Array` commit 70a6c4201925f57be1f94d9da3547fdefc7bbb53 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 15:46:34 2018 -0500 :art: Fix lint errors commit 2ca7cdbc31d4120d6c6a838a6dcf43bc209d9788 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 15:07:09 2018 -0500 Skip `autoOrientImage` for non-JPEG images commit 58eac383013c16ca363a4ed33dca5c7ba61284e5 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 14:55:35 2018 -0500 Move new-style modules to `window.Signal` namespace commit 02c9328877dce289d6116a18b1c223891bd3cd0b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 14:35:23 2018 -0500 Extract `npm run test-modules` command commit 2c708eb94fba468b81ea9427734896114f5a7807 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 13:25:51 2018 -0500 Extract `Message.process` commit 4a2e52f68a77536a0fa04aa3c29ad3e541a8fa7e Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 13:25:12 2018 -0500 Fix EditorConfig commit a346bab5db082720f5d47363f06301380e870425 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 13:13:02 2018 -0500 Remove `vim` directives on ESLint-ed files commit 7ec885c6359e495b407d5bc3eac9431d47c37fc6 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 13:08:24 2018 -0500 Remove CSP whitelisting of `blob:` We no longer use `autoOrientImage` using blob URLs. Bring this back if we decide to auto-orient legacy attachments. commit 879b6f58f4a3f4a9ed6915af6b1be46c1e90e0ca Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:57:05 2018 -0500 Use `Message` type to determine send function Throws on invalid message type. commit 5203d945c98fd2562ae4e22c5c9838d27dec305b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:56:48 2018 -0500 Whitelist `Whisper` global commit 8ad0b066a3690d3382b86bf6ac00c03df7d1e20b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:56:32 2018 -0500 Add `Whisper.Types` namespace This avoids namespace collision for `Whisper.Message`. commit 785a949fce2656ca7dcaf0869d6b9e0648114e80 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:55:43 2018 -0500 Add `Message` type commit 674a7357abf0dcc365455695d56c0479998ebf27 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:35:23 2018 -0500 Run ESLint on `Conversation::sendMessage` commit cd985aa700caa80946245b17ea1b856449f152a0 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:34:38 2018 -0500 Document type signature of `FileInputView::readFile` commit d70d70e52c49588a1dc9833dfe5dd7128e13607f Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:31:16 2018 -0500 Move attachment processing closer to sending This helps ensure processing happens uniformly, regardless of which code paths are taken to send an attachment. commit 532ac3e273a26b97f831247f9ee3412621b5c112 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:22:29 2018 -0500 Process attachment before it’s sent Picked this place since it already had various async steps, similar to `onMessageReceived` for the incoming `Attachment.process`. Could we try have this live closer to where we store it in IndexedDB, e.g. `Conversation::sendMessage`? commit a4582ae2fb6e1d3487131ba1f8fa6a00170cb32c Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:21:42 2018 -0500 Refactor `getFile` and `getFiles` Lint them using ESLint. commit 07e9114e65046d791fc4f6ed90d6e2e938ad559d Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:37:31 2018 -0500 Document incoming and outgoing attachments fields Note how outgoing message attachments only have 4 fields. This presumably means the others are not used in our code and could be discarded for simplicity. commit fdc3ef289d6ec1be344a12d496839d5ba747bb6a Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:36:21 2018 -0500 Highlight that `dataURLToBlob` is synchronous commit b9c6bf600fcecedfd649ef2ae3c8629cced4e45a Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:35:49 2018 -0500 Add EditorConfig configuration commit e56101e229d56810c8e31ad7289043a152c6c449 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:34:23 2018 -0500 Replace custom with `blob-util` functions IMPORTANT: All of them are async so we need to use `await`, otherwise we get strange or silent errors. commit f95150f6a9569fabcb31f3acd9f6b7bf50b5d145 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:17:30 2018 -0500 Revert "Replace custom functions with `blob-util`" This reverts commit 8a81e9c01bfe80c0e1bf76737092206c06949512. commit 33860d93f3d30ec55c32f3f4a58729df2eb43f0d Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:13:02 2018 -0500 Revert "Replace `blueimp-canvas-to-blob` with `blob-util`" This reverts commit 31b3e853e4afc78fe80995921aa4152d9f6e4783. commit 7a0ba6fed622d76a3c39c7f03de541a7edb5b8dd Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:12:58 2018 -0500 Replace `blueimp-canvas-to-blob` with `blob-util` commit 47a5f2bfd8b3f546e27e8d2b7e1969755d825a66 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 10:55:34 2018 -0500 Replace custom functions with `blob-util` commit 1cfa0efdb4fb1265369e2bf243c21f04f044fa01 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 10:47:02 2018 -0500 Add `blob-util` dependency commit 9ac26be1bd783cd5070d886de107dd3ad9c91ad1 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 10:46:44 2018 -0500 Document why we drop original image data during auto-orient commit 4136d6c382b99f41760a4da519d0db537fa7de8d Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 10:46:27 2018 -0500 Extract `DEFAULT_JPEG_QUALITY` commit 4a7156327eb5f94dba80cb300b344ac591226b0e Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 10:37:11 2018 -0500 Drop support for invalid `image/jpg` MIME type commit 69fe96581f25413194032232f1bf704312e4754c Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:54:30 2018 -0500 Document `window.onInvalidStateError` global commit a48ba1c77458da38583ee9cd488f70a59f6ee0fd Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:54:04 2018 -0500 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. commit e6d1cf826befc17ad4ec72fda8e761701665635e Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:16:23 2018 -0500 Move async attachment processing to `onMessageReceived` We previously processed attachments in `handleDataMessage` which is mostly a synchronous function, except for the saving of the model. Moving the processing into the already async `onMessageReceived` improves code clarity. commit be6ca2a9aae5b59c360817deb1e18d39d705755e Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:14:49 2018 -0500 Document import of ES2015+ modules commit eaaf7c41608fb988b8f4bbaa933cff110115610e Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:14:29 2018 -0500 :art: Fix lint error commit a25b0e2e3d0f72c6a7bf0a15683f02450d5209ee Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:13:57 2018 -0500 :art: Organize `require`s commit e0cc3d8fab6529d01b388acddf8605908c3d236b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:07:17 2018 -0500 Implement attachment process version Instead of keeping track of last normalization (processing) date, we now keep track of an internal processing version that will help us understand what kind of processing has already been completed for a given attachment. This will let us retroactively upgrade existing attachments. As we add more processing steps, we can build a processing pipeline that can convert any attachment processing version into a higher one, e.g. 4 -> 5 -> 6 -> 7. commit ad9083d0fdb880bc518e02251e51a39f7e1c585f Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:50:31 2018 -0500 Ignore ES2015+ files during JSCS linting commit 96641205f734927aaebc2342d977c555799c3e3b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:48:07 2018 -0500 Improve ESLint ignore rules Apparently, using unqualified `/**` patterns prevents `!` include patterns. Using qualified glob patterns, e.g. `js/models/**/*.js`, lets us work around this. commit 255e0ab15bd1a0ca8ca5746e42d23977c8765d01 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:44:59 2018 -0500 :abc: ESLint ignored files commit ebcb70258a26f234bd602072ac7c0a1913128132 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:35:47 2018 -0500 Whitelist `browser` environment for ESLint commit 3eaace6f3a21421c5aaaaf01592408c7ed83ecd3 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:35:05 2018 -0500 Use `MIME` module commit ba2cf7770e614415733414a2dcc48f110b929892 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:32:54 2018 -0500 :art: Fix lint errors commit 65acc86e8580e88f7a6611eb4b8fa5d7291f7a3f Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:30:42 2018 -0500 Add ES2015+ files to JSHint ignored list commit 8b6494ae6c9247acdfa059a9b361ec5ffcdb39f0 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:29:20 2018 -0500 Document potentially unexpected `autoScale` behavior commit 8b4c69b2002d1777d3621be10f92cbf432f9d4d6 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:26:47 2018 -0500 Test CommonJS modules separately Not sure how to test them as part of Grunt `unit-tests` task as `test/index.html` doesn’t allow for inclusion of CommonJS modules that use `require`. The tests are silently skipped. commit 213400e4b2bba3efee856a25b40e269221c3c39d Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:24:27 2018 -0500 Add `MIME` type module commit 37a726e4fb4b3ed65914463122a5662847b5adee Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 20:18:05 2018 -0500 Return proper `Error` from `blobArrayToBuffer` commit 164752db5612220e4dcf58d57bcd682cb489a399 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 20:15:41 2018 -0500 :art: Fix ESLint errors commit d498dd79a067c75098dd3179814c914780e5cb4f Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 20:14:33 2018 -0500 Update `Attachment` type field definitions commit 141155a1533ff8fb616b70ea313432781bbebffd Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 20:12:50 2018 -0500 Move `blueimp-canvas-to-blob` from Bower to npm commit 7ccb833e5d286ddd6235d3e491c62ac1e4544510 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:33:50 2018 -0500 :art: Clarify data flow commit e7da41591fde5a830467bebf1b6f51c1f7293e74 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:31:21 2018 -0500 Use `blobUrl` for consistency commit 523a80eefe0e2858aa1fb2bb9539ec44da502963 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:28:06 2018 -0500 Remove just-in-time image auto-orient for lightbox We can bring this back if our users would like auto-orient for old attachments. commit 0739feae9c47dd523c10740d6cdf746d539f270c Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:27:21 2018 -0500 Remove just-in-time auto-orient of message attachments We can bring this back if our users would like auto-orient for old attachments. But better yet, we might implement this as database migration. commit ed43c66f92830ee233d5a94d0545eea4da43894d Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:26:24 2018 -0500 Auto-orient JPEG attachments upon receipt commit e2eb8e36b017b048d57602fca14e45d657e0e1a1 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:25:26 2018 -0500 Expose `Attachment` type through `Whisper.Attachment` commit 9638fbc987b84f143ca34211dc4666d96248ea2f Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:23:39 2018 -0500 Use `contentType` from `model` commit 032c0ced46c3876cb9474b26f9d53d6f1c6b16a0 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:23:04 2018 -0500 Return `Error` object for `autoOrientImage` failures commit ff04bad8510c4b21aef350bed2b1887d0e055b98 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:22:32 2018 -0500 Add `options` for `autoOrientImage` output type / quality commit 87745b5586d1e182b51c9f9bc5e4eaf6dbc16722 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:18:46 2018 -0500 Add `Attachment` type Defines various functions on attachments, e.g. normalization (auto-orient JPEGs, etc.) commit de27fdc10a53bc8882a9c978e82265db9ac6d6f5 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:16:34 2018 -0500 Add `yarn grunt` shortcut This allows us to use local `grunt-cli` for `grunt dev`. commit 59974db5a5da0d8f4cdc8ce5c4e3c974ecd5e754 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 10:10:11 2018 -0500 Improve readability commit b5ba96f1e6f40f2e1fa77490c583217768e1f412 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 10:08:12 2018 -0500 Use `snake_case` for module names Prevents problems across case-sensitive and case-insensitive file systems. We can work around this in the future using a lint rule such as `eslint-plugin-require-path-exists`. See discussion: https://github.com/signalapp/Signal-Desktop/pull/2040#discussion_r167365931 commit 48c5d3155c96ef628b00d99b52975e580d1d5501 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 10:05:44 2018 -0500 :art: Use destructuring commit 4822f49f22382a99ebf142b337375f7c25251d76 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 17:41:40 2018 -0500 Auto-orient images in lightbox view commit 7317110809677dddbbef3fadbf912cdba1c010bf Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 17:40:14 2018 -0500 Document magic number for escape key commit c790d07389a7d0bbf5298de83dbcfa8be1e7696b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 17:38:35 2018 -0500 Make second `View` argument an `options` object commit fbe010bb63d0088af9dfe11f153437fab34247e0 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 17:27:40 2018 -0500 Allow `loadImage` to fetch `blob://` URLs commit ec35710d002b019a273eeb48f94dcaf2babe5d96 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:57:48 2018 -0500 :art: Shorten `autoOrientImage` import commit d07433e3cf316c6a143a0c9393ba26df9e3af17b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:57:19 2018 -0500 Make `autoOrientImage` module standalone commit c285bf5e33cdf10e0ef71e72cd6f55aef0df96ef Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:55:44 2018 -0500 Replace `loadImage` with `autoOrientImage` commit 44318549235af01fd061c25f557c93fd21cebb7a Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:53:23 2018 -0500 Add `autoOrientImage` module This module exposes `loadImage` with a `Promise` based interface and pre- populates `orientation: true` option to auto-orient input. Returns data URL as string. The module uses a named export as refactoring references of modules with `default` (`module.exports`) export references can be error-prone. See: https://basarat.gitbooks.io/typescript/docs/tips/defaultIsBad.html commit c77063afc6366fe49615052796fe46f9b369de39 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:44:30 2018 -0500 Auto-orient preview images See: #998 commit 06dba5eb8f662c11af3a9ba8395bb453ab2e5f8d Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:43:23 2018 -0500 TODO: Use native `Canvas::toBlob` One challenge is that `Canvas::toBlob` is async whereas `dataURLtoBlob` is sync. commit b15c304a3125dd023fd90990e6225a7303f3596f Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:42:45 2018 -0500 Make `null` check strict Appeases JSHint. ESLint has a nice `smart` option for `eqeqeq` rule: https://eslint.org/docs/rules/eqeqeq#smart commit ea70b92d9b18201758e11fdc25b09afc97b50055 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 15:23:58 2018 -0500 Use `Canvas::toDataURL` to preserve `ImageView` logic This way, all the other code paths remain untouched in case we want to remove the auto-orient code once Chrome supports the `image-orientation` CSS property. See: - #998 - https://developer.mozilla.org/en-US/docs/Web/CSS/image-orientation commit 62fd744f9f27d951573a68d2cdfe7ba2a3784b41 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 14:38:04 2018 -0500 Use CSS to constrain auto-oriented images commit f4d3392687168c237441b29140c7968b49dbef9e Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 14:35:02 2018 -0500 Replace `ImageView` `el` with auto-oriented `canvas` See: #998 commit 1602d7f610e4993ad1291f88197f9ead1e25e776 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 14:25:48 2018 -0500 Pass `Blob` to `View` (for `ImageView`) This allows us to do JPEG auto-orientation based on EXIF metadata. commit e6a414f2b2a80da1137b839b348a38510efd04bb Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 14:25:12 2018 -0500 :hocho: Remove newline commit 5f0d9570d7862fc428ff89c2ecfd332a744537e5 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 11:17:02 2018 -0500 Expose `blueimp-load-image` as `window.loadImage` commit 1e1c62fe2f6a76dbcf1998dd468c26187c9871dc Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 11:16:46 2018 -0500 Add `blueimp-load-image` npm dependency commit ad17fa8a68a21ca5ddec336801b8568009bef3d4 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 11:14:40 2018 -0500 Remove `blueimp-load-image` Bower dependency
2018-02-21 15:26:59 +00:00
type: 'outgoing',
sent: true,
unidentifiedDeliveries: data.unidentifiedDeliveries || [],
expirationStartTimestamp: Math.min(
data.expirationStartTimestamp || data.timestamp || Date.now(),
Date.now()
),
} as WhatIsThis);
Auto-orient image attachments based on EXIF metadata As described in #998, images are sometimes displayed with an incorrect orientation. This is because cameras often write files in the native sensor byte order and attach the `Orientation` EXIF metadata to tell end-user devices how to display the images based on the original author’s capture orientation. Electron/Chromium (and therefore Signal Desktop) currently doesn’t support applying this metadata for `<img>` tags, e.g. CSS `image-orientation: from- image`. As a workaround, this change uses the `loadImage` library with the `orientation: true` flag to auto-orient images ~~before display~~ upon receipt and before sending. **Changes** - [x] ~~Auto-orient images during display in message list view~~ - [x] Ensure image is not displayed until loaded (to prevent layout reflow) . - [x] Auto-orient images upon receipt and before storing in IndexedDB (~~or preserve original data until Chromium offers native fix?~~) - [x] Auto-orient images in compose area preview. - [x] ~~Auto-orient images in lightbox view~~ - [x] Auto-orient images before sending / storage. - [x] Add EditorConfig for sharing code styles across editors. - [x] Fix ESLint ignore file. - [x] Change `function-paren-newline` ESLint rule from `consistent` to `multiline`. - [x] Add `operator-linebreak` ESLint rule for consistency. - [x] Added `blob-util` dependency for converting between array buffers, blobs, etc. - [x] Extracted `createMessageHandler` to consolidate logic for `onMessageReceived` and `onSentMessage`. - [x] Introduce `async` / `await` to simplify async coding (restore control flow for branching, loops, and exceptions). - [x] Introduce `window.Signal` namespace for exposing ES2015+ CommonJS modules. - [x] Introduce rudimentary `Message` and `Attachment` types to begin defining a schema and versioning. This will allow us to track which changes, e.g. auto-orient JPEGs, per message / attachment as well as which fields are stored. - [x] Renamed `window.dataURLtoBlob` to `window.dataURLToBlobSync` to both fix the strange `camelCase` as well as to highlight that this operation is synchronous and therefore blocks the user thread. - [x] Normalize all JPEG MIME types to `image/jpeg`, eliminating the invalid `image/jpg`. - [x] Add `npm run test-modules` command for testing non-browser specific CommonJS modules. - **Stretch Goals** - [ ] ~~Restrict `autoOrientImage` to `Blob` to narrow API interface.~~ Do this once we use PureScript. - [ ] ~~Return non-JPEGs as no-op from `autoOrientImage`.~~ Skipping `autoOrientImage` for non-JPEGs altogether. - [ ] Retroactively auto-orient existing JPEG image attachments in the background. --- Fixes #998 --- - **Blog:** EXIF Orientation Handling Is a Ghetto: https://www.daveperrett.com/articles/2012/07/28/exif-orientation-handling-is-a-ghetto/ - **Chromium Bug:** EXIF orientation is ignored: https://bugs.chromium.org/p/chromium/issues/detail?id=56845 - **Chromium Bug:** Support for the CSS image-orientation CSS property: https://bugs.chromium.org/p/chromium/issues/detail?id=158753 --- commit ce5090b473a2448229dc38e4c3f15d7ad0137714 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 16 10:35:36 2018 -0500 Inline message descriptors commit 329036e59c138c1e950ec7c654eebd7d87076de5 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Thu Feb 15 17:34:40 2018 -0500 Clarify order of operations Semantically, it makes more sense to do `getFile` before `clearForm` even though it seems to work either way. commit f9d4cfb2ba0d8aa308b0923bbe6066ea34cb97bd Author: Daniel Gasienica <daniel@gasienica.ch> Date: Thu Feb 15 17:18:26 2018 -0500 Simplify `operator-linebreak` configuration Enabling `before` caused more code changes and it turns out our previous configuration is already the default. commit db588997acdd90ed2ad829174ecbba744383c78b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Thu Feb 15 17:15:59 2018 -0500 Remove obsolete TODO commit 799c8817633f6afa0b731fc3b5434e463bd850e3 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Thu Feb 15 17:12:18 2018 -0500 Enable ESLint `function-paren-newline` `multiline` Per discussion. commit b660b6bc8ef41df7601a411213d6cda80821df87 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Thu Feb 15 17:10:48 2018 -0500 Use `messageDescriptor.id` not `source` commit 5e7309d176f4a7e97d3dc4c738e6b0ccd4792871 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 16:29:01 2018 -0500 Remove unnecessary `eslint-env` commit 393b3da55eabd7413596c86cc3971b063a0efe31 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 16:19:17 2018 -0500 Refactor `onSentMessage` and `onMessageReceived` Since they are so similar, we create the handlers using new `createMessageHandler` function. This allows us to ensure both synced and received messages go through schema upgrade pipeline. commit b3db0bf179c9a5bea96480cde28c6fa7193ac117 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 16:18:21 2018 -0500 Add `Message` descriptor functions commit 8febf125b1b42fe4ae1888dd50fcee2749dc1ff0 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 14:46:56 2018 -0500 Fix typo commit 98d951ef77bd578b313a4ff4b496b793e82e88d5 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 12:22:39 2018 -0500 Remove `promises` reference commit a0e9559ed5bed947dabf28cb672e63d39948d854 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 12:22:13 2018 -0500 Fix `AttachmentView::mediaType` fall-through commit 67be916a83951b8a1f9b22efe78a6da6b1825f38 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 12:03:41 2018 -0500 Remove minor TODOs commit 0af186e118256b62905de38487ffacc41693ff47 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 11:44:41 2018 -0500 Enable ESLint for `js/views/attachment_view.js` commit 28a2dc5b8a28e1a087924fdc7275bf7d9a577b92 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 11:44:12 2018 -0500 Remove dynamic type checks commit f4ce36fcfc2737de32d911cd6103f889097813f6 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 11:27:56 2018 -0500 Rename `process` to `upgradeSchema` - `Message.process` -> `Message.upgradeSchema` - `Attachment.process` -> `Attachment.upgradeSchema` - `Attachment::processVersion` -> `Attachment::schemaVersion` Document version history. commit 41b92c0a31050ba05ddb1c43171d651f3568b9ac Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 11:11:50 2018 -0500 Add `operator-linebreak` ESLint rule Based on the following discussion: https://github.com/signalapp/Signal-Desktop/pull/2040#discussion_r168029106 commit 462defbe55879060fe25bc69103d4429bae2b2f6 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Wed Feb 14 11:01:30 2018 -0500 Add missing `await` for `ConversationController.getOrCreateAndWait` Tested this by setting `if` condition to `true` and confirming it works. It turns rotating a profile key is more involved and might require registering a new account according to Matthew. commit c08058ee4b883b3e23a40683de802ac81ed74874 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 16:32:24 2018 -0500 Convert `FileList` to `Array` commit 70a6c4201925f57be1f94d9da3547fdefc7bbb53 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 15:46:34 2018 -0500 :art: Fix lint errors commit 2ca7cdbc31d4120d6c6a838a6dcf43bc209d9788 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 15:07:09 2018 -0500 Skip `autoOrientImage` for non-JPEG images commit 58eac383013c16ca363a4ed33dca5c7ba61284e5 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 14:55:35 2018 -0500 Move new-style modules to `window.Signal` namespace commit 02c9328877dce289d6116a18b1c223891bd3cd0b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 14:35:23 2018 -0500 Extract `npm run test-modules` command commit 2c708eb94fba468b81ea9427734896114f5a7807 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 13:25:51 2018 -0500 Extract `Message.process` commit 4a2e52f68a77536a0fa04aa3c29ad3e541a8fa7e Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 13:25:12 2018 -0500 Fix EditorConfig commit a346bab5db082720f5d47363f06301380e870425 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 13:13:02 2018 -0500 Remove `vim` directives on ESLint-ed files commit 7ec885c6359e495b407d5bc3eac9431d47c37fc6 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 13:08:24 2018 -0500 Remove CSP whitelisting of `blob:` We no longer use `autoOrientImage` using blob URLs. Bring this back if we decide to auto-orient legacy attachments. commit 879b6f58f4a3f4a9ed6915af6b1be46c1e90e0ca Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:57:05 2018 -0500 Use `Message` type to determine send function Throws on invalid message type. commit 5203d945c98fd2562ae4e22c5c9838d27dec305b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:56:48 2018 -0500 Whitelist `Whisper` global commit 8ad0b066a3690d3382b86bf6ac00c03df7d1e20b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:56:32 2018 -0500 Add `Whisper.Types` namespace This avoids namespace collision for `Whisper.Message`. commit 785a949fce2656ca7dcaf0869d6b9e0648114e80 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:55:43 2018 -0500 Add `Message` type commit 674a7357abf0dcc365455695d56c0479998ebf27 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:35:23 2018 -0500 Run ESLint on `Conversation::sendMessage` commit cd985aa700caa80946245b17ea1b856449f152a0 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:34:38 2018 -0500 Document type signature of `FileInputView::readFile` commit d70d70e52c49588a1dc9833dfe5dd7128e13607f Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:31:16 2018 -0500 Move attachment processing closer to sending This helps ensure processing happens uniformly, regardless of which code paths are taken to send an attachment. commit 532ac3e273a26b97f831247f9ee3412621b5c112 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:22:29 2018 -0500 Process attachment before it’s sent Picked this place since it already had various async steps, similar to `onMessageReceived` for the incoming `Attachment.process`. Could we try have this live closer to where we store it in IndexedDB, e.g. `Conversation::sendMessage`? commit a4582ae2fb6e1d3487131ba1f8fa6a00170cb32c Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 12:21:42 2018 -0500 Refactor `getFile` and `getFiles` Lint them using ESLint. commit 07e9114e65046d791fc4f6ed90d6e2e938ad559d Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:37:31 2018 -0500 Document incoming and outgoing attachments fields Note how outgoing message attachments only have 4 fields. This presumably means the others are not used in our code and could be discarded for simplicity. commit fdc3ef289d6ec1be344a12d496839d5ba747bb6a Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:36:21 2018 -0500 Highlight that `dataURLToBlob` is synchronous commit b9c6bf600fcecedfd649ef2ae3c8629cced4e45a Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:35:49 2018 -0500 Add EditorConfig configuration commit e56101e229d56810c8e31ad7289043a152c6c449 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:34:23 2018 -0500 Replace custom with `blob-util` functions IMPORTANT: All of them are async so we need to use `await`, otherwise we get strange or silent errors. commit f95150f6a9569fabcb31f3acd9f6b7bf50b5d145 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:17:30 2018 -0500 Revert "Replace custom functions with `blob-util`" This reverts commit 8a81e9c01bfe80c0e1bf76737092206c06949512. commit 33860d93f3d30ec55c32f3f4a58729df2eb43f0d Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:13:02 2018 -0500 Revert "Replace `blueimp-canvas-to-blob` with `blob-util`" This reverts commit 31b3e853e4afc78fe80995921aa4152d9f6e4783. commit 7a0ba6fed622d76a3c39c7f03de541a7edb5b8dd Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 11:12:58 2018 -0500 Replace `blueimp-canvas-to-blob` with `blob-util` commit 47a5f2bfd8b3f546e27e8d2b7e1969755d825a66 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 10:55:34 2018 -0500 Replace custom functions with `blob-util` commit 1cfa0efdb4fb1265369e2bf243c21f04f044fa01 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 10:47:02 2018 -0500 Add `blob-util` dependency commit 9ac26be1bd783cd5070d886de107dd3ad9c91ad1 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 10:46:44 2018 -0500 Document why we drop original image data during auto-orient commit 4136d6c382b99f41760a4da519d0db537fa7de8d Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 10:46:27 2018 -0500 Extract `DEFAULT_JPEG_QUALITY` commit 4a7156327eb5f94dba80cb300b344ac591226b0e Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 10:37:11 2018 -0500 Drop support for invalid `image/jpg` MIME type commit 69fe96581f25413194032232f1bf704312e4754c Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:54:30 2018 -0500 Document `window.onInvalidStateError` global commit a48ba1c77458da38583ee9cd488f70a59f6ee0fd Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:54:04 2018 -0500 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. commit e6d1cf826befc17ad4ec72fda8e761701665635e Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:16:23 2018 -0500 Move async attachment processing to `onMessageReceived` We previously processed attachments in `handleDataMessage` which is mostly a synchronous function, except for the saving of the model. Moving the processing into the already async `onMessageReceived` improves code clarity. commit be6ca2a9aae5b59c360817deb1e18d39d705755e Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:14:49 2018 -0500 Document import of ES2015+ modules commit eaaf7c41608fb988b8f4bbaa933cff110115610e Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:14:29 2018 -0500 :art: Fix lint error commit a25b0e2e3d0f72c6a7bf0a15683f02450d5209ee Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:13:57 2018 -0500 :art: Organize `require`s commit e0cc3d8fab6529d01b388acddf8605908c3d236b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 09:07:17 2018 -0500 Implement attachment process version Instead of keeping track of last normalization (processing) date, we now keep track of an internal processing version that will help us understand what kind of processing has already been completed for a given attachment. This will let us retroactively upgrade existing attachments. As we add more processing steps, we can build a processing pipeline that can convert any attachment processing version into a higher one, e.g. 4 -> 5 -> 6 -> 7. commit ad9083d0fdb880bc518e02251e51a39f7e1c585f Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:50:31 2018 -0500 Ignore ES2015+ files during JSCS linting commit 96641205f734927aaebc2342d977c555799c3e3b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:48:07 2018 -0500 Improve ESLint ignore rules Apparently, using unqualified `/**` patterns prevents `!` include patterns. Using qualified glob patterns, e.g. `js/models/**/*.js`, lets us work around this. commit 255e0ab15bd1a0ca8ca5746e42d23977c8765d01 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:44:59 2018 -0500 :abc: ESLint ignored files commit ebcb70258a26f234bd602072ac7c0a1913128132 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:35:47 2018 -0500 Whitelist `browser` environment for ESLint commit 3eaace6f3a21421c5aaaaf01592408c7ed83ecd3 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:35:05 2018 -0500 Use `MIME` module commit ba2cf7770e614415733414a2dcc48f110b929892 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:32:54 2018 -0500 :art: Fix lint errors commit 65acc86e8580e88f7a6611eb4b8fa5d7291f7a3f Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:30:42 2018 -0500 Add ES2015+ files to JSHint ignored list commit 8b6494ae6c9247acdfa059a9b361ec5ffcdb39f0 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:29:20 2018 -0500 Document potentially unexpected `autoScale` behavior commit 8b4c69b2002d1777d3621be10f92cbf432f9d4d6 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:26:47 2018 -0500 Test CommonJS modules separately Not sure how to test them as part of Grunt `unit-tests` task as `test/index.html` doesn’t allow for inclusion of CommonJS modules that use `require`. The tests are silently skipped. commit 213400e4b2bba3efee856a25b40e269221c3c39d Author: Daniel Gasienica <daniel@gasienica.ch> Date: Tue Feb 13 08:24:27 2018 -0500 Add `MIME` type module commit 37a726e4fb4b3ed65914463122a5662847b5adee Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 20:18:05 2018 -0500 Return proper `Error` from `blobArrayToBuffer` commit 164752db5612220e4dcf58d57bcd682cb489a399 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 20:15:41 2018 -0500 :art: Fix ESLint errors commit d498dd79a067c75098dd3179814c914780e5cb4f Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 20:14:33 2018 -0500 Update `Attachment` type field definitions commit 141155a1533ff8fb616b70ea313432781bbebffd Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 20:12:50 2018 -0500 Move `blueimp-canvas-to-blob` from Bower to npm commit 7ccb833e5d286ddd6235d3e491c62ac1e4544510 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:33:50 2018 -0500 :art: Clarify data flow commit e7da41591fde5a830467bebf1b6f51c1f7293e74 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:31:21 2018 -0500 Use `blobUrl` for consistency commit 523a80eefe0e2858aa1fb2bb9539ec44da502963 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:28:06 2018 -0500 Remove just-in-time image auto-orient for lightbox We can bring this back if our users would like auto-orient for old attachments. commit 0739feae9c47dd523c10740d6cdf746d539f270c Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:27:21 2018 -0500 Remove just-in-time auto-orient of message attachments We can bring this back if our users would like auto-orient for old attachments. But better yet, we might implement this as database migration. commit ed43c66f92830ee233d5a94d0545eea4da43894d Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:26:24 2018 -0500 Auto-orient JPEG attachments upon receipt commit e2eb8e36b017b048d57602fca14e45d657e0e1a1 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:25:26 2018 -0500 Expose `Attachment` type through `Whisper.Attachment` commit 9638fbc987b84f143ca34211dc4666d96248ea2f Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:23:39 2018 -0500 Use `contentType` from `model` commit 032c0ced46c3876cb9474b26f9d53d6f1c6b16a0 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:23:04 2018 -0500 Return `Error` object for `autoOrientImage` failures commit ff04bad8510c4b21aef350bed2b1887d0e055b98 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:22:32 2018 -0500 Add `options` for `autoOrientImage` output type / quality commit 87745b5586d1e182b51c9f9bc5e4eaf6dbc16722 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:18:46 2018 -0500 Add `Attachment` type Defines various functions on attachments, e.g. normalization (auto-orient JPEGs, etc.) commit de27fdc10a53bc8882a9c978e82265db9ac6d6f5 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 16:16:34 2018 -0500 Add `yarn grunt` shortcut This allows us to use local `grunt-cli` for `grunt dev`. commit 59974db5a5da0d8f4cdc8ce5c4e3c974ecd5e754 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 10:10:11 2018 -0500 Improve readability commit b5ba96f1e6f40f2e1fa77490c583217768e1f412 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 10:08:12 2018 -0500 Use `snake_case` for module names Prevents problems across case-sensitive and case-insensitive file systems. We can work around this in the future using a lint rule such as `eslint-plugin-require-path-exists`. See discussion: https://github.com/signalapp/Signal-Desktop/pull/2040#discussion_r167365931 commit 48c5d3155c96ef628b00d99b52975e580d1d5501 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Mon Feb 12 10:05:44 2018 -0500 :art: Use destructuring commit 4822f49f22382a99ebf142b337375f7c25251d76 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 17:41:40 2018 -0500 Auto-orient images in lightbox view commit 7317110809677dddbbef3fadbf912cdba1c010bf Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 17:40:14 2018 -0500 Document magic number for escape key commit c790d07389a7d0bbf5298de83dbcfa8be1e7696b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 17:38:35 2018 -0500 Make second `View` argument an `options` object commit fbe010bb63d0088af9dfe11f153437fab34247e0 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 17:27:40 2018 -0500 Allow `loadImage` to fetch `blob://` URLs commit ec35710d002b019a273eeb48f94dcaf2babe5d96 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:57:48 2018 -0500 :art: Shorten `autoOrientImage` import commit d07433e3cf316c6a143a0c9393ba26df9e3af17b Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:57:19 2018 -0500 Make `autoOrientImage` module standalone commit c285bf5e33cdf10e0ef71e72cd6f55aef0df96ef Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:55:44 2018 -0500 Replace `loadImage` with `autoOrientImage` commit 44318549235af01fd061c25f557c93fd21cebb7a Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:53:23 2018 -0500 Add `autoOrientImage` module This module exposes `loadImage` with a `Promise` based interface and pre- populates `orientation: true` option to auto-orient input. Returns data URL as string. The module uses a named export as refactoring references of modules with `default` (`module.exports`) export references can be error-prone. See: https://basarat.gitbooks.io/typescript/docs/tips/defaultIsBad.html commit c77063afc6366fe49615052796fe46f9b369de39 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:44:30 2018 -0500 Auto-orient preview images See: #998 commit 06dba5eb8f662c11af3a9ba8395bb453ab2e5f8d Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:43:23 2018 -0500 TODO: Use native `Canvas::toBlob` One challenge is that `Canvas::toBlob` is async whereas `dataURLtoBlob` is sync. commit b15c304a3125dd023fd90990e6225a7303f3596f Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 16:42:45 2018 -0500 Make `null` check strict Appeases JSHint. ESLint has a nice `smart` option for `eqeqeq` rule: https://eslint.org/docs/rules/eqeqeq#smart commit ea70b92d9b18201758e11fdc25b09afc97b50055 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 15:23:58 2018 -0500 Use `Canvas::toDataURL` to preserve `ImageView` logic This way, all the other code paths remain untouched in case we want to remove the auto-orient code once Chrome supports the `image-orientation` CSS property. See: - #998 - https://developer.mozilla.org/en-US/docs/Web/CSS/image-orientation commit 62fd744f9f27d951573a68d2cdfe7ba2a3784b41 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 14:38:04 2018 -0500 Use CSS to constrain auto-oriented images commit f4d3392687168c237441b29140c7968b49dbef9e Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 14:35:02 2018 -0500 Replace `ImageView` `el` with auto-oriented `canvas` See: #998 commit 1602d7f610e4993ad1291f88197f9ead1e25e776 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 14:25:48 2018 -0500 Pass `Blob` to `View` (for `ImageView`) This allows us to do JPEG auto-orientation based on EXIF metadata. commit e6a414f2b2a80da1137b839b348a38510efd04bb Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 14:25:12 2018 -0500 :hocho: Remove newline commit 5f0d9570d7862fc428ff89c2ecfd332a744537e5 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 11:17:02 2018 -0500 Expose `blueimp-load-image` as `window.loadImage` commit 1e1c62fe2f6a76dbcf1998dd468c26187c9871dc Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 11:16:46 2018 -0500 Add `blueimp-load-image` npm dependency commit ad17fa8a68a21ca5ddec336801b8568009bef3d4 Author: Daniel Gasienica <daniel@gasienica.ch> Date: Fri Feb 9 11:14:40 2018 -0500 Remove `blueimp-load-image` Bower dependency
2018-02-21 15:26:59 +00:00
}
2020-09-09 02:25:05 +00:00
// Matches event data from `libtextsecure` `MessageReceiver::handleSentMessage`:
const getDescriptorForSent = ({
message,
destination,
destinationUuid,
}: WhatIsThis) => {
2020-09-09 02:25:05 +00:00
if (message.groupV2) {
const { id } = message.groupV2;
const conversationId = window.ConversationController.ensureGroup(id, {
2020-09-09 02:25:05 +00:00
groupVersion: 2,
masterKey: message.groupV2.masterKey,
secretParams: message.groupV2.secretParams,
publicParams: message.groupV2.publicParams,
});
return {
type: Message.GROUP,
id: conversationId,
};
}
if (message.group) {
const { id } = message.group;
const conversationId = window.ConversationController.ensureGroup(id);
2020-09-09 02:25:05 +00:00
return {
type: Message.GROUP,
id: conversationId,
};
}
return {
type: Message.PRIVATE,
id: window.ConversationController.ensureContactIds({
2020-09-09 02:25:05 +00:00
e164: destination,
uuid: destinationUuid,
highTrust: true,
}),
};
};
// Note: We do very little in this function, since everything in handleDataMessage is
// inside a conversation-specific queue(). Any code here might run before an earlier
// message is processed in handleDataMessage().
function onSentMessage(event: WhatIsThis) {
const { data, confirm } = event;
const messageDescriptor = getDescriptorForSent(data);
const { PROFILE_KEY_UPDATE } = window.textsecure.protobuf.DataMessage.Flags;
// eslint-disable-next-line no-bitwise
const isProfileUpdate = Boolean(data.message.flags & PROFILE_KEY_UPDATE);
if (isProfileUpdate) {
2020-04-29 21:24:12 +00:00
return handleMessageSentProfileUpdate({
data,
confirm,
messageDescriptor,
});
}
const message = createSentMessage(data, messageDescriptor);
2020-04-29 21:24:12 +00:00
if (data.message.reaction) {
window.normalizeUuids(
data.message.reaction,
['targetAuthorUuid'],
'background::onSentMessage'
);
2020-01-17 22:23:19 +00:00
const { reaction } = data.message;
2020-09-09 02:25:05 +00:00
window.log.info('Queuing sent reaction for', reaction.targetTimestamp);
const reactionModel = window.Whisper.Reactions.add({
2020-01-17 22:23:19 +00:00
emoji: reaction.emoji,
remove: reaction.remove,
targetAuthorE164: reaction.targetAuthorE164,
targetAuthorUuid: reaction.targetAuthorUuid,
2020-09-09 02:25:05 +00:00
targetTimestamp: reaction.targetTimestamp,
2020-01-17 22:23:19 +00:00
timestamp: Date.now(),
fromId: window.ConversationController.getOurConversationId(),
2020-01-23 23:57:37 +00:00
fromSync: true,
2020-01-17 22:23:19 +00:00
});
// Note: We do not wait for completion here
window.Whisper.Reactions.onReaction(reactionModel);
2019-09-26 19:56:31 +00:00
event.confirm();
2020-04-29 21:24:12 +00:00
return Promise.resolve();
}
if (data.message.delete) {
const { delete: del } = data.message;
2020-09-09 02:25:05 +00:00
window.log.info('Queuing sent DOE for', del.targetSentTimestamp);
const deleteModel = window.Whisper.Deletes.add({
2020-04-29 21:24:12 +00:00
targetSentTimestamp: del.targetSentTimestamp,
serverTimestamp: del.serverTimestamp,
fromId: window.ConversationController.getOurConversationId(),
2020-04-29 21:24:12 +00:00
});
// Note: We do not wait for completion here
window.Whisper.Deletes.onDelete(deleteModel);
2020-04-29 21:24:12 +00:00
confirm();
return Promise.resolve();
}
// Don't wait for handleDataMessage, as it has its own per-conversation queueing
message.handleDataMessage(data.message, event.confirm, {
data,
});
2020-04-29 21:24:12 +00:00
return Promise.resolve();
2018-04-27 21:25:04 +00:00
}
function initIncomingMessage(data: WhatIsThis, descriptor: WhatIsThis) {
return new window.Whisper.Message({
2018-04-27 21:25:04 +00:00
source: data.source,
sourceUuid: data.sourceUuid,
2018-04-27 21:25:04 +00:00
sourceDevice: data.sourceDevice,
sent_at: data.timestamp,
2020-04-29 21:24:12 +00:00
serverTimestamp: data.serverTimestamp,
received_at: Date.now(),
2020-09-09 02:25:05 +00:00
conversationId: descriptor.id,
unidentifiedDeliveryReceived: data.unidentifiedDeliveryReceived,
2018-04-27 21:25:04 +00:00
type: 'incoming',
unread: 1,
} as WhatIsThis);
2018-04-27 21:25:04 +00:00
}
async function unlinkAndDisconnect() {
window.Whisper.events.trigger('unauthorized');
if (messageReceiver) {
await messageReceiver.stopProcessing();
await window.waitForAllBatchers();
messageReceiver.unregisterBatchers();
2019-09-26 19:56:31 +00:00
messageReceiver = null;
}
2019-09-26 19:56:31 +00:00
onEmpty();
window.log.warn(
'Client is no longer authorized; deleting local configuration'
);
window.Signal.Util.Registration.remove();
const NUMBER_ID_KEY = 'number_id';
const VERSION_KEY = 'version';
const LAST_PROCESSED_INDEX_KEY = 'attachmentMigration_lastProcessedIndex';
const IS_MIGRATION_COMPLETE_KEY = 'attachmentMigration_isComplete';
const previousNumberId = window.textsecure.storage.get(NUMBER_ID_KEY);
const lastProcessedIndex = window.textsecure.storage.get(
LAST_PROCESSED_INDEX_KEY
);
const isMigrationComplete = window.textsecure.storage.get(
IS_MIGRATION_COMPLETE_KEY
);
try {
await window.textsecure.storage.protocol.removeAllConfiguration();
// These two bits of data are important to ensure that the app loads up
// the conversation list, instead of showing just the QR code screen.
window.Signal.Util.Registration.markEverDone();
await window.textsecure.storage.put(NUMBER_ID_KEY, previousNumberId);
// These two are important to ensure we don't rip through every message
// in the database attempting to upgrade it after starting up again.
await window.textsecure.storage.put(
IS_MIGRATION_COMPLETE_KEY,
isMigrationComplete || false
);
await window.textsecure.storage.put(
LAST_PROCESSED_INDEX_KEY,
lastProcessedIndex || null
);
await window.textsecure.storage.put(VERSION_KEY, window.getVersion());
2018-05-25 01:50:49 +00:00
window.log.info('Successfully cleared local configuration');
} catch (eraseError) {
window.log.error(
'Something went wrong clearing local configuration',
eraseError && eraseError.stack ? eraseError.stack : eraseError
);
}
}
function onError(ev: WhatIsThis) {
const { error } = ev;
window.log.error('background onError:', Errors.toLogFormat(error));
if (
error &&
error.name === 'HTTPError' &&
(error.code === 401 || error.code === 403)
) {
2020-04-29 21:24:12 +00:00
return unlinkAndDisconnect();
2018-04-27 21:25:04 +00:00
}
if (
error &&
error.name === 'HTTPError' &&
(error.code === -1 || error.code === 502)
) {
2018-04-27 21:25:04 +00:00
// Failed to connect to server
if (navigator.onLine) {
window.log.info('retrying in 1 minute');
reconnectTimer = setTimeout(connect, 60000);
2018-04-27 21:25:04 +00:00
window.Whisper.events.trigger('reconnectTimer');
2018-04-27 21:25:04 +00:00
}
2020-04-29 21:24:12 +00:00
return Promise.resolve();
2018-04-27 21:25:04 +00:00
}
if (ev.proto) {
if (error && error.name === 'MessageCounterError') {
2018-04-27 21:25:04 +00:00
if (ev.confirm) {
ev.confirm();
}
2018-04-27 21:25:04 +00:00
// Ignore this message. It is likely a duplicate delivery
// because the server lost our ack the first time.
2020-04-29 21:24:12 +00:00
return Promise.resolve();
2018-04-27 21:25:04 +00:00
}
2018-05-25 01:50:49 +00:00
const envelope = ev.proto;
2020-06-12 22:36:32 +00:00
const message = initIncomingMessage(envelope, {
type: Message.PRIVATE,
id: window.ConversationController.ensureContactIds({
2020-06-12 22:36:32 +00:00
e164: envelope.source,
uuid: envelope.sourceUuid,
}),
});
2018-05-25 01:50:49 +00:00
const conversationId = message.get('conversationId');
const conversation = window.ConversationController.get(conversationId);
2018-05-25 01:50:49 +00:00
2020-09-09 02:25:05 +00:00
if (!conversation) {
window.log.warn(
'onError: No conversation id, cannot save error bubble'
);
ev.confirm();
return Promise.resolve();
}
2019-09-26 19:56:31 +00:00
// This matches the queueing behavior used in Message.handleDataMessage
conversation.queueJob(async () => {
const existingMessage = await window.Signal.Data.getMessageBySender(
message.attributes,
{
Message: window.Whisper.Message,
}
);
if (existingMessage) {
ev.confirm();
window.log.warn(
`Got duplicate error for message ${message.idForLogging()}`
);
return;
}
const model = new window.Whisper.Message({
2019-09-26 19:56:31 +00:00
...message.attributes,
id: window.getGuid(),
});
await model.saveErrors(error || new Error('Error was null'), {
skipSave: true,
});
2018-05-25 01:50:49 +00:00
window.MessageController.register(model.id, model);
2019-09-26 19:56:31 +00:00
await window.Signal.Data.saveMessage(model.attributes, {
Message: window.Whisper.Message,
2019-09-26 19:56:31 +00:00
forceSave: true,
});
2018-05-25 01:50:49 +00:00
2019-09-26 19:56:31 +00:00
conversation.set({
active_at: Date.now(),
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
unreadCount: conversation.get('unreadCount')! + 1,
2019-09-26 19:56:31 +00:00
});
2018-05-25 01:50:49 +00:00
2019-09-26 19:56:31 +00:00
const conversationTimestamp = conversation.get('timestamp');
const messageTimestamp = model.get('timestamp');
if (
!conversationTimestamp ||
messageTimestamp > conversationTimestamp
) {
conversation.set({ timestamp: model.get('sent_at') });
}
2019-09-26 19:56:31 +00:00
conversation.trigger('newmessage', model);
conversation.notify(model);
window.Whisper.events.trigger('incrementProgress');
2019-09-26 19:56:31 +00:00
if (ev.confirm) {
ev.confirm();
}
window.Signal.Data.updateConversation(conversation.attributes);
2019-09-26 19:56:31 +00:00
});
2018-04-27 21:25:04 +00:00
}
2018-04-27 21:25:04 +00:00
throw error;
}
async function onViewSync(ev: WhatIsThis) {
2019-09-26 19:56:31 +00:00
ev.confirm();
const { source, sourceUuid, timestamp } = ev;
2019-08-05 20:53:15 +00:00
window.log.info(`view sync ${source} ${timestamp}`);
2019-06-26 19:33:13 +00:00
const sync = window.Whisper.ViewSyncs.add({
2019-06-26 19:33:13 +00:00
source,
sourceUuid,
2019-06-26 19:33:13 +00:00
timestamp,
});
window.Whisper.ViewSyncs.onSync(sync);
2019-06-26 19:33:13 +00:00
}
async function onFetchLatestSync(ev: WhatIsThis) {
ev.confirm();
const { eventType } = ev;
const FETCH_LATEST_ENUM =
window.textsecure.protobuf.SyncMessage.FetchLatest.Type;
switch (eventType) {
case FETCH_LATEST_ENUM.LOCAL_PROFILE:
// Intentionally do nothing since we'll be receiving the
// window.storage manifest request and will update local profile along with that.
break;
case FETCH_LATEST_ENUM.STORAGE_MANIFEST:
window.log.info('onFetchLatestSync: fetching latest manifest');
2020-09-09 00:56:23 +00:00
await window.Signal.Services.runStorageServiceSyncJob();
break;
default:
window.log.info(
`onFetchLatestSync: Unknown type encountered ${eventType}`
);
}
}
async function onKeysSync(ev: WhatIsThis) {
ev.confirm();
const { storageServiceKey } = ev;
2020-09-09 00:56:23 +00:00
if (storageServiceKey === null) {
window.log.info('onKeysSync: deleting window.storageKey');
window.storage.remove('storageKey');
2020-09-09 00:56:23 +00:00
}
if (storageServiceKey) {
window.log.info('onKeysSync: received keys');
const storageServiceKeyBase64 = window.Signal.Crypto.arrayBufferToBase64(
storageServiceKey
);
window.storage.put('storageKey', storageServiceKeyBase64);
2020-09-09 00:56:23 +00:00
await window.Signal.Services.runStorageServiceSyncJob();
}
}
async function onMessageRequestResponse(ev: WhatIsThis) {
2020-05-27 21:37:06 +00:00
ev.confirm();
const { threadE164, threadUuid, groupId, messageRequestResponseType } = ev;
const args = {
threadE164,
threadUuid,
groupId,
type: messageRequestResponseType,
};
window.log.info('message request response', args);
const sync = window.Whisper.MessageRequests.add(args);
2020-05-27 21:37:06 +00:00
window.Whisper.MessageRequests.onResponse(sync);
2020-05-27 21:37:06 +00:00
}
function onReadReceipt(ev: WhatIsThis) {
2018-05-25 01:50:49 +00:00
const readAt = ev.timestamp;
const { envelopeTimestamp, timestamp, source, sourceUuid } = ev.read;
const reader = window.ConversationController.ensureContactIds({
e164: source,
uuid: sourceUuid,
highTrust: true,
});
window.log.info(
'read receipt',
source,
sourceUuid,
envelopeTimestamp,
reader,
'for sent message',
timestamp
);
2018-04-27 21:25:04 +00:00
2019-09-26 19:56:31 +00:00
ev.confirm();
if (!window.storage.get('read-receipt-setting') || !reader) {
2019-09-26 19:56:31 +00:00
return;
}
const receipt = window.Whisper.ReadReceipts.add({
2018-05-25 01:50:49 +00:00
reader,
timestamp,
read_at: readAt,
2018-04-27 21:25:04 +00:00
});
Feature: Blue check marks for read messages if opted in (#1489) * Refactor delivery receipt event handler * Rename the delivery receipt event For less ambiguity with read receipts. * Rename synced read event For less ambiguity with read receipts from other Signal users. * Add support for incoming receipt messages Handle ReceiptMessages, which may include encrypted delivery receipts or read receipts from recipients of our sent messages. // FREEBIE * Rename ReadReceipts to ReadSyncs * Render read messages with blue double checks * Send read receipts to senders of incoming messages // FREEBIE * Move ReadSyncs to their own file // FREEBIE * Fixup old comments on read receipts (now read syncs) And some variable renaming for extra clarity. // FREEBIE * Add global setting for read receipts Don't send read receipt messages unless the setting is enabled. Don't process read receipts if the setting is disabled. // FREEBIE * Sync read receipt setting from mobile Toggling this setting on your mobile device should sync it to Desktop. When linking, use the setting in the provisioning message. // FREEBIE * Send receipt messages silently Avoid generating phantom messages on ios // FREEBIE * Save recipients on the outgoing message models For accurate tracking and display of sent/delivered/read state, even if group membership changes later. // FREEBIE * Fix conversation type in profile key update handling // FREEBIE * Set recipients on synced sent messages * Render saved recipients in message detail if available For older messages, where we did not save the intended set of recipients at the time of sending, fall back to the current group membership. // FREEBIE * Record who has been successfully sent to // FREEBIE * Record who a message has been delivered to * Invert the not-clickable class * Fix readReceipt setting sync when linking * Render per recipient sent/delivered/read status In the message detail view for outgoing messages, render each recipient's individual sent/delivered/read status with respect to this message, as long as there are no errors associated with the recipient (ie, safety number changes, user not registered, etc...) since the error icon is displayed in that case. *Messages sent before this change may not have per-recipient status lists and will simply show no status icon. // FREEBIE * Add configuration sync request Send these requests in a one-off fashion when: 1. We have just setup from a chrome app import 2. We have just upgraded to read-receipt support // FREEBIE * Expose sendRequestConfigurationSyncMessage // FREEBIE * Fix handling of incoming delivery receipts - union with array FREEBIE
2017-10-04 22:28:43 +00:00
2019-09-26 19:56:31 +00:00
// Note: We do not wait for completion here
window.Whisper.ReadReceipts.onReceipt(receipt);
2018-04-27 21:25:04 +00:00
}
Feature: Blue check marks for read messages if opted in (#1489) * Refactor delivery receipt event handler * Rename the delivery receipt event For less ambiguity with read receipts. * Rename synced read event For less ambiguity with read receipts from other Signal users. * Add support for incoming receipt messages Handle ReceiptMessages, which may include encrypted delivery receipts or read receipts from recipients of our sent messages. // FREEBIE * Rename ReadReceipts to ReadSyncs * Render read messages with blue double checks * Send read receipts to senders of incoming messages // FREEBIE * Move ReadSyncs to their own file // FREEBIE * Fixup old comments on read receipts (now read syncs) And some variable renaming for extra clarity. // FREEBIE * Add global setting for read receipts Don't send read receipt messages unless the setting is enabled. Don't process read receipts if the setting is disabled. // FREEBIE * Sync read receipt setting from mobile Toggling this setting on your mobile device should sync it to Desktop. When linking, use the setting in the provisioning message. // FREEBIE * Send receipt messages silently Avoid generating phantom messages on ios // FREEBIE * Save recipients on the outgoing message models For accurate tracking and display of sent/delivered/read state, even if group membership changes later. // FREEBIE * Fix conversation type in profile key update handling // FREEBIE * Set recipients on synced sent messages * Render saved recipients in message detail if available For older messages, where we did not save the intended set of recipients at the time of sending, fall back to the current group membership. // FREEBIE * Record who has been successfully sent to // FREEBIE * Record who a message has been delivered to * Invert the not-clickable class * Fix readReceipt setting sync when linking * Render per recipient sent/delivered/read status In the message detail view for outgoing messages, render each recipient's individual sent/delivered/read status with respect to this message, as long as there are no errors associated with the recipient (ie, safety number changes, user not registered, etc...) since the error icon is displayed in that case. *Messages sent before this change may not have per-recipient status lists and will simply show no status icon. // FREEBIE * Add configuration sync request Send these requests in a one-off fashion when: 1. We have just setup from a chrome app import 2. We have just upgraded to read-receipt support // FREEBIE * Expose sendRequestConfigurationSyncMessage // FREEBIE * Fix handling of incoming delivery receipts - union with array FREEBIE
2017-10-04 22:28:43 +00:00
function onReadSync(ev: WhatIsThis) {
2018-05-25 01:50:49 +00:00
const readAt = ev.timestamp;
const { envelopeTimestamp, sender, senderUuid, timestamp } = ev.read;
const senderId = window.ConversationController.ensureContactIds({
e164: sender,
uuid: senderUuid,
});
window.log.info(
'read sync',
sender,
senderUuid,
envelopeTimestamp,
senderId,
'for message',
timestamp
);
Feature: Blue check marks for read messages if opted in (#1489) * Refactor delivery receipt event handler * Rename the delivery receipt event For less ambiguity with read receipts. * Rename synced read event For less ambiguity with read receipts from other Signal users. * Add support for incoming receipt messages Handle ReceiptMessages, which may include encrypted delivery receipts or read receipts from recipients of our sent messages. // FREEBIE * Rename ReadReceipts to ReadSyncs * Render read messages with blue double checks * Send read receipts to senders of incoming messages // FREEBIE * Move ReadSyncs to their own file // FREEBIE * Fixup old comments on read receipts (now read syncs) And some variable renaming for extra clarity. // FREEBIE * Add global setting for read receipts Don't send read receipt messages unless the setting is enabled. Don't process read receipts if the setting is disabled. // FREEBIE * Sync read receipt setting from mobile Toggling this setting on your mobile device should sync it to Desktop. When linking, use the setting in the provisioning message. // FREEBIE * Send receipt messages silently Avoid generating phantom messages on ios // FREEBIE * Save recipients on the outgoing message models For accurate tracking and display of sent/delivered/read state, even if group membership changes later. // FREEBIE * Fix conversation type in profile key update handling // FREEBIE * Set recipients on synced sent messages * Render saved recipients in message detail if available For older messages, where we did not save the intended set of recipients at the time of sending, fall back to the current group membership. // FREEBIE * Record who has been successfully sent to // FREEBIE * Record who a message has been delivered to * Invert the not-clickable class * Fix readReceipt setting sync when linking * Render per recipient sent/delivered/read status In the message detail view for outgoing messages, render each recipient's individual sent/delivered/read status with respect to this message, as long as there are no errors associated with the recipient (ie, safety number changes, user not registered, etc...) since the error icon is displayed in that case. *Messages sent before this change may not have per-recipient status lists and will simply show no status icon. // FREEBIE * Add configuration sync request Send these requests in a one-off fashion when: 1. We have just setup from a chrome app import 2. We have just upgraded to read-receipt support // FREEBIE * Expose sendRequestConfigurationSyncMessage // FREEBIE * Fix handling of incoming delivery receipts - union with array FREEBIE
2017-10-04 22:28:43 +00:00
const receipt = window.Whisper.ReadSyncs.add({
senderId,
2018-05-25 01:50:49 +00:00
sender,
senderUuid,
2018-05-25 01:50:49 +00:00
timestamp,
read_at: readAt,
2018-04-27 21:25:04 +00:00
});
Feature: Blue check marks for read messages if opted in (#1489) * Refactor delivery receipt event handler * Rename the delivery receipt event For less ambiguity with read receipts. * Rename synced read event For less ambiguity with read receipts from other Signal users. * Add support for incoming receipt messages Handle ReceiptMessages, which may include encrypted delivery receipts or read receipts from recipients of our sent messages. // FREEBIE * Rename ReadReceipts to ReadSyncs * Render read messages with blue double checks * Send read receipts to senders of incoming messages // FREEBIE * Move ReadSyncs to their own file // FREEBIE * Fixup old comments on read receipts (now read syncs) And some variable renaming for extra clarity. // FREEBIE * Add global setting for read receipts Don't send read receipt messages unless the setting is enabled. Don't process read receipts if the setting is disabled. // FREEBIE * Sync read receipt setting from mobile Toggling this setting on your mobile device should sync it to Desktop. When linking, use the setting in the provisioning message. // FREEBIE * Send receipt messages silently Avoid generating phantom messages on ios // FREEBIE * Save recipients on the outgoing message models For accurate tracking and display of sent/delivered/read state, even if group membership changes later. // FREEBIE * Fix conversation type in profile key update handling // FREEBIE * Set recipients on synced sent messages * Render saved recipients in message detail if available For older messages, where we did not save the intended set of recipients at the time of sending, fall back to the current group membership. // FREEBIE * Record who has been successfully sent to // FREEBIE * Record who a message has been delivered to * Invert the not-clickable class * Fix readReceipt setting sync when linking * Render per recipient sent/delivered/read status In the message detail view for outgoing messages, render each recipient's individual sent/delivered/read status with respect to this message, as long as there are no errors associated with the recipient (ie, safety number changes, user not registered, etc...) since the error icon is displayed in that case. *Messages sent before this change may not have per-recipient status lists and will simply show no status icon. // FREEBIE * Add configuration sync request Send these requests in a one-off fashion when: 1. We have just setup from a chrome app import 2. We have just upgraded to read-receipt support // FREEBIE * Expose sendRequestConfigurationSyncMessage // FREEBIE * Fix handling of incoming delivery receipts - union with array FREEBIE
2017-10-04 22:28:43 +00:00
2018-04-27 21:25:04 +00:00
receipt.on('remove', ev.confirm);
Feature: Blue check marks for read messages if opted in (#1489) * Refactor delivery receipt event handler * Rename the delivery receipt event For less ambiguity with read receipts. * Rename synced read event For less ambiguity with read receipts from other Signal users. * Add support for incoming receipt messages Handle ReceiptMessages, which may include encrypted delivery receipts or read receipts from recipients of our sent messages. // FREEBIE * Rename ReadReceipts to ReadSyncs * Render read messages with blue double checks * Send read receipts to senders of incoming messages // FREEBIE * Move ReadSyncs to their own file // FREEBIE * Fixup old comments on read receipts (now read syncs) And some variable renaming for extra clarity. // FREEBIE * Add global setting for read receipts Don't send read receipt messages unless the setting is enabled. Don't process read receipts if the setting is disabled. // FREEBIE * Sync read receipt setting from mobile Toggling this setting on your mobile device should sync it to Desktop. When linking, use the setting in the provisioning message. // FREEBIE * Send receipt messages silently Avoid generating phantom messages on ios // FREEBIE * Save recipients on the outgoing message models For accurate tracking and display of sent/delivered/read state, even if group membership changes later. // FREEBIE * Fix conversation type in profile key update handling // FREEBIE * Set recipients on synced sent messages * Render saved recipients in message detail if available For older messages, where we did not save the intended set of recipients at the time of sending, fall back to the current group membership. // FREEBIE * Record who has been successfully sent to // FREEBIE * Record who a message has been delivered to * Invert the not-clickable class * Fix readReceipt setting sync when linking * Render per recipient sent/delivered/read status In the message detail view for outgoing messages, render each recipient's individual sent/delivered/read status with respect to this message, as long as there are no errors associated with the recipient (ie, safety number changes, user not registered, etc...) since the error icon is displayed in that case. *Messages sent before this change may not have per-recipient status lists and will simply show no status icon. // FREEBIE * Add configuration sync request Send these requests in a one-off fashion when: 1. We have just setup from a chrome app import 2. We have just upgraded to read-receipt support // FREEBIE * Expose sendRequestConfigurationSyncMessage // FREEBIE * Fix handling of incoming delivery receipts - union with array FREEBIE
2017-10-04 22:28:43 +00:00
2019-09-26 19:56:31 +00:00
// Note: Here we wait, because we want read states to be in the database
// before we move on.
return window.Whisper.ReadSyncs.onReceipt(receipt);
2018-04-27 21:25:04 +00:00
}
async function onVerified(ev: WhatIsThis) {
const e164 = ev.verified.destination;
const uuid = ev.verified.destinationUuid;
2018-05-25 01:50:49 +00:00
const key = ev.verified.identityKey;
let state;
2019-09-26 19:56:31 +00:00
if (ev.confirm) {
ev.confirm();
}
const c = new window.Whisper.Conversation({
e164,
uuid,
type: 'private',
} as WhatIsThis);
const error = c.validate();
2018-04-27 21:25:04 +00:00
if (error) {
window.log.error(
'Invalid verified sync received:',
e164,
uuid,
Errors.toLogFormat(error as WhatIsThis)
);
2018-04-27 21:25:04 +00:00
return;
}
2018-04-27 21:25:04 +00:00
switch (ev.verified.state) {
case window.textsecure.protobuf.Verified.State.DEFAULT:
2018-04-27 21:25:04 +00:00
state = 'DEFAULT';
break;
case window.textsecure.protobuf.Verified.State.VERIFIED:
2018-04-27 21:25:04 +00:00
state = 'VERIFIED';
break;
case window.textsecure.protobuf.Verified.State.UNVERIFIED:
2018-04-27 21:25:04 +00:00
state = 'UNVERIFIED';
break;
2018-05-25 01:50:49 +00:00
default:
window.log.error(`Got unexpected verified state: ${ev.verified.state}`);
2018-04-27 21:25:04 +00:00
}
window.log.info(
2018-04-27 21:25:04 +00:00
'got verified sync for',
e164,
uuid,
2018-04-27 21:25:04 +00:00
state,
ev.viaContactSync ? 'via contact sync' : ''
);
const verifiedId = window.ConversationController.ensureContactIds({
e164,
uuid,
highTrust: true,
});
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const contact = window.ConversationController.get(verifiedId)!;
2018-05-25 01:50:49 +00:00
const options = {
viaSyncMessage: true,
viaContactSync: ev.viaContactSync,
key,
};
if (state === 'VERIFIED') {
await contact.setVerified(options);
} else if (state === 'DEFAULT') {
await contact.setVerifiedDefault(options);
} else {
await contact.setUnverified(options);
}
2018-04-27 21:25:04 +00:00
}
function onDeliveryReceipt(ev: WhatIsThis) {
2018-05-25 01:50:49 +00:00
const { deliveryReceipt } = ev;
const {
envelopeTimestamp,
sourceUuid,
source,
sourceDevice,
timestamp,
} = deliveryReceipt;
2019-09-26 19:56:31 +00:00
ev.confirm();
const deliveredTo = window.ConversationController.ensureContactIds({
e164: source,
uuid: sourceUuid,
highTrust: true,
});
window.log.info(
'delivery receipt from',
source,
sourceUuid,
sourceDevice,
deliveredTo,
envelopeTimestamp,
'for sent message',
timestamp
);
if (!deliveredTo) {
window.log.info('no conversation for', source, sourceUuid);
return;
}
const receipt = window.Whisper.DeliveryReceipts.add({
timestamp,
deliveredTo,
2018-04-27 21:25:04 +00:00
});
2019-09-26 19:56:31 +00:00
// Note: We don't wait for completion here
window.Whisper.DeliveryReceipts.onReceipt(receipt);
2018-04-27 21:25:04 +00:00
}
})();