mirror of
https://github.com/nextcloud/talk-android
synced 2025-07-15 08:45:04 +01:00
Fix issues with room joining
This commit is contained in:
parent
3a1b7fb9f0
commit
c422467933
@ -72,7 +72,7 @@ class NextcloudTalkRepositoryImpl(private val apiService: ApiService) : Nextclou
|
||||
return apiService.joinConversation(user.getCredentials(), ApiUtils.getUrlForSettingMyselfAsActiveParticipant(user.baseUrl, conversationToken), conversationPassword)
|
||||
}
|
||||
|
||||
override suspend fun exitConversationForUser(user: UserNgEntity, conversationToken: String): GenericOverall {
|
||||
override suspend fun exitConversationForUser(user: User, conversationToken: String): GenericOverall {
|
||||
return apiService.exitConversation(user.getCredentials(), ApiUtils.getUrlForSettingMyselfAsActiveParticipant(user.baseUrl, conversationToken))
|
||||
}
|
||||
|
||||
|
@ -82,7 +82,7 @@ interface NextcloudTalkRepository {
|
||||
): ConversationOverall
|
||||
|
||||
suspend fun exitConversationForUser(
|
||||
userNgEntity: UserNgEntity,
|
||||
user: User,
|
||||
conversationToken: String
|
||||
): GenericOverall
|
||||
|
||||
|
@ -456,11 +456,13 @@ class ChatView(private val bundle: Bundle) : BaseView(), ImageLoaderInterface {
|
||||
viewModel.view = this
|
||||
setupViews()
|
||||
toolbar?.setOnClickListener(toolbarOnClickListener)
|
||||
viewModel.joinConversation()
|
||||
}
|
||||
|
||||
override fun onDetach(view: View) {
|
||||
super.onDetach(view)
|
||||
viewModel.view = null
|
||||
viewModel.leaveConversation()
|
||||
toolbar?.setOnClickListener(null)
|
||||
}
|
||||
|
||||
|
@ -96,7 +96,6 @@ class ChatViewModel constructor(application: Application,
|
||||
this@ChatViewModel.user = user
|
||||
this@ChatViewModel.initConversation = conversationsRepository.getConversationForUserWithToken(user.id!!, conversationToken)
|
||||
this@ChatViewModel.conversationPassword = conversationPassword
|
||||
globalService.getConversation(conversationToken, this@ChatViewModel)
|
||||
}
|
||||
}
|
||||
|
||||
@ -171,6 +170,23 @@ class ChatViewModel constructor(application: Application,
|
||||
}
|
||||
}
|
||||
|
||||
fun joinConversation() {
|
||||
initConversation?.token?.let {
|
||||
viewModelScope.launch {
|
||||
globalService.getConversation(it, this@ChatViewModel)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun leaveConversation() {
|
||||
conversation.value?.let {
|
||||
viewModelScope.launch {
|
||||
globalService.exitConversation(it.token!!, this@ChatViewModel)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun gotConversationInfoForUser(userNgEntity: UserNgEntity, conversation: Conversation?, operationStatus: GlobalServiceInterface.OperationStatus) {
|
||||
if (operationStatus == GlobalServiceInterface.OperationStatus.STATUS_OK) {
|
||||
if (userNgEntity.id == user.id && conversation!!.token == initConversation?.token) {
|
||||
@ -190,6 +206,10 @@ class ChatViewModel constructor(application: Application,
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun leftConversationForUser(user: User, conversation: Conversation?, operationStatus: GlobalServiceInterface.OperationStatus) {
|
||||
// We left the conversation
|
||||
}
|
||||
|
||||
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)
|
||||
|
@ -7,7 +7,7 @@ class HashMapHashMapConverter {
|
||||
@TypeConverter
|
||||
fun fromDoubleHashMapToString(map: HashMap<String, HashMap<String, String>>?): String? {
|
||||
if (map == null) {
|
||||
return ""
|
||||
return LoganSquare.serialize(hashMapOf<String, HashMap<String, String>>())
|
||||
}
|
||||
|
||||
return LoganSquare.serialize(map)
|
||||
@ -16,7 +16,7 @@ class HashMapHashMapConverter {
|
||||
@TypeConverter
|
||||
fun fromStringToDoubleHashMap(value: String?): HashMap<String, HashMap<String, String>>? {
|
||||
if (value.isNullOrEmpty()) {
|
||||
return null
|
||||
return hashMapOf()
|
||||
}
|
||||
|
||||
return LoganSquare.parseMap(value, HashMap::class.java) as HashMap<String, HashMap<String, String>>?
|
||||
|
@ -29,11 +29,13 @@ import com.nextcloud.talk.models.json.chat.ChatMessage
|
||||
import com.nextcloud.talk.models.json.chat.ChatOverall
|
||||
import com.nextcloud.talk.models.json.conversations.Conversation
|
||||
import com.nextcloud.talk.models.json.conversations.ConversationOverall
|
||||
import com.nextcloud.talk.models.json.generic.GenericOverall
|
||||
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.ConversationsRepository
|
||||
import com.nextcloud.talk.newarch.domain.repository.offline.MessagesRepository
|
||||
import com.nextcloud.talk.newarch.domain.repository.offline.UsersRepository
|
||||
import com.nextcloud.talk.newarch.domain.usecases.ExitConversationUseCase
|
||||
import com.nextcloud.talk.newarch.domain.usecases.GetConversationUseCase
|
||||
import com.nextcloud.talk.newarch.domain.usecases.JoinConversationUseCase
|
||||
import com.nextcloud.talk.newarch.domain.usecases.SendChatMessageUseCase
|
||||
@ -45,6 +47,7 @@ import com.nextcloud.talk.newarch.utils.NetworkComponents
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import okhttp3.OkHttpClient
|
||||
import org.koin.core.KoinComponent
|
||||
import org.koin.core.parameter.parametersOf
|
||||
@ -128,6 +131,22 @@ 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)
|
||||
exitConversationUseCase.invoke(applicationScope, parametersOf(currentUser, conversationToken), object: UseCaseResponse<GenericOverall> {
|
||||
override suspend fun onSuccess(result: GenericOverall) {
|
||||
globalServiceInterface.leftConversationForUser(currentUser, currentConversation.value, GlobalServiceInterface.OperationStatus.STATUS_OK)
|
||||
withContext(Dispatchers.Main) {
|
||||
currentConversation.postValue(null)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun onError(errorModel: ErrorModel?) {
|
||||
globalServiceInterface.leftConversationForUser(currentUser, currentConversation.value, GlobalServiceInterface.OperationStatus.STATUS_FAILED)
|
||||
}
|
||||
})
|
||||
}
|
||||
suspend fun getConversation(conversationToken: String, globalServiceInterface: GlobalServiceInterface) {
|
||||
val currentUser = currentUserLiveData.value
|
||||
val getConversationUseCase = GetConversationUseCase(networkComponents.getRepository(true, currentUser!!.toUser()), apiErrorHandler)
|
||||
@ -165,7 +184,9 @@ class GlobalService constructor(usersRepository: UsersRepository,
|
||||
override suspend fun onSuccess(result: ConversationOverall) {
|
||||
currentUser?.let {
|
||||
conversationsRepository.saveConversationsForUser(it.id, listOf(result.ocs.data), false)
|
||||
currentConversation.postValue(conversationsRepository.getConversationForUserWithToken(it.id, result.ocs!!.data!!.token!!))
|
||||
withContext(Dispatchers.Main) {
|
||||
currentConversation.postValue(conversationsRepository.getConversationForUserWithToken(it.id, result.ocs!!.data!!.token!!))
|
||||
}
|
||||
globalServiceInterface.joinedConversationForUser(it, currentConversation.value, GlobalServiceInterface.OperationStatus.STATUS_OK)
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,7 @@
|
||||
package com.nextcloud.talk.newarch.services
|
||||
|
||||
import com.nextcloud.talk.models.json.conversations.Conversation
|
||||
import com.nextcloud.talk.newarch.local.models.User
|
||||
import com.nextcloud.talk.newarch.local.models.UserNgEntity
|
||||
|
||||
interface GlobalServiceInterface {
|
||||
@ -33,4 +34,5 @@ interface GlobalServiceInterface {
|
||||
|
||||
suspend fun gotConversationInfoForUser(userNgEntity: UserNgEntity, conversation: Conversation?, operationStatus: OperationStatus)
|
||||
suspend fun joinedConversationForUser(userNgEntity: UserNgEntity, conversation: Conversation?, operationStatus: OperationStatus)
|
||||
suspend fun leftConversationForUser(user: User, conversation: Conversation?, operationStatus: OperationStatus)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user