Skip to content

Commit

Permalink
feat: navigate to original reply message (WPB-1694) (#2672)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandreferris authored Feb 7, 2024
1 parent 9625981 commit b25ae64
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ import com.ramcosta.composedestinations.result.ResultRecipient
import com.wire.android.R
import com.wire.android.appLogger
import com.wire.android.media.audiomessage.AudioState
import com.wire.android.model.Clickable
import com.wire.android.model.SnackBarMessage
import com.wire.android.navigation.BackStackMode
import com.wire.android.navigation.NavigationCommand
Expand Down Expand Up @@ -693,7 +694,8 @@ private fun ConversationScreen(
tempWritableImageUri = tempWritableImageUri,
tempWritableVideoUri = tempWritableVideoUri,
onLinkClick = onLinkClick,
onTypingEvent = onTypingEvent
onTypingEvent = onTypingEvent,
onNavigateToReplyOriginalMessage = conversationMessagesViewModel::navigateToReplyOriginalMessage
)
}
}
Expand Down Expand Up @@ -737,7 +739,8 @@ private fun ConversationScreenContent(
tempWritableImageUri: Uri?,
tempWritableVideoUri: Uri?,
onLinkClick: (String) -> Unit,
onTypingEvent: (TypingIndicatorMode) -> Unit
onTypingEvent: (TypingIndicatorMode) -> Unit,
onNavigateToReplyOriginalMessage: (UIMessage) -> Unit
) {
val lazyPagingMessages = messages.collectAsLazyPagingItems()

Expand Down Expand Up @@ -768,7 +771,8 @@ private fun ConversationScreenContent(
onFailedMessageCancelClicked = onFailedMessageCancelClicked,
onFailedMessageRetryClicked = onFailedMessageRetryClicked,
onLinkClick = onLinkClick,
selectedMessageId = selectedMessageId
selectedMessageId = selectedMessageId,
onNavigateToReplyOriginalMessage = onNavigateToReplyOriginalMessage
)
},
onChangeSelfDeletionClicked = onChangeSelfDeletionClicked,
Expand Down Expand Up @@ -835,7 +839,8 @@ fun MessageList(
onFailedMessageRetryClicked: (String) -> Unit,
onFailedMessageCancelClicked: (String) -> Unit,
onLinkClick: (String) -> Unit,
selectedMessageId: String?
selectedMessageId: String?,
onNavigateToReplyOriginalMessage: (UIMessage) -> Unit
) {
val mostRecentMessage = lazyPagingMessages.itemCount.takeIf { it > 0 }?.let { lazyPagingMessages[0] }

Expand Down Expand Up @@ -907,6 +912,12 @@ fun MessageList(
onFailedMessageCancelClicked = onFailedMessageCancelClicked,
onFailedMessageRetryClicked = onFailedMessageRetryClicked,
onLinkClick = onLinkClick,
onReplyClickable = Clickable(
enabled = true,
onClick = {
onNavigateToReplyOriginalMessage(message)
}
),
isSelectedMessage = (message.header.messageId == selectedMessageId)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ fun MessageItem(
defaultBackgroundColor: Color = Color.Transparent,
shouldDisplayMessageStatus: Boolean = true,
shouldDisplayFooter: Boolean = true,
onReplyClickable: Clickable? = null,
isSelectedMessage: Boolean = false
) {
with(message) {
Expand Down Expand Up @@ -277,7 +278,8 @@ fun MessageItem(
onLongClick = onLongClick,
onOpenProfile = onOpenProfile,
onLinkClick = onLinkClick,
clickable = !isContentClickable
clickable = !isContentClickable,
onReplyClickable = onReplyClickable
)
}
if (isMyMessage && shouldDisplayMessageStatus) {
Expand Down Expand Up @@ -507,7 +509,8 @@ private fun MessageContent(
onLongClick: (() -> Unit)? = null,
onOpenProfile: (String) -> Unit,
onLinkClick: (String) -> Unit,
clickable: Boolean
clickable: Boolean,
onReplyClickable: Clickable? = null
) {
when (messageContent) {
is UIMessageContent.ImageMessage -> {
Expand All @@ -528,8 +531,11 @@ private fun MessageContent(
messageContent.messageBody.quotedMessage?.let {
VerticalSpace.x4()
when (it) {
is UIQuotedMessage.UIQuotedData -> QuotedMessage(it)
UIQuotedMessage.UnavailableData -> QuotedUnavailable(QuotedMessageStyle.COMPLETE)
is UIQuotedMessage.UIQuotedData -> QuotedMessage(
messageData = it,
clickable = onReplyClickable
)
UIQuotedMessage.UnavailableData -> QuotedUnavailable(style = QuotedMessageStyle.COMPLETE)
}
VerticalSpace.x4()
}
Expand All @@ -553,8 +559,11 @@ private fun MessageContent(
messageContent.messageBody?.quotedMessage?.let {
VerticalSpace.x4()
when (it) {
is UIQuotedMessage.UIQuotedData -> QuotedMessage(it)
UIQuotedMessage.UnavailableData -> QuotedUnavailable(QuotedMessageStyle.COMPLETE)
is UIQuotedMessage.UIQuotedData -> QuotedMessage(
messageData = it,
clickable = onReplyClickable
)
UIQuotedMessage.UnavailableData -> QuotedUnavailable(style = QuotedMessageStyle.COMPLETE)
}
VerticalSpace.x4()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ private fun AssetMessagesListContent(
defaultBackgroundColor = colorsScheme().backgroundVariant,
shouldDisplayMessageStatus = false,
shouldDisplayFooter = false,
onLinkClick = { }
onLinkClick = { },
onReplyClickable = null
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import com.wire.android.ui.home.conversations.ConversationSnackbarMessages
import com.wire.android.ui.home.conversations.ConversationSnackbarMessages.OnResetSession
import com.wire.android.ui.home.conversations.model.AssetBundle
import com.wire.android.ui.home.conversations.model.UIMessage
import com.wire.android.ui.home.conversations.model.UIMessageContent
import com.wire.android.ui.home.conversations.model.UIQuotedMessage
import com.wire.android.ui.home.conversations.usecase.GetMessagesForConversationUseCase
import com.wire.android.ui.navArgs
import com.wire.android.util.FileManager
Expand Down Expand Up @@ -111,6 +113,19 @@ class ConversationMessagesViewModel @Inject constructor(
observeAudioPlayerState()
}

fun navigateToReplyOriginalMessage(message: UIMessage) {
if (message.messageContent is UIMessageContent.TextMessage) {
val originalMessageId =
((message.messageContent as UIMessageContent.TextMessage)
.messageBody.quotedMessage as UIQuotedMessage.UIQuotedData)
.messageId
conversationViewState = conversationViewState.copy(
searchedMessageId = originalMessageId
)
loadPaginatedMessages()
}
}

private fun clearOrphanedTypingEvents() {
viewModelScope.launch { clearUsersTypingEvents() }
}
Expand Down
Loading

0 comments on commit b25ae64

Please sign in to comment.