From ca22b4635f9bda92bc0baaffa8b84838a1019d40 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Mon, 22 Feb 2021 12:00:08 +1100 Subject: [PATCH] fixup some building of sync message issues --- ts/components/session/ActionsPanel.tsx | 2 +- ts/models/message.ts | 2 +- ts/receiver/queuedJob.ts | 2 +- .../outgoing/content/data/ChatMessage.ts | 22 ++++++++++++++----- ts/session/sending/MessageQueue.ts | 6 ++++- 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/ts/components/session/ActionsPanel.tsx b/ts/components/session/ActionsPanel.tsx index b834aa846..1292fcc0d 100644 --- a/ts/components/session/ActionsPanel.tsx +++ b/ts/components/session/ActionsPanel.tsx @@ -66,7 +66,7 @@ class ActionsPanelPrivate extends React.Component { } // init the messageQueue. In the constructor, we had all not send messages // this call does nothing except calling the constructor, which will continue sending message in the pipeline - getMessageQueue(); + void getMessageQueue().processAllPending(); const theme = window.Events.getThemeSetting(); window.setTheme(theme); diff --git a/ts/models/message.ts b/ts/models/message.ts index 298f1cd4b..eac7138d6 100644 --- a/ts/models/message.ts +++ b/ts/models/message.ts @@ -1020,7 +1020,7 @@ export class MessageModel extends Backbone.Model { await this.commit(); } - public async sendSyncMessageOnly(dataMessage: any) { + public async sendSyncMessageOnly(dataMessage: DataMessage) { const now = Date.now(); this.set({ sent_to: [UserUtils.getOurPubKeyStrFromCache()], diff --git a/ts/receiver/queuedJob.ts b/ts/receiver/queuedJob.ts index 321300249..fc06d17eb 100644 --- a/ts/receiver/queuedJob.ts +++ b/ts/receiver/queuedJob.ts @@ -211,7 +211,7 @@ async function handleExpireTimer( await conversation.updateExpirationTimer( expireTimer, source, - message.get('received_at'), + message.get('sent_at') || message.get('received_at'), { fromGroupUpdate: message.isGroupUpdate(), // WHAT DOES GROUP UPDATE HAVE TO DO WITH THIS??? } diff --git a/ts/session/messages/outgoing/content/data/ChatMessage.ts b/ts/session/messages/outgoing/content/data/ChatMessage.ts index fcd5ad6f4..119aac9c8 100644 --- a/ts/session/messages/outgoing/content/data/ChatMessage.ts +++ b/ts/session/messages/outgoing/content/data/ChatMessage.ts @@ -127,15 +127,25 @@ export class ChatMessage extends DataMessage { const timestamp = toNumber(sentTimestamp); const body = dataMessage.body || undefined; + + const wrapToUInt8Array = (buffer: any) => { + if (!buffer) { + return undefined; + } + if (buffer instanceof Uint8Array) { + // Audio messages are already uint8Array + return buffer; + } + return new Uint8Array(buffer.toArrayBuffer()); + }; const attachments = (dataMessage.attachments || []).map(attachment => { + const key = wrapToUInt8Array(attachment.key); + const digest = wrapToUInt8Array(attachment.digest); + return { ...attachment, - key: attachment.key - ? new Uint8Array((attachment.key as any).toArrayBuffer()) - : undefined, - digest: attachment.digest - ? new Uint8Array((attachment.digest as any).toArrayBuffer()) - : undefined, + key, + digest, }; }) as Array; const quote = (dataMessage.quote as Quote) || undefined; diff --git a/ts/session/sending/MessageQueue.ts b/ts/session/sending/MessageQueue.ts index 0d4914083..b7655d7e4 100644 --- a/ts/session/sending/MessageQueue.ts +++ b/ts/session/sending/MessageQueue.ts @@ -169,7 +169,11 @@ export class MessageQueue { }); } - private async processAllPending() { + /** + * This method should be called when the app is started and the user loggedin to fetch + * existing message waiting to be sent in the cache of message + */ + public async processAllPending() { const devices = await this.pendingMessageCache.getDevices(); const promises = devices.map(async device => this.processPending(device));