mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-22 21:19:31 +01:00
Fix adding users
Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
parent
1d28cd5b9d
commit
e62aa00d5f
@ -27,6 +27,7 @@ import com.nextcloud.talk.newarch.domain.repository.offline.UsersRepository
|
||||
import com.nextcloud.talk.newarch.domain.usecases.*
|
||||
import com.nextcloud.talk.newarch.features.account.loginentry.LoginEntryViewModelFactory
|
||||
import com.nextcloud.talk.newarch.features.account.serverentry.ServerEntryViewModelFactory
|
||||
import com.nextcloud.talk.newarch.utils.NetworkComponents
|
||||
import com.nextcloud.talk.utils.preferences.AppPreferences
|
||||
import org.koin.android.ext.koin.androidApplication
|
||||
import org.koin.dsl.module
|
||||
@ -38,7 +39,7 @@ val AccountModule = module {
|
||||
)
|
||||
}
|
||||
factory {
|
||||
createLoginEntryViewModelFactory(androidApplication(), get(), get(), get(), get(), get(), get(), get())
|
||||
createLoginEntryViewModelFactory(androidApplication(), get(), get(), get())
|
||||
}
|
||||
}
|
||||
|
||||
@ -53,15 +54,11 @@ fun createServerEntryViewModelFactory(
|
||||
|
||||
fun createLoginEntryViewModelFactory(
|
||||
application: Application,
|
||||
getProfileUseCase: GetProfileUseCase,
|
||||
getCapabilitiesUseCase: GetCapabilitiesUseCase,
|
||||
getSignalingSettingsUseCase: GetSignalingSettingsUseCase,
|
||||
registerPushWithServerUseCase: RegisterPushWithServerUseCase,
|
||||
registerPushWithProxyUseCase: RegisterPushWithProxyUseCase,
|
||||
networkComponents: NetworkComponents,
|
||||
appPreferences: AppPreferences,
|
||||
usersRepository: UsersRepository
|
||||
): LoginEntryViewModelFactory {
|
||||
return LoginEntryViewModelFactory(
|
||||
application, getProfileUseCase, getCapabilitiesUseCase, getSignalingSettingsUseCase, registerPushWithServerUseCase, registerPushWithProxyUseCase, appPreferences, usersRepository
|
||||
application, networkComponents, appPreferences, usersRepository
|
||||
)
|
||||
}
|
@ -35,6 +35,7 @@ import com.nextcloud.talk.models.json.signaling.settings.SignalingSettingsOveral
|
||||
import com.nextcloud.talk.models.json.userprofile.UserProfileOverall
|
||||
import com.nextcloud.talk.newarch.mvvm.BaseViewModel
|
||||
import com.nextcloud.talk.newarch.data.model.ErrorModel
|
||||
import com.nextcloud.talk.newarch.data.source.remote.ApiErrorHandler
|
||||
import com.nextcloud.talk.newarch.domain.repository.offline.UsersRepository
|
||||
import com.nextcloud.talk.newarch.domain.usecases.*
|
||||
import com.nextcloud.talk.newarch.domain.usecases.base.UseCaseResponse
|
||||
@ -42,6 +43,7 @@ import com.nextcloud.talk.newarch.local.models.User
|
||||
import com.nextcloud.talk.newarch.local.models.other.UserStatus
|
||||
import com.nextcloud.talk.newarch.local.models.toUser
|
||||
import com.nextcloud.talk.newarch.local.models.toUserEntity
|
||||
import com.nextcloud.talk.newarch.utils.NetworkComponents
|
||||
import com.nextcloud.talk.utils.PushUtils
|
||||
import com.nextcloud.talk.utils.preferences.AppPreferences
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@ -50,13 +52,9 @@ import kotlinx.coroutines.withContext
|
||||
import org.koin.core.parameter.parametersOf
|
||||
import java.net.URLDecoder
|
||||
|
||||
class LoginEntryViewModel constructor(
|
||||
class LoginEntryViewModel(
|
||||
application: Application,
|
||||
private val getProfileUseCase: GetProfileUseCase,
|
||||
private val getCapabilitiesUseCase: GetCapabilitiesUseCase,
|
||||
private val getSignalingSettingsUseCase: GetSignalingSettingsUseCase,
|
||||
private val registerPushWithServerUseCase: RegisterPushWithServerUseCase,
|
||||
private val registerPushWithProxyUseCase: RegisterPushWithProxyUseCase,
|
||||
private val networkComponents: NetworkComponents,
|
||||
private val appPreferences: AppPreferences,
|
||||
private val usersRepository: UsersRepository) :
|
||||
BaseViewModel<LoginEntryView>(application) {
|
||||
@ -131,9 +129,12 @@ class LoginEntryViewModel constructor(
|
||||
}
|
||||
|
||||
private fun getProfile(loginData: LoginData) {
|
||||
user!!.id = -1
|
||||
user!!.username = loginData.username!!
|
||||
user!!.baseUrl = loginData.serverUrl!!
|
||||
user!!.token = loginData.token
|
||||
val repository = networkComponents.getRepository(false, user!!)
|
||||
val getProfileUseCase = GetProfileUseCase(repository, ApiErrorHandler())
|
||||
getProfileUseCase.invoke(viewModelScope, parametersOf(user!!.toUserEntity()), object : UseCaseResponse<UserProfileOverall> {
|
||||
override suspend fun onSuccess(result: UserProfileOverall) {
|
||||
result.ocs.data.userId?.let { userId ->
|
||||
@ -152,6 +153,8 @@ class LoginEntryViewModel constructor(
|
||||
}
|
||||
|
||||
private fun getCapabilities() {
|
||||
val repository = networkComponents.getRepository(false, user!!)
|
||||
val getCapabilitiesUseCase = GetCapabilitiesUseCase(repository, ApiErrorHandler())
|
||||
getCapabilitiesUseCase.invoke(viewModelScope, parametersOf(user!!.baseUrl), object : UseCaseResponse<CapabilitiesOverall> {
|
||||
override suspend fun onSuccess(result: CapabilitiesOverall) {
|
||||
user!!.capabilities = result.ocs.data.capabilities
|
||||
@ -165,6 +168,8 @@ class LoginEntryViewModel constructor(
|
||||
}
|
||||
|
||||
private fun getSignalingSettings() {
|
||||
val repository = networkComponents.getRepository(false, user!!)
|
||||
val getSignalingSettingsUseCase = GetSignalingSettingsUseCase(repository, ApiErrorHandler())
|
||||
getSignalingSettingsUseCase.invoke(viewModelScope, parametersOf(user!!.toUserEntity()), object : UseCaseResponse<SignalingSettingsOverall> {
|
||||
override suspend fun onSuccess(result: SignalingSettingsOverall) {
|
||||
user!!.signalingSettings = result.ocs.signalingSettings
|
||||
@ -200,6 +205,8 @@ class LoginEntryViewModel constructor(
|
||||
|
||||
private fun registerForPushWithServer(token: String) {
|
||||
val options = PushUtils(usersRepository).getMapForPushRegistrationWithServer(context, token)
|
||||
val repository = networkComponents.getRepository(false, user!!)
|
||||
val registerPushWithServerUseCase = RegisterPushWithServerUseCase(repository, ApiErrorHandler())
|
||||
registerPushWithServerUseCase.invoke(viewModelScope, parametersOf(user!!.toUserEntity(), options), object : UseCaseResponse<PushRegistrationOverall> {
|
||||
override suspend fun onSuccess(result: PushRegistrationOverall) {
|
||||
user!!.pushConfiguration!!.deviceIdentifier = result.ocs.data.deviceIdentifier
|
||||
@ -223,6 +230,9 @@ class LoginEntryViewModel constructor(
|
||||
val options = PushUtils(usersRepository).getMapForPushRegistrationWithServer(user!!.toUserEntity())
|
||||
|
||||
if (options != null) {
|
||||
val repository = networkComponents.getRepository(false, user!!)
|
||||
val registerPushWithProxyUseCase = RegisterPushWithProxyUseCase(repository, ApiErrorHandler())
|
||||
|
||||
registerPushWithProxyUseCase.invoke(viewModelScope, parametersOf(user!!.toUserEntity(), options), object : UseCaseResponse<Any> {
|
||||
override suspend fun onSuccess(result: Any) {
|
||||
user!!.pushConfiguration!!.pushConfigurationStateWrapper = PushConfigurationStateWrapper(PushConfigurationState.PROXY_REGISTRATION_DONE, null)
|
||||
|
@ -27,10 +27,11 @@ import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.nextcloud.talk.newarch.domain.repository.offline.UsersRepository
|
||||
import com.nextcloud.talk.newarch.domain.usecases.*
|
||||
import com.nextcloud.talk.newarch.utils.NetworkComponents
|
||||
import com.nextcloud.talk.utils.preferences.AppPreferences
|
||||
|
||||
class LoginEntryViewModelFactory constructor(private val application: Application, private val getProfileUseCase: GetProfileUseCase, private val getCapabilitiesUseCase: GetCapabilitiesUseCase, private val getSignalingSettingsUseCase: GetSignalingSettingsUseCase, private val registerPushWithServerUseCase: RegisterPushWithServerUseCase, private val registerPushWithProxyUseCase: RegisterPushWithProxyUseCase, private val appPreferences: AppPreferences, private val usersRepository: UsersRepository) : ViewModelProvider.Factory {
|
||||
class LoginEntryViewModelFactory constructor(private val application: Application, private val networkComponents: NetworkComponents, private val appPreferences: AppPreferences, private val usersRepository: UsersRepository) : ViewModelProvider.Factory {
|
||||
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
|
||||
return LoginEntryViewModel(application, getProfileUseCase, getCapabilitiesUseCase, getSignalingSettingsUseCase, registerPushWithServerUseCase, registerPushWithProxyUseCase, appPreferences, usersRepository) as T
|
||||
return LoginEntryViewModel(application, networkComponents, appPreferences, usersRepository) as T
|
||||
}
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ class ChatViewModel constructor(application: Application,
|
||||
}
|
||||
}
|
||||
} else {
|
||||
val sendChatMessageUseCase = SendChatMessageUseCase(networkComponents.getRepository(false, user), apiErrorHandler)
|
||||
val sendChatMessageUseCase = SendChatMessageUseCase(networkComponents.getRepository(false, user), ApiErrorHandler())
|
||||
// No reference id needed here
|
||||
initConversation?.let {
|
||||
sendChatMessageUseCase.invoke(viewModelScope, parametersOf(user, it.token, editable, replyTo, null), object : UseCaseResponse<Response<ChatOverall>> {
|
||||
@ -212,7 +212,7 @@ class ChatViewModel constructor(application: Application,
|
||||
|
||||
private suspend fun pullPastMessagesForUserAndConversation(userNgEntity: UserNgEntity, conversation: Conversation) {
|
||||
if (userNgEntity.id == user.id && conversation.token == initConversation?.token && view != null) {
|
||||
val getChatMessagesUseCase = GetChatMessagesUseCase(networkComponents.getRepository(true, userNgEntity.toUser()), apiErrorHandler)
|
||||
val getChatMessagesUseCase = GetChatMessagesUseCase(networkComponents.getRepository(true, userNgEntity.toUser()), ApiErrorHandler())
|
||||
val lastReadMessageId = conversation.lastReadMessageId
|
||||
getChatMessagesUseCase.invoke(viewModelScope, parametersOf(user, conversation.token, 0, lastReadMessageId, 1), object : UseCaseResponse<Response<ChatOverall>> {
|
||||
override suspend fun onSuccess(result: Response<ChatOverall>) {
|
||||
@ -243,7 +243,7 @@ class ChatViewModel constructor(application: Application,
|
||||
|
||||
suspend fun pullFutureMessagesForUserAndConversation(userNgEntity: UserNgEntity, conversation: Conversation, lastGivenMessage: Int = 0) {
|
||||
if (userNgEntity.id == user.id && conversation.token == initConversation?.token && view != null) {
|
||||
val getChatMessagesUseCase = GetChatMessagesUseCase(networkComponents.getRepository(true, userNgEntity.toUser()), apiErrorHandler)
|
||||
val getChatMessagesUseCase = GetChatMessagesUseCase(networkComponents.getRepository(true, userNgEntity.toUser()), ApiErrorHandler())
|
||||
var lastKnownMessageId = lastGivenMessage
|
||||
if (lastGivenMessage == 0) {
|
||||
lastKnownMessageId = conversation.lastReadMessageId.toInt()
|
||||
|
@ -50,7 +50,9 @@ class SettingsViewFooterSource(private val context: Context) : FooterSource<User
|
||||
results.add(Data(user, context.resources.getString(R.string.nc_settings_new_account)))
|
||||
user
|
||||
} else {
|
||||
null
|
||||
val user = User(-1, "-1", "-1", "")
|
||||
results.add(Data(user, context.resources.getString(R.string.nc_settings_new_account)))
|
||||
user
|
||||
}
|
||||
|
||||
return results
|
||||
|
@ -30,7 +30,7 @@ import com.nextcloud.talk.newarch.local.models.User
|
||||
|
||||
@Dao
|
||||
abstract class MessagesDao {
|
||||
@Query("SELECT * FROM messages WHERE conversation_id = :conversationId ORDER BY timestamp ASC")
|
||||
@Query("SELECT * FROM messages WHERE conversation_id = :conversationId ORDER BY timestamp ASC, message_id ASC")
|
||||
abstract fun getMessagesWithUserForConversation(conversationId: String):
|
||||
LiveData<List<MessageEntity>>
|
||||
|
||||
@ -48,7 +48,7 @@ abstract class MessagesDao {
|
||||
)
|
||||
abstract suspend fun updateMessageId(newId: String, conversationId: String, referenceId: String)
|
||||
|
||||
@Query("SELECT * FROM messages WHERE conversation_id = :conversationId AND (message_id >= :messageId OR message_id = 0) ORDER BY timestamp ASC")
|
||||
@Query("SELECT * FROM messages WHERE conversation_id = :conversationId AND (message_id >= :messageId OR message_id = 0) ORDER BY timestamp ASC, message_id ASC")
|
||||
abstract fun getMessagesWithUserForConversationSince(conversationId: String, messageId: Long): LiveData<List<MessageEntity>>
|
||||
|
||||
@Query("SELECT * FROM messages WHERE conversation_id = :conversationId AND message_id = :messageId")
|
||||
|
@ -111,7 +111,7 @@ class GlobalService constructor(usersRepository: UsersRepository,
|
||||
} else {
|
||||
currentUser?.let { user ->
|
||||
if (chatMessage.internalConversationId == conversation.databaseId && conversation.databaseUserId == currentUser.id) {
|
||||
val sendChatMessageUseCase = SendChatMessageUseCase(networkComponents.getRepository(false, user), apiErrorHandler)
|
||||
val sendChatMessageUseCase = SendChatMessageUseCase(networkComponents.getRepository(false, user), ApiErrorHandler())
|
||||
sendChatMessageUseCase.invoke(applicationScope, parametersOf(user, conversation.token, chatMessage.message, chatMessage.parentMessage?.jsonMessageId, chatMessage.referenceId), object : UseCaseResponse<Response<ChatOverall>> {
|
||||
override suspend fun onSuccess(result: Response<ChatOverall>) {
|
||||
messagesOperations.remove(pair.first.internalMessageId!!)
|
||||
@ -133,7 +133,7 @@ class GlobalService constructor(usersRepository: UsersRepository,
|
||||
|
||||
suspend fun exitConversation(conversationToken: String, globalServiceInterface: GlobalServiceInterface) {
|
||||
val currentUser = currentUserLiveData.value!!.toUser()
|
||||
val exitConversationUseCase = ExitConversationUseCase(networkComponents.getRepository(true, currentUser), apiErrorHandler)
|
||||
val exitConversationUseCase = ExitConversationUseCase(networkComponents.getRepository(true, currentUser), ApiErrorHandler())
|
||||
exitConversationUseCase.invoke(applicationScope, parametersOf(currentUser, conversationToken), object: UseCaseResponse<GenericOverall> {
|
||||
override suspend fun onSuccess(result: GenericOverall) {
|
||||
globalServiceInterface.leftConversationForUser(currentUser, currentConversation.value, GlobalServiceInterface.OperationStatus.STATUS_OK)
|
||||
@ -149,7 +149,7 @@ class GlobalService constructor(usersRepository: UsersRepository,
|
||||
}
|
||||
suspend fun getConversation(conversationToken: String, globalServiceInterface: GlobalServiceInterface) {
|
||||
val currentUser = currentUserLiveData.value
|
||||
val getConversationUseCase = GetConversationUseCase(networkComponents.getRepository(true, currentUser!!.toUser()), apiErrorHandler)
|
||||
val getConversationUseCase = GetConversationUseCase(networkComponents.getRepository(true, currentUser!!.toUser()), ApiErrorHandler())
|
||||
getConversationUseCase.invoke(applicationScope, parametersOf(
|
||||
currentUser,
|
||||
conversationToken
|
||||
@ -174,7 +174,7 @@ class GlobalService constructor(usersRepository: UsersRepository,
|
||||
|
||||
suspend fun joinConversation(conversationToken: String, conversationPassword: String?, globalServiceInterface: GlobalServiceInterface) {
|
||||
val currentUser = currentUserLiveData.value
|
||||
val joinConversationUseCase = JoinConversationUseCase(networkComponents.getRepository(true, currentUser!!.toUser()), apiErrorHandler)
|
||||
val joinConversationUseCase = JoinConversationUseCase(networkComponents.getRepository(true, currentUser!!.toUser()), ApiErrorHandler())
|
||||
joinConversationUseCase.invoke(applicationScope, parametersOf(
|
||||
currentUser,
|
||||
conversationToken,
|
||||
|
@ -56,7 +56,7 @@ class NetworkComponents(
|
||||
usersMultipleOperationsRepositoryMap[user.id]
|
||||
}
|
||||
|
||||
if (mappedNextcloudTalkRepository != null) {
|
||||
if (mappedNextcloudTalkRepository != null && user.id != -1L) {
|
||||
return mappedNextcloudTalkRepository
|
||||
}
|
||||
|
||||
@ -71,7 +71,7 @@ class NetworkComponents(
|
||||
usersMultipleOperationOkHttpMap[user.id]
|
||||
}
|
||||
|
||||
if (mappedOkHttpClient != null) {
|
||||
if (mappedOkHttpClient != null && user.id != -1L) {
|
||||
return mappedOkHttpClient
|
||||
}
|
||||
|
||||
@ -91,7 +91,7 @@ class NetworkComponents(
|
||||
fun getImageLoader(user: User): ImageLoader {
|
||||
var mappedImageLoader = usersImageLoaderMap[user.id]
|
||||
|
||||
if (mappedImageLoader == null) {
|
||||
if (mappedImageLoader == null || user.id == -1L) {
|
||||
mappedImageLoader = ImageLoader(androidApplication) {
|
||||
availableMemoryPercentage(0.5)
|
||||
bitmapPoolPercentage(0.5)
|
||||
|
Loading…
Reference in New Issue
Block a user