Add navigate to thread functionality on search results thread summary

This commit is contained in:
ariskotsomitopoulos 2022-05-04 17:06:18 +03:00
parent f4b1e06ad1
commit ad50c22e97
3 changed files with 23 additions and 5 deletions

View File

@ -98,7 +98,8 @@ class SearchFragment @Inject constructor(
is Success -> {
views.stateView.state = StateView.State.Empty(
title = getString(R.string.search_no_results),
image = ContextCompat.getDrawable(requireContext(), R.drawable.ic_search_no_results))
image = ContextCompat.getDrawable(requireContext(), R.drawable.ic_search_no_results)
)
}
else -> Unit
}
@ -120,20 +121,32 @@ class SearchFragment @Inject constructor(
override fun onItemClicked(event: Event) =
navigateToEvent(event)
override fun onThreadSummaryClicked(event: Event) {
navigateToEvent(event, true)
}
/**
* Navigate and highlight the event. If this is a thread event,
* user will be redirected to the appropriate thread room
* @param event the event to navigate and highlight
* @param forceNavigateToThread force navigate within the thread (ex. when user clicks on thread summary)
*/
private fun navigateToEvent(event: Event) {
private fun navigateToEvent(event: Event, forceNavigateToThread: Boolean = false) {
val roomId = event.roomId ?: return
event.getRootThreadEventId()?.let {
val rootThreadEventId = if (forceNavigateToThread) {
event.eventId
} else {
event.getRootThreadEventId()
}
rootThreadEventId?.let {
val threadTimelineArgs = ThreadTimelineArgs(
roomId = roomId,
displayName = fragmentArgs.roomDisplayName,
avatarUrl = fragmentArgs.roomAvatarUrl,
roomEncryptionTrustLevel = null,
rootThreadEventId = it)
rootThreadEventId = it
)
navigator.openThread(requireContext(), threadTimelineArgs, event.eventId)
} ?: openRoom(roomId, event.eventId)
}

View File

@ -56,6 +56,7 @@ class SearchResultController @Inject constructor(
interface Listener {
fun onItemClicked(event: Event)
fun onThreadSummaryClicked(event: Event)
fun loadMore()
}
@ -125,11 +126,13 @@ class SearchResultController @Inject constructor(
.formattedDate(dateFormatter.format(event.originServerTs, DateFormatKind.MESSAGE_SIMPLE))
.spannable(spannable.toEpoxyCharSequence())
.sender(eventAndSender.sender
?: eventAndSender.event.senderId?.let { session.roomService().getRoomMember(it, data.roomId) }?.toMatrixItem())
?: eventAndSender.event.senderId?.let { session.roomService().getRoomMember(it, data.roomId) }?.toMatrixItem()
)
.threadDetails(event.threadDetails)
.threadSummaryFormatted(displayableEventFormatter.formatThreadSummary(event.threadDetails?.threadSummaryLatestEvent).toString())
.areThreadMessagesEnabled(userPreferencesProvider.areThreadMessagesEnabled())
.listener { listener?.onItemClicked(eventAndSender.event) }
.threadSummaryListener { listener?.onThreadSummaryClicked(eventAndSender.event) }
.let { result.add(it) }
}

View File

@ -46,6 +46,7 @@ abstract class SearchResultItem : VectorEpoxyModel<SearchResultItem.Holder>() {
@EpoxyAttribute var areThreadMessagesEnabled: Boolean = false
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var listener: ClickListener? = null
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var threadSummaryListener: ClickListener? = null
override fun bind(holder: Holder) {
super.bind(holder)
@ -66,6 +67,7 @@ abstract class SearchResultItem : VectorEpoxyModel<SearchResultItem.Holder>() {
val displayName = it.threadSummarySenderInfo?.displayName
val avatarUrl = it.threadSummarySenderInfo?.avatarUrl
avatarRenderer.render(MatrixItem.UserItem(userId, displayName, avatarUrl), holder.threadSummaryAvatarImageView)
holder.threadSummaryConstraintLayout.onClick(threadSummaryListener)
} else {
showFromThread(holder)
}