File tree Expand file tree Collapse file tree
flipchatApp/src/main/kotlin/xyz/flipchat/app/features/profile Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -10,8 +10,10 @@ import com.getcode.util.resources.ResourceHelper
1010import com.getcode.view.BaseViewModel2
1111import dagger.hilt.android.lifecycle.HiltViewModel
1212import kotlinx.coroutines.flow.distinctUntilChanged
13+ import kotlinx.coroutines.flow.filter
1314import kotlinx.coroutines.flow.filterIsInstance
1415import kotlinx.coroutines.flow.filterNot
16+ import kotlinx.coroutines.flow.flatMapLatest
1517import kotlinx.coroutines.flow.launchIn
1618import kotlinx.coroutines.flow.map
1719import 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 }
You can’t perform that action at this time.
0 commit comments