Skip to content

Commit 9b1b41d

Browse files
authored
Avoid fetching FCM token during logout in demo-app (#1797)
* Don't fetch fcm token during logout * 1. Replace first with firstOrNull to avoid exception 2. Bring back `streamVideo.logOut()` which clears device token storage from local * 1. Add try-catch to catch io exception 2. Update kdoc
1 parent 93baaa7 commit 9b1b41d

3 files changed

Lines changed: 13 additions & 43 deletions

File tree

demo-app/src/main/kotlin/io/getstream/video/android/ui/join/CallJoinViewModel.kt

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,18 @@ import androidx.lifecycle.ViewModel
2020
import androidx.lifecycle.viewModelScope
2121
import com.google.android.gms.auth.api.signin.GoogleSignInClient
2222
import dagger.hilt.android.lifecycle.HiltViewModel
23-
import io.getstream.android.push.PushProvider
2423
import io.getstream.chat.android.client.ChatClient
2524
import io.getstream.video.android.core.Call
2625
import io.getstream.video.android.core.StreamVideo
2726
import io.getstream.video.android.data.datasource.local.InMemoryStore
2827
import io.getstream.video.android.datastore.delegate.StreamUserDataStore
29-
import io.getstream.video.android.model.Device
3028
import io.getstream.video.android.model.User
3129
import io.getstream.video.android.model.mapper.isValidCallCid
3230
import io.getstream.video.android.model.mapper.toTypeAndId
3331
import io.getstream.video.android.tooling.util.StreamBuildFlavorUtil
3432
import io.getstream.video.android.util.InitializedState
3533
import io.getstream.video.android.util.NetworkMonitor
3634
import io.getstream.video.android.util.StreamVideoInitHelper
37-
import io.getstream.video.android.util.fcmToken
3835
import kotlinx.coroutines.flow.Flow
3936
import kotlinx.coroutines.flow.MutableSharedFlow
4037
import kotlinx.coroutines.flow.MutableStateFlow
@@ -43,10 +40,12 @@ import kotlinx.coroutines.flow.SharingStarted
4340
import kotlinx.coroutines.flow.collectLatest
4441
import kotlinx.coroutines.flow.filterNotNull
4542
import kotlinx.coroutines.flow.first
43+
import kotlinx.coroutines.flow.firstOrNull
4644
import kotlinx.coroutines.flow.flatMapLatest
4745
import kotlinx.coroutines.flow.flowOf
4846
import kotlinx.coroutines.flow.shareIn
4947
import kotlinx.coroutines.launch
48+
import java.io.IOException
5049
import java.util.UUID
5150
import javax.inject.Inject
5251

@@ -144,15 +143,12 @@ class CallJoinViewModel @Inject constructor(
144143
googleSignInClient.signOut()
145144

146145
StreamVideo.instanceOrNull()?.let { streamVideo ->
147-
fcmToken?.let { fcmToken ->
148-
streamVideo.deleteDevice(
149-
Device(
150-
id = fcmToken,
151-
pushProvider = PushProvider.FIREBASE.key,
152-
pushProviderName = "firebase",
153-
),
154-
)
146+
val device = try {
147+
streamVideo.getDevice().firstOrNull()
148+
} catch (_: IOException) {
149+
null
155150
}
151+
device?.let { streamVideo.deleteDevice(it) }
156152
streamVideo.logOut()
157153
}
158154

demo-app/src/main/kotlin/io/getstream/video/android/util/PushNotifications.kt

Lines changed: 0 additions & 32 deletions
This file was deleted.

stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/StreamVideo.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import kotlinx.coroutines.Deferred
3535
import kotlinx.coroutines.flow.Flow
3636
import kotlinx.coroutines.flow.MutableStateFlow
3737
import kotlinx.coroutines.flow.StateFlow
38+
import java.io.IOException
3839

3940
/**
4041
* The main interface to control the Video calls. [StreamVideoClient] implements this interface.
@@ -112,7 +113,12 @@ public interface StreamVideo : NotificationHandler {
112113
/**
113114
* Get a cached device used to receive push notifications.
114115
*
116+
* Collecting the returned [Flow] accesses persistent storage and may throw an [IOException]
117+
* if the stored device cannot be read. Consumers that treat device retrieval as a best-effort
118+
* operation should handle [IOException] explicitly without swallowing coroutine cancellation.
119+
*
115120
* @return stream of Device.
121+
* @throws IOException when the returned flow is collected and persistent storage cannot be read.
116122
*/
117123
public fun getDevice(): Flow<Device?>
118124

0 commit comments

Comments
 (0)