mirror of
https://github.com/element-hq/element-android
synced 2024-11-24 02:15:35 +03:00
SearchTask implementation.
This commit is contained in:
parent
051b431f1d
commit
b521f36569
3 changed files with 83 additions and 1 deletions
|
@ -61,6 +61,8 @@ import org.matrix.android.sdk.internal.session.room.relation.FindReactionEventFo
|
|||
import org.matrix.android.sdk.internal.session.room.relation.UpdateQuickReactionTask
|
||||
import org.matrix.android.sdk.internal.session.room.reporting.DefaultReportContentTask
|
||||
import org.matrix.android.sdk.internal.session.room.reporting.ReportContentTask
|
||||
import org.matrix.android.sdk.internal.session.room.search.DefaultSearchTask
|
||||
import org.matrix.android.sdk.internal.session.room.search.SearchTask
|
||||
import org.matrix.android.sdk.internal.session.room.state.DefaultSendStateTask
|
||||
import org.matrix.android.sdk.internal.session.room.state.SendStateTask
|
||||
import org.matrix.android.sdk.internal.session.room.tags.AddTagToRoomTask
|
||||
|
@ -195,4 +197,7 @@ internal abstract class RoomModule {
|
|||
|
||||
@Binds
|
||||
abstract fun bindDeleteTagFromRoomTask(task: DefaultDeleteTagFromRoomTask): DeleteTagFromRoomTask
|
||||
|
||||
@Binds
|
||||
abstract fun bindSearchTask(task: DefaultSearchTask): SearchTask
|
||||
}
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* Copyright 2020 New Vector Ltd
|
||||
* Copyright 2020 The Matrix.org Foundation C.I.C.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.matrix.android.sdk.internal.session.room.search
|
||||
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import org.matrix.android.sdk.internal.network.executeRequest
|
||||
import org.matrix.android.sdk.internal.session.room.RoomAPI
|
||||
import org.matrix.android.sdk.internal.session.room.search.request.SearchRequestBody
|
||||
import org.matrix.android.sdk.internal.session.room.search.request.SearchRequestCategories
|
||||
import org.matrix.android.sdk.internal.session.room.search.request.SearchRequestEventContext
|
||||
import org.matrix.android.sdk.internal.session.room.search.request.SearchRequestFilter
|
||||
import org.matrix.android.sdk.internal.session.room.search.request.SearchRequestOrder
|
||||
import org.matrix.android.sdk.internal.session.room.search.request.SearchRequestRoomEvents
|
||||
import org.matrix.android.sdk.internal.session.room.search.response.SearchResponse
|
||||
import org.matrix.android.sdk.internal.task.Task
|
||||
import javax.inject.Inject
|
||||
|
||||
internal interface SearchTask : Task<SearchTask.Params, SearchResponse> {
|
||||
|
||||
data class Params(
|
||||
val searchTerm: String,
|
||||
val rooms: List<String>,
|
||||
val nextBatch: String? = null,
|
||||
val orderByRecent: Boolean,
|
||||
val limit: Int,
|
||||
val beforeLimit: Int,
|
||||
val afterLimit: Int,
|
||||
val includeProfile: Boolean
|
||||
)
|
||||
}
|
||||
|
||||
internal class DefaultSearchTask @Inject constructor(
|
||||
private val roomAPI: RoomAPI,
|
||||
private val eventBus: EventBus
|
||||
) : SearchTask {
|
||||
|
||||
override suspend fun execute(params: SearchTask.Params): SearchResponse {
|
||||
return executeRequest(eventBus) {
|
||||
val searchRequestBody = SearchRequestBody(
|
||||
searchCategories = SearchRequestCategories(
|
||||
roomEvents = SearchRequestRoomEvents(
|
||||
searchTerm = params.searchTerm,
|
||||
orderBy = if (params.orderByRecent) SearchRequestOrder.RECENT else SearchRequestOrder.RANK,
|
||||
filter = SearchRequestFilter(
|
||||
limit = params.limit,
|
||||
rooms = params.rooms
|
||||
),
|
||||
eventContext = SearchRequestEventContext(
|
||||
beforeLimit = params.beforeLimit,
|
||||
afterLimit = params.afterLimit,
|
||||
includeProfile = params.includeProfile
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
apiCall = roomAPI.search(params.nextBatch, searchRequestBody)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -29,5 +29,8 @@ class SearchResponseRoomEvents(
|
|||
val count: Int? = null,
|
||||
// List of words which should be highlighted, useful for stemming which may change the query terms.
|
||||
@Json(name = "highlights")
|
||||
val highlights: List<String>? = null
|
||||
val highlights: List<String>? = null,
|
||||
// Token that can be used to get the next batch of results, by passing as the next_batch parameter to the next call. If this field is absent, there are no more results.
|
||||
@Json(name = "next_batch")
|
||||
val nextBatch: String? = null
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue