Create separate search module.

This commit is contained in:
Onuray Sahin 2020-09-28 18:51:30 +03:00 committed by Benoit Marty
parent 70be853acd
commit 430a0d2492
6 changed files with 85 additions and 24 deletions

View File

@ -50,6 +50,7 @@ import org.matrix.android.sdk.internal.session.room.send.EncryptEventWorker
import org.matrix.android.sdk.internal.session.room.send.MultipleEventSendingDispatcherWorker
import org.matrix.android.sdk.internal.session.room.send.RedactEventWorker
import org.matrix.android.sdk.internal.session.room.send.SendEventWorker
import org.matrix.android.sdk.internal.session.search.SearchModule
import org.matrix.android.sdk.internal.session.signout.SignOutModule
import org.matrix.android.sdk.internal.session.sync.SyncModule
import org.matrix.android.sdk.internal.session.sync.SyncTask
@ -86,7 +87,8 @@ import org.matrix.android.sdk.internal.util.MatrixCoroutineDispatchers
ProfileModule::class,
SessionAssistedInjectModule::class,
AccountModule::class,
CallModule::class
CallModule::class,
SearchModule::class
]
)
@SessionScope

View File

@ -39,7 +39,6 @@ import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.accountdata.AccountDataService
import org.matrix.android.sdk.api.session.homeserver.HomeServerCapabilitiesService
import org.matrix.android.sdk.api.session.permalinks.PermalinkService
import org.matrix.android.sdk.api.session.search.SearchService
import org.matrix.android.sdk.api.session.securestorage.SecureStorageService
import org.matrix.android.sdk.api.session.securestorage.SharedSecretStorageService
import org.matrix.android.sdk.api.session.typing.TypingUsersTracker
@ -82,10 +81,7 @@ import org.matrix.android.sdk.internal.session.permalinks.DefaultPermalinkServic
import org.matrix.android.sdk.internal.session.room.EventRelationsAggregationProcessor
import org.matrix.android.sdk.internal.session.room.create.RoomCreateEventProcessor
import org.matrix.android.sdk.internal.session.room.prune.RedactionEventProcessor
import org.matrix.android.sdk.internal.session.search.DefaultSearchService
import org.matrix.android.sdk.internal.session.room.tombstone.RoomTombstoneEventProcessor
import org.matrix.android.sdk.internal.session.search.DefaultSearchTask
import org.matrix.android.sdk.internal.session.search.SearchTask
import org.matrix.android.sdk.internal.session.securestorage.DefaultSecureStorageService
import org.matrix.android.sdk.internal.session.typing.DefaultTypingUsersTracker
import org.matrix.android.sdk.internal.session.user.accountdata.DefaultAccountDataService
@ -372,10 +368,4 @@ internal abstract class SessionModule {
@Binds
abstract fun bindTypingUsersTracker(tracker: DefaultTypingUsersTracker): TypingUsersTracker
@Binds
abstract fun bindSearchService(service: DefaultSearchService): SearchService
@Binds
abstract fun bindSearchTask(task: DefaultSearchTask): SearchTask
}

View File

@ -35,13 +35,11 @@ import org.matrix.android.sdk.internal.session.room.membership.joining.InviteBod
import org.matrix.android.sdk.internal.session.room.membership.threepid.ThreePidInviteBody
import org.matrix.android.sdk.internal.session.room.relation.RelationsResponse
import org.matrix.android.sdk.internal.session.room.reporting.ReportContentBody
import org.matrix.android.sdk.internal.session.search.request.SearchRequestBody
import org.matrix.android.sdk.internal.session.room.send.SendResponse
import org.matrix.android.sdk.internal.session.room.tags.TagBody
import org.matrix.android.sdk.internal.session.room.timeline.EventContextResponse
import org.matrix.android.sdk.internal.session.room.timeline.PaginationResponse
import org.matrix.android.sdk.internal.session.room.typing.TypingBody
import org.matrix.android.sdk.internal.session.search.response.SearchResponse
import retrofit2.Call
import retrofit2.http.Body
import retrofit2.http.DELETE
@ -367,12 +365,4 @@ internal interface RoomAPI {
fun deleteTag(@Path("userId") userId: String,
@Path("roomId") roomId: String,
@Path("tag") tag: String): Call<Unit>
/**
* Performs a full text search across different categories.
*/
@POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "search")
fun search(
@Query("next_batch") nextBatch: String?,
@Body body: SearchRequestBody): Call<SearchResponse>
}

View File

@ -0,0 +1,36 @@
/*
* Copyright (c) 2020 New Vector Ltd
*
* 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.search
import org.matrix.android.sdk.internal.network.NetworkConstants
import org.matrix.android.sdk.internal.session.search.request.SearchRequestBody
import org.matrix.android.sdk.internal.session.search.response.SearchResponse
import retrofit2.Call
import retrofit2.http.Body
import retrofit2.http.POST
import retrofit2.http.Query
internal interface SearchAPI {
/**
* Performs a full text search across different categories.
*/
@POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "search")
fun search(
@Query("next_batch") nextBatch: String?,
@Body body: SearchRequestBody): Call<SearchResponse>
}

View File

@ -0,0 +1,44 @@
/*
* Copyright (c) 2020 New Vector Ltd
*
* 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.search
import dagger.Binds
import dagger.Module
import dagger.Provides
import org.matrix.android.sdk.api.session.search.SearchService
import org.matrix.android.sdk.internal.session.SessionScope
import retrofit2.Retrofit
@Module
internal abstract class SearchModule {
@Module
companion object {
@Provides
@JvmStatic
@SessionScope
fun providesSearchAPI(retrofit: Retrofit): SearchAPI {
return retrofit.create(SearchAPI::class.java)
}
}
@Binds
abstract fun bindSearchService(service: DefaultSearchService): SearchService
@Binds
abstract fun bindSearchTask(task: DefaultSearchTask): SearchTask
}

View File

@ -20,7 +20,6 @@ package org.matrix.android.sdk.internal.session.search
import org.greenrobot.eventbus.EventBus
import org.matrix.android.sdk.api.session.search.SearchResult
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.session.room.RoomAPI
import org.matrix.android.sdk.internal.session.search.request.SearchRequestBody
import org.matrix.android.sdk.internal.session.search.request.SearchRequestCategories
import org.matrix.android.sdk.internal.session.search.request.SearchRequestEventContext
@ -46,7 +45,7 @@ internal interface SearchTask : Task<SearchTask.Params, SearchResult> {
}
internal class DefaultSearchTask @Inject constructor(
private val roomAPI: RoomAPI,
private val searchAPI: SearchAPI,
private val eventBus: EventBus
) : SearchTask {
@ -69,7 +68,7 @@ internal class DefaultSearchTask @Inject constructor(
)
)
)
apiCall = roomAPI.search(params.nextBatch, searchRequestBody)
apiCall = searchAPI.search(params.nextBatch, searchRequestBody)
}.toDomain().apply { results = results?.reversed() }
}