From 9fe42691ea783403195ea5cc054cc59fffc55eac Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 31 Mar 2023 15:59:23 +0200 Subject: [PATCH] Close MatrixClient after usage --- .../android/libraries/push/impl/PushersManager.kt | 7 +++---- .../android/libraries/push/impl/push/PushHandler.kt | 12 +++++++----- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/PushersManager.kt b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/PushersManager.kt index 8455624585..8407360385 100644 --- a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/PushersManager.kt +++ b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/PushersManager.kt @@ -77,10 +77,9 @@ class PushersManager @Inject constructor( sessionStore.getAllSessions().toUserList().forEach { userId -> val userDataStore = userPushStoreFactory.create(userId) if (userDataStore.isFirebase()) { - val client = matrixAuthenticationService.restoreSession(SessionId(userId)).getOrNull() - client ?: return@forEach - registerPusher(client, firebaseToken, PushConfig.pusher_http_url) - // TODO EAx Close sessions + matrixAuthenticationService.restoreSession(SessionId(userId)).getOrNull()?.use { client -> + registerPusher(client, firebaseToken, PushConfig.pusher_http_url) + } } else { Timber.d("This session is not using Firebase pusher") } diff --git a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/push/PushHandler.kt b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/push/PushHandler.kt index bab955b419..2f7a1947c5 100644 --- a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/push/PushHandler.kt +++ b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/push/PushHandler.kt @@ -141,11 +141,13 @@ class PushHandler @Inject constructor( // Restore session val session = matrixAuthenticationService.restoreSession(SessionId(userId)).getOrNull() ?: return // TODO EAx, no need for a session? - val notificationData = session.notificationService().getNotification( - userId = userId, - roomId = pushData.roomId, - eventId = pushData.eventId, - ) + val notificationData = session.use { + it.notificationService().getNotification( + userId = userId, + roomId = pushData.roomId, + eventId = pushData.eventId, + ) + } // TODO Remove Timber.w("Notification: $notificationData")