From 1bd15481729221810b66b6754c39e7ee45a71080 Mon Sep 17 00:00:00 2001 From: Mikunj Date: Tue, 30 Jun 2020 15:55:49 +1000 Subject: [PATCH] Add sendSyncMessageOnly --- js/models/conversations.js | 6 ++++-- js/models/messages.js | 44 ++++++++++++++++++++++++++++++++++---- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/js/models/conversations.js b/js/models/conversations.js index 53d760458..8db43448f 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -1648,8 +1648,10 @@ }; if (this.isMe()) { - await message.markMessageSyncOnly(); - // sending of the message is handled in the 'private' case below + const expirationTimerMessage = new libsession.Messages.Outgoing.ExpirationTimerUpdateMessage( + expireUpdate + ); + return message.sendSyncMessageOnly(expirationTimerMessage); } if (this.get('type') === 'private') { diff --git a/js/models/messages.js b/js/models/messages.js index 0b800ba4d..1c88034d2 100644 --- a/js/models/messages.js +++ b/js/models/messages.js @@ -1079,8 +1079,7 @@ if (recipients.length === 1 && recipients[0] === this.OUR_NUMBER) { this.trigger('pending'); // FIXME audric add back profileKey - await this.markMessageSyncOnly(); - // sending is done in the private case below + return this.sendSyncMessageOnly(chatMessage); } if (conversation.isPrivate()) { @@ -1155,9 +1154,9 @@ // Special-case the self-send case - we send only a sync message if (number === this.OUR_NUMBER) { - await this.markMessageSyncOnly(); - // sending is done in the private case below + return this.sendSyncMessageOnly(chatMessage); } + const conversation = this.getConversation(); const recipientPubKey = new libsession.Types.PubKey(number); @@ -1316,6 +1315,43 @@ Message: Whisper.Message, }); }, + + async sendSyncMessageOnly(dataMessage) { + this.set({ + sent_to: [this.OUR_NUMBER], + sent: true, + expirationStartTimestamp: Date.now(), + }); + + await window.Signal.Data.saveMessage(this.attributes, { + Message: Whisper.Message, + }); + + const data = + dataMessage instanceof libsession.Message.Outgoing.DataMessage + ? dataMessage.dataProto() + : dataMessage; + await this.sendSyncMessage(data); + }, + + async sendSyncMessage(dataMessage) { + // TODO: Return here if we've already sent a sync message + if (this.get('synced')) { + return; + } + + const syncMessage = new libsession.Message.Outgoing.SentSyncMessage({ + timestamp: this.get('sent_at'), + dataMessage, + destination: this.id, + expirationStartTimestamp: this.get('expirationStartTimestamp'), + sent_to: this.get('sent_to'), + unidentifiedDeliveries: this.get('unidentifiedDeliveries'), + }); + + await libsession.getMessageQueue().sendSyncMessage(syncMessage); + }, + send(promise) { this.trigger('pending'); return promise