From 5ab2f86b6636e6aa6d98337735582877d5f91094 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Espino=20Garc=C3=ADa?= Date: Wed, 5 Jul 2023 20:01:51 +0200 Subject: [PATCH] Fix ios cache (#7412) * Fix Keychain cache * Fix * Fix import --- .../java/com/mattermost/rnbeta/MattermostManagedModule.java | 5 +++++ app/managers/session_manager.ts | 2 ++ app/utils/mattermost_managed.ts | 4 ++++ ios/Gekidou/Sources/Gekidou/Keychain.swift | 4 ++++ ios/GekidouWrapper.swift | 4 ++++ ios/Mattermost/MattermostManaged.m | 4 ++++ 6 files changed, 23 insertions(+) diff --git a/android/app/src/main/java/com/mattermost/rnbeta/MattermostManagedModule.java b/android/app/src/main/java/com/mattermost/rnbeta/MattermostManagedModule.java index 765fc2fe8..368cfe2a8 100644 --- a/android/app/src/main/java/com/mattermost/rnbeta/MattermostManagedModule.java +++ b/android/app/src/main/java/com/mattermost/rnbeta/MattermostManagedModule.java @@ -221,6 +221,11 @@ public class MattermostManagedModule extends ReactContextBaseJavaModule { } } + @ReactMethod + public void invalidateKeychainCache(String serverUrl) { + // Not using cache + } + private static class SaveDataTask extends GuardedResultAsyncTask { private final WeakReference weakContext; private final String fromFile; diff --git a/app/managers/session_manager.ts b/app/managers/session_manager.ts index 0e21ca4a4..e039e5627 100644 --- a/app/managers/session_manager.ts +++ b/app/managers/session_manager.ts @@ -22,6 +22,7 @@ import {getThemeFromState} from '@screens/navigation'; import EphemeralStore from '@store/ephemeral_store'; import {deleteFileCache, deleteFileCacheByDir} from '@utils/file'; import {isMainActivity} from '@utils/helpers'; +import {invalidateKeychainCache} from '@utils/mattermost_managed'; import {addNewServer} from '@utils/server'; import type {LaunchType} from '@typings/launch'; @@ -115,6 +116,7 @@ class SessionManager { private terminateSession = async (serverUrl: string, removeServer: boolean) => { cancelSessionNotification(serverUrl); await removeServerCredentials(serverUrl); + invalidateKeychainCache(serverUrl); PushNotifications.removeServerNotifications(serverUrl); NetworkManager.invalidateClient(serverUrl); diff --git a/app/utils/mattermost_managed.ts b/app/utils/mattermost_managed.ts index 04f3af1e8..f85207a11 100644 --- a/app/utils/mattermost_managed.ts +++ b/app/utils/mattermost_managed.ts @@ -64,3 +64,7 @@ export const deleteEntititesFile = (callback?: (success: boolean) => void) => { callback(true); } }; + +export const invalidateKeychainCache = (serverUrl: string) => { + MattermostManaged.invalidateKeychainCache(serverUrl); +}; diff --git a/ios/Gekidou/Sources/Gekidou/Keychain.swift b/ios/Gekidou/Sources/Gekidou/Keychain.swift index a31f7aeb9..b1bbf0036 100644 --- a/ios/Gekidou/Sources/Gekidou/Keychain.swift +++ b/ios/Gekidou/Sources/Gekidou/Keychain.swift @@ -100,6 +100,10 @@ public class Keychain: NSObject { return nil } + + public func invalidateToken(for serverUrl: String) { + tokenCache.removeValue(forKey: serverUrl) + } private func buildIdentityQuery(for host: String) throws -> [CFString: Any] { guard let hostData = host.data(using: .utf8) else { diff --git a/ios/GekidouWrapper.swift b/ios/GekidouWrapper.swift index 8a82055a6..e1386515f 100644 --- a/ios/GekidouWrapper.swift +++ b/ios/GekidouWrapper.swift @@ -42,4 +42,8 @@ import Gekidou return nil } + + @objc func invalidateToken(for url: String) { + Keychain.default.invalidateToken(for: url) + } } diff --git a/ios/Mattermost/MattermostManaged.m b/ios/Mattermost/MattermostManaged.m index 89bb75381..2bea2d069 100644 --- a/ios/Mattermost/MattermostManaged.m +++ b/ios/Mattermost/MattermostManaged.m @@ -153,6 +153,10 @@ RCT_EXPORT_METHOD(removeListeners:(double)count) { // Keep: Required for RN built in Event Emitter Calls. } +RCT_EXPORT_METHOD(invalidateKeychainCache:(NSString *) serverUrl) +{ + [[GekidouWrapper default] invalidateTokenFor:serverUrl]; +} RCT_EXPORT_METHOD(createThumbnail:(NSDictionary *)config findEventsWithResolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {