Skip to content

Commit

Permalink
Merge branch 'develop' into fix/share-conversation-list-update
Browse files Browse the repository at this point in the history
  • Loading branch information
sbakhtiarov authored Jan 15, 2025
2 parents 2c03bd9 + cdfd79a commit a00bc0a
Show file tree
Hide file tree
Showing 12 changed files with 165 additions and 17 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 @@ -100,6 +100,9 @@ import com.wire.android.ui.home.conversations.details.SearchAndMediaRow
import com.wire.android.ui.home.conversations.details.dialog.ClearConversationContentDialog
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.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.model.DialogState
import com.wire.android.ui.home.conversationslist.model.Membership
import com.wire.android.ui.legalhold.banner.LegalHoldSubjectBanner
Expand Down Expand Up @@ -267,6 +270,10 @@ fun OtherProfileScreenContent(
changeConversationFavoriteViewModel: ChangeConversationFavoriteVM =
hiltViewModelScoped<ChangeConversationFavoriteVMImpl, ChangeConversationFavoriteVM, ChangeConversationFavoriteStateArgs>(
ChangeConversationFavoriteStateArgs
),
removeConversationFromFolderViewModel: RemoveConversationFromFolderVM =
hiltViewModelScoped<RemoveConversationFromFolderVMImpl, RemoveConversationFromFolderVM, RemoveConversationFromFolderArgs>(
RemoveConversationFromFolderArgs
)
) {
val otherUserProfileScreenState = rememberOtherUserProfileScreenState()
Expand Down Expand Up @@ -303,6 +310,7 @@ fun OtherProfileScreenContent(
})
}

SnackBarMessageHandler(removeConversationFromFolderViewModel.infoMessage, onEmitted = closeBottomSheet)
SnackBarMessageHandler(changeConversationFavoriteViewModel.infoMessage, onEmitted = closeBottomSheet)

val tabItems by remember(state) {
Expand Down Expand Up @@ -392,7 +400,8 @@ fun OtherProfileScreenContent(
archivingStatusState = archivingConversationDialogState::show,
changeFavoriteState = changeConversationFavoriteViewModel::changeFavoriteState,
closeBottomSheet = closeBottomSheet,
onMoveToFolder = onMoveToFolder
onMoveToFolder = onMoveToFolder,
removeFromFolder = removeConversationFromFolderViewModel::removeFromFolder
)
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import com.wire.android.ui.home.conversations.folder.ConversationFoldersNavArgs
import com.wire.android.ui.home.conversationslist.model.DialogState
import com.wire.android.ui.home.conversationslist.model.GroupDialogState
import com.wire.android.ui.userprofile.other.OtherUserProfileBottomSheetEventsHandler
import com.wire.kalium.logic.data.conversation.ConversationFolder
import com.wire.kalium.logic.data.id.ConversationId

@Composable
fun OtherUserProfileBottomSheetContent(
Expand All @@ -39,6 +41,7 @@ fun OtherUserProfileBottomSheetContent(
changeFavoriteState: (GroupDialogState, addToFavorite: Boolean) -> Unit,
closeBottomSheet: () -> Unit,
getBottomSheetVisibility: () -> Boolean,
removeFromFolder: (conversationId: ConversationId, conversationName: String, folder: ConversationFolder) -> Unit,
onMoveToFolder: ((ConversationFoldersNavArgs) -> Unit)?
) {
when (val state = bottomSheetState.bottomSheetContentState) {
Expand All @@ -56,6 +59,7 @@ fun OtherUserProfileBottomSheetContent(
},
changeFavoriteState = changeFavoriteState,
moveConversationToFolder = onMoveToFolder,
removeFromFolder = removeFromFolder,
updateConversationArchiveStatus = {
if (!it.isArchived) {
archivingStatusState(it)
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,7 @@
<string name="label_add_to_favourites">Add to Favorites</string>
<string name="label_remove_from_favourites">Remove from Favorites</string>
<string name="label_move_to_folder">Move to Folder...</string>
<string name="label_remove_from_folder">Remove from Folder β€œ%1$s”</string>
<string name="label_new_folder">New Folder</string>
<string name="folder_create_description">Create a new folder by pressing the\nβ€œNew Folder” button</string>
<string name="label_move_to_archive">Move to Archive</string>
Expand Down Expand Up @@ -1683,4 +1684,7 @@ In group conversations, the group admin can overwrite this setting.</string>
<!-- Move to Folder -->
<string name="move_to_folder_success">β€œ%1$s” was moved to β€œ%2$s”</string>
<string name="move_to_folder_failed">β€œ%1$s” could not be moved</string>
<string name="remove_from_folder_success">β€œ%1$s” was removed from β€œ%2$s”</string>
<string name="remove_from_folder_failed">β€œ%1$s” could not be removed</string>

</resources>

0 comments on commit a00bc0a

Please sign in to comment.