diff --git a/CHANGELOG.md b/CHANGELOG.md index b48c4993d10..960d36d01f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ ### 🐞 Fixed - Fix `ChatClient::queryBlockedMembers` not working. [#5532](https://github.com/GetStream/stream-chat-android/pull/5532) - Fix `ChatClient::blockUser` and `ChatClient::unblockUser` response parsing. [#5532](https://github.com/GetStream/stream-chat-android/pull/5532) +- Fix rare bug where the `ConnectivityState` is not updated to `Offline` after disconnecting the device from network. [#5538](https://github.com/GetStream/stream-chat-android/pull/5538) ### ⬆️ Improved diff --git a/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/network/NetworkStateProvider.kt b/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/network/NetworkStateProvider.kt index a5d56bb5f8a..ce5873ce789 100644 --- a/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/network/NetworkStateProvider.kt +++ b/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/network/NetworkStateProvider.kt @@ -30,11 +30,14 @@ internal class NetworkStateProvider( private val scope: CoroutineScope, private val connectivityManager: ConnectivityManager, ) { - private val logger by taggedLogger("Chat:NetworkStateProvider") private val lock: Any = Any() + + private val availableNetworks: MutableSet = mutableSetOf() + private val callback = object : ConnectivityManager.NetworkCallback() { override fun onAvailable(network: Network) { + availableNetworks.add(network) notifyListenersIfNetworkStateChanged() } @@ -43,7 +46,12 @@ internal class NetworkStateProvider( } override fun onLost(network: Network) { + availableNetworks.remove(network) notifyListenersIfNetworkStateChanged() + if (availableNetworks.isEmpty()) { + // No available networks, notify listeners about disconnection + listeners.onDisconnected() + } } }