tiny changes on the unsend logic

pull/1969/head
Audric Ackermann 4 years ago
parent 13d828c02c
commit 844d3befef
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -607,14 +607,14 @@ export async function deleteMessagesById(
await doDeleteMessagesById(selectedMessages, conversation, true); await doDeleteMessagesById(selectedMessages, conversation, true);
// explicity close modal for this case. // explicity close modal for this case.
window.inboxStore?.dispatch(updateConfirmModal(null)); window.inboxStore?.dispatch(updateConfirmModal(null));
} else { return;
}
if (window.lokiFeatureFlags?.useUnsendRequests) { if (window.lokiFeatureFlags?.useUnsendRequests) {
showDeletionTypeModal(); showDeletionTypeModal();
} else { } else {
await doDeleteMessagesById(selectedMessages, conversation, false); await doDeleteMessagesById(selectedMessages, conversation, false);
window.inboxStore?.dispatch(updateConfirmModal(null)); window.inboxStore?.dispatch(updateConfirmModal(null));
} }
}
}, },
closeAfterInput: false, closeAfterInput: false,
}) })

@ -845,10 +845,10 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
return true; return true;
} }
public async unsendMessages(messages: Array<MessageModel>, onlyDeleteForSender: boolean = false) { public async unsendMessages(messages: Array<MessageModel>) {
const results = await Promise.all( const results = await Promise.all(
messages.map(async message => { messages.map(async message => {
return this.unsendMessage(message, onlyDeleteForSender); return this.unsendMessage(message, false);
}) })
); );
return _.every(results); return _.every(results);
@ -863,9 +863,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
onlyDeleteForSender: boolean = false onlyDeleteForSender: boolean = false
): Promise<boolean> { ): Promise<boolean> {
if (!message.get('messageHash')) { if (!message.get('messageHash')) {
window?.log?.error( window?.log?.error(`message ${message.id}, cannot find hash: ${message.get('messageHash')}`);
`message with id ${message.get('id')} cannot find hash: ${message.get('messageHash')}`
);
return false; return false;
} }
const ownPrimaryDevicePubkey = UserUtils.getOurPubKeyFromCache(); const ownPrimaryDevicePubkey = UserUtils.getOurPubKeyFromCache();
@ -880,6 +878,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
//#region building request //#region building request
const author = message.get('source'); 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; const timestamp = message.getPropsForMessage().timestamp;
if (!timestamp) { if (!timestamp) {
window?.log?.error('cannot find timestamp - aborting unsend request'); window?.log?.error('cannot find timestamp - aborting unsend request');
@ -898,7 +897,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
// 1-1 Session // 1-1 Session
if (!this.isGroup()) { if (!this.isGroup()) {
// sending to recipient // sending to recipient
getMessageQueue() await getMessageQueue()
.sendToPubKey(new PubKey(destinationId), unsendMessage) .sendToPubKey(new PubKey(destinationId), unsendMessage)
.catch(window?.log?.error); .catch(window?.log?.error);
return this.deleteMessage(message); return this.deleteMessage(message);
@ -906,7 +905,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
// closed groups // closed groups
if (this.isClosedGroup() && this.id) { if (this.isClosedGroup() && this.id) {
getMessageQueue() await getMessageQueue()
.sendToGroup(unsendMessage, undefined, PubKey.cast(this.id)) .sendToGroup(unsendMessage, undefined, PubKey.cast(this.id))
.catch(window?.log?.error); .catch(window?.log?.error);
// not calling deleteMessage as it'll be called by the unsend handler when it's received // not calling deleteMessage as it'll be called by the unsend handler when it's received

Loading…
Cancel
Save