Skip to content

Commit

Permalink
Merge branch 'develop' into fix/self-user-refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
sbakhtiarov authored Jan 16, 2025
2 parents f516e21 + f1eef77 commit b01b7d7
Show file tree
Hide file tree
Showing 15 changed files with 174 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -347,4 +347,9 @@ class ConversationModule {
@Provides
fun provideMoveConversationToFolderUseCase(conversationScope: ConversationScope) =
conversationScope.moveConversationToFolder

@ViewModelScoped
@Provides
fun provideRemoveConversationFromFolderUseCase(conversationScope: ConversationScope) =
conversationScope.removeConversationFromFolder
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ fun ConversationSheetContent(
onMutingConversationStatusChange: () -> Unit,
changeFavoriteState: (GroupDialogState, addToFavorite: Boolean) -> Unit,
moveConversationToFolder: ((ConversationFoldersNavArgs) -> Unit)?,
removeFromFolder: (conversationId: ConversationId, conversationName: String, folder: ConversationFolder) -> Unit,
updateConversationArchiveStatus: (DialogState) -> Unit,
clearConversationContent: (DialogState) -> Unit,
blockUser: (BlockUserDialogState) -> Unit,
Expand All @@ -59,6 +60,7 @@ fun ConversationSheetContent(
conversationSheetContent = conversationSheetState.conversationSheetContent!!,
changeFavoriteState = changeFavoriteState,
moveConversationToFolder = moveConversationToFolder,
removeFromFolder = removeFromFolder,
updateConversationArchiveStatus = updateConversationArchiveStatus,
clearConversationContent = clearConversationContent,
blockUserClick = blockUser,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ import com.wire.android.ui.home.conversationslist.model.GroupDialogState
import com.wire.android.ui.home.conversationslist.model.getMutedStatusTextResource
import com.wire.android.ui.theme.wireColorScheme
import com.wire.android.ui.theme.wireTypography
import com.wire.kalium.logic.data.conversation.ConversationFolder
import com.wire.kalium.logic.data.conversation.MutedConversationStatus
import com.wire.kalium.logic.data.id.ConversationId
import com.wire.kalium.logic.data.user.ConnectionState

// items cannot be simplified
Expand All @@ -61,6 +63,7 @@ internal fun ConversationMainSheetContent(
conversationSheetContent: ConversationSheetContent,
changeFavoriteState: (dialogState: GroupDialogState, addToFavorite: Boolean) -> Unit,
moveConversationToFolder: ((ConversationFoldersNavArgs) -> Unit)?,
removeFromFolder: (conversationId: ConversationId, conversationName: String, folder: ConversationFolder) -> Unit,
updateConversationArchiveStatus: (DialogState) -> Unit,
clearConversationContent: (DialogState) -> Unit,
blockUserClick: (BlockUserDialogState) -> Unit,
Expand Down Expand Up @@ -164,6 +167,26 @@ internal fun ConversationMainSheetContent(
)
}
}
if (conversationSheetContent.folder != null) {
add {
MenuBottomSheetItem(
leading = {
MenuItemIcon(
id = R.drawable.ic_folder,
contentDescription = null,
)
},
title = stringResource(R.string.label_remove_from_folder, conversationSheetContent.folder.name),
onItemClick = {
removeFromFolder(
conversationSheetContent.conversationId,
conversationSheetContent.title,
conversationSheetContent.folder
)
}
)
}
}
add {
MenuBottomSheetItem(
leading = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ import com.wire.android.ui.home.conversations.details.participants.GroupConversa
import com.wire.android.ui.home.conversations.details.participants.model.UIParticipant
import com.wire.android.ui.home.conversations.folder.ConversationFoldersNavArgs
import com.wire.android.ui.home.conversations.folder.ConversationFoldersNavBackArgs
import com.wire.android.ui.home.conversations.folder.RemoveConversationFromFolderVM
import com.wire.android.ui.home.conversationslist.model.DialogState
import com.wire.android.ui.home.conversationslist.model.GroupDialogState
import com.wire.android.ui.legalhold.dialog.subject.LegalHoldSubjectConversationDialog
Expand All @@ -124,6 +125,7 @@ import com.wire.android.ui.theme.wireTypography
import com.wire.android.util.ui.PreviewMultipleThemes
import com.wire.android.util.ui.UIText
import com.wire.kalium.logic.data.conversation.Conversation
import com.wire.kalium.logic.data.conversation.ConversationFolder
import com.wire.kalium.logic.data.conversation.MutedConversationStatus
import com.wire.kalium.logic.data.id.ConversationId
import com.wire.kalium.logic.data.id.GroupID
Expand All @@ -143,7 +145,8 @@ fun GroupConversationDetailsScreen(
groupConversationDetailResultRecipient: ResultRecipient<EditConversationNameScreenDestination, Boolean>,
conversationFoldersScreenResultRecipient:
ResultRecipient<ConversationFoldersScreenDestination, ConversationFoldersNavBackArgs>,
viewModel: GroupConversationDetailsViewModel = hiltViewModel()
viewModel: GroupConversationDetailsViewModel = hiltViewModel(),
removeConversationFromFolderVM: RemoveConversationFromFolderVM = hiltViewModel(),
) {
val scope = rememberCoroutineScope()
val resources = LocalContext.current.resources
Expand Down Expand Up @@ -254,7 +257,8 @@ fun GroupConversationDetailsScreen(
) ?: false,
onMoveToFolder = {
navigator.navigate(NavigationCommand(ConversationFoldersScreenDestination(it)))
}
},
removeFromFolder = removeConversationFromFolderVM::removeFromFolder
)

val tryAgainSnackBarMessage = stringResource(id = R.string.error_unknown_message)
Expand Down Expand Up @@ -308,6 +312,7 @@ private fun GroupConversationDetailsContent(
isAbandonedOneOnOneConversation: Boolean,
onSearchConversationMessagesClick: () -> Unit,
onConversationMediaClick: () -> Unit,
removeFromFolder: (conversationId: ConversationId, conversationName: String, folder: ConversationFolder) -> Unit,
onMoveToFolder: (ConversationFoldersNavArgs) -> Unit = {},
initialPageIndex: GroupConversationDetailsTabItem = GroupConversationDetailsTabItem.OPTIONS,
changeConversationFavoriteStateViewModel: ChangeConversationFavoriteVM =
Expand Down Expand Up @@ -493,6 +498,7 @@ private fun GroupConversationDetailsContent(
},
changeFavoriteState = changeConversationFavoriteStateViewModel::changeFavoriteState,
moveConversationToFolder = onMoveToFolder,
removeFromFolder = removeFromFolder,
updateConversationArchiveStatus = {
// Only show the confirmation dialog if the conversation is not archived
if (!it.isArchived) {
Expand Down Expand Up @@ -648,6 +654,7 @@ fun PreviewGroupConversationDetails() {
onConversationMediaClick = {},
isAbandonedOneOnOneConversation = false,
initialPageIndex = GroupConversationDetailsTabItem.PARTICIPANTS,
removeFromFolder = { _, _, _ -> }
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,6 @@ class GroupConversationDetailsViewModel @Inject constructor(
}
}

@Suppress("EmptyFunctionBlock")
override fun onMoveConversationToFolder(conversationId: ConversationId?) {
}

override fun updateConversationArchiveStatus(
dialogState: DialogState,
timestamp: Long,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import com.wire.kalium.util.DateTimeUtil
@Suppress("TooManyFunctions")
interface GroupConversationDetailsBottomSheetEventsHandler {
fun onMutingConversationStatusChange(conversationId: ConversationId?, status: MutedConversationStatus, onMessage: (UIText) -> Unit)
fun onMoveConversationToFolder(conversationId: ConversationId? = null)
fun updateConversationArchiveStatus(
dialogState: DialogState,
timestamp: Long = DateTimeUtil.currentInstant().toEpochMilliseconds(),
Expand All @@ -46,7 +45,6 @@ interface GroupConversationDetailsBottomSheetEventsHandler {
) {
}

override fun onMoveConversationToFolder(conversationId: ConversationId?) {}
override fun updateConversationArchiveStatus(
dialogState: DialogState,
timestamp: Long,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Wire
* Copyright (C) 2024 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.wire.android.ui.home.conversations.folder

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.wire.android.R
import com.wire.android.di.ScopedArgs
import com.wire.android.di.ViewModelScopedPreview
import com.wire.android.model.DefaultSnackBarMessage
import com.wire.android.model.SnackBarMessage
import com.wire.android.util.dispatchers.DispatcherProvider
import com.wire.android.util.ui.UIText
import com.wire.kalium.logic.data.conversation.ConversationFolder
import com.wire.kalium.logic.data.id.ConversationId
import com.wire.kalium.logic.feature.conversation.folder.RemoveConversationFromFolderUseCase
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import kotlinx.serialization.Serializable
import javax.inject.Inject

@ViewModelScopedPreview
interface RemoveConversationFromFolderVM {
val infoMessage: SharedFlow<SnackBarMessage>
get() = MutableSharedFlow()

fun removeFromFolder(conversationId: ConversationId, conversationName: String, folder: ConversationFolder) {}
}

@HiltViewModel
class RemoveConversationFromFolderVMImpl @Inject constructor(
private val dispatchers: DispatcherProvider,
private val removeConversationFromFolder: RemoveConversationFromFolderUseCase,
) : ViewModel(), RemoveConversationFromFolderVM {

private val _infoMessage = MutableSharedFlow<SnackBarMessage>()
override val infoMessage = _infoMessage.asSharedFlow()

override fun removeFromFolder(conversationId: ConversationId, conversationName: String, folder: ConversationFolder) {
viewModelScope.launch {
val result = withContext(dispatchers.io()) {
removeConversationFromFolder.invoke(
conversationId,
folder.id
)
}
when (result) {
is RemoveConversationFromFolderUseCase.Result.Failure -> _infoMessage.emit(
DefaultSnackBarMessage(
UIText.StringResource(
R.string.remove_from_folder_failed,
conversationName,
)
)
)

RemoveConversationFromFolderUseCase.Result.Success -> _infoMessage.emit(
DefaultSnackBarMessage(
UIText.StringResource(
R.string.remove_from_folder_success,
conversationName,
folder.name
)
)
)
}
}
}
}

@Serializable
data object RemoveConversationFromFolderArgs : ScopedArgs {
override val key = "RemoveConversationFromFolderArgsKey"
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ import com.wire.android.ui.home.conversations.details.dialog.ClearConversationCo
import com.wire.android.ui.home.conversations.details.menu.DeleteConversationGroupDialog
import com.wire.android.ui.home.conversations.details.menu.DeleteConversationGroupLocallyDialog
import com.wire.android.ui.home.conversations.details.menu.LeaveConversationGroupDialog
import com.wire.android.ui.home.conversations.folder.RemoveConversationFromFolderArgs
import com.wire.android.ui.home.conversations.folder.RemoveConversationFromFolderVM
import com.wire.android.ui.home.conversations.folder.RemoveConversationFromFolderVMImpl
import com.wire.android.ui.home.conversationslist.common.ConversationList
import com.wire.android.ui.home.conversationslist.model.ConversationItem
import com.wire.android.ui.home.conversationslist.model.ConversationsSource
Expand Down Expand Up @@ -108,6 +111,10 @@ fun ConversationsScreenContent(
hiltViewModelScoped<ChangeConversationFavoriteVMImpl, ChangeConversationFavoriteVM, ChangeConversationFavoriteStateArgs>(
ChangeConversationFavoriteStateArgs
),
removeConversationFromFolderViewModel: RemoveConversationFromFolderVM =
hiltViewModelScoped<RemoveConversationFromFolderVMImpl, RemoveConversationFromFolderVM, RemoveConversationFromFolderArgs>(
RemoveConversationFromFolderArgs
)
) {
var currentConversationOptionNavigation by remember {
mutableStateOf<ConversationOptionNavigation>(ConversationOptionNavigation.Home)
Expand All @@ -119,12 +126,6 @@ fun ConversationsScreenContent(

val context = LocalContext.current

LaunchedEffect(Unit) {
conversationListViewModel.infoMessage.collect {
sheetState.hide()
}
}

LaunchedEffect(Unit) {
conversationListViewModel.closeBottomSheet.collect {
sheetState.hide()
Expand Down Expand Up @@ -327,6 +328,7 @@ fun ConversationsScreenContent(
moveConversationToFolder = { navArgs ->
navigator.navigate(NavigationCommand(ConversationFoldersScreenDestination(navArgs)))
},
removeFromFolder = removeConversationFromFolderViewModel::removeFromFolder,
updateConversationArchiveStatus = showConfirmationDialogOrUnarchive(),
clearConversationContent = clearContentDialogState::show,
blockUser = blockUserDialogState::show,
Expand All @@ -339,7 +341,12 @@ fun ConversationsScreenContent(
)
}

SnackBarMessageHandler(infoMessages = conversationListViewModel.infoMessage)
SnackBarMessageHandler(infoMessages = conversationListViewModel.infoMessage, onEmitted = {
sheetState.hide()
})
SnackBarMessageHandler(infoMessages = removeConversationFromFolderViewModel.infoMessage, onEmitted = {
sheetState.hide()
})
SnackBarMessageHandler(infoMessages = changeConversationFavoriteStateViewModel.infoMessage, onEmitted = {
sheetState.hide()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ fun ConversationList(
modifier: Modifier = Modifier,
lazyListState: LazyListState = rememberLazyListState(),
isSelectableList: Boolean = false,
selectedConversations: List<ConversationItem> = emptyList(),
selectedConversations: List<ConversationId> = emptyList(),
onOpenConversation: (ConversationItem) -> Unit = {},
onEditConversation: (ConversationItem) -> Unit = {},
onOpenUserProfile: (UserId) -> Unit = {},
Expand Down Expand Up @@ -116,7 +116,7 @@ fun ConversationList(
ConversationItemFactory(
conversation = item,
isSelectableItem = isSelectableList,
isChecked = selectedConversations.contains(item),
isChecked = selectedConversations.contains(item.conversationId),
onConversationSelectedOnRadioGroup = { onConversationSelectedOnRadioGroup(item) },
openConversation = onOpenConversation,
openMenu = onEditConversation,
Expand Down Expand Up @@ -283,6 +283,7 @@ fun PreviewConversationListSelect() = WireTheme {
ConversationList(
lazyPagingConversations = previewConversationFoldersFlow(list = conversationFolders).collectAsLazyPagingItems(),
isSelectableList = true,
selectedConversations = conversationFolders.filterIsInstance<ConversationItem>().filterIndexed { index, _ -> index % 3 == 0 },
selectedConversations = conversationFolders.filterIsInstance<ConversationItem>().filterIndexed { index, _ -> index % 3 == 0 }
.map { it.conversationId },
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package com.wire.android.ui.sharing
import androidx.compose.runtime.Stable
import androidx.paging.PagingData
import com.wire.android.ui.home.conversationslist.model.ConversationFolderItem
import com.wire.android.ui.home.conversationslist.model.ConversationItem
import com.wire.kalium.logic.data.id.ConversationId
import com.wire.kalium.logic.data.message.SelfDeletionTimer
import kotlinx.collections.immutable.PersistentList
import kotlinx.collections.immutable.persistentListOf
Expand All @@ -33,7 +33,7 @@ data class ImportMediaAuthenticatedState(
val importedText: String? = null,
val isImporting: Boolean = false,
val conversations: Flow<PagingData<ConversationFolderItem>> = emptyFlow(),
val selectedConversationItem: List<ConversationItem> = persistentListOf(),
val selectedConversationItem: List<ConversationId> = persistentListOf(),
val selfDeletingTimer: SelfDeletionTimer = SelfDeletionTimer.Enabled(null)
) {
@Stable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class ImportMediaAuthenticatedViewModel @Inject constructor(
viewModelScope.launch {
with(conversationItem) {
importMediaState = importMediaState.copy(
selectedConversationItem = listOf(this),
selectedConversationItem = listOf(this.conversationId),
selfDeletingTimer = observeSelfDeletionSettingsForConversation(
conversationId = conversationId,
considerSelfUserSettings = true
Expand Down Expand Up @@ -225,11 +225,11 @@ class ImportMediaAuthenticatedViewModel @Inject constructor(
selfDeletingTimer = SelfDeletionTimer.Enabled(selfDeletionDuration.value)
)
val logMap = importMediaState.selfDeletingTimer.toLogString(
"user timer update for conversationId=${it.conversationId.toLogString()} on ImportMediaScreen"
"user timer update for conversationId=${it.toLogString()} on ImportMediaScreen"
)
appLogger.d("$SELF_DELETION_LOG_TAG: $logMap")
persistNewSelfDeletionTimerUseCase(
conversationId = it.conversationId,
conversationId = it,
newSelfDeletionTimer = importMediaState.selfDeletingTimer
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ private fun ImportMediaAuthenticatedContent(
NavigationCommand(
ConversationScreenDestination(
ConversationNavArgs(
conversationId = conversationItem.conversationId,
conversationId = conversationItem,
pendingBundles = ArrayList(it),
pendingTextBundle = importedText
)
Expand Down
Loading

0 comments on commit b01b7d7

Please sign in to comment.