Skip to content

Commit

Permalink
fix: empty conversation list on import media [WPB-10483] 🍒 (#3401)
Browse files Browse the repository at this point in the history
Co-authored-by: Jakub Żerko <[email protected]>
  • Loading branch information
github-actions[bot] and Garzas authored Aug 29, 2024
1 parent 0b6296e commit 42c16e9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ class ImportMediaAuthenticatedViewModel @Inject constructor(
val searchQueryTextState: TextFieldState = TextFieldState()
var importMediaState by mutableStateOf(ImportMediaAuthenticatedState())
private set
var avatarAsset by mutableStateOf<ImageAsset.UserAvatarAsset?>(null)
private set

private val _infoMessage = MutableSharedFlow<SnackBarMessage>()
val infoMessage = _infoMessage.asSharedFlow()
Expand All @@ -115,10 +117,9 @@ class ImportMediaAuthenticatedViewModel @Inject constructor(
private fun loadUserAvatar() = viewModelScope.launch(dispatchers.io()) {
getSelf().collect { selfUser ->
withContext(dispatchers.main()) {
importMediaState =
importMediaState.copy(avatarAsset = selfUser.previewPicture?.let {
ImageAsset.UserAvatarAsset(wireSessionImageLoader, it)
})
avatarAsset = selfUser.previewPicture?.let {
ImageAsset.UserAvatarAsset(wireSessionImageLoader, it)
}
}
}
}
Expand All @@ -145,8 +146,10 @@ class ImportMediaAuthenticatedViewModel @Inject constructor(
}
.flowOn(dispatchers.io())
.collect { updatedState ->
importMediaState =
importMediaState.copy(shareableConversationListState = updatedState)
withContext(dispatchers.main()) {
importMediaState =
importMediaState.copy(shareableConversationListState = updatedState)
}
}
}

Expand Down Expand Up @@ -380,7 +383,6 @@ class ImportMediaAuthenticatedViewModel @Inject constructor(

@Stable
data class ImportMediaAuthenticatedState(
val avatarAsset: ImageAsset.UserAvatarAsset? = null,
val importedAssets: PersistentList<ImportedMediaAsset> = persistentListOf(),
val importedText: String? = null,
val isImporting: Boolean = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import androidx.hilt.navigation.compose.hiltViewModel
import com.ramcosta.composedestinations.annotation.RootNavGraph
import com.wire.android.R
import com.wire.android.model.Clickable
import com.wire.android.model.ImageAsset
import com.wire.android.model.SnackBarMessage
import com.wire.android.model.UserAvatarData
import com.wire.android.navigation.BackStackMode
Expand Down Expand Up @@ -190,12 +191,14 @@ private fun ImportMediaAuthenticatedContent(
if (isRestrictedInTeam) {
ImportMediaRestrictedContent(
importMediaAuthenticatedState = importMediaViewModel.importMediaState,
avatarAsset = null,
navigateBack = navigator.finish
)
} else {
ImportMediaRegularContent(
importMediaAuthenticatedState = importMediaViewModel.importMediaState,
searchQueryTextState = importMediaViewModel.searchQueryTextState,
avatarAsset = importMediaViewModel.avatarAsset,
onConversationClicked = importMediaViewModel::onConversationClicked,
checkRestrictionsAndSendImportedMedia = {
with(importMediaViewModel.importMediaState) {
Expand Down Expand Up @@ -245,6 +248,7 @@ private fun ImportMediaAuthenticatedContent(
@Composable
fun ImportMediaRestrictedContent(
importMediaAuthenticatedState: ImportMediaAuthenticatedState,
avatarAsset: ImageAsset.UserAvatarAsset?,
navigateBack: () -> Unit,
modifier: Modifier = Modifier,
) {
Expand Down Expand Up @@ -279,6 +283,7 @@ fun ImportMediaRestrictedContent(
@Composable
fun ImportMediaRegularContent(
importMediaAuthenticatedState: ImportMediaAuthenticatedState,
avatarAsset: ImageAsset.UserAvatarAsset?,
searchQueryTextState: TextFieldState,
onConversationClicked: (conversationId: ConversationId) -> Unit,
checkRestrictionsAndSendImportedMedia: () -> Unit,
Expand Down Expand Up @@ -639,6 +644,7 @@ fun PreviewImportMediaScreenRestricted() {
WireTheme {
ImportMediaRestrictedContent(
importMediaAuthenticatedState = ImportMediaAuthenticatedState(),
avatarAsset = null,
navigateBack = {}
)
}
Expand Down Expand Up @@ -697,6 +703,7 @@ fun PreviewImportMediaScreenRegular() {
)
),
),
avatarAsset = null,
searchQueryTextState = rememberTextFieldState(),
onConversationClicked = {},
checkRestrictionsAndSendImportedMedia = {},
Expand All @@ -719,6 +726,7 @@ fun PreviewImportMediaTextScreenRegular() {
"This is a second line with a veeeeeeeeeeeeeeeeeeeeeeeeeeery long shared text message"
),
searchQueryTextState = rememberTextFieldState(),
avatarAsset = null,
onConversationClicked = {},
checkRestrictionsAndSendImportedMedia = {},
onNewSelfDeletionTimerPicked = {},
Expand Down

0 comments on commit 42c16e9

Please sign in to comment.