From b87b437c76251a51858dc516cb094392b1e0ba33 Mon Sep 17 00:00:00 2001 From: Thilo Molitor Date: Mon, 12 Aug 2024 17:06:03 +0200 Subject: [PATCH] Use workaround for ios bug not properly removing share intentions When removing or disabling a contact, all share intentions for all contacts on this account should be properly removed to nos provide dangling share extension in ios' ui. --- Monal/Classes/HelperTools.h | 1 + Monal/Classes/HelperTools.m | 8 ++++++++ Monal/Classes/MLXMPPManager.m | 5 +---- Monal/Classes/XMPPEdit.m | 10 ++-------- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Monal/Classes/HelperTools.h b/Monal/Classes/HelperTools.h index 26907830c..f715771d4 100644 --- a/Monal/Classes/HelperTools.h +++ b/Monal/Classes/HelperTools.h @@ -130,6 +130,7 @@ void swizzle(Class c, SEL orig, SEL new); +(void) configureFileProtection:(NSString*) protectionLevel forFile:(NSString*) file; +(void) configureFileProtectionFor:(NSString*) file; +(BOOL) isContactBlacklistedForEncryption:(MLContact*) contact; ++(void) removeAllShareInteractionsForAccountNo:(NSNumber*) accountNo; +(NSDictionary*) splitJid:(NSString*) jid; +(void) scheduleBackgroundTask:(BOOL) force; diff --git a/Monal/Classes/HelperTools.m b/Monal/Classes/HelperTools.m index 213fcb736..ef0944761 100644 --- a/Monal/Classes/HelperTools.m +++ b/Monal/Classes/HelperTools.m @@ -1534,6 +1534,14 @@ +(BOOL) isContactBlacklistedForEncryption:(MLContact*) contact return blacklisted; } ++(void) removeAllShareInteractionsForAccountNo:(NSNumber*) accountNo +{ + DDLogInfo(@"Removing share interaction for all contacts on account id %@", accountNo); + for(MLContact* contact in [[DataLayer sharedInstance] contactList]) + if(contact.accountId.intValue == accountNo.intValue) + [contact removeShareInteractions]; +} + +(void) scheduleBackgroundTask:(BOOL) force { DDLogInfo(@"Scheduling new BackgroundTask with force=%s...", force ? "yes" : "no"); diff --git a/Monal/Classes/MLXMPPManager.m b/Monal/Classes/MLXMPPManager.m index 148c549cc..747d189fb 100644 --- a/Monal/Classes/MLXMPPManager.m +++ b/Monal/Classes/MLXMPPManager.m @@ -768,10 +768,7 @@ -(void) removeAccountForAccountNo:(NSNumber*) accountNo [self disconnectAccount:accountNo withExplicitLogout:YES]; [[DataLayer sharedInstance] removeAccount:accountNo]; [SAMKeychain deletePasswordForService:kMonalKeychainName account:accountNo.stringValue]; - [INInteraction deleteAllInteractionsWithCompletion:^(NSError* error) { - if(error != nil) - DDLogError(@"Could not delete all SiriKit interactions: %@", error); - }]; + [HelperTools removeAllShareInteractionsForAccountNo:accountNo]; // trigger UI removal [[MLNotificationQueue currentQueue] postNotificationName:kMonalRefresh object:nil userInfo:nil]; } diff --git a/Monal/Classes/XMPPEdit.m b/Monal/Classes/XMPPEdit.m index 21bd556fb..fa15e12f7 100644 --- a/Monal/Classes/XMPPEdit.m +++ b/Monal/Classes/XMPPEdit.m @@ -376,10 +376,7 @@ -(IBAction) save:(id) sender { DDLogVerbose(@"Making sure newly created account is not connected and deleting all SiriKit interactions: %@", self.accountNo); [[MLXMPPManager sharedInstance] disconnectAccount:self.accountNo withExplicitLogout:YES]; - [INInteraction deleteAllInteractionsWithCompletion:^(NSError* error) { - if(error != nil) - DDLogError(@"Could not delete all SiriKit interactions: %@", error); - }]; + [HelperTools removeAllShareInteractionsForAccountNo:self.accountNo]; } //trigger view updates to make sure enabled/disabled account state propagates to all ui elements [[MLNotificationQueue currentQueue] postNotificationName:kMonalRefresh object:nil userInfo:nil]; @@ -400,10 +397,7 @@ -(IBAction) save:(id) sender { DDLogVerbose(@"Account is not enabled anymore, deleting all SiriKit interactions and making sure it's disconnected: %@", self.accountNo); [[MLXMPPManager sharedInstance] disconnectAccount:self.accountNo withExplicitLogout:YES]; - [INInteraction deleteAllInteractionsWithCompletion:^(NSError* error) { - if(error != nil) - DDLogError(@"Could not delete all SiriKit interactions: %@", error); - }]; + [HelperTools removeAllShareInteractionsForAccountNo:self.accountNo]; } //this case makes sure we recreate a completely new account instance below (using our new settings) if the account details changed else if(self.detailsChanged)