Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Adding option on bottom sheet to archive use cases #2262

Merged
merged 18 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import com.wire.kalium.logic.feature.conversation.RefreshConversationsWithoutMet
import com.wire.kalium.logic.feature.conversation.RemoveMemberFromConversationUseCase
import com.wire.kalium.logic.feature.conversation.RenameConversationUseCase
import com.wire.kalium.logic.feature.conversation.UpdateConversationAccessRoleUseCase
import com.wire.kalium.logic.feature.conversation.UpdateConversationArchivedStatusUseCase
import com.wire.kalium.logic.feature.conversation.UpdateConversationMutedStatusUseCase
import com.wire.kalium.logic.feature.conversation.UpdateConversationReadDateUseCase
import com.wire.kalium.logic.feature.conversation.UpdateConversationReceiptModeUseCase
Expand Down Expand Up @@ -216,4 +217,9 @@ class ConversationModule {
@Provides
fun provideClearConversationContentUseCase(conversationScope: ConversationScope): ClearConversationContentUseCase =
conversationScope.clearConversationContent

@ViewModelScoped
@Provides
fun provideUpdateConversationArchivedStatusUseCase(conversationScope: ConversationScope): UpdateConversationArchivedStatusUseCase =
conversationScope.updateConversationArchivedStatus
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fun ConversationSheetContent(
onMutingConversationStatusChange: () -> Unit,
addConversationToFavourites: () -> Unit,
moveConversationToFolder: () -> Unit,
moveConversationToArchive: () -> Unit,
moveConversationToArchive: (DialogState) -> Unit,
clearConversationContent: (DialogState) -> Unit,
blockUser: (BlockUserDialogState) -> Unit,
unblockUser: (UnblockUserDialogState) -> Unit,
Expand All @@ -61,7 +61,7 @@ fun ConversationSheetContent(
//
// addConversationToFavourites = addConversationToFavourites,
// moveConversationToFolder = moveConversationToFolder,
// moveConversationToArchive = moveConversationToArchive,
moveConversationToArchive = moveConversationToArchive,
clearConversationContent = clearConversationContent,
blockUserClick = blockUser,
unblockUserClick = unblockUser,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,9 @@ import com.wire.kalium.logic.data.user.ConnectionState
internal fun ConversationMainSheetContent(
conversationSheetContent: ConversationSheetContent,
// TODO(profile): enable when implemented
//
// addConversationToFavourites: () -> Unit,
// moveConversationToFolder: () -> Unit,
// moveConversationToArchive: () -> Unit,
moveConversationToArchive: (DialogState) -> Unit,
clearConversationContent: (DialogState) -> Unit,
blockUserClick: (BlockUserDialogState) -> Unit,
unblockUserClick: (UnblockUserDialogState) -> Unit,
Expand Down Expand Up @@ -135,18 +134,27 @@ internal fun ConversationMainSheetContent(
// onItemClick = moveConversationToFolder
// )
// }
// add {
// MenuBottomSheetItem(
// icon = {
// MenuItemIcon(
// id = R.drawable.ic_archive,
// contentDescription = stringResource(R.string.content_description_move_to_archive),
// )
// },
// title = stringResource(R.string.label_move_to_archive),
// onItemClick = moveConversationToArchive
// )
// }
add {
MenuBottomSheetItem(
icon = {
MenuItemIcon(
id = R.drawable.ic_archive,
contentDescription = stringResource(R.string.content_description_move_to_archive),
)
},
title = stringResource(R.string.label_move_to_archive),
onItemClick = {
with(conversationSheetContent) {
moveConversationToArchive(
DialogState(
conversationId,
title,
conversationTypeDetail
)
)
}
})
}
add {
MenuBottomSheetItem(
icon = {
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/kotlin/com/wire/android/ui/home/HomeScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,9 @@ private fun handleSnackBarMessage(
is HomeSnackbarState.ClearConversationContentSuccess -> stringResource(
if (messageType.isGroup) R.string.group_content_deleted else R.string.conversation_content_deleted
)

HomeSnackbarState.ArchivingConversationError -> stringResource(id = R.string.error_archiving_conversation)
HomeSnackbarState.ArchivingConversationSuccess -> stringResource(id = R.string.success_archiving_conversation)
}

LaunchedEffect(messageType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ sealed class HomeSnackbarState {
object DeleteConversationGroupError : HomeSnackbarState()
object LeftConversationSuccess : HomeSnackbarState()
object LeaveConversationError : HomeSnackbarState()
object ArchivingConversationSuccess : HomeSnackbarState()
object ArchivingConversationError : HomeSnackbarState()
}
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,13 @@ private fun GroupConversationDetailsContent(
},
addConversationToFavourites = bottomSheetEventsHandler::onAddConversationToFavourites,
moveConversationToFolder = bottomSheetEventsHandler::onMoveConversationToFolder,
moveConversationToArchive = bottomSheetEventsHandler::onMoveConversationToArchive,
moveConversationToArchive = {
bottomSheetEventsHandler.onMoveConversationToArchive(
conversationId = conversationSheetContent!!.conversationId,
gongracr marked this conversation as resolved.
Show resolved Hide resolved
shouldArchive = true,
closeBottomSheetAndShowSnackbarMessage
)
},
clearConversationContent = clearConversationDialogState::show,
blockUser = {},
unblockUser = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,14 @@ import com.wire.kalium.logic.data.conversation.ConversationDetails
import com.wire.kalium.logic.data.conversation.MutedConversationStatus
import com.wire.kalium.logic.data.id.ConversationId
import com.wire.kalium.logic.data.id.QualifiedID
import com.wire.kalium.logic.feature.conversation.ArchiveStatusUpdateResult
import com.wire.kalium.logic.feature.conversation.ClearConversationContentUseCase
import com.wire.kalium.logic.feature.conversation.ConversationUpdateReceiptModeResult
import com.wire.kalium.logic.feature.conversation.ConversationUpdateStatusResult
import com.wire.kalium.logic.feature.conversation.ObserveConversationDetailsUseCase
import com.wire.kalium.logic.feature.conversation.RemoveMemberFromConversationUseCase
import com.wire.kalium.logic.feature.conversation.UpdateConversationAccessRoleUseCase
import com.wire.kalium.logic.feature.conversation.UpdateConversationArchivedStatusUseCase
import com.wire.kalium.logic.feature.conversation.UpdateConversationMutedStatusUseCase
import com.wire.kalium.logic.feature.conversation.UpdateConversationReceiptModeUseCase
import com.wire.kalium.logic.feature.publicuser.RefreshUsersWithoutMetadataUseCase
Expand Down Expand Up @@ -91,6 +93,7 @@ class GroupConversationDetailsViewModel @Inject constructor(
private val clearConversationContent: ClearConversationContentUseCase,
private val updateConversationReceiptMode: UpdateConversationReceiptModeUseCase,
private val observeSelfDeletionTimerSettingsForConversation: ObserveSelfDeletionTimerSettingsForConversationUseCase,
private val updateConversationArchivedStatus: UpdateConversationArchivedStatusUseCase,
override val savedStateHandle: SavedStateHandle,
private val isMLSEnabled: IsMLSEnabledUseCase,
refreshUsersWithoutMetadata: RefreshUsersWithoutMetadataUseCase,
Expand Down Expand Up @@ -375,8 +378,20 @@ class GroupConversationDetailsViewModel @Inject constructor(
override fun onMoveConversationToFolder(conversationId: ConversationId?) {
}

@Suppress("EmptyFunctionBlock")
override fun onMoveConversationToArchive(conversationId: ConversationId?) {
override fun onMoveConversationToArchive(
conversationId: ConversationId,
shouldArchive: Boolean,
onMessage: (UIText) -> Unit
) {
viewModelScope.launch {
requestInProgress = true
val result = withContext(dispatcher.io()) { updateConversationArchivedStatus(conversationId, shouldArchive) }
requestInProgress = false
when (result) {
ArchiveStatusUpdateResult.Failure -> onMessage(UIText.StringResource(R.string.error_archiving_conversation))
ArchiveStatusUpdateResult.Success -> onMessage(UIText.StringResource(R.string.success_archiving_conversation))
}
}
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ interface GroupConversationDetailsBottomSheetEventsHandler {
fun onMutingConversationStatusChange(conversationId: ConversationId?, status: MutedConversationStatus, onMessage: (UIText) -> Unit)
fun onAddConversationToFavourites(conversationId: ConversationId? = null)
fun onMoveConversationToFolder(conversationId: ConversationId? = null)
fun onMoveConversationToArchive(conversationId: ConversationId? = null)
fun onMoveConversationToArchive(conversationId: ConversationId, shouldArchive: Boolean, onMessage: (UIText) -> Unit)
fun onClearConversationContent(dialogState: DialogState, onMessage: (UIText) -> Unit)

companion object {
Expand All @@ -40,10 +40,12 @@ interface GroupConversationDetailsBottomSheetEventsHandler {
conversationId: ConversationId?,
status: MutedConversationStatus,
onMessage: (UIText) -> Unit
) {}
) {
}

override fun onAddConversationToFavourites(conversationId: ConversationId?) {}
override fun onMoveConversationToFolder(conversationId: ConversationId?) {}
override fun onMoveConversationToArchive(conversationId: ConversationId?) {}
override fun onMoveConversationToArchive(conversationId: ConversationId, shouldArchive: Boolean, onMessage: (UIText) -> Unit) {}
override fun onClearConversationContent(dialogState: DialogState, onMessage: (UIText) -> Unit) {}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,14 @@ import com.wire.kalium.logic.feature.connection.BlockUserResult
import com.wire.kalium.logic.feature.connection.BlockUserUseCase
import com.wire.kalium.logic.feature.connection.UnblockUserResult
import com.wire.kalium.logic.feature.connection.UnblockUserUseCase
import com.wire.kalium.logic.feature.conversation.ArchiveStatusUpdateResult
import com.wire.kalium.logic.feature.conversation.ClearConversationContentUseCase
import com.wire.kalium.logic.feature.conversation.ConversationUpdateStatusResult
import com.wire.kalium.logic.feature.conversation.LeaveConversationUseCase
import com.wire.kalium.logic.feature.conversation.ObserveConversationListDetailsUseCase
import com.wire.kalium.logic.feature.conversation.RefreshConversationsWithoutMetadataUseCase
import com.wire.kalium.logic.feature.conversation.RemoveMemberFromConversationUseCase
import com.wire.kalium.logic.feature.conversation.UpdateConversationArchivedStatusUseCase
import com.wire.kalium.logic.feature.conversation.UpdateConversationMutedStatusUseCase
import com.wire.kalium.logic.feature.publicuser.RefreshUsersWithoutMetadataUseCase
import com.wire.kalium.logic.feature.team.DeleteTeamConversationUseCase
Expand Down Expand Up @@ -108,7 +110,8 @@ class ConversationListViewModel @Inject constructor(
private val userTypeMapper: UserTypeMapper,
private val endCall: EndCallUseCase,
private val refreshUsersWithoutMetadata: RefreshUsersWithoutMetadataUseCase,
private val refreshConversationsWithoutMetadata: RefreshConversationsWithoutMetadataUseCase
private val refreshConversationsWithoutMetadata: RefreshConversationsWithoutMetadataUseCase,
private val updateConversationArchivedStatus: UpdateConversationArchivedStatusUseCase,
) : ViewModel() {

var conversationListState by mutableStateOf(ConversationListState())
Expand Down Expand Up @@ -148,7 +151,7 @@ class ConversationListViewModel @Inject constructor(
}
viewModelScope.launch {
searchQueryFlow.combine(
observeConversationListDetails()
observeConversationListDetails(fetchArchivedConversations = false)
gongracr marked this conversation as resolved.
Show resolved Hide resolved
.map {
it.map { conversationDetails ->
conversationDetails.toConversationItem(
Expand Down Expand Up @@ -417,9 +420,20 @@ class ConversationListViewModel @Inject constructor(
fun moveConversationToFolder(id: String = "") {
}

// TODO: needs to be implemented
@Suppress("EmptyFunctionBlock")
fun moveConversationToArchive(id: String = "") {
fun moveConversationToArchive(conversationId: ConversationId, isArchiving: Boolean) {
viewModelScope.launch {
requestInProgress = true
val result = withContext(dispatcher.io()) { updateConversationArchivedStatus(conversationId, isArchiving) }
requestInProgress = false
when (result) {
is ArchiveStatusUpdateResult.Failure -> {
homeSnackBarState.emit(HomeSnackbarState.ArchivingConversationError)
}
is ArchiveStatusUpdateResult.Success -> {
homeSnackBarState.emit(HomeSnackbarState.ArchivingConversationSuccess)
}
}
}
}

fun clearConversationContent(dialogState: DialogState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,13 @@ fun ConversationRouterHomeBridge(
},
addConversationToFavourites = viewModel::addConversationToFavourites,
moveConversationToFolder = viewModel::moveConversationToFolder,
moveConversationToArchive = viewModel::moveConversationToArchive,
moveConversationToArchive = {
viewModel.moveConversationToArchive(
conversationId = it.conversationId,
isArchiving = true // All conversations at this point are not archived
)
onCloseBottomSheet()
},
clearConversationContent = clearContentDialogState::show,
blockUser = blockUserDialogState::show,
unblockUser = unblockUserDialogState::show,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class ImportMediaAuthenticatedViewModel @Inject constructor(
@OptIn(ExperimentalCoroutinesApi::class)
private suspend fun observeConversationWithSearch() = viewModelScope.launch {
searchQueryFlow.mapLatest { searchQuery ->
val conversations = observeConversationListDetails().first()
val conversations = observeConversationListDetails(fetchArchivedConversations = false).first()
.mapNotNull { conversationDetails ->
conversationDetails.toConversationItem(
wireSessionImageLoader,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ interface OtherUserProfileBottomSheetEventsHandler {
fun onMutingConversationStatusChange(conversationId: ConversationId?, status: MutedConversationStatus)
fun onAddConversationToFavourites(conversationId: ConversationId? = null)
fun onMoveConversationToFolder(conversationId: ConversationId? = null)
fun onMoveConversationToArchive(conversationId: ConversationId? = null)
fun onMoveConversationToArchive(conversationId: ConversationId, shouldArchiveConversation: Boolean)
fun onClearConversationContent(dialogState: DialogState)

companion object {
Expand All @@ -81,7 +81,7 @@ interface OtherUserProfileBottomSheetEventsHandler {
override fun onMutingConversationStatusChange(conversationId: ConversationId?, status: MutedConversationStatus) {}
override fun onAddConversationToFavourites(conversationId: ConversationId?) {}
override fun onMoveConversationToFolder(conversationId: ConversationId?) {}
override fun onMoveConversationToArchive(conversationId: ConversationId?) {}
override fun onMoveConversationToArchive(conversationId: ConversationId, shouldArchiveConversation: Boolean) {}
override fun onClearConversationContent(dialogState: DialogState) {}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ sealed class OtherUserProfileInfoMessageType(override val uiText: UIText) : Snac
OtherUserProfileInfoMessageType(UIText.StringResource(R.string.blocking_user_success, name))

object MutingOperationError : OtherUserProfileInfoMessageType(UIText.StringResource(R.string.error_updating_muting_setting))

object UnblockingUserOperationError : OtherUserProfileInfoMessageType(UIText.StringResource(R.string.error_unblocking_user))

object ConversationContentDeleted : OtherUserProfileInfoMessageType(UIText.StringResource(R.string.conversation_content_deleted))

object ConversationContentDeleteFailure :
OtherUserProfileInfoMessageType(UIText.StringResource(R.string.conversation_content_delete_failure))

object ArchiveConversationError : OtherUserProfileInfoMessageType(UIText.StringResource(R.string.error_archiving_conversation))
object ArchiveConversationSuccess : OtherUserProfileInfoMessageType(UIText.StringResource(R.string.success_archiving_conversation))

}
Loading