■ ■ ■ ■ ■ ■
feature-calls/src/main/kotlin/io/getstream/whatsappclone/calls/WhatsAppCallsViewModel.kt
| skipped 18 lines |
19 | 19 | | import androidx.lifecycle.ViewModel |
20 | 20 | | import androidx.lifecycle.viewModelScope |
21 | 21 | | import dagger.hilt.android.lifecycle.HiltViewModel |
| 22 | + | import io.getstream.whatsappclone.data.model.WhatsAppUserUiState |
22 | 23 | | import io.getstream.whatsappclone.data.repository.CallHistoryRepository |
23 | | - | import io.getstream.whatsappclone.model.WhatsAppUser |
| 24 | + | import io.getstream.whatsappclone.model.WhatsAppUserExtensive |
24 | 25 | | import kotlinx.coroutines.flow.SharingStarted |
25 | 26 | | import kotlinx.coroutines.flow.StateFlow |
26 | 27 | | import kotlinx.coroutines.flow.flatMapLatest |
| skipped 6 lines |
33 | 34 | | callHistoryRepository: CallHistoryRepository |
34 | 35 | | ) : ViewModel() { |
35 | 36 | | |
36 | | - | val whatsAppUserState: StateFlow<WhatsAppUiState> = |
| 37 | + | val whatsAppUserState: StateFlow<WhatsAppUserUiState> = |
37 | 38 | | callHistoryRepository.getCallHistoryUsersStream() |
38 | 39 | | .flatMapLatest { |
39 | 40 | | if (it.isSuccess) { |
40 | | - | flowOf(WhatsAppUiState.Success(it.getOrThrow())) |
| 41 | + | flowOf( |
| 42 | + | WhatsAppUserUiState.Success( |
| 43 | + | WhatsAppUserExtensive(it.getOrThrow()) |
| 44 | + | ) |
| 45 | + | ) |
41 | 46 | | } else { |
42 | | - | flowOf(WhatsAppUiState.Error) |
| 47 | + | flowOf(WhatsAppUserUiState.Error) |
43 | 48 | | } |
44 | 49 | | } |
45 | 50 | | .stateIn( |
46 | 51 | | scope = viewModelScope, |
47 | 52 | | started = SharingStarted.WhileSubscribed(5_000), |
48 | | - | initialValue = WhatsAppUiState.Loading |
| 53 | + | initialValue = WhatsAppUserUiState.Loading |
49 | 54 | | ) |
50 | 55 | | } |
51 | 56 | | |
52 | | - | sealed interface WhatsAppUiState { |
53 | | - | data class Success(val whatsAppUsers: List<WhatsAppUser>) : WhatsAppUiState |
54 | | - | object Error : WhatsAppUiState |
55 | | - | object Loading : WhatsAppUiState |
56 | | - | } |
57 | | - | |