From af40ceda6c80f55ecdec1badd99dd69ffafeb55c Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Thu, 14 Feb 2019 09:36:24 -0800 Subject: [PATCH] Note to Self timer fixes for bugs reported by beta users --- js/models/conversations.js | 18 ++++++++++++++++-- js/models/messages.js | 11 +++++++++-- libtextsecure/sendmessage.js | 12 +++++++++--- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/js/models/conversations.js b/js/models/conversations.js index 048f304e2..396161bc1 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -1257,10 +1257,24 @@ const sendOptions = this.getSendOptions(); let promise; + if (this.isMe()) { + const dataMessage = await textsecure.messaging.getMessageProto( + this.get('id'), + null, + [], + null, + [], + message.get('sent_at'), + expireTimer, + profileKey + ); + return message.sendSyncMessageOnly(dataMessage); + } + if (this.get('type') === 'private') { promise = textsecure.messaging.sendExpirationTimerUpdateToNumber( this.get('id'), - this.get('expireTimer'), + expireTimer, message.get('sent_at'), profileKey, sendOptions @@ -1269,7 +1283,7 @@ promise = textsecure.messaging.sendExpirationTimerUpdateToGroup( this.get('id'), this.getRecipients(), - this.get('expireTimer'), + expireTimer, message.get('sent_at'), profileKey, sendOptions diff --git a/js/models/messages.js b/js/models/messages.js index b674aa8e7..8d3188ee5 100644 --- a/js/models/messages.js +++ b/js/models/messages.js @@ -632,7 +632,7 @@ // back to the conversation's current recipients const phoneNumbers = this.isIncoming() ? [this.get('source')] - : this.get('sent_to') || this.conversation.getRecipients(); + : this.get('sent_to') || this.getConversation().getRecipients(); // This will make the error message for outgoing key errors a bit nicer const allErrors = (this.get('errors') || []).map(error => { @@ -1062,8 +1062,15 @@ this.set({ dataMessage }); try { - await this.sendSyncMessage(); + const result = await this.sendSyncMessage(); this.set({ + // These are the same as a normal send + sent_to: [this.OUR_NUMBER], + sent: true, + expirationStartTimestamp: Date.now(), + unidentifiedDeliveries: result ? result.unidentifiedDeliveries : null, + + // These are unique to a Note to Self message - immediately read/delivered delivered_to: [this.OUR_NUMBER], read_by: [this.OUR_NUMBER], }); diff --git a/libtextsecure/sendmessage.js b/libtextsecure/sendmessage.js index 5357d1d73..e92c480e8 100644 --- a/libtextsecure/sendmessage.js +++ b/libtextsecure/sendmessage.js @@ -846,7 +846,7 @@ MessageSender.prototype = { ) ); - const sendToContact = deleteAllSessions(number) + const sendToContactPromise = deleteAllSessions(number) .catch(logError('resetSession/deleteAllSessions1 error:')) .then(() => { window.log.info( @@ -866,8 +866,14 @@ MessageSender.prototype = { ) ); + const myNumber = textsecure.storage.user.getNumber(); + // We already sent the reset session to our other devices in the code above! + if (number === myNumber) { + return sendToContactPromise; + } + const buffer = proto.toArrayBuffer(); - const sendSync = this.sendSyncMessage( + const sendSyncPromise = this.sendSyncMessage( buffer, timestamp, number, @@ -877,7 +883,7 @@ MessageSender.prototype = { options ).catch(logError('resetSession/sendSync error:')); - return Promise.all([sendToContact, sendSync]); + return Promise.all([sendToContactPromise, sendSyncPromise]); }, sendMessageToGroup(