-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: missing ServerConfig crashes after session expired / logout [WPB…
…-5960] (#2352) (#2354) * fix: missing ServerConfig crashes after session expired / logout [WPB-5960] * simplify LogoutCallback * make LogoutCallback suspend * changes after review * make LogoutCallback to become interface to fix tests Co-authored-by: Michał Saleniuk <[email protected]> Co-authored-by: Oussama Hassine <[email protected]>
- Loading branch information
1 parent
52f2033
commit 46924bb
Showing
18 changed files
with
133 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/auth/LogoutCallbackManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2024 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
*/ | ||
package com.wire.kalium.logic.feature.auth | ||
|
||
import co.touchlab.stately.collections.ConcurrentMutableList | ||
import com.wire.kalium.logic.data.logout.LogoutReason | ||
import com.wire.kalium.logic.data.user.UserId | ||
|
||
/** | ||
* This manager is used to register callbacks that will be called when a user session is being logged out. | ||
* The app may have some actions to perform outside the kalium as well when a user is logged out, like clearing the data store, etc. | ||
* When logout action is triggered by the user, then the app can execute these actions right after the [LogoutUseCase] result, | ||
* but when the logout is triggered automatically by some event (i.e. session expired, device removed, account removed), | ||
* then the app will not be able to execute these actions without registering to this manager. | ||
*/ | ||
interface LogoutCallbackManager { | ||
fun register(callback: LogoutCallback) | ||
fun unregister(callback: LogoutCallback) | ||
} | ||
|
||
internal class LogoutCallbackManagerImpl : LogoutCallbackManager, LogoutCallback { | ||
private val callbacks = ConcurrentMutableList<LogoutCallback>() | ||
override fun register(callback: LogoutCallback) { callbacks.add(callback) } | ||
override fun unregister(callback: LogoutCallback) { callbacks.remove(callback) } | ||
override suspend fun invoke(userId: UserId, reason: LogoutReason) { callbacks.forEach { it(userId, reason) } } | ||
} | ||
|
||
interface LogoutCallback { | ||
suspend operator fun invoke(userId: UserId, reason: LogoutReason) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.