diff --git a/ios/XMTPModule.swift b/ios/XMTPModule.swift index 06feda5d4..965c31817 100644 --- a/ios/XMTPModule.swift +++ b/ios/XMTPModule.swift @@ -47,16 +47,32 @@ public class XMTPModule: Module { actor ClientsManager { private var clients: [String: XMTP.Client] = [:] - // A method to update the conversations + // A method to update the client func updateClient(key: String, client: XMTP.Client) { ContentJson.initCodecs(client: client) clients[key] = client } - // A method to retrieve a conversation + // A method to retrieve a client func getClient(key: String) -> XMTP.Client? { return clients[key] } + + // A method to disconnect all dbs + func dropAllLocalDatabaseConnections() throws { + for (_, client) in clients { + // Call the method on each client + try client.dropLocalDatabaseConnection() + } + } + + // A method to disconnect all dbs + func reconnectAllLocalDatabaseConnections() async throws { + for (_, client) in clients { + // Call the method on each client + try await client.reconnectLocalDatabase() + } + } } enum Error: Swift.Error { @@ -1459,6 +1475,18 @@ public class XMTPModule: Module { } return await client.contacts.isGroupDenied(groupId: groupId) } + + OnAppBecomesActive { + Task { + try await clientsManager.reconnectAllLocalDatabaseConnections() + } + } + + OnAppEntersBackground { + Task { + try await clientsManager.dropAllLocalDatabaseConnections() + } + } } //