Skip to content

Commit

Permalink
fix: disable message options for gallery asset [WPB-9047] (#3084)
Browse files Browse the repository at this point in the history
  • Loading branch information
Garzas authored Jun 6, 2024
1 parent 9b16675 commit af34214
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ import com.wire.android.ui.home.conversations.call.ConversationCallViewState
import com.wire.android.ui.home.conversations.composer.MessageComposerViewModel
import com.wire.android.ui.home.conversations.delete.DeleteMessageDialog
import com.wire.android.ui.home.conversations.details.GroupConversationDetailsNavBackArgs
import com.wire.android.ui.home.conversations.edit.EditMessageMenuItems
import com.wire.android.ui.home.conversations.edit.editMessageMenuItems
import com.wire.android.ui.home.conversations.info.ConversationDetailsData
import com.wire.android.ui.home.conversations.info.ConversationInfoViewModel
import com.wire.android.ui.home.conversations.info.ConversationInfoViewState
Expand Down Expand Up @@ -399,7 +399,8 @@ fun ConversationScreen(
conversationId = conversationId,
messageId = message.header.messageId,
isSelfAsset = isSelfMessage,
isEphemeral = message.header.messageStatus.expirationStatus is ExpirationStatus.Expirable
isEphemeral = message.header.messageStatus.expirationStatus is ExpirationStatus.Expirable,
messageOptionsEnabled = true
)
)
)
Expand Down Expand Up @@ -751,8 +752,9 @@ private fun ConversationScreen(

val menuItems = when (val menuType = conversationScreenState.bottomSheetMenuType) {
is ConversationScreenState.BottomSheetMenuType.Edit -> {
EditMessageMenuItems(
editMessageMenuItems(
message = menuType.selectedMessage,
messageOptionsEnabled = true,
hideEditMessageMenu = conversationScreenState::hideContextMenu,
onCopyClick = conversationScreenState::copyMessage,
onDeleteClick = onDeleteMessage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,47 @@ import com.wire.android.ui.edit.ReactionOption
import com.wire.android.ui.edit.ReplyMessageOption

@Composable
fun AssetEditMenuItems(
fun assetEditMenuItems(
isEphemeral: Boolean,
isUploading: Boolean = false,
messageOptionsEnabled: Boolean,
onDeleteClick: () -> Unit,
onDetailsClick: () -> Unit,
onShareAsset: () -> Unit,
onDownloadAsset: () -> Unit,
onReplyClick: () -> Unit,
onReactionClick: (String) -> Unit,
isUploading: Boolean = false,
onOpenAsset: (() -> Unit)? = null
): List<@Composable () -> Unit> {
return buildList {
if (!isUploading) {
if (!isEphemeral) add { ReactionOption(onReactionClick) }
add { MessageDetailsMenuOption(onDetailsClick) }
if (!isEphemeral) add { ReplyMessageOption(onReplyClick) }
add { DownloadAssetExternallyOption(onDownloadAsset) }
if (!isEphemeral) add { ShareAssetMenuOption(onShareAsset) }
if (onOpenAsset != null && !isEphemeral) add { OpenAssetExternallyOption(onOpenAsset) }
when {
isUploading -> {
add { DeleteItemMenuOption(onDeleteClick) }
}

isEphemeral -> {
if (messageOptionsEnabled) {
add { MessageDetailsMenuOption(onDetailsClick) }
}
add { DownloadAssetExternallyOption(onDownloadAsset) }
add { DeleteItemMenuOption(onDeleteClick) }
}

!messageOptionsEnabled -> {
add { DownloadAssetExternallyOption(onDownloadAsset) }
add { ShareAssetMenuOption(onShareAsset) }
add { DeleteItemMenuOption(onDeleteClick) }
}

else -> {
add { ReactionOption(onReactionClick) }
add { MessageDetailsMenuOption(onDetailsClick) }
add { ReplyMessageOption(onReplyClick) }
add { DownloadAssetExternallyOption(onDownloadAsset) }
add { ShareAssetMenuOption(onShareAsset) }
if (onOpenAsset != null) add { OpenAssetExternallyOption(onOpenAsset) }
add { DeleteItemMenuOption(onDeleteClick) }
}
}
add { DeleteItemMenuOption(onDeleteClick) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ import com.wire.android.util.ui.UIText
import com.wire.kalium.logic.data.message.mention.MessageMention

@Composable
fun EditMessageMenuItems(
fun editMessageMenuItems(
message: UIMessage.Regular,
messageOptionsEnabled: Boolean,
hideEditMessageMenu: (OnComplete) -> Unit,
onCopyClick: (String) -> Unit,
onDeleteClick: (messageId: String, Boolean) -> Unit,
Expand Down Expand Up @@ -117,7 +118,8 @@ fun EditMessageMenuItems(
}

return if (message.isAssetMessage) {
AssetEditMenuItems(
assetEditMenuItems(
messageOptionsEnabled = messageOptionsEnabled,
isEphemeral = message.header.messageStatus.expirationStatus is ExpirationStatus.Expirable,
isUploading = message.isPending,
onDeleteClick = onDeleteItemClick,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ fun ConversationMediaScreen(
conversationId = conversationId,
messageId = messageId,
isSelfAsset = isSelfAsset,
isEphemeral = false
isEphemeral = false,
messageOptionsEnabled = false
)
)
)
Expand Down Expand Up @@ -135,10 +136,10 @@ fun ConversationMediaScreen(
@Composable
private fun Content(
state: ConversationAssetMessagesViewState,
onNavigationPressed: () -> Unit = {},
onImageFullScreenMode: (conversationId: ConversationId, messageId: String, isSelfAsset: Boolean) -> Unit,
audioMessagesState: PersistentMap<String, AudioState> = persistentMapOf(),
onAudioItemClicked: (String) -> Unit,
onNavigationPressed: () -> Unit = {},
audioMessagesState: PersistentMap<String, AudioState> = persistentMapOf(),
onAssetItemClicked: (String) -> Unit
) {
val scope = rememberCoroutineScope()
Expand Down Expand Up @@ -211,7 +212,7 @@ enum class ConversationMediaScreenTabItem(@StringRes val titleResId: Int) : TabI

@PreviewMultipleThemes
@Composable
fun previewConversationMediaScreenEmptyContent() {
fun PreviewConversationMediaScreenEmptyContent() {
WireTheme {
Content(
state = ConversationAssetMessagesViewState(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ data class MediaGalleryNavArgs(
val conversationId: ConversationId,
val messageId: String,
val isSelfAsset: Boolean,
val isEphemeral: Boolean
val isEphemeral: Boolean,
val messageOptionsEnabled: Boolean
)

@Parcelize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import com.wire.android.ui.common.visbility.rememberVisibilityState
import com.wire.android.ui.home.conversations.MediaGallerySnackbarMessages
import com.wire.android.ui.home.conversations.PermissionPermanentlyDeniedDialogState
import com.wire.android.ui.home.conversations.delete.DeleteMessageDialog
import com.wire.android.ui.home.conversations.edit.AssetEditMenuItems
import com.wire.android.ui.home.conversations.edit.assetEditMenuItems
import com.wire.android.util.permission.rememberWriteStorageRequestFlow
import com.wire.android.util.ui.openDownloadFolder

Expand All @@ -58,8 +58,9 @@ import com.wire.android.util.ui.openDownloadFolder
@Composable
fun MediaGalleryScreen(
navigator: Navigator,
mediaGalleryViewModel: MediaGalleryViewModel = hiltViewModel(),
resultNavigator: ResultBackNavigator<MediaGalleryNavBackArgs>
resultNavigator: ResultBackNavigator<MediaGalleryNavBackArgs>,
modifier: Modifier = Modifier,
mediaGalleryViewModel: MediaGalleryViewModel = hiltViewModel()
) {
val permissionPermanentlyDeniedDialogState =
rememberVisibilityState<PermissionPermanentlyDeniedDialogState>()
Expand Down Expand Up @@ -91,6 +92,7 @@ fun MediaGalleryScreen(

with(viewModelState) {
WireScaffold(
modifier = modifier,
topBar = {
MediaGalleryScreenTopAppBar(
title = screenTitle
Expand All @@ -108,7 +110,8 @@ fun MediaGalleryScreen(
MenuModalSheetLayout(
sheetState = mediaGalleryScreenState.modalBottomSheetState,
coroutineScope = scope,
menuItems = AssetEditMenuItems(
menuItems = assetEditMenuItems(
messageOptionsEnabled = viewModelState.messageBottomSheetOptionsEnabled,
isEphemeral = viewModelState.isEphemeral,
onDeleteClick = {
mediaGalleryScreenState.showContextualMenu(false)
Expand Down Expand Up @@ -158,7 +161,12 @@ fun MediaGalleryScreen(
}

@Composable
fun MediaGalleryContent(navigator: Navigator, viewModel: MediaGalleryViewModel, mediaGalleryScreenState: MediaGalleryScreenState) {
fun MediaGalleryContent(
navigator: Navigator,
viewModel: MediaGalleryViewModel,
mediaGalleryScreenState: MediaGalleryScreenState,
modifier: Modifier = Modifier
) {
val context = LocalContext.current
val uiState = viewModel.mediaGalleryViewState
suspend fun showSnackbarMessage(message: String, actionLabel: String?, messageCode: MediaGallerySnackbarMessages) {
Expand All @@ -180,7 +188,7 @@ fun MediaGalleryContent(navigator: Navigator, viewModel: MediaGalleryViewModel,
}

Box(
Modifier
modifier
.fillMaxWidth()
.fillMaxHeight()
.background(colorsScheme().surface)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,12 @@ class MediaGalleryViewModel @Inject constructor(

private val messageId = imageAsset.messageId
private val conversationId = imageAsset.conversationId
var mediaGalleryViewState by mutableStateOf(MediaGalleryViewState(isEphemeral = imageAsset.isEphemeral))
var mediaGalleryViewState by mutableStateOf(
MediaGalleryViewState(
isEphemeral = imageAsset.isEphemeral,
messageBottomSheetOptionsEnabled = mediaGalleryNavArgs.messageOptionsEnabled
)
)
private set

val deleteMessageHelper = DeleteMessageDialogHelper(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ data class MediaGalleryViewState(
val deleteMessageDialogsState: DeleteMessageDialogsState = DeleteMessageDialogsState.States(
forYourself = DeleteMessageDialogActiveState.Hidden,
forEveryone = DeleteMessageDialogActiveState.Hidden
)
),
val messageBottomSheetOptionsEnabled: Boolean
)
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ class MediaGalleryViewModelTest {
conversationId = dummyConversationId,
messageId = dummyPrivateAsset,
isSelfAsset = true,
isEphemeral = false
isEphemeral = false,
messageOptionsEnabled = true
)

coEvery { deleteMessage(any(), any(), any()) } returns Either.Right(Unit)
Expand Down

0 comments on commit af34214

Please sign in to comment.