From 2b42290bca46efaea7cc207573e999cba38f581c Mon Sep 17 00:00:00 2001 From: warrickct Date: Wed, 23 Feb 2022 20:19:47 +1100 Subject: [PATCH] Fixing case where restoring device restores declined message requests. --- ts/models/conversation.ts | 32 ++++++++++++++++++++++++++++++++ ts/receiver/configMessage.ts | 5 +++++ 2 files changed, 37 insertions(+) diff --git a/ts/models/conversation.ts b/ts/models/conversation.ts index d395bb6bf..1f31e9964 100644 --- a/ts/models/conversation.ts +++ b/ts/models/conversation.ts @@ -716,6 +716,38 @@ export class ConversationModel extends Backbone.Model { } } + /** + * Does this conversation contain the properties to be considered a message request + */ + public isRequest(): boolean { + // return !this.isMe() && !this.isApproved() && this.isPrivate() && !this.isBlocked(); + return ConversationModel.hasValidRequestValues({ + isMe: this.isMe(), + isApproved: this.isApproved(), + isBlocked: this.isBlocked(), + isPrivate: this.isPrivate(), + }); + } + + /** + * Method to evalute if a convo contains the right values + * @param values Required properties to evaluate if this is a message request + * @returns + */ + public static hasValidRequestValues({ + isMe, + isApproved, + isBlocked, + isPrivate, + }: { + isMe?: boolean; + isApproved?: boolean; + isBlocked?: boolean; + isPrivate?: boolean; + }): boolean { + return Boolean(!isMe && !isApproved && isPrivate && !isBlocked); + } + public async sendMessageRequestResponse(isApproved: boolean) { if (!this.isPrivate()) { return; diff --git a/ts/receiver/configMessage.ts b/ts/receiver/configMessage.ts index ad6f53707..d968d15a6 100644 --- a/ts/receiver/configMessage.ts +++ b/ts/receiver/configMessage.ts @@ -16,6 +16,7 @@ import { removeFromCache } from './cache'; import { handleNewClosedGroup } from './closedGroups'; import { updateProfileOneAtATime } from './dataMessage'; import { EnvelopePlus } from './types'; +import { ConversationInteraction } from '../interactions'; async function handleOurProfileUpdate( sentAt: number | Long, @@ -176,6 +177,10 @@ const handleContactReceived = async ( // only set for explicit true/false values incase outdated sender doesn't have the fields if (contactReceived.isBlocked === true) { + if (contactConvo.isRequest()) { + // handling case where restored device's declined message requests were getting restored + ConversationInteraction.deleteAllMessagesByConvoIdNoConfirmation(contactConvo.id); + } await BlockedNumberController.block(contactConvo.id); } else if (contactReceived.isBlocked === false) { await BlockedNumberController.unblock(contactConvo.id);