mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-22 13:09:46 +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))
|
.contextModule(ContextModule(applicationContext))
|
||||||
.databaseModule(DatabaseModule())
|
.databaseModule(DatabaseModule())
|
||||||
.restModule(RestModule(applicationContext))
|
.restModule(RestModule(applicationContext))
|
||||||
.userModule(UserModule())
|
|
||||||
.arbitraryStorageModule(ArbitraryStorageModule())
|
.arbitraryStorageModule(ArbitraryStorageModule())
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
@ -2547,7 +2547,6 @@ class ChatController(args: Bundle) :
|
|||||||
val intent = Intent(activity, MessageSearchActivity::class.java)
|
val intent = Intent(activity, MessageSearchActivity::class.java)
|
||||||
intent.putExtra(KEY_CONVERSATION_NAME, currentConversation?.displayName)
|
intent.putExtra(KEY_CONVERSATION_NAME, currentConversation?.displayName)
|
||||||
intent.putExtra(KEY_ROOM_TOKEN, roomToken)
|
intent.putExtra(KEY_ROOM_TOKEN, roomToken)
|
||||||
intent.putExtra(KEY_USER_ENTITY, conversationUser as Parcelable)
|
|
||||||
startActivityForResult(intent, REQUEST_CODE_MESSAGE_SEARCH)
|
startActivityForResult(intent, REQUEST_CODE_MESSAGE_SEARCH)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -326,7 +326,7 @@ public class ConversationsListController extends BaseController implements Flexi
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
searchHelper = new MessageSearchHelper(currentUser, unifiedSearchRepository);
|
searchHelper = new MessageSearchHelper(unifiedSearchRepository);
|
||||||
|
|
||||||
credentials = ApiUtils.getCredentials(currentUser.getUsername(), currentUser.getToken());
|
credentials = ApiUtils.getCredentials(currentUser.getUsername(), currentUser.getToken());
|
||||||
if (getActivity() != null && getActivity() instanceof MainActivity) {
|
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.repositories.unifiedsearch.UnifiedSearchRepositoryImpl
|
||||||
import com.nextcloud.talk.shareditems.repositories.SharedItemsRepository
|
import com.nextcloud.talk.shareditems.repositories.SharedItemsRepository
|
||||||
import com.nextcloud.talk.shareditems.repositories.SharedItemsRepositoryImpl
|
import com.nextcloud.talk.shareditems.repositories.SharedItemsRepositoryImpl
|
||||||
|
import com.nextcloud.talk.utils.database.user.CurrentUserProvider
|
||||||
import dagger.Module
|
import dagger.Module
|
||||||
import dagger.Provides
|
import dagger.Provides
|
||||||
|
|
||||||
@ -37,7 +38,7 @@ class RepositoryModule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
fun provideUnifiedSearchRepository(ncApi: NcApi): UnifiedSearchRepository {
|
fun provideUnifiedSearchRepository(ncApi: NcApi, userProvider: CurrentUserProvider): UnifiedSearchRepository {
|
||||||
return UnifiedSearchRepositoryImpl(ncApi)
|
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.models.database.UserEntity
|
||||||
import com.nextcloud.talk.utils.DisplayUtils
|
import com.nextcloud.talk.utils.DisplayUtils
|
||||||
import com.nextcloud.talk.utils.bundle.BundleKeys
|
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 com.nextcloud.talk.utils.rx.SearchViewObservable.Companion.observeSearchView
|
||||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||||
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
|
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
|
||||||
@ -60,6 +61,9 @@ class MessageSearchActivity : BaseActivity() {
|
|||||||
@Inject
|
@Inject
|
||||||
lateinit var viewModelFactory: ViewModelProvider.Factory
|
lateinit var viewModelFactory: ViewModelProvider.Factory
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var userProvider: CurrentUserProvider
|
||||||
|
|
||||||
private lateinit var binding: ActivityMessageSearchBinding
|
private lateinit var binding: ActivityMessageSearchBinding
|
||||||
private lateinit var searchView: SearchView
|
private lateinit var searchView: SearchView
|
||||||
|
|
||||||
@ -80,9 +84,9 @@ class MessageSearchActivity : BaseActivity() {
|
|||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
|
|
||||||
viewModel = ViewModelProvider(this, viewModelFactory)[MessageSearchViewModel::class.java]
|
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)!!
|
val roomToken = intent.getStringExtra(BundleKeys.KEY_ROOM_TOKEN)!!
|
||||||
viewModel.initialize(user, roomToken)
|
viewModel.initialize(roomToken)
|
||||||
setupStateObserver()
|
setupStateObserver()
|
||||||
|
|
||||||
binding.swipeRefreshLayout.setOnRefreshListener {
|
binding.swipeRefreshLayout.setOnRefreshListener {
|
||||||
|
@ -22,14 +22,12 @@
|
|||||||
package com.nextcloud.talk.messagesearch
|
package com.nextcloud.talk.messagesearch
|
||||||
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import com.nextcloud.talk.models.database.UserEntity
|
|
||||||
import com.nextcloud.talk.models.domain.SearchMessageEntry
|
import com.nextcloud.talk.models.domain.SearchMessageEntry
|
||||||
import com.nextcloud.talk.repositories.unifiedsearch.UnifiedSearchRepository
|
import com.nextcloud.talk.repositories.unifiedsearch.UnifiedSearchRepository
|
||||||
import io.reactivex.Observable
|
import io.reactivex.Observable
|
||||||
import io.reactivex.disposables.Disposable
|
import io.reactivex.disposables.Disposable
|
||||||
|
|
||||||
class MessageSearchHelper @JvmOverloads constructor(
|
class MessageSearchHelper @JvmOverloads constructor(
|
||||||
private val user: UserEntity,
|
|
||||||
private val unifiedSearchRepository: UnifiedSearchRepository,
|
private val unifiedSearchRepository: UnifiedSearchRepository,
|
||||||
private val fromRoom: String? = null
|
private val fromRoom: String? = null
|
||||||
) {
|
) {
|
||||||
@ -84,7 +82,6 @@ class MessageSearchHelper @JvmOverloads constructor(
|
|||||||
return when {
|
return when {
|
||||||
fromRoom != null -> {
|
fromRoom != null -> {
|
||||||
unifiedSearchRepository.searchInRoom(
|
unifiedSearchRepository.searchInRoom(
|
||||||
userEntity = user,
|
|
||||||
roomToken = fromRoom,
|
roomToken = fromRoom,
|
||||||
searchTerm = search,
|
searchTerm = search,
|
||||||
cursor = cursor
|
cursor = cursor
|
||||||
@ -92,7 +89,6 @@ class MessageSearchHelper @JvmOverloads constructor(
|
|||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
unifiedSearchRepository.searchMessages(
|
unifiedSearchRepository.searchMessages(
|
||||||
userEntity = user,
|
|
||||||
searchTerm = search,
|
searchTerm = search,
|
||||||
cursor = cursor
|
cursor = cursor
|
||||||
)
|
)
|
||||||
|
@ -26,11 +26,9 @@ import android.util.Log
|
|||||||
import androidx.lifecycle.LiveData
|
import androidx.lifecycle.LiveData
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import com.nextcloud.talk.models.database.UserEntity
|
|
||||||
import com.nextcloud.talk.models.domain.SearchMessageEntry
|
import com.nextcloud.talk.models.domain.SearchMessageEntry
|
||||||
import com.nextcloud.talk.repositories.unifiedsearch.UnifiedSearchRepository
|
import com.nextcloud.talk.repositories.unifiedsearch.UnifiedSearchRepository
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||||
import io.reactivex.disposables.Disposable
|
|
||||||
import io.reactivex.schedulers.Schedulers
|
import io.reactivex.schedulers.Schedulers
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@ -66,10 +64,8 @@ class MessageSearchViewModel @Inject constructor(private val unifiedSearchReposi
|
|||||||
val state: LiveData<ViewState>
|
val state: LiveData<ViewState>
|
||||||
get() = _state
|
get() = _state
|
||||||
|
|
||||||
private var searchDisposable: Disposable? = null
|
fun initialize(roomToken: String) {
|
||||||
|
messageSearchHelper = MessageSearchHelper(unifiedSearchRepository, roomToken)
|
||||||
fun initialize(user: UserEntity, roomToken: String) {
|
|
||||||
messageSearchHelper = MessageSearchHelper(user, unifiedSearchRepository, roomToken)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("CheckResult") // handled by helper
|
@SuppressLint("CheckResult") // handled by helper
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.nextcloud.talk.repositories.unifiedsearch
|
package com.nextcloud.talk.repositories.unifiedsearch
|
||||||
|
|
||||||
import com.nextcloud.talk.models.database.UserEntity
|
|
||||||
import com.nextcloud.talk.models.domain.SearchMessageEntry
|
import com.nextcloud.talk.models.domain.SearchMessageEntry
|
||||||
import io.reactivex.Observable
|
import io.reactivex.Observable
|
||||||
|
|
||||||
@ -12,14 +11,12 @@ interface UnifiedSearchRepository {
|
|||||||
)
|
)
|
||||||
|
|
||||||
fun searchMessages(
|
fun searchMessages(
|
||||||
userEntity: UserEntity,
|
|
||||||
searchTerm: String,
|
searchTerm: String,
|
||||||
cursor: Int = 0,
|
cursor: Int = 0,
|
||||||
limit: Int = DEFAULT_PAGE_SIZE
|
limit: Int = DEFAULT_PAGE_SIZE
|
||||||
): Observable<UnifiedSearchResults<SearchMessageEntry>>
|
): Observable<UnifiedSearchResults<SearchMessageEntry>>
|
||||||
|
|
||||||
fun searchInRoom(
|
fun searchInRoom(
|
||||||
userEntity: UserEntity,
|
|
||||||
roomToken: String,
|
roomToken: String,
|
||||||
searchTerm: String,
|
searchTerm: String,
|
||||||
cursor: Int = 0,
|
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.UnifiedSearchEntry
|
||||||
import com.nextcloud.talk.models.json.unifiedsearch.UnifiedSearchResponseData
|
import com.nextcloud.talk.models.json.unifiedsearch.UnifiedSearchResponseData
|
||||||
import com.nextcloud.talk.utils.ApiUtils
|
import com.nextcloud.talk.utils.ApiUtils
|
||||||
|
import com.nextcloud.talk.utils.database.user.CurrentUserProvider
|
||||||
import io.reactivex.Observable
|
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(
|
override fun searchMessages(
|
||||||
userEntity: UserEntity,
|
|
||||||
searchTerm: String,
|
searchTerm: String,
|
||||||
cursor: Int,
|
cursor: Int,
|
||||||
limit: Int
|
limit: Int
|
||||||
): Observable<UnifiedSearchRepository.UnifiedSearchResults<SearchMessageEntry>> {
|
): Observable<UnifiedSearchRepository.UnifiedSearchResults<SearchMessageEntry>> {
|
||||||
val apiObservable = api.performUnifiedSearch(
|
val apiObservable = api.performUnifiedSearch(
|
||||||
ApiUtils.getCredentials(userEntity.username, userEntity.token),
|
credentials,
|
||||||
ApiUtils.getUrlForUnifiedSearch(userEntity.baseUrl, PROVIDER_TALK_MESSAGE),
|
ApiUtils.getUrlForUnifiedSearch(userEntity.baseUrl, PROVIDER_TALK_MESSAGE),
|
||||||
searchTerm,
|
searchTerm,
|
||||||
null,
|
null,
|
||||||
@ -49,14 +56,13 @@ class UnifiedSearchRepositoryImpl(private val api: NcApi) : UnifiedSearchReposit
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun searchInRoom(
|
override fun searchInRoom(
|
||||||
userEntity: UserEntity,
|
|
||||||
roomToken: String,
|
roomToken: String,
|
||||||
searchTerm: String,
|
searchTerm: String,
|
||||||
cursor: Int,
|
cursor: Int,
|
||||||
limit: Int
|
limit: Int
|
||||||
): Observable<UnifiedSearchRepository.UnifiedSearchResults<SearchMessageEntry>> {
|
): Observable<UnifiedSearchRepository.UnifiedSearchResults<SearchMessageEntry>> {
|
||||||
val apiObservable = api.performUnifiedSearch(
|
val apiObservable = api.performUnifiedSearch(
|
||||||
ApiUtils.getCredentials(userEntity.username, userEntity.token),
|
credentials,
|
||||||
ApiUtils.getUrlForUnifiedSearch(userEntity.baseUrl, PROVIDER_TALK_MESSAGE_CURRENT),
|
ApiUtils.getUrlForUnifiedSearch(userEntity.baseUrl, PROVIDER_TALK_MESSAGE_CURRENT),
|
||||||
searchTerm,
|
searchTerm,
|
||||||
fromUrlForRoom(roomToken),
|
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
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* 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.dagger.modules.DatabaseModule
|
||||||
import com.nextcloud.talk.application.NextcloudTalkApplication;
|
import dagger.Binds
|
||||||
import com.nextcloud.talk.dagger.modules.DatabaseModule;
|
import dagger.Module
|
||||||
import dagger.Module;
|
import dagger.Provides
|
||||||
import dagger.Provides;
|
import io.requery.Persistable
|
||||||
import io.requery.Persistable;
|
import io.requery.reactivex.ReactiveEntityStore
|
||||||
import io.requery.reactivex.ReactiveEntityStore;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
@Module(includes = [DatabaseModule::class])
|
||||||
|
abstract class UserModule {
|
||||||
|
|
||||||
@Module(includes = DatabaseModule.class)
|
@Binds
|
||||||
@AutoInjector(NextcloudTalkApplication.class)
|
abstract fun bindCurrentUserProvider(userUtils: UserUtils): CurrentUserProvider
|
||||||
public class UserModule {
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
public UserModule() {
|
|
||||||
}
|
|
||||||
|
|
||||||
|
companion object {
|
||||||
@Provides
|
@Provides
|
||||||
public UserUtils provideUserUtils(ReactiveEntityStore<Persistable> dataStore) {
|
fun provideUserUtils(dataStore: ReactiveEntityStore<Persistable?>?): UserUtils {
|
||||||
return new UserUtils(dataStore);
|
return UserUtils(dataStore)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -36,7 +36,7 @@ import io.requery.Persistable;
|
|||||||
import io.requery.query.Result;
|
import io.requery.query.Result;
|
||||||
import io.requery.reactivex.ReactiveEntityStore;
|
import io.requery.reactivex.ReactiveEntityStore;
|
||||||
|
|
||||||
public class UserUtils {
|
public class UserUtils implements CurrentUserProvider {
|
||||||
private ReactiveEntityStore<Persistable> dataStore;
|
private ReactiveEntityStore<Persistable> dataStore;
|
||||||
|
|
||||||
UserUtils(ReactiveEntityStore<Persistable> dataStore) {
|
UserUtils(ReactiveEntityStore<Persistable> dataStore) {
|
||||||
@ -83,6 +83,7 @@ public class UserUtils {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public @Nullable UserEntity getCurrentUser() {
|
public @Nullable UserEntity getCurrentUser() {
|
||||||
Result findUserQueryResult = dataStore.select(User.class).where(UserEntity.CURRENT.eq(Boolean.TRUE)
|
Result findUserQueryResult = dataStore.select(User.class).where(UserEntity.CURRENT.eq(Boolean.TRUE)
|
||||||
.and(UserEntity.SCHEDULED_FOR_DELETION.notEqual(Boolean.TRUE)))
|
.and(UserEntity.SCHEDULED_FOR_DELETION.notEqual(Boolean.TRUE)))
|
||||||
|
@ -21,7 +21,6 @@
|
|||||||
|
|
||||||
package com.nextcloud.talk.test.fakes
|
package com.nextcloud.talk.test.fakes
|
||||||
|
|
||||||
import com.nextcloud.talk.models.database.UserEntity
|
|
||||||
import com.nextcloud.talk.models.domain.SearchMessageEntry
|
import com.nextcloud.talk.models.domain.SearchMessageEntry
|
||||||
import com.nextcloud.talk.repositories.unifiedsearch.UnifiedSearchRepository
|
import com.nextcloud.talk.repositories.unifiedsearch.UnifiedSearchRepository
|
||||||
import io.reactivex.Observable
|
import io.reactivex.Observable
|
||||||
@ -32,7 +31,6 @@ class FakeUnifiedSearchRepository : UnifiedSearchRepository {
|
|||||||
var lastRequestedCursor = -1
|
var lastRequestedCursor = -1
|
||||||
|
|
||||||
override fun searchMessages(
|
override fun searchMessages(
|
||||||
userEntity: UserEntity,
|
|
||||||
searchTerm: String,
|
searchTerm: String,
|
||||||
cursor: Int,
|
cursor: Int,
|
||||||
limit: Int
|
limit: Int
|
||||||
@ -42,7 +40,6 @@ class FakeUnifiedSearchRepository : UnifiedSearchRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun searchInRoom(
|
override fun searchInRoom(
|
||||||
userEntity: UserEntity,
|
|
||||||
roomToken: String,
|
roomToken: String,
|
||||||
searchTerm: String,
|
searchTerm: String,
|
||||||
cursor: Int,
|
cursor: Int,
|
||||||
|
Loading…
Reference in New Issue
Block a user