Enhance search functionality to support threads

This commit is contained in:
ariskotsomitopoulos 2021-12-01 12:57:53 +00:00
parent e7b8b90b0a
commit 0241d66f8e
5 changed files with 32 additions and 15 deletions

View file

@ -1024,7 +1024,12 @@ class TimelineFragment @Inject constructor(
private fun handleSearchAction() {
if (session.getRoom(timelineArgs.roomId)?.isEncrypted() == false) {
navigator.openSearch(requireContext(), timelineArgs.roomId)
navigator.openSearch(
context = requireContext(),
roomId = timelineArgs.roomId,
roomDisplayName = roomDetailViewModel.getRoomSummary()?.displayName,
roomAvatarUrl = roomDetailViewModel.getRoomSummary()?.avatarUrl
)
} else {
showDialogWithMessage(getString(R.string.search_is_not_supported_in_e2e_room))
}

View file

@ -37,13 +37,17 @@ import im.vector.app.core.extensions.trackItemsVisibilityChange
import im.vector.app.core.platform.StateView
import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.databinding.FragmentSearchBinding
import im.vector.app.features.home.room.threads.arguments.ThreadTimelineArgs
import kotlinx.parcelize.Parcelize
import org.matrix.android.sdk.api.session.events.model.Event
import org.matrix.android.sdk.api.session.events.model.getRootThreadEventId
import javax.inject.Inject
@Parcelize
data class SearchArgs(
val roomId: String
val roomId: String,
val roomDisplayName: String?,
val roomAvatarUrl: String?
) : Parcelable
class SearchFragment @Inject constructor(
@ -112,10 +116,20 @@ class SearchFragment @Inject constructor(
searchViewModel.handle(SearchAction.Retry)
}
override fun onItemClicked(event: Event) {
event.roomId?.let {
navigator.openRoom(requireContext(), it, event.eventId)
}
override fun onItemClicked(event: Event) =
navigateToEvent(event)
/**
* 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
*/
private fun navigateToEvent(event: Event) {
val roomId = event.roomId ?: return
event.getRootThreadEventId()?.let {
val threadTimelineArgs = ThreadTimelineArgs(roomId, displayName = fragmentArgs.roomDisplayName, fragmentArgs.roomAvatarUrl, it)
navigator.openThread(requireContext(), threadTimelineArgs, event.eventId)
} ?: navigator.openRoom(requireContext(), roomId, event.eventId)
}
override fun loadMore() {

View file

@ -54,10 +54,6 @@ class SearchResultController @Inject constructor(
fun loadMore()
}
init {
setData(null)
}
override fun buildModels(data: SearchViewState?) {
data ?: return

View file

@ -492,8 +492,11 @@ class DefaultNavigator @Inject constructor(
}
}
override fun openSearch(context: Context, roomId: String) {
val intent = SearchActivity.newIntent(context, SearchArgs(roomId))
override fun openSearch(context: Context,
roomId: String,
roomDisplayName: String?,
roomAvatarUrl: String?) {
val intent = SearchActivity.newIntent(context, SearchArgs(roomId, roomDisplayName, roomAvatarUrl))
context.startActivity(intent)
}
@ -522,7 +525,7 @@ class DefaultNavigator @Inject constructor(
threadTimelineArgs = threadTimelineArgs,
threadListArgs = null,
eventIdToNavigate = eventIdToNavigate
))
))
}
override fun openThreadList(context: Context, threadTimelineArgs: ThreadTimelineArgs) {

View file

@ -136,7 +136,7 @@ interface Navigator {
inMemory: List<AttachmentData> = emptyList(),
options: ((MutableList<Pair<View, String>>) -> Unit)?)
fun openSearch(context: Context, roomId: String)
fun openSearch(context: Context, roomId: String, roomDisplayName: String?, roomAvatarUrl: String?)
fun openDevTools(context: Context, roomId: String)
@ -145,5 +145,4 @@ interface Navigator {
fun openThread(context: Context, threadTimelineArgs: ThreadTimelineArgs, eventIdToNavigate: String? = null)
fun openThreadList(context: Context, threadTimelineArgs: ThreadTimelineArgs)
}