From 844d3befef3ba36aa5afd7ceb830f2033e9a2ad8 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Fri, 15 Oct 2021 11:53:44 +1100 Subject: [PATCH] tiny changes on the unsend logic --- ts/interactions/conversationInteractions.ts | 12 ++++++------ ts/models/conversation.ts | 13 ++++++------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/ts/interactions/conversationInteractions.ts b/ts/interactions/conversationInteractions.ts index 0882d2c7f..3160ed6db 100644 --- a/ts/interactions/conversationInteractions.ts +++ b/ts/interactions/conversationInteractions.ts @@ -607,13 +607,13 @@ export async function deleteMessagesById( await doDeleteMessagesById(selectedMessages, conversation, true); // explicity close modal for this case. window.inboxStore?.dispatch(updateConfirmModal(null)); + return; + } + if (window.lokiFeatureFlags?.useUnsendRequests) { + showDeletionTypeModal(); } else { - if (window.lokiFeatureFlags?.useUnsendRequests) { - showDeletionTypeModal(); - } else { - await doDeleteMessagesById(selectedMessages, conversation, false); - window.inboxStore?.dispatch(updateConfirmModal(null)); - } + await doDeleteMessagesById(selectedMessages, conversation, false); + window.inboxStore?.dispatch(updateConfirmModal(null)); } }, closeAfterInput: false, diff --git a/ts/models/conversation.ts b/ts/models/conversation.ts index dd4a416cd..8eee66971 100644 --- a/ts/models/conversation.ts +++ b/ts/models/conversation.ts @@ -845,10 +845,10 @@ export class ConversationModel extends Backbone.Model { return true; } - public async unsendMessages(messages: Array, onlyDeleteForSender: boolean = false) { + public async unsendMessages(messages: Array) { const results = await Promise.all( messages.map(async message => { - return this.unsendMessage(message, onlyDeleteForSender); + return this.unsendMessage(message, false); }) ); return _.every(results); @@ -863,9 +863,7 @@ export class ConversationModel extends Backbone.Model { onlyDeleteForSender: boolean = false ): Promise { if (!message.get('messageHash')) { - window?.log?.error( - `message with id ${message.get('id')} cannot find hash: ${message.get('messageHash')}` - ); + window?.log?.error(`message ${message.id}, cannot find hash: ${message.get('messageHash')}`); return false; } const ownPrimaryDevicePubkey = UserUtils.getOurPubKeyFromCache(); @@ -880,6 +878,7 @@ export class ConversationModel extends Backbone.Model { //#region building request const author = message.get('source'); + // call getPropsForMessage here so we get the received_at or sent_at timestamp in timestamp const timestamp = message.getPropsForMessage().timestamp; if (!timestamp) { window?.log?.error('cannot find timestamp - aborting unsend request'); @@ -898,7 +897,7 @@ export class ConversationModel extends Backbone.Model { // 1-1 Session if (!this.isGroup()) { // sending to recipient - getMessageQueue() + await getMessageQueue() .sendToPubKey(new PubKey(destinationId), unsendMessage) .catch(window?.log?.error); return this.deleteMessage(message); @@ -906,7 +905,7 @@ export class ConversationModel extends Backbone.Model { // closed groups if (this.isClosedGroup() && this.id) { - getMessageQueue() + await getMessageQueue() .sendToGroup(unsendMessage, undefined, PubKey.cast(this.id)) .catch(window?.log?.error); // not calling deleteMessage as it'll be called by the unsend handler when it's received