mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-15 01:35:07 +08:00
Use the session SearchService to search in a room.
This commit is contained in:
parent
0092a7057e
commit
272bdf95cb
@ -60,9 +60,10 @@ class SearchMessagesTest : InstrumentedTest {
|
||||
fun sendTextMessageAndSearchPartOfItUsingRoom() {
|
||||
doTest { cryptoTestData ->
|
||||
cryptoTestData.firstSession
|
||||
.getRoom(cryptoTestData.roomId)!!
|
||||
.searchService()
|
||||
.search(
|
||||
searchTerm = "lore",
|
||||
roomId = cryptoTestData.roomId,
|
||||
limit = 10,
|
||||
includeProfile = true,
|
||||
afterLimit = 0,
|
||||
|
@ -38,7 +38,6 @@ import org.matrix.android.sdk.api.session.room.timeline.TimelineService
|
||||
import org.matrix.android.sdk.api.session.room.typing.TypingService
|
||||
import org.matrix.android.sdk.api.session.room.uploads.UploadsService
|
||||
import org.matrix.android.sdk.api.session.room.version.RoomVersionService
|
||||
import org.matrix.android.sdk.api.session.search.SearchResult
|
||||
import org.matrix.android.sdk.api.session.space.Space
|
||||
import org.matrix.android.sdk.api.util.Optional
|
||||
|
||||
@ -84,26 +83,6 @@ interface Room :
|
||||
*/
|
||||
fun roomSummary(): RoomSummary?
|
||||
|
||||
/**
|
||||
* Generic function to search a term in a room.
|
||||
* Ref: https://matrix.org/docs/spec/client_server/latest#module-search
|
||||
* @param searchTerm the term to search
|
||||
* @param nextBatch the token that retrieved from the previous response. Should be provided to get the next batch of results
|
||||
* @param orderByRecent if true, the most recent message events will return in the first places of the list
|
||||
* @param limit the maximum number of events to return.
|
||||
* @param beforeLimit how many events before the result are returned.
|
||||
* @param afterLimit how many events after the result are returned.
|
||||
* @param includeProfile requests that the server returns the historic profile information for the users that sent the events that were returned.
|
||||
* @return The search result
|
||||
*/
|
||||
suspend fun search(searchTerm: String,
|
||||
nextBatch: String?,
|
||||
orderByRecent: Boolean,
|
||||
limit: Int,
|
||||
beforeLimit: Int,
|
||||
afterLimit: Int,
|
||||
includeProfile: Boolean): SearchResult
|
||||
|
||||
/**
|
||||
* Use this room as a Space, if the type is correct.
|
||||
*/
|
||||
|
@ -42,14 +42,12 @@ import org.matrix.android.sdk.api.session.room.timeline.TimelineService
|
||||
import org.matrix.android.sdk.api.session.room.typing.TypingService
|
||||
import org.matrix.android.sdk.api.session.room.uploads.UploadsService
|
||||
import org.matrix.android.sdk.api.session.room.version.RoomVersionService
|
||||
import org.matrix.android.sdk.api.session.search.SearchResult
|
||||
import org.matrix.android.sdk.api.session.space.Space
|
||||
import org.matrix.android.sdk.api.util.Optional
|
||||
import org.matrix.android.sdk.api.util.awaitCallback
|
||||
import org.matrix.android.sdk.internal.session.permalinks.ViaParameterFinder
|
||||
import org.matrix.android.sdk.internal.session.room.state.SendStateTask
|
||||
import org.matrix.android.sdk.internal.session.room.summary.RoomSummaryDataSource
|
||||
import org.matrix.android.sdk.internal.session.search.SearchTask
|
||||
import org.matrix.android.sdk.internal.session.space.DefaultSpace
|
||||
import java.security.InvalidParameterException
|
||||
|
||||
@ -76,7 +74,6 @@ internal class DefaultRoom(override val roomId: String,
|
||||
private val roomVersionService: RoomVersionService,
|
||||
private val sendStateTask: SendStateTask,
|
||||
private val viaParameterFinder: ViaParameterFinder,
|
||||
private val searchTask: SearchTask,
|
||||
override val coroutineDispatchers: MatrixCoroutineDispatchers
|
||||
) :
|
||||
Room,
|
||||
@ -140,34 +137,14 @@ internal class DefaultRoom(override val roomId: String,
|
||||
eventType = EventType.STATE_ROOM_ENCRYPTION,
|
||||
body = mapOf(
|
||||
"algorithm" to algorithm
|
||||
))
|
||||
)
|
||||
)
|
||||
|
||||
sendStateTask.execute(params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun search(searchTerm: String,
|
||||
nextBatch: String?,
|
||||
orderByRecent: Boolean,
|
||||
limit: Int,
|
||||
beforeLimit: Int,
|
||||
afterLimit: Int,
|
||||
includeProfile: Boolean): SearchResult {
|
||||
return searchTask.execute(
|
||||
SearchTask.Params(
|
||||
searchTerm = searchTerm,
|
||||
roomId = roomId,
|
||||
nextBatch = nextBatch,
|
||||
orderByRecent = orderByRecent,
|
||||
limit = limit,
|
||||
beforeLimit = beforeLimit,
|
||||
afterLimit = afterLimit,
|
||||
includeProfile = includeProfile
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
override fun asSpace(): Space? {
|
||||
if (roomSummary()?.roomType != RoomType.SPACE) return null
|
||||
return DefaultSpace(this, roomSummaryDataSource, viaParameterFinder)
|
||||
|
@ -41,7 +41,6 @@ import org.matrix.android.sdk.internal.session.room.timeline.DefaultTimelineServ
|
||||
import org.matrix.android.sdk.internal.session.room.typing.DefaultTypingService
|
||||
import org.matrix.android.sdk.internal.session.room.uploads.DefaultUploadsService
|
||||
import org.matrix.android.sdk.internal.session.room.version.DefaultRoomVersionService
|
||||
import org.matrix.android.sdk.internal.session.search.SearchTask
|
||||
import javax.inject.Inject
|
||||
|
||||
internal interface RoomFactory {
|
||||
@ -71,7 +70,6 @@ internal class DefaultRoomFactory @Inject constructor(private val cryptoService:
|
||||
private val roomAccountDataServiceFactory: DefaultRoomAccountDataService.Factory,
|
||||
private val sendStateTask: SendStateTask,
|
||||
private val viaParameterFinder: ViaParameterFinder,
|
||||
private val searchTask: SearchTask,
|
||||
private val coroutineDispatchers: MatrixCoroutineDispatchers) :
|
||||
RoomFactory {
|
||||
|
||||
@ -99,7 +97,6 @@ internal class DefaultRoomFactory @Inject constructor(private val cryptoService:
|
||||
roomAccountDataService = roomAccountDataServiceFactory.create(roomId),
|
||||
roomVersionService = roomVersionServiceFactory.create(roomId),
|
||||
sendStateTask = sendStateTask,
|
||||
searchTask = searchTask,
|
||||
viaParameterFinder = viaParameterFinder,
|
||||
coroutineDispatchers = coroutineDispatchers
|
||||
)
|
||||
|
@ -35,7 +35,7 @@ import org.matrix.android.sdk.api.session.search.SearchResult
|
||||
|
||||
class SearchViewModel @AssistedInject constructor(
|
||||
@Assisted private val initialState: SearchViewState,
|
||||
session: Session
|
||||
private val session: Session
|
||||
) : VectorViewModel<SearchViewState, SearchAction, SearchViewEvents>(initialState) {
|
||||
|
||||
private val room = session.getRoom(initialState.roomId)
|
||||
@ -101,8 +101,9 @@ class SearchViewModel @AssistedInject constructor(
|
||||
|
||||
currentTask = viewModelScope.launch {
|
||||
try {
|
||||
val result = room.search(
|
||||
val result = session.searchService().search(
|
||||
searchTerm = state.searchTerm,
|
||||
roomId = initialState.roomId,
|
||||
nextBatch = nextBatch,
|
||||
orderByRecent = true,
|
||||
beforeLimit = 0,
|
||||
|
Loading…
Reference in New Issue
Block a user