mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-21 12:39:58 +01:00
Message search: avoid passing user entity to repository, inject userProvider instead
Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
This commit is contained in:
parent
c10c45630c
commit
eddb90d31b
@ -213,7 +213,6 @@ class NextcloudTalkApplication : MultiDexApplication(), LifecycleObserver {
|
||||
.contextModule(ContextModule(applicationContext))
|
||||
.databaseModule(DatabaseModule())
|
||||
.restModule(RestModule(applicationContext))
|
||||
.userModule(UserModule())
|
||||
.arbitraryStorageModule(ArbitraryStorageModule())
|
||||
.build()
|
||||
}
|
||||
|
@ -2547,7 +2547,6 @@ class ChatController(args: Bundle) :
|
||||
val intent = Intent(activity, MessageSearchActivity::class.java)
|
||||
intent.putExtra(KEY_CONVERSATION_NAME, currentConversation?.displayName)
|
||||
intent.putExtra(KEY_ROOM_TOKEN, roomToken)
|
||||
intent.putExtra(KEY_USER_ENTITY, conversationUser as Parcelable)
|
||||
startActivityForResult(intent, REQUEST_CODE_MESSAGE_SEARCH)
|
||||
}
|
||||
|
||||
|
@ -326,7 +326,7 @@ public class ConversationsListController extends BaseController implements Flexi
|
||||
return;
|
||||
}
|
||||
|
||||
searchHelper = new MessageSearchHelper(currentUser, unifiedSearchRepository);
|
||||
searchHelper = new MessageSearchHelper(unifiedSearchRepository);
|
||||
|
||||
credentials = ApiUtils.getCredentials(currentUser.getUsername(), currentUser.getToken());
|
||||
if (getActivity() != null && getActivity() instanceof MainActivity) {
|
||||
|
@ -26,6 +26,7 @@ import com.nextcloud.talk.repositories.unifiedsearch.UnifiedSearchRepository
|
||||
import com.nextcloud.talk.repositories.unifiedsearch.UnifiedSearchRepositoryImpl
|
||||
import com.nextcloud.talk.shareditems.repositories.SharedItemsRepository
|
||||
import com.nextcloud.talk.shareditems.repositories.SharedItemsRepositoryImpl
|
||||
import com.nextcloud.talk.utils.database.user.CurrentUserProvider
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
|
||||
@ -37,7 +38,7 @@ class RepositoryModule {
|
||||
}
|
||||
|
||||
@Provides
|
||||
fun provideUnifiedSearchRepository(ncApi: NcApi): UnifiedSearchRepository {
|
||||
return UnifiedSearchRepositoryImpl(ncApi)
|
||||
fun provideUnifiedSearchRepository(ncApi: NcApi, userProvider: CurrentUserProvider): UnifiedSearchRepository {
|
||||
return UnifiedSearchRepositoryImpl(ncApi, userProvider)
|
||||
}
|
||||
}
|
||||
|
@ -43,6 +43,7 @@ import com.nextcloud.talk.databinding.ActivityMessageSearchBinding
|
||||
import com.nextcloud.talk.models.database.UserEntity
|
||||
import com.nextcloud.talk.utils.DisplayUtils
|
||||
import com.nextcloud.talk.utils.bundle.BundleKeys
|
||||
import com.nextcloud.talk.utils.database.user.CurrentUserProvider
|
||||
import com.nextcloud.talk.utils.rx.SearchViewObservable.Companion.observeSearchView
|
||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
|
||||
@ -60,6 +61,9 @@ class MessageSearchActivity : BaseActivity() {
|
||||
@Inject
|
||||
lateinit var viewModelFactory: ViewModelProvider.Factory
|
||||
|
||||
@Inject
|
||||
lateinit var userProvider: CurrentUserProvider
|
||||
|
||||
private lateinit var binding: ActivityMessageSearchBinding
|
||||
private lateinit var searchView: SearchView
|
||||
|
||||
@ -80,9 +84,9 @@ class MessageSearchActivity : BaseActivity() {
|
||||
setContentView(binding.root)
|
||||
|
||||
viewModel = ViewModelProvider(this, viewModelFactory)[MessageSearchViewModel::class.java]
|
||||
user = intent.getParcelableExtra(BundleKeys.KEY_USER_ENTITY)!!
|
||||
user = userProvider.currentUser!!
|
||||
val roomToken = intent.getStringExtra(BundleKeys.KEY_ROOM_TOKEN)!!
|
||||
viewModel.initialize(user, roomToken)
|
||||
viewModel.initialize(roomToken)
|
||||
setupStateObserver()
|
||||
|
||||
binding.swipeRefreshLayout.setOnRefreshListener {
|
||||
|
@ -22,14 +22,12 @@
|
||||
package com.nextcloud.talk.messagesearch
|
||||
|
||||
import android.util.Log
|
||||
import com.nextcloud.talk.models.database.UserEntity
|
||||
import com.nextcloud.talk.models.domain.SearchMessageEntry
|
||||
import com.nextcloud.talk.repositories.unifiedsearch.UnifiedSearchRepository
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.disposables.Disposable
|
||||
|
||||
class MessageSearchHelper @JvmOverloads constructor(
|
||||
private val user: UserEntity,
|
||||
private val unifiedSearchRepository: UnifiedSearchRepository,
|
||||
private val fromRoom: String? = null
|
||||
) {
|
||||
@ -84,7 +82,6 @@ class MessageSearchHelper @JvmOverloads constructor(
|
||||
return when {
|
||||
fromRoom != null -> {
|
||||
unifiedSearchRepository.searchInRoom(
|
||||
userEntity = user,
|
||||
roomToken = fromRoom,
|
||||
searchTerm = search,
|
||||
cursor = cursor
|
||||
@ -92,7 +89,6 @@ class MessageSearchHelper @JvmOverloads constructor(
|
||||
}
|
||||
else -> {
|
||||
unifiedSearchRepository.searchMessages(
|
||||
userEntity = user,
|
||||
searchTerm = search,
|
||||
cursor = cursor
|
||||
)
|
||||
|
@ -26,11 +26,9 @@ import android.util.Log
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.nextcloud.talk.models.database.UserEntity
|
||||
import com.nextcloud.talk.models.domain.SearchMessageEntry
|
||||
import com.nextcloud.talk.repositories.unifiedsearch.UnifiedSearchRepository
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.disposables.Disposable
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import javax.inject.Inject
|
||||
|
||||
@ -66,10 +64,8 @@ class MessageSearchViewModel @Inject constructor(private val unifiedSearchReposi
|
||||
val state: LiveData<ViewState>
|
||||
get() = _state
|
||||
|
||||
private var searchDisposable: Disposable? = null
|
||||
|
||||
fun initialize(user: UserEntity, roomToken: String) {
|
||||
messageSearchHelper = MessageSearchHelper(user, unifiedSearchRepository, roomToken)
|
||||
fun initialize(roomToken: String) {
|
||||
messageSearchHelper = MessageSearchHelper(unifiedSearchRepository, roomToken)
|
||||
}
|
||||
|
||||
@SuppressLint("CheckResult") // handled by helper
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.nextcloud.talk.repositories.unifiedsearch
|
||||
|
||||
import com.nextcloud.talk.models.database.UserEntity
|
||||
import com.nextcloud.talk.models.domain.SearchMessageEntry
|
||||
import io.reactivex.Observable
|
||||
|
||||
@ -12,14 +11,12 @@ interface UnifiedSearchRepository {
|
||||
)
|
||||
|
||||
fun searchMessages(
|
||||
userEntity: UserEntity,
|
||||
searchTerm: String,
|
||||
cursor: Int = 0,
|
||||
limit: Int = DEFAULT_PAGE_SIZE
|
||||
): Observable<UnifiedSearchResults<SearchMessageEntry>>
|
||||
|
||||
fun searchInRoom(
|
||||
userEntity: UserEntity,
|
||||
roomToken: String,
|
||||
searchTerm: String,
|
||||
cursor: Int = 0,
|
||||
|
@ -27,18 +27,25 @@ import com.nextcloud.talk.models.domain.SearchMessageEntry
|
||||
import com.nextcloud.talk.models.json.unifiedsearch.UnifiedSearchEntry
|
||||
import com.nextcloud.talk.models.json.unifiedsearch.UnifiedSearchResponseData
|
||||
import com.nextcloud.talk.utils.ApiUtils
|
||||
import com.nextcloud.talk.utils.database.user.CurrentUserProvider
|
||||
import io.reactivex.Observable
|
||||
|
||||
class UnifiedSearchRepositoryImpl(private val api: NcApi) : UnifiedSearchRepository {
|
||||
class UnifiedSearchRepositoryImpl(private val api: NcApi, private val userProvider: CurrentUserProvider) :
|
||||
UnifiedSearchRepository {
|
||||
|
||||
private val userEntity: UserEntity
|
||||
get() = userProvider.currentUser!!
|
||||
|
||||
private val credentials: String
|
||||
get() = ApiUtils.getCredentials(userEntity.username, userEntity.token)
|
||||
|
||||
override fun searchMessages(
|
||||
userEntity: UserEntity,
|
||||
searchTerm: String,
|
||||
cursor: Int,
|
||||
limit: Int
|
||||
): Observable<UnifiedSearchRepository.UnifiedSearchResults<SearchMessageEntry>> {
|
||||
val apiObservable = api.performUnifiedSearch(
|
||||
ApiUtils.getCredentials(userEntity.username, userEntity.token),
|
||||
credentials,
|
||||
ApiUtils.getUrlForUnifiedSearch(userEntity.baseUrl, PROVIDER_TALK_MESSAGE),
|
||||
searchTerm,
|
||||
null,
|
||||
@ -49,14 +56,13 @@ class UnifiedSearchRepositoryImpl(private val api: NcApi) : UnifiedSearchReposit
|
||||
}
|
||||
|
||||
override fun searchInRoom(
|
||||
userEntity: UserEntity,
|
||||
roomToken: String,
|
||||
searchTerm: String,
|
||||
cursor: Int,
|
||||
limit: Int
|
||||
): Observable<UnifiedSearchRepository.UnifiedSearchResults<SearchMessageEntry>> {
|
||||
val apiObservable = api.performUnifiedSearch(
|
||||
ApiUtils.getCredentials(userEntity.username, userEntity.token),
|
||||
credentials,
|
||||
ApiUtils.getUrlForUnifiedSearch(userEntity.baseUrl, PROVIDER_TALK_MESSAGE_CURRENT),
|
||||
searchTerm,
|
||||
fromUrlForRoom(roomToken),
|
||||
|
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Nextcloud Talk application
|
||||
*
|
||||
* @author Álvaro Brey
|
||||
* Copyright (C) 2022 Álvaro Brey
|
||||
* Copyright (C) 2022 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.nextcloud.talk.utils.database.user
|
||||
|
||||
import com.nextcloud.talk.models.database.UserEntity
|
||||
|
||||
interface CurrentUserProvider {
|
||||
val currentUser: UserEntity?
|
||||
}
|
@ -17,28 +17,25 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.nextcloud.talk.utils.database.user;
|
||||
package com.nextcloud.talk.utils.database.user
|
||||
|
||||
import autodagger.AutoInjector;
|
||||
import com.nextcloud.talk.application.NextcloudTalkApplication;
|
||||
import com.nextcloud.talk.dagger.modules.DatabaseModule;
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import io.requery.Persistable;
|
||||
import io.requery.reactivex.ReactiveEntityStore;
|
||||
import com.nextcloud.talk.dagger.modules.DatabaseModule
|
||||
import dagger.Binds
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import io.requery.Persistable
|
||||
import io.requery.reactivex.ReactiveEntityStore
|
||||
|
||||
import javax.inject.Inject;
|
||||
@Module(includes = [DatabaseModule::class])
|
||||
abstract class UserModule {
|
||||
|
||||
@Module(includes = DatabaseModule.class)
|
||||
@AutoInjector(NextcloudTalkApplication.class)
|
||||
public class UserModule {
|
||||
@Binds
|
||||
abstract fun bindCurrentUserProvider(userUtils: UserUtils): CurrentUserProvider
|
||||
|
||||
@Inject
|
||||
public UserModule() {
|
||||
}
|
||||
|
||||
@Provides
|
||||
public UserUtils provideUserUtils(ReactiveEntityStore<Persistable> dataStore) {
|
||||
return new UserUtils(dataStore);
|
||||
companion object {
|
||||
@Provides
|
||||
fun provideUserUtils(dataStore: ReactiveEntityStore<Persistable?>?): UserUtils {
|
||||
return UserUtils(dataStore)
|
||||
}
|
||||
}
|
||||
}
|
@ -36,7 +36,7 @@ import io.requery.Persistable;
|
||||
import io.requery.query.Result;
|
||||
import io.requery.reactivex.ReactiveEntityStore;
|
||||
|
||||
public class UserUtils {
|
||||
public class UserUtils implements CurrentUserProvider {
|
||||
private ReactiveEntityStore<Persistable> dataStore;
|
||||
|
||||
UserUtils(ReactiveEntityStore<Persistable> dataStore) {
|
||||
@ -83,6 +83,7 @@ public class UserUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable UserEntity getCurrentUser() {
|
||||
Result findUserQueryResult = dataStore.select(User.class).where(UserEntity.CURRENT.eq(Boolean.TRUE)
|
||||
.and(UserEntity.SCHEDULED_FOR_DELETION.notEqual(Boolean.TRUE)))
|
||||
|
@ -21,7 +21,6 @@
|
||||
|
||||
package com.nextcloud.talk.test.fakes
|
||||
|
||||
import com.nextcloud.talk.models.database.UserEntity
|
||||
import com.nextcloud.talk.models.domain.SearchMessageEntry
|
||||
import com.nextcloud.talk.repositories.unifiedsearch.UnifiedSearchRepository
|
||||
import io.reactivex.Observable
|
||||
@ -32,7 +31,6 @@ class FakeUnifiedSearchRepository : UnifiedSearchRepository {
|
||||
var lastRequestedCursor = -1
|
||||
|
||||
override fun searchMessages(
|
||||
userEntity: UserEntity,
|
||||
searchTerm: String,
|
||||
cursor: Int,
|
||||
limit: Int
|
||||
@ -42,7 +40,6 @@ class FakeUnifiedSearchRepository : UnifiedSearchRepository {
|
||||
}
|
||||
|
||||
override fun searchInRoom(
|
||||
userEntity: UserEntity,
|
||||
roomToken: String,
|
||||
searchTerm: String,
|
||||
cursor: Int,
|
||||
|
Loading…
Reference in New Issue
Block a user