From a133c2a3b9b70011c3fddcacdd77f9bc3703981c Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Fri, 15 Nov 2024 18:06:23 +0100 Subject: [PATCH] refactor Signed-off-by: sowjanyakch --- .../ConversationInfoActivity.kt | 3 +-- .../viewmodel/ConversationInfoViewModel.kt | 2 +- .../ConversationInfoEditViewModel.kt | 27 +++++++------------ 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt b/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt index 8fa81c85c..da36a2d09 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt @@ -266,7 +266,6 @@ class ConversationInfoActivity : Snackbar.make(binding.root, R.string.conversation_read_only_failed, Snackbar.LENGTH_LONG).show() } is ConversationInfoViewModel.SetConversationReadOnlyViewState.None -> { - } } } @@ -919,7 +918,7 @@ class ConversationInfoActivity : } private fun makeConversationReadOnly(roomToken: String, state: Int) { - viewModel.setConversationReadOnly( roomToken, state) + viewModel.setConversationReadOnly(roomToken, state) } private fun initRecordingConsentOption() { diff --git a/app/src/main/java/com/nextcloud/talk/conversationinfo/viewmodel/ConversationInfoViewModel.kt b/app/src/main/java/com/nextcloud/talk/conversationinfo/viewmodel/ConversationInfoViewModel.kt index 4dedfcb93..b6b4ef288 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationinfo/viewmodel/ConversationInfoViewModel.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationinfo/viewmodel/ConversationInfoViewModel.kt @@ -269,7 +269,7 @@ class ConversationInfoViewModel @Inject constructor( conversationsRepository.unarchiveConversation(user.getCredentials(), url) } - fun clearChatHistory(apiVersion: Int, roomToken: String) { + fun clearChatHistory(apiVersion: Int, roomToken: String) { viewModelScope.launch { try { conversationsRepository.clearChatHistory(apiVersion, roomToken) diff --git a/app/src/main/java/com/nextcloud/talk/conversationinfoedit/viewmodel/ConversationInfoEditViewModel.kt b/app/src/main/java/com/nextcloud/talk/conversationinfoedit/viewmodel/ConversationInfoEditViewModel.kt index a7ddbf605..29d171f05 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationinfoedit/viewmodel/ConversationInfoEditViewModel.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationinfoedit/viewmodel/ConversationInfoEditViewModel.kt @@ -15,8 +15,6 @@ import com.nextcloud.talk.chat.data.network.ChatNetworkDataSource import com.nextcloud.talk.conversationinfoedit.data.ConversationInfoEditRepository import com.nextcloud.talk.data.user.model.User import com.nextcloud.talk.models.domain.ConversationModel -import com.nextcloud.talk.models.json.generic.GenericMeta -import com.nextcloud.talk.repositories.conversations.ConversationsRepositoryImpl.Companion.STATUS_CODE_OK import io.reactivex.Observer import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.Disposable @@ -77,33 +75,26 @@ class ConversationInfoEditViewModel @Inject constructor( ?.subscribe(DeleteConversationAvatarObserver()) } - fun renameRoom(roomToken: String, newRoomName: String) { + fun renameRoom(roomToken: String, newRoomName: String) { viewModelScope.launch { try { - val renameRoomResult = conversationInfoEditRepository.renameConversation(roomToken, newRoomName) - val statusCode: GenericMeta? = renameRoomResult.ocs?.meta - val result = statusCode?.statusCode == STATUS_CODE_OK - if (result) { - _renameRoomUiState.value = RenameRoomUiState.Success(result) - } + conversationInfoEditRepository.renameConversation(roomToken, newRoomName) + _renameRoomUiState.value = RenameRoomUiState.Success } catch (exception: Exception) { _renameRoomUiState.value = RenameRoomUiState.Error(exception) } } } - fun setConversationDescription(roomToken: String, conversationDescription: String?) { + fun setConversationDescription(roomToken: String, conversationDescription: String?) { viewModelScope.launch { try { - val setConversationDescriptionResult = conversationInfoEditRepository.setConversationDescription( + conversationInfoEditRepository.setConversationDescription( roomToken, conversationDescription ) - val statusCode: GenericMeta? = setConversationDescriptionResult.ocs?.meta - val result = statusCode?.statusCode == STATUS_CODE_OK - if (result) { - _setConversationDescriptionUiState.value = SetConversationDescriptionUiState.Success(result) - } + + _setConversationDescriptionUiState.value = SetConversationDescriptionUiState.Success } catch (exception: Exception) { _setConversationDescriptionUiState.value = SetConversationDescriptionUiState.Error(exception) } @@ -173,13 +164,13 @@ class ConversationInfoEditViewModel @Inject constructor( sealed class RenameRoomUiState { data object None : RenameRoomUiState() - data class Success(val result: Boolean) : RenameRoomUiState() + data object Success : RenameRoomUiState() data class Error(val exception: Exception) : RenameRoomUiState() } sealed class SetConversationDescriptionUiState { data object None : SetConversationDescriptionUiState() - data class Success(val result: Boolean) : SetConversationDescriptionUiState() + data object Success : SetConversationDescriptionUiState() data class Error(val exception: Exception) : SetConversationDescriptionUiState() } }