Skip to content

Commit 1ca60db

Browse files
committed
fix(fc): re-handle connect/disconnects for own user profile
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent 88ec644 commit 1ca60db

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

flipchatApp/src/main/kotlin/xyz/flipchat/app/features/profile/ProfileViewModel.kt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ import com.getcode.util.resources.ResourceHelper
1010
import com.getcode.view.BaseViewModel2
1111
import dagger.hilt.android.lifecycle.HiltViewModel
1212
import kotlinx.coroutines.flow.distinctUntilChanged
13+
import kotlinx.coroutines.flow.filter
1314
import kotlinx.coroutines.flow.filterIsInstance
1415
import kotlinx.coroutines.flow.filterNot
16+
import kotlinx.coroutines.flow.flatMapLatest
1517
import kotlinx.coroutines.flow.launchIn
1618
import kotlinx.coroutines.flow.map
1719
import kotlinx.coroutines.flow.mapNotNull
@@ -85,11 +87,14 @@ class ProfileViewModel @Inject constructor(
8587
}
8688

8789
init {
88-
// userManager.state
89-
// .mapNotNull { UserProfile(it.displayName.orEmpty(), it.linkedSocialProfiles) }
90-
// .distinctUntilChanged()
91-
// .onEach { dispatchEvent(Event.OnUserLoaded(it)) }
92-
// .launchIn(viewModelScope)
90+
// handle self user updates (connects/disconnects)
91+
stateFlow
92+
.filter { it.isSelf }
93+
.flatMapLatest { userManager.state }
94+
.mapNotNull { UserProfile(it.displayName.orEmpty(), it.linkedSocialProfiles) }
95+
.distinctUntilChanged()
96+
.onEach { dispatchEvent(Event.OnUserLoaded(true, it)) }
97+
.launchIn(viewModelScope)
9398

9499
userManager.state
95100
.mapNotNull { it.flags }

0 commit comments

Comments
 (0)