Wire up Message
/ Attachment
migration functions on startup
Makes `migrationContext` obsolete.
This commit is contained in:
parent
867f73b80a
commit
0c06fff47b
5 changed files with 25 additions and 26 deletions
|
@ -15,7 +15,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const { Errors, Message } = window.Signal.Types;
|
const { Errors, Message } = window.Signal.Types;
|
||||||
const { context: migrationsContext } = window.Signal.Migrations;
|
const { upgradeMessageSchema } = window.Signal.Migrations;
|
||||||
|
|
||||||
// Implicitly used in `indexeddb-backbonejs-adapter`:
|
// Implicitly used in `indexeddb-backbonejs-adapter`:
|
||||||
// https://github.com/signalapp/Signal-Desktop/blob/4033a9f8137e62ed286170ed5d4941982b1d3a64/components/indexeddb-backbonejs-adapter/backbone-indexeddb.js#L569
|
// https://github.com/signalapp/Signal-Desktop/blob/4033a9f8137e62ed286170ed5d4941982b1d3a64/components/indexeddb-backbonejs-adapter/backbone-indexeddb.js#L569
|
||||||
|
@ -574,8 +574,7 @@
|
||||||
return event.confirm();
|
return event.confirm();
|
||||||
}
|
}
|
||||||
|
|
||||||
const upgradedMessage =
|
const upgradedMessage = await upgradeMessageSchema(data.message);
|
||||||
await Message.upgradeSchema(data.message, migrationsContext);
|
|
||||||
await ConversationController.getOrCreateAndWait(
|
await ConversationController.getOrCreateAndWait(
|
||||||
messageDescriptor.id,
|
messageDescriptor.id,
|
||||||
messageDescriptor.type
|
messageDescriptor.type
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
window.Whisper = window.Whisper || {};
|
window.Whisper = window.Whisper || {};
|
||||||
|
|
||||||
const { Attachment, Message } = window.Signal.Types;
|
const { Attachment, Message } = window.Signal.Types;
|
||||||
const { context: migrationContext } = window.Signal.Migrations;
|
const { upgradeMessageSchema, loadAttachmentData } = window.Signal.Migrations;
|
||||||
|
|
||||||
// TODO: Factor out private and group subclasses of Conversation
|
// TODO: Factor out private and group subclasses of Conversation
|
||||||
|
|
||||||
|
@ -618,7 +618,7 @@
|
||||||
now
|
now
|
||||||
);
|
);
|
||||||
|
|
||||||
const messageWithSchema = await Message.upgradeSchema({
|
const messageWithSchema = await upgradeMessageSchema({
|
||||||
type: 'outgoing',
|
type: 'outgoing',
|
||||||
body,
|
body,
|
||||||
conversationId: this.id,
|
conversationId: this.id,
|
||||||
|
@ -627,7 +627,7 @@
|
||||||
received_at: now,
|
received_at: now,
|
||||||
expireTimer: this.get('expireTimer'),
|
expireTimer: this.get('expireTimer'),
|
||||||
recipients: this.getRecipients(),
|
recipients: this.getRecipients(),
|
||||||
}, migrationContext);
|
});
|
||||||
const message = this.messageCollection.add(messageWithSchema);
|
const message = this.messageCollection.add(messageWithSchema);
|
||||||
if (this.isPrivate()) {
|
if (this.isPrivate()) {
|
||||||
message.set({ destination: this.id });
|
message.set({ destination: this.id });
|
||||||
|
@ -657,9 +657,8 @@
|
||||||
profileKey = storage.get('profileKey');
|
profileKey = storage.get('profileKey');
|
||||||
}
|
}
|
||||||
|
|
||||||
const loadData = Attachment.loadData(migrationContext.readAttachmentData);
|
|
||||||
const attachmentsWithData =
|
const attachmentsWithData =
|
||||||
await Promise.all(messageWithSchema.attachments.map(loadData));
|
await Promise.all(messageWithSchema.attachments.map(loadAttachmentData));
|
||||||
message.send(sendFunction(
|
message.send(sendFunction(
|
||||||
this.get('id'),
|
this.get('id'),
|
||||||
body,
|
body,
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
window.Whisper = window.Whisper || {};
|
window.Whisper = window.Whisper || {};
|
||||||
|
|
||||||
const { Attachment, Message: TypedMessage } = window.Signal.Types;
|
const { Attachment, Message: TypedMessage } = window.Signal.Types;
|
||||||
const { context: migrationContext } = window.Signal.Migrations;
|
const { deleteAttachmentData } = window.Signal.Migrations;
|
||||||
|
|
||||||
var Message = window.Whisper.Message = Backbone.Model.extend({
|
var Message = window.Whisper.Message = Backbone.Model.extend({
|
||||||
database : Whisper.Database,
|
database : Whisper.Database,
|
||||||
|
@ -147,9 +147,7 @@
|
||||||
async onDestroy() {
|
async onDestroy() {
|
||||||
this.revokeImageUrl();
|
this.revokeImageUrl();
|
||||||
const attachments = this.get('attachments');
|
const attachments = this.get('attachments');
|
||||||
const deleteData =
|
await Promise.all(attachments.map(deleteAttachmentData));
|
||||||
Attachment.deleteData(migrationContext.deleteAttachmentData);
|
|
||||||
await Promise.all(attachments.map(deleteData));
|
|
||||||
},
|
},
|
||||||
/* jshint ignore:end */
|
/* jshint ignore:end */
|
||||||
/* eslint-disable */
|
/* eslint-disable */
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
window.Whisper = window.Whisper || {};
|
window.Whisper = window.Whisper || {};
|
||||||
|
|
||||||
const { Attachment } = window.Signal.Types;
|
const { Attachment } = window.Signal.Types;
|
||||||
const { context: migrationContext } = window.Signal.Migrations;
|
const { loadAttachmentData } = window.Signal.Migrations;
|
||||||
|
|
||||||
var URL_REGEX = /(^|[\s\n]|<br\/?>)((?:https?|ftp):\/\/[\-A-Z0-9\u00A0-\uD7FF\uE000-\uFDCF\uFDF0-\uFFFD+\u0026\u2019@#\/%?=()~_|!:,.;]*[\-A-Z0-9+\u0026@#\/%=~()_|])/gi;
|
var URL_REGEX = /(^|[\s\n]|<br\/?>)((?:https?|ftp):\/\/[\-A-Z0-9\u00A0-\uD7FF\uE000-\uFDCF\uFDF0-\uFFFD+\u0026\u2019@#\/%?=()~_|!:,.;]*[\-A-Z0-9+\u0026@#\/%=~()_|])/gi;
|
||||||
|
|
||||||
|
@ -416,11 +416,10 @@
|
||||||
return this.loadedAttachmentViews;
|
return this.loadedAttachmentViews;
|
||||||
}
|
}
|
||||||
|
|
||||||
const loadData = Attachment.loadData(migrationContext.readAttachmentData);
|
|
||||||
const attachments = this.model.get('attachments') || [];
|
const attachments = this.model.get('attachments') || [];
|
||||||
const loadedAttachmentViews = Promise.all(attachments.map(attachment =>
|
const loadedAttachmentViews = Promise.all(attachments.map(attachment =>
|
||||||
new Promise(async (resolve) => {
|
new Promise(async (resolve) => {
|
||||||
const attachmentWithData = await loadData(attachment);
|
const attachmentWithData = await loadAttachmentData(attachment);
|
||||||
const view = new Whisper.AttachmentView({
|
const view = new Whisper.AttachmentView({
|
||||||
model: attachmentWithData,
|
model: attachmentWithData,
|
||||||
timestamp: this.model.get('sent_at'),
|
timestamp: this.model.get('sent_at'),
|
||||||
|
|
26
preload.js
26
preload.js
|
@ -4,7 +4,9 @@
|
||||||
console.log('preload');
|
console.log('preload');
|
||||||
const electron = require('electron');
|
const electron = require('electron');
|
||||||
|
|
||||||
|
const Attachment = require('./js/modules/types/attachment');
|
||||||
const Attachments = require('./app/attachments');
|
const Attachments = require('./app/attachments');
|
||||||
|
const Message = require('./js/modules/types/message');
|
||||||
|
|
||||||
const { app } = electron.remote;
|
const { app } = electron.remote;
|
||||||
|
|
||||||
|
@ -113,25 +115,27 @@
|
||||||
const readAttachmentData = Attachments.readData(attachmentsPath);
|
const readAttachmentData = Attachments.readData(attachmentsPath);
|
||||||
const writeAttachmentData = Attachments.writeData(attachmentsPath);
|
const writeAttachmentData = Attachments.writeData(attachmentsPath);
|
||||||
|
|
||||||
|
// Injected context functions to keep `Message` agnostic from Electron:
|
||||||
|
const upgradeSchemaContext = {
|
||||||
|
writeAttachmentData,
|
||||||
|
};
|
||||||
|
const upgradeMessageSchema = message =>
|
||||||
|
Message.upgradeSchema(message, upgradeSchemaContext);
|
||||||
|
|
||||||
window.Signal = window.Signal || {};
|
window.Signal = window.Signal || {};
|
||||||
window.Signal.Logs = require('./js/modules/logs');
|
window.Signal.Logs = require('./js/modules/logs');
|
||||||
window.Signal.OS = require('./js/modules/os');
|
window.Signal.OS = require('./js/modules/os');
|
||||||
window.Signal.Backup = require('./js/modules/backup');
|
window.Signal.Backup = require('./js/modules/backup');
|
||||||
window.Signal.Crypto = require('./js/modules/crypto');
|
window.Signal.Crypto = require('./js/modules/crypto');
|
||||||
|
window.Signal.Migrations = {};
|
||||||
window.Signal.Migrations = window.Signal.Migrations || {};
|
window.Signal.Migrations.loadAttachmentData = Attachment.loadData(readAttachmentData);
|
||||||
// Injected context functions to keep `Message` agnostic from Electron:
|
window.Signal.Migrations.deleteAttachmentData = Attachment.deleteData(deleteAttachmentData);
|
||||||
window.Signal.Migrations.context = {
|
window.Signal.Migrations.upgradeMessageSchema = upgradeMessageSchema;
|
||||||
deleteAttachmentData,
|
|
||||||
readAttachmentData,
|
|
||||||
writeAttachmentData,
|
|
||||||
};
|
|
||||||
window.Signal.Migrations.V17 = require('./js/modules/migrations/17');
|
window.Signal.Migrations.V17 = require('./js/modules/migrations/17');
|
||||||
|
|
||||||
window.Signal.Types = window.Signal.Types || {};
|
window.Signal.Types = window.Signal.Types || {};
|
||||||
window.Signal.Types.Attachment = require('./js/modules/types/attachment');
|
window.Signal.Types.Attachment = Attachment;
|
||||||
window.Signal.Types.Errors = require('./js/modules/types/errors');
|
window.Signal.Types.Errors = require('./js/modules/types/errors');
|
||||||
window.Signal.Types.Message = require('./js/modules/types/message');
|
window.Signal.Types.Message = Message;
|
||||||
window.Signal.Types.MIME = require('./js/modules/types/mime');
|
window.Signal.Types.MIME = require('./js/modules/types/mime');
|
||||||
window.Signal.Types.Settings = require('./js/modules/types/settings');
|
window.Signal.Types.Settings = require('./js/modules/types/settings');
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue