Wire up writeAttachment
This commit is contained in:
parent
aa82a2a5fb
commit
e0428355be
5 changed files with 27 additions and 3 deletions
|
@ -5,6 +5,9 @@ const isString = require('lodash/isString');
|
|||
const Path = require('path');
|
||||
|
||||
|
||||
// _writeAttachmentData :: AttachmentsPath ->
|
||||
// ArrayBuffer ->
|
||||
// IO (Promise Path)
|
||||
exports.writeAttachmentData = (root) => {
|
||||
if (!isString(root)) {
|
||||
throw new TypeError('`root` must be a path');
|
||||
|
@ -23,11 +26,13 @@ exports.writeAttachmentData = (root) => {
|
|||
};
|
||||
};
|
||||
|
||||
// _getAttachmentName :: Unit -> IO String
|
||||
exports._getAttachmentName = () => {
|
||||
const buffer = crypto.randomBytes(32);
|
||||
return buffer.toString('hex');
|
||||
};
|
||||
|
||||
// _getAttachmentPath :: Unit -> IO Path
|
||||
exports._getAttachmentPath = () => {
|
||||
const name = exports._getAttachmentName();
|
||||
const prefix = name.slice(0, 3);
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
'use strict';
|
||||
|
||||
const { Errors, Message } = window.Signal.Types;
|
||||
const { context: migrationsContext } = window.Signal.Migrations;
|
||||
|
||||
// Implicitly used in `indexeddb-backbonejs-adapter`:
|
||||
// https://github.com/signalapp/Signal-Desktop/blob/4033a9f8137e62ed286170ed5d4941982b1d3a64/components/indexeddb-backbonejs-adapter/backbone-indexeddb.js#L569
|
||||
|
@ -573,7 +574,8 @@
|
|||
return event.confirm();
|
||||
}
|
||||
|
||||
const upgradedMessage = await Message.upgradeSchema(data.message);
|
||||
const upgradedMessage =
|
||||
await Message.upgradeSchema(data.message, migrationsContext);
|
||||
await ConversationController.getOrCreateAndWait(
|
||||
messageDescriptor.id,
|
||||
messageDescriptor.type
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
window.Whisper = window.Whisper || {};
|
||||
|
||||
const { Attachment, Message } = window.Signal.Types;
|
||||
const { context: migrationContext } = window.Signal.Migrations;
|
||||
|
||||
// TODO: Factor out private and group subclasses of Conversation
|
||||
|
||||
|
@ -626,7 +627,7 @@
|
|||
received_at: now,
|
||||
expireTimer: this.get('expireTimer'),
|
||||
recipients: this.getRecipients(),
|
||||
});
|
||||
}, migrationContext);
|
||||
const message = this.messageCollection.add(messageWithSchema);
|
||||
if (this.isPrivate()) {
|
||||
message.set({ destination: this.id });
|
||||
|
|
7
main.js
7
main.js
|
@ -16,6 +16,7 @@ const {
|
|||
|
||||
const packageJson = require('./package.json');
|
||||
|
||||
const Attachments = require('./app/attachments');
|
||||
const autoUpdate = require('./app/auto_update');
|
||||
const createTrayIcon = require('./app/tray_icon');
|
||||
const GlobalErrors = require('./js/modules/global_errors');
|
||||
|
@ -417,7 +418,7 @@ app.on('ready', () => {
|
|||
let loggingSetupError;
|
||||
logging.initialize().catch((error) => {
|
||||
loggingSetupError = error;
|
||||
}).then(() => {
|
||||
}).then(async () => {
|
||||
/* eslint-enable more/no-then */
|
||||
logger = logging.getLogger();
|
||||
logger.info('app ready');
|
||||
|
@ -431,6 +432,10 @@ app.on('ready', () => {
|
|||
locale = loadLocale({ appLocale, logger });
|
||||
}
|
||||
|
||||
console.log('Ensure attachments directory exists');
|
||||
const userDataPath = app.getPath('userData');
|
||||
await Attachments.ensureDirectory(userDataPath);
|
||||
|
||||
ready = true;
|
||||
|
||||
autoUpdate.initialize(getMainWindow, locale.messages);
|
||||
|
|
11
preload.js
11
preload.js
|
@ -4,6 +4,11 @@
|
|||
console.log('preload');
|
||||
const electron = require('electron');
|
||||
|
||||
const Attachments = require('./app/attachments');
|
||||
|
||||
const { app } = electron.remote;
|
||||
|
||||
|
||||
window.PROTO_ROOT = 'protos';
|
||||
window.config = require('url').parse(window.location.toString(), true).query;
|
||||
window.wrapDeferred = function(deferred) {
|
||||
|
@ -110,6 +115,12 @@
|
|||
window.Signal.Crypto = require('./js/modules/crypto');
|
||||
|
||||
window.Signal.Migrations = window.Signal.Migrations || {};
|
||||
const attachmentsPath = Attachments.getPath(app.getPath('userData'));
|
||||
const { writeAttachmentData } = require('./app/types/attachment/write_attachment_data');
|
||||
// Injected context functions to keep `Message` agnostic from Electron:
|
||||
window.Signal.Migrations.context = {
|
||||
writeAttachmentData: writeAttachmentData(attachmentsPath),
|
||||
};
|
||||
window.Signal.Migrations.V17 = require('./js/modules/migrations/17');
|
||||
|
||||
window.Signal.Types = window.Signal.Types || {};
|
||||
|
|
Loading…
Add table
Reference in a new issue