From cedf1f09e980d190c77b7f711cce281832efb973 Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Fri, 15 Nov 2024 12:08:04 +0100 Subject: [PATCH 01/12] Implement renameRoom in ConversationInfoEditRepository Signed-off-by: sowjanyakch --- .../repository/ConversationRepository.kt | 3 --- .../repository/ConversationRepositoryImpl.kt | 17 ---------------- .../data/ConversationInfoEditRepository.kt | 3 +++ .../ConversationInfoEditRepositoryImpl.kt | 20 ++++++++++++++++++- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/conversation/repository/ConversationRepository.kt b/app/src/main/java/com/nextcloud/talk/conversation/repository/ConversationRepository.kt index 70c50aa644..96580c646a 100644 --- a/app/src/main/java/com/nextcloud/talk/conversation/repository/ConversationRepository.kt +++ b/app/src/main/java/com/nextcloud/talk/conversation/repository/ConversationRepository.kt @@ -8,13 +8,10 @@ package com.nextcloud.talk.conversation.repository import com.nextcloud.talk.models.json.conversations.ConversationEnums import com.nextcloud.talk.models.json.conversations.RoomOverall -import com.nextcloud.talk.models.json.generic.GenericOverall import io.reactivex.Observable interface ConversationRepository { - fun renameConversation(roomToken: String, roomNameNew: String): Observable - fun createConversation( roomName: String, conversationType: ConversationEnums.ConversationType? diff --git a/app/src/main/java/com/nextcloud/talk/conversation/repository/ConversationRepositoryImpl.kt b/app/src/main/java/com/nextcloud/talk/conversation/repository/ConversationRepositoryImpl.kt index f5dae7059a..8f344f5e55 100644 --- a/app/src/main/java/com/nextcloud/talk/conversation/repository/ConversationRepositoryImpl.kt +++ b/app/src/main/java/com/nextcloud/talk/conversation/repository/ConversationRepositoryImpl.kt @@ -11,7 +11,6 @@ import com.nextcloud.talk.data.user.model.User import com.nextcloud.talk.models.RetrofitBucket import com.nextcloud.talk.models.json.conversations.ConversationEnums import com.nextcloud.talk.models.json.conversations.RoomOverall -import com.nextcloud.talk.models.json.generic.GenericOverall import com.nextcloud.talk.utils.ApiUtils import com.nextcloud.talk.utils.database.user.CurrentUserProviderNew import io.reactivex.Observable @@ -24,22 +23,7 @@ class ConversationRepositoryImpl(private val ncApi: NcApi, currentUserProvider: val currentUser: User = currentUserProvider.currentUser.blockingGet() val credentials: String = ApiUtils.getCredentials(currentUser.username, currentUser.token)!! - override fun renameConversation(roomToken: String, roomNameNew: String): Observable { - val apiVersion = ApiUtils.getConversationApiVersion(currentUser, intArrayOf(ApiUtils.API_V4, ApiUtils.API_V1)) - return ncApi.renameRoom( - credentials, - ApiUtils.getUrlForRoom( - apiVersion, - currentUser.baseUrl!!, - roomToken - ), - roomNameNew - ) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .retry(API_RETRIES) - } override fun createConversation( roomName: String, @@ -76,6 +60,5 @@ class ConversationRepositoryImpl(private val ncApi: NcApi, currentUserProvider: companion object { private const val ROOM_TYPE_PUBLIC = "3" private const val ROOM_TYPE_GROUP = "2" - const val API_RETRIES: Long = 3 } } diff --git a/app/src/main/java/com/nextcloud/talk/conversationinfoedit/data/ConversationInfoEditRepository.kt b/app/src/main/java/com/nextcloud/talk/conversationinfoedit/data/ConversationInfoEditRepository.kt index 83628ca7c7..7f06b7a2b6 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationinfoedit/data/ConversationInfoEditRepository.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationinfoedit/data/ConversationInfoEditRepository.kt @@ -8,6 +8,7 @@ package com.nextcloud.talk.conversationinfoedit.data import com.nextcloud.talk.data.user.model.User import com.nextcloud.talk.models.domain.ConversationModel +import com.nextcloud.talk.models.json.generic.GenericOverall import io.reactivex.Observable import java.io.File @@ -16,4 +17,6 @@ interface ConversationInfoEditRepository { fun uploadConversationAvatar(user: User, file: File, roomToken: String): Observable fun deleteConversationAvatar(user: User, roomToken: String): Observable + + suspend fun renameConversation(roomToken: String, roomNameNew: String): GenericOverall } diff --git a/app/src/main/java/com/nextcloud/talk/conversationinfoedit/data/ConversationInfoEditRepositoryImpl.kt b/app/src/main/java/com/nextcloud/talk/conversationinfoedit/data/ConversationInfoEditRepositoryImpl.kt index 8ed719a4c7..4a02f26679 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationinfoedit/data/ConversationInfoEditRepositoryImpl.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationinfoedit/data/ConversationInfoEditRepositoryImpl.kt @@ -7,8 +7,10 @@ package com.nextcloud.talk.conversationinfoedit.data import com.nextcloud.talk.api.NcApi +import com.nextcloud.talk.api.NcApiCoroutines import com.nextcloud.talk.data.user.model.User import com.nextcloud.talk.models.domain.ConversationModel +import com.nextcloud.talk.models.json.generic.GenericOverall import com.nextcloud.talk.utils.ApiUtils import com.nextcloud.talk.utils.Mimetype import com.nextcloud.talk.utils.database.user.CurrentUserProviderNew @@ -18,7 +20,9 @@ import okhttp3.MultipartBody import okhttp3.RequestBody.Companion.asRequestBody import java.io.File -class ConversationInfoEditRepositoryImpl(private val ncApi: NcApi, currentUserProvider: CurrentUserProviderNew) : +class ConversationInfoEditRepositoryImpl(private val ncApi: NcApi, + private val ncApiCoroutines: NcApiCoroutines, + currentUserProvider: CurrentUserProviderNew) : ConversationInfoEditRepository { val currentUser: User = currentUserProvider.currentUser.blockingGet() @@ -53,4 +57,18 @@ class ConversationInfoEditRepositoryImpl(private val ncApi: NcApi, currentUserPr ApiUtils.getUrlForConversationAvatar(1, user.baseUrl!!, roomToken) ).map { ConversationModel.mapToConversationModel(it.ocs?.data!!, user) } } + + override suspend fun renameConversation(roomToken: String, newRoomName: String): GenericOverall { + val apiVersion = ApiUtils.getConversationApiVersion(currentUser, intArrayOf(ApiUtils.API_V4, ApiUtils.API_V1)) + + return ncApiCoroutines.renameRoom( + credentials, + ApiUtils.getUrlForRoom( + apiVersion, + currentUser.baseUrl!!, + roomToken + ), + newRoomName + ) + } } From 9525986dde2361ac979cba36d6404e0efb5b427d Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Fri, 15 Nov 2024 13:13:13 +0100 Subject: [PATCH 02/12] convert rxjava to coroutines - renameRoom Signed-off-by: sowjanyakch --- .../RenameConversationDialogFragment.kt | 24 ++++--- .../viewmodel/RenameConversationViewModel.kt | 70 ------------------- .../ConversationInfoEditActivity.kt | 69 ++++++++---------- .../ConversationInfoEditViewModel.kt | 29 ++++++++ .../talk/dagger/modules/RepositoryModule.kt | 3 +- .../talk/dagger/modules/ViewModelModule.kt | 6 -- 6 files changed, 73 insertions(+), 128 deletions(-) delete mode 100644 app/src/main/java/com/nextcloud/talk/conversation/viewmodel/RenameConversationViewModel.kt diff --git a/app/src/main/java/com/nextcloud/talk/conversation/RenameConversationDialogFragment.kt b/app/src/main/java/com/nextcloud/talk/conversation/RenameConversationDialogFragment.kt index 71ce7d09bb..e5ddcdfa10 100644 --- a/app/src/main/java/com/nextcloud/talk/conversation/RenameConversationDialogFragment.kt +++ b/app/src/main/java/com/nextcloud/talk/conversation/RenameConversationDialogFragment.kt @@ -27,7 +27,7 @@ import com.google.android.material.snackbar.Snackbar import com.nextcloud.android.common.ui.theme.utils.ColorRole import com.nextcloud.talk.R import com.nextcloud.talk.application.NextcloudTalkApplication -import com.nextcloud.talk.conversation.viewmodel.RenameConversationViewModel +import com.nextcloud.talk.conversationinfoedit.viewmodel.ConversationInfoEditViewModel import com.nextcloud.talk.conversationlist.ConversationsListActivity import com.nextcloud.talk.databinding.DialogRenameConversationBinding import com.nextcloud.talk.events.ConversationsListFetchDataEvent @@ -49,7 +49,7 @@ class RenameConversationDialogFragment : DialogFragment() { lateinit var eventBus: EventBus private lateinit var binding: DialogRenameConversationBinding - private lateinit var viewModel: RenameConversationViewModel + private lateinit var viewModel: ConversationInfoEditViewModel private var emojiPopup: EmojiPopup? = null @@ -61,7 +61,7 @@ class RenameConversationDialogFragment : DialogFragment() { NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this) - viewModel = ViewModelProvider(this, viewModelFactory)[RenameConversationViewModel::class.java] + viewModel = ViewModelProvider(this, viewModelFactory)[ConversationInfoEditViewModel::class.java] roomToken = arguments?.getString(KEY_ROOM_TOKEN)!! initialName = arguments?.getString(INITIAL_NAME)!! } @@ -102,7 +102,7 @@ class RenameConversationDialogFragment : DialogFragment() { val positiveButton = (dialog as AlertDialog).getButton(AlertDialog.BUTTON_POSITIVE) positiveButton.isEnabled = false positiveButton.setOnClickListener { - viewModel.renameConversation(roomToken, binding.textEdit.text.toString()) + viewModel.renameRoom(roomToken, binding.textEdit.text.toString()) } themeDialog() @@ -169,13 +169,17 @@ class RenameConversationDialogFragment : DialogFragment() { } private fun setupStateObserver() { - viewModel.viewState.observe(viewLifecycleOwner) { state -> + viewModel.renameRoomUiState.observe(viewLifecycleOwner) { state -> when (state) { - is RenameConversationViewModel.InitialState -> {} - is RenameConversationViewModel.RenamingState -> {} - is RenameConversationViewModel.RenamingSuccessState -> handleSuccess() - is RenameConversationViewModel.RenamingFailedState -> showError() - else -> {} + is ConversationInfoEditViewModel.RenameRoomUiState.None ->{ + + } + is ConversationInfoEditViewModel.RenameRoomUiState.Success ->{ + handleSuccess() + } + is ConversationInfoEditViewModel.RenameRoomUiState.Error ->{ + showError() + } } } } diff --git a/app/src/main/java/com/nextcloud/talk/conversation/viewmodel/RenameConversationViewModel.kt b/app/src/main/java/com/nextcloud/talk/conversation/viewmodel/RenameConversationViewModel.kt deleted file mode 100644 index c998f91f01..0000000000 --- a/app/src/main/java/com/nextcloud/talk/conversation/viewmodel/RenameConversationViewModel.kt +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Nextcloud Talk - Android Client - * - * SPDX-FileCopyrightText: 2023 Marcel Hibbe - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package com.nextcloud.talk.conversation.viewmodel - -import android.util.Log -import androidx.lifecycle.LiveData -import androidx.lifecycle.MutableLiveData -import androidx.lifecycle.ViewModel -import com.nextcloud.talk.conversation.repository.ConversationRepository -import com.nextcloud.talk.models.json.generic.GenericOverall -import io.reactivex.Observer -import io.reactivex.android.schedulers.AndroidSchedulers -import io.reactivex.disposables.Disposable -import io.reactivex.schedulers.Schedulers -import javax.inject.Inject - -class RenameConversationViewModel @Inject constructor(private val repository: ConversationRepository) : ViewModel() { - - sealed class ViewState - object InitialState : ViewState() - object RenamingState : ViewState() - object RenamingSuccessState : ViewState() - object RenamingFailedState : ViewState() - - private val _viewState: MutableLiveData = MutableLiveData( - InitialState - ) - val viewState: LiveData - get() = _viewState - - fun renameConversation(roomToken: String, roomNameNew: String) { - _viewState.value = RenamingState - - repository.renameConversation( - roomToken, - roomNameNew - ) - .subscribeOn(Schedulers.io()) - ?.observeOn(AndroidSchedulers.mainThread()) - ?.subscribe(RenameConversationObserver()) - } - - inner class RenameConversationObserver : Observer { - - lateinit var genericOverall: GenericOverall - - override fun onSubscribe(d: Disposable) = Unit - - override fun onNext(response: GenericOverall) { - genericOverall = response - } - - override fun onError(e: Throwable) { - Log.e(TAG, "Failed to rename conversation", e) - _viewState.value = RenamingFailedState - } - - override fun onComplete() { - _viewState.value = RenamingSuccessState - } - } - - companion object { - private val TAG = RenameConversationViewModel::class.java.simpleName - } -} diff --git a/app/src/main/java/com/nextcloud/talk/conversationinfoedit/ConversationInfoEditActivity.kt b/app/src/main/java/com/nextcloud/talk/conversationinfoedit/ConversationInfoEditActivity.kt index 24dba4f13d..61ac942637 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationinfoedit/ConversationInfoEditActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationinfoedit/ConversationInfoEditActivity.kt @@ -172,6 +172,29 @@ class ConversationInfoEditActivity : BaseActivity() { else -> {} } } + conversationInfoEditViewModel.renameRoomUiState.observe(this){uiState -> + when(uiState){ + is ConversationInfoEditViewModel.RenameRoomUiState.None ->{ + + } + is ConversationInfoEditViewModel.RenameRoomUiState.Success ->{ + if (CapabilitiesUtil.isConversationDescriptionEndpointAvailable(spreedCapabilities)) { + saveConversationDescription() + } else { + finish() + } + } + is ConversationInfoEditViewModel.RenameRoomUiState.Error ->{ + Snackbar.make( + binding.root, + context.getString(R.string.default_error_msg), + Snackbar.LENGTH_LONG + ).show() + Log.e(TAG, "Error while saving conversation name", uiState.exception) + } + } + } + } private fun setupAvatarOptions() { @@ -236,47 +259,11 @@ class ConversationInfoEditActivity : BaseActivity() { } private fun saveConversationNameAndDescription() { - val apiVersion = - ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(ApiUtils.API_V4, ApiUtils.API_V1)) - - ncApi.renameRoom( - credentials, - ApiUtils.getUrlForRoom( - apiVersion, - conversationUser.baseUrl!!, - conversation!!.token - ), - binding.conversationName.text.toString() - ) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .retry(1) - .subscribe(object : Observer { - override fun onSubscribe(d: Disposable) { - // unused atm - } - - override fun onNext(genericOverall: GenericOverall) { - if (CapabilitiesUtil.isConversationDescriptionEndpointAvailable(spreedCapabilities)) { - saveConversationDescription() - } else { - finish() - } - } - - override fun onError(e: Throwable) { - Snackbar.make( - binding.root, - context.getString(R.string.default_error_msg), - Snackbar.LENGTH_LONG - ).show() - Log.e(TAG, "Error while saving conversation name", e) - } - - override fun onComplete() { - // unused atm - } - }) + val newRoomName = binding.conversationName.text.toString() + conversationInfoEditViewModel.renameRoom( + conversation!!.token, + newRoomName + ) } fun saveConversationDescription() { 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 ff8af59556..a23df454fd 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 @@ -10,14 +10,18 @@ import android.util.Log import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope 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 import io.reactivex.schedulers.Schedulers +import kotlinx.coroutines.launch import java.io.File import javax.inject.Inject @@ -42,6 +46,10 @@ class ConversationInfoEditViewModel @Inject constructor( val viewState: LiveData get() = _viewState + private val _renameRoomUiState = MutableLiveData(RenameRoomUiState.None) + val renameRoomUiState:LiveData + get() = _renameRoomUiState + fun getRoom(user: User, token: String) { _viewState.value = GetRoomStartState repository.getRoom(user, token) @@ -64,6 +72,21 @@ class ConversationInfoEditViewModel @Inject constructor( ?.subscribe(DeleteConversationAvatarObserver()) } + 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) + } + }catch(exception:Exception){ + _renameRoomUiState.value = RenameRoomUiState.Error(exception) + } + } + } + inner class GetRoomObserver : Observer { override fun onSubscribe(d: Disposable) { // unused atm @@ -124,4 +147,10 @@ class ConversationInfoEditViewModel @Inject constructor( companion object { private val TAG = ConversationInfoEditViewModel::class.simpleName } + + sealed class RenameRoomUiState{ + data object None: RenameRoomUiState() + data class Success(val result:Boolean): RenameRoomUiState() + data class Error(val exception:Exception): RenameRoomUiState() + } } diff --git a/app/src/main/java/com/nextcloud/talk/dagger/modules/RepositoryModule.kt b/app/src/main/java/com/nextcloud/talk/dagger/modules/RepositoryModule.kt index 1926cbf0e5..3529889600 100644 --- a/app/src/main/java/com/nextcloud/talk/dagger/modules/RepositoryModule.kt +++ b/app/src/main/java/com/nextcloud/talk/dagger/modules/RepositoryModule.kt @@ -159,9 +159,10 @@ class RepositoryModule { @Provides fun provideConversationInfoEditRepository( ncApi: NcApi, + ncApiCoroutines: NcApiCoroutines, userProvider: CurrentUserProviderNew ): ConversationInfoEditRepository { - return ConversationInfoEditRepositoryImpl(ncApi, userProvider) + return ConversationInfoEditRepositoryImpl(ncApi, ncApiCoroutines,userProvider) } @Provides diff --git a/app/src/main/java/com/nextcloud/talk/dagger/modules/ViewModelModule.kt b/app/src/main/java/com/nextcloud/talk/dagger/modules/ViewModelModule.kt index f1ac935fe3..e4c7600508 100644 --- a/app/src/main/java/com/nextcloud/talk/dagger/modules/ViewModelModule.kt +++ b/app/src/main/java/com/nextcloud/talk/dagger/modules/ViewModelModule.kt @@ -13,7 +13,6 @@ import com.nextcloud.talk.chat.viewmodels.ChatViewModel import com.nextcloud.talk.contacts.ContactsViewModel import com.nextcloud.talk.chat.viewmodels.MessageInputViewModel import com.nextcloud.talk.conversation.viewmodel.ConversationViewModel -import com.nextcloud.talk.conversation.viewmodel.RenameConversationViewModel import com.nextcloud.talk.conversationcreation.ConversationCreationViewModel import com.nextcloud.talk.conversationinfo.viewmodel.ConversationInfoViewModel import com.nextcloud.talk.conversationinfoedit.viewmodel.ConversationInfoEditViewModel @@ -138,11 +137,6 @@ abstract class ViewModelModule { @ViewModelKey(ConversationInfoEditViewModel::class) abstract fun conversationInfoEditViewModel(viewModel: ConversationInfoEditViewModel): ViewModel - @Binds - @IntoMap - @ViewModelKey(RenameConversationViewModel::class) - abstract fun renameConversationViewModel(viewModel: RenameConversationViewModel): ViewModel - @Binds @IntoMap @ViewModelKey(ConversationViewModel::class) From 1beffd9e2225c73408b37646ae63971f52c0c99e Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Fri, 15 Nov 2024 13:14:09 +0100 Subject: [PATCH 03/12] remove unused endpoint Signed-off-by: sowjanyakch --- app/src/main/java/com/nextcloud/talk/api/NcApi.java | 7 ------- .../talk/conversation/RenameConversationDialogFragment.kt | 1 + 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/api/NcApi.java b/app/src/main/java/com/nextcloud/talk/api/NcApi.java index 2e39a926c3..e8e1a51ed9 100644 --- a/app/src/main/java/com/nextcloud/talk/api/NcApi.java +++ b/app/src/main/java/com/nextcloud/talk/api/NcApi.java @@ -125,13 +125,6 @@ Observable createRoom(@Header("Authorization") String authorization Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /room/roomToken */ - @FormUrlEncoded - @PUT - Observable renameRoom(@Header("Authorization") String authorization, - @Url String url, - @Field("roomName") String roomName); - - @FormUrlEncoded @PUT Observable setConversationDescription(@Header("Authorization") String authorization, diff --git a/app/src/main/java/com/nextcloud/talk/conversation/RenameConversationDialogFragment.kt b/app/src/main/java/com/nextcloud/talk/conversation/RenameConversationDialogFragment.kt index e5ddcdfa10..451016bfe7 100644 --- a/app/src/main/java/com/nextcloud/talk/conversation/RenameConversationDialogFragment.kt +++ b/app/src/main/java/com/nextcloud/talk/conversation/RenameConversationDialogFragment.kt @@ -184,6 +184,7 @@ class RenameConversationDialogFragment : DialogFragment() { } } + @SuppressLint("StringFormatInvalid") private fun handleSuccess() { eventBus.post(ConversationsListFetchDataEvent()) From 6cce2783b91adcea3526319a1797d24ed385e34c Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Fri, 15 Nov 2024 13:44:12 +0100 Subject: [PATCH 04/12] convert rxjava to coroutines - setConversationDescription Signed-off-by: sowjanyakch --- .../ConversationInfoEditActivity.kt | 65 +++++++------------ .../data/ConversationInfoEditRepository.kt | 2 + .../ConversationInfoEditRepositoryImpl.kt | 15 +++++ .../ConversationInfoEditViewModel.kt | 25 +++++++ 4 files changed, 65 insertions(+), 42 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/conversationinfoedit/ConversationInfoEditActivity.kt b/app/src/main/java/com/nextcloud/talk/conversationinfoedit/ConversationInfoEditActivity.kt index 61ac942637..2f750368b5 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationinfoedit/ConversationInfoEditActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationinfoedit/ConversationInfoEditActivity.kt @@ -36,15 +36,10 @@ import com.nextcloud.talk.extensions.loadUserAvatar import com.nextcloud.talk.models.domain.ConversationModel import com.nextcloud.talk.models.json.capabilities.SpreedCapability import com.nextcloud.talk.models.json.conversations.ConversationEnums -import com.nextcloud.talk.models.json.generic.GenericOverall import com.nextcloud.talk.utils.ApiUtils import com.nextcloud.talk.utils.CapabilitiesUtil import com.nextcloud.talk.utils.PickImage import com.nextcloud.talk.utils.bundle.BundleKeys -import io.reactivex.Observer -import io.reactivex.android.schedulers.AndroidSchedulers -import io.reactivex.disposables.Disposable -import io.reactivex.schedulers.Schedulers import java.io.File import javax.inject.Inject @@ -195,6 +190,27 @@ class ConversationInfoEditActivity : BaseActivity() { } } + conversationInfoEditViewModel.setConversationDescriptionUiState.observe(this){ uiState -> + when(uiState){ + is ConversationInfoEditViewModel.SetConversationDescriptionUiState.None ->{ + + } + is ConversationInfoEditViewModel.SetConversationDescriptionUiState.Success ->{ + finish() + } + is ConversationInfoEditViewModel.SetConversationDescriptionUiState.Error ->{ + Snackbar.make( + binding.root, + context.getString(R.string.default_error_msg), + Snackbar.LENGTH_LONG + ).show() + Log.e(TAG, "Error while saving conversation description", uiState.exception) + + } + } + + } + } private fun setupAvatarOptions() { @@ -267,43 +283,8 @@ class ConversationInfoEditActivity : BaseActivity() { } fun saveConversationDescription() { - val apiVersion = - ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(ApiUtils.API_V4, ApiUtils.API_V1)) - - ncApi.setConversationDescription( - credentials, - ApiUtils.getUrlForConversationDescription( - apiVersion, - conversationUser.baseUrl!!, - conversation!!.token - ), - binding.conversationDescription.text.toString() - ) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .retry(1) - .subscribe(object : Observer { - override fun onSubscribe(d: Disposable) { - // unused atm - } - - override fun onNext(genericOverall: GenericOverall) { - finish() - } - - override fun onError(e: Throwable) { - Snackbar.make( - binding.root, - context.getString(R.string.default_error_msg), - Snackbar.LENGTH_LONG - ).show() - Log.e(TAG, "Error while saving conversation description", e) - } - - override fun onComplete() { - // unused atm - } - }) + val conversationDescription = binding.conversationDescription.text.toString() + conversationInfoEditViewModel.setConversationDescription(conversation!!.token, conversationDescription) } private fun handleResult(result: ActivityResult, onResult: (result: ActivityResult) -> Unit) { diff --git a/app/src/main/java/com/nextcloud/talk/conversationinfoedit/data/ConversationInfoEditRepository.kt b/app/src/main/java/com/nextcloud/talk/conversationinfoedit/data/ConversationInfoEditRepository.kt index 7f06b7a2b6..a705003265 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationinfoedit/data/ConversationInfoEditRepository.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationinfoedit/data/ConversationInfoEditRepository.kt @@ -19,4 +19,6 @@ interface ConversationInfoEditRepository { fun deleteConversationAvatar(user: User, roomToken: String): Observable suspend fun renameConversation(roomToken: String, roomNameNew: String): GenericOverall + + suspend fun setConversationDescription(roomToken:String, conversationDescription:String?): GenericOverall } diff --git a/app/src/main/java/com/nextcloud/talk/conversationinfoedit/data/ConversationInfoEditRepositoryImpl.kt b/app/src/main/java/com/nextcloud/talk/conversationinfoedit/data/ConversationInfoEditRepositoryImpl.kt index 4a02f26679..ee188f5887 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationinfoedit/data/ConversationInfoEditRepositoryImpl.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationinfoedit/data/ConversationInfoEditRepositoryImpl.kt @@ -71,4 +71,19 @@ class ConversationInfoEditRepositoryImpl(private val ncApi: NcApi, newRoomName ) } + + override suspend fun setConversationDescription( + roomToken: String, + conversationDescription: String? + ): GenericOverall { + return ncApiCoroutines.setConversationDescription( + credentials, + ApiUtils.getUrlForConversationDescription( + apiVersion, + currentUser.baseUrl!!, + roomToken + ), + conversationDescription + ) + } } 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 a23df454fd..8d4c8a7612 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 @@ -50,6 +50,10 @@ class ConversationInfoEditViewModel @Inject constructor( val renameRoomUiState:LiveData get() = _renameRoomUiState + private val _setConversationDescriptionUiState = MutableLiveData(SetConversationDescriptionUiState.None) + val setConversationDescriptionUiState:LiveData + get() = _setConversationDescriptionUiState + fun getRoom(user: User, token: String) { _viewState.value = GetRoomStartState repository.getRoom(user, token) @@ -87,6 +91,21 @@ class ConversationInfoEditViewModel @Inject constructor( } } + fun setConversationDescription(roomToken:String, conversationDescription:String?){ + viewModelScope.launch{ + try{ + val setConversationDescriptionResult = conversationInfoEditRepository.setConversationDescription(roomToken, conversationDescription) + val statusCode: GenericMeta? = setConversationDescriptionResult.ocs?.meta + val result = statusCode?.statusCode == STATUS_CODE_OK + if(result){ + _setConversationDescriptionUiState.value = SetConversationDescriptionUiState.Success(result) + } + }catch(exception:Exception){ + _setConversationDescriptionUiState.value = SetConversationDescriptionUiState.Error(exception) + } + } + } + inner class GetRoomObserver : Observer { override fun onSubscribe(d: Disposable) { // unused atm @@ -153,4 +172,10 @@ class ConversationInfoEditViewModel @Inject constructor( data class Success(val result:Boolean): RenameRoomUiState() data class Error(val exception:Exception): RenameRoomUiState() } + + sealed class SetConversationDescriptionUiState{ + data object None: SetConversationDescriptionUiState() + data class Success(val result:Boolean):SetConversationDescriptionUiState() + data class Error(val exception:Exception):SetConversationDescriptionUiState() + } } From 6955995654e016f8c5fdaf9442fc78d2826a5fd4 Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Fri, 15 Nov 2024 13:45:49 +0100 Subject: [PATCH 05/12] remove unused endpoints Signed-off-by: sowjanyakch --- app/src/main/java/com/nextcloud/talk/api/NcApi.java | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/api/NcApi.java b/app/src/main/java/com/nextcloud/talk/api/NcApi.java index e8e1a51ed9..3082825c2b 100644 --- a/app/src/main/java/com/nextcloud/talk/api/NcApi.java +++ b/app/src/main/java/com/nextcloud/talk/api/NcApi.java @@ -118,19 +118,6 @@ Observable createRoom(@Header("Authorization") String authorization @Url String url, @QueryMap Map options); - /* - QueryMap items are as follows: - - "roomName" : "newName" - - Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /room/roomToken - */ - - @FormUrlEncoded - @PUT - Observable setConversationDescription(@Header("Authorization") String authorization, - @Url String url, - @Field("description") String description); - /* QueryMap items are as follows: - "newParticipant" : "user" From 7a8eb3ca22e995755adb92b7bfd93765e350f0ec Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Fri, 15 Nov 2024 14:33:08 +0100 Subject: [PATCH 06/12] convert rxjava to coroutines - clearChatHistory Signed-off-by: sowjanyakch --- .../com/nextcloud/talk/api/NcApiCoroutines.kt | 6 ++ .../ConversationInfoActivity.kt | 56 ++++++++----------- .../viewmodel/ConversationInfoViewModel.kt | 27 +++++++++ .../conversations/ConversationsRepository.kt | 2 + .../ConversationsRepositoryImpl.kt | 7 +++ 5 files changed, 66 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt b/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt index cee5671f64..8c94e9a9b8 100644 --- a/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt +++ b/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt @@ -140,4 +140,10 @@ interface NcApiCoroutines { @Url url: String, @Field("password") password: String ): GenericOverall + + @DELETE + suspend fun clearChatHistory( + @Header("Authorization") authorization: String, + @Url url: String + ): GenericOverall } 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 9d40b112d8..3a0593502a 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt @@ -269,6 +269,29 @@ class ConversationInfoActivity : } } } + + viewModel.clearChatHistoryViewState.observe(this){uiState -> + when(uiState){ + is ConversationInfoViewModel.ClearChatHistoryViewState.None ->{ + + } + is ConversationInfoViewModel.ClearChatHistoryViewState.Success ->{ + Snackbar.make( + binding.root, + context.getString(R.string.nc_clear_history_success), + Snackbar.LENGTH_LONG + ).show() + + + } + is ConversationInfoViewModel.ClearChatHistoryViewState.Error ->{ + Snackbar.make(binding.root, R.string.nc_common_error_sorry, Snackbar.LENGTH_LONG).show() + Log.e(TAG, "failed to clear chat history", uiState.exception) + + } + } + + } } private fun setupActionBar() { @@ -670,7 +693,6 @@ class ConversationInfoActivity : intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) startActivity(intent) } - WorkInfo.State.FAILED -> { val errorType = workInfo.outputData.getString("error_type") if (errorType == LeaveConversationWorker.ERROR_NO_OTHER_MODERATORS_OR_OWNERS_LEFT) { @@ -687,7 +709,6 @@ class ConversationInfoActivity : ).show() } } - else -> { } } @@ -725,36 +746,7 @@ class ConversationInfoActivity : } private fun clearHistory() { - val apiVersion = ApiUtils.getChatApiVersion(spreedCapabilities, intArrayOf(1)) - - ncApi.clearChatHistory( - credentials, - ApiUtils.getUrlForChat(apiVersion, conversationUser.baseUrl!!, conversationToken) - ) - ?.subscribeOn(Schedulers.io()) - ?.observeOn(AndroidSchedulers.mainThread()) - ?.subscribe(object : Observer { - override fun onSubscribe(d: Disposable) { - // unused atm - } - - override fun onNext(genericOverall: GenericOverall) { - Snackbar.make( - binding.root, - context.getString(R.string.nc_clear_history_success), - Snackbar.LENGTH_LONG - ).show() - } - - override fun onError(e: Throwable) { - Snackbar.make(binding.root, R.string.nc_common_error_sorry, Snackbar.LENGTH_LONG).show() - Log.e(TAG, "failed to clear chat history", e) - } - - override fun onComplete() { - // unused atm - } - }) + viewModel.clearChatHistory(conversationToken) } private fun deleteConversation() { 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 efad9cfc47..e746ca4865 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 @@ -18,9 +18,11 @@ import com.nextcloud.talk.chat.data.network.ChatNetworkDataSource import com.nextcloud.talk.data.user.model.User import com.nextcloud.talk.models.domain.ConversationModel import com.nextcloud.talk.models.json.capabilities.SpreedCapability +import com.nextcloud.talk.models.json.generic.GenericMeta import com.nextcloud.talk.models.json.generic.GenericOverall import com.nextcloud.talk.models.json.participants.TalkBan import com.nextcloud.talk.repositories.conversations.ConversationsRepository +import com.nextcloud.talk.repositories.conversations.ConversationsRepositoryImpl.Companion.STATUS_CODE_OK import com.nextcloud.talk.utils.ApiUtils import io.reactivex.Observer import io.reactivex.android.schedulers.AndroidSchedulers @@ -110,6 +112,10 @@ class ConversationInfoViewModel @Inject constructor( val getCapabilitiesViewState: LiveData get() = _getCapabilitiesViewState + private val _clearChatHistoryViewState:MutableLiveData = MutableLiveData(ClearChatHistoryViewState.None) + val clearChatHistoryViewState:LiveData + get() = _clearChatHistoryViewState + fun getRoom(user: User, token: String) { _viewState.value = GetRoomStartState chatNetworkDataSource.getRoom(user, token) @@ -279,6 +285,21 @@ class ConversationInfoViewModel @Inject constructor( conversationsRepository.unarchiveConversation(user.getCredentials(), url) } + fun clearChatHistory(roomToken:String){ + viewModelScope.launch{ + try{ + val clearChatResult = conversationsRepository.clearChatHistory(roomToken) + val statusCode: GenericMeta? = clearChatResult.ocs?.meta + val result = statusCode?.statusCode == STATUS_CODE_OK + if (result) { + _clearChatHistoryViewState.value = ClearChatHistoryViewState.Success + } + }catch(exception:Exception){ + _clearChatHistoryViewState.value = ClearChatHistoryViewState.Error(exception) + } + } + } + inner class GetRoomObserver : Observer { override fun onSubscribe(d: Disposable) { // unused atm @@ -302,6 +323,12 @@ class ConversationInfoViewModel @Inject constructor( private val TAG = ConversationInfoViewModel::class.simpleName } + sealed class ClearChatHistoryViewState{ + data object None: ClearChatHistoryViewState() + data object Success:ClearChatHistoryViewState() + data class Error(val exception:Exception):ClearChatHistoryViewState() + } + sealed class AllowGuestsUIState { data object None : AllowGuestsUIState() data class Success(val allow: Boolean) : AllowGuestsUIState() diff --git a/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepository.kt b/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepository.kt index e4114bfafe..f20d0dbdf9 100644 --- a/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepository.kt +++ b/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepository.kt @@ -26,4 +26,6 @@ interface ConversationsRepository { suspend fun setPassword(password: String, token: String): GenericOverall fun setConversationReadOnly(credentials: String, url: String, state: Int): Observable + + suspend fun clearChatHistory(roomToken:String): GenericOverall } diff --git a/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepositoryImpl.kt b/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepositoryImpl.kt index 254f0e4f7d..fde1039f50 100644 --- a/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepositoryImpl.kt +++ b/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepositoryImpl.kt @@ -91,6 +91,13 @@ class ConversationsRepositoryImpl( return result } + override suspend fun clearChatHistory(roomToken:String): GenericOverall { + return coroutineApi.clearChatHistory( + credentials, + ApiUtils.getUrlForChat(apiVersion(), user.baseUrl!!, roomToken) + ) + } + private fun apiVersion(): Int { return ApiUtils.getConversationApiVersion(user, intArrayOf(ApiUtils.API_V4)) } From 66686d760244ca4e289259acfde72246abb3bb03 Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Fri, 15 Nov 2024 15:33:55 +0100 Subject: [PATCH 07/12] get correct api version for chat Signed-off-by: sowjanyakch --- .../talk/conversationinfo/ConversationInfoActivity.kt | 3 ++- .../conversationinfo/viewmodel/ConversationInfoViewModel.kt | 4 ++-- .../repositories/conversations/ConversationsRepository.kt | 2 +- .../repositories/conversations/ConversationsRepositoryImpl.kt | 3 ++- 4 files changed, 7 insertions(+), 5 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 3a0593502a..77ca78d558 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt @@ -746,7 +746,8 @@ class ConversationInfoActivity : } private fun clearHistory() { - viewModel.clearChatHistory(conversationToken) + val apiVersion = ApiUtils.getChatApiVersion(spreedCapabilities, intArrayOf(1)) + viewModel.clearChatHistory(apiVersion,conversationToken) } private fun deleteConversation() { 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 e746ca4865..f24c994ed4 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 @@ -285,10 +285,10 @@ class ConversationInfoViewModel @Inject constructor( conversationsRepository.unarchiveConversation(user.getCredentials(), url) } - fun clearChatHistory(roomToken:String){ + fun clearChatHistory(apiVersion:Int,roomToken:String){ viewModelScope.launch{ try{ - val clearChatResult = conversationsRepository.clearChatHistory(roomToken) + val clearChatResult = conversationsRepository.clearChatHistory(apiVersion,roomToken) val statusCode: GenericMeta? = clearChatResult.ocs?.meta val result = statusCode?.statusCode == STATUS_CODE_OK if (result) { diff --git a/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepository.kt b/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepository.kt index f20d0dbdf9..c22e7f55f4 100644 --- a/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepository.kt +++ b/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepository.kt @@ -27,5 +27,5 @@ interface ConversationsRepository { fun setConversationReadOnly(credentials: String, url: String, state: Int): Observable - suspend fun clearChatHistory(roomToken:String): GenericOverall + suspend fun clearChatHistory(apiVersion:Int,roomToken:String): GenericOverall } diff --git a/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepositoryImpl.kt b/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepositoryImpl.kt index fde1039f50..7e2ef91c5a 100644 --- a/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepositoryImpl.kt +++ b/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepositoryImpl.kt @@ -92,9 +92,10 @@ class ConversationsRepositoryImpl( } override suspend fun clearChatHistory(roomToken:String): GenericOverall { + override suspend fun clearChatHistory(apiVersion:Int,roomToken:String): GenericOverall { return coroutineApi.clearChatHistory( credentials, - ApiUtils.getUrlForChat(apiVersion(), user.baseUrl!!, roomToken) + ApiUtils.getUrlForChat(apiVersion, user.baseUrl!!, roomToken) ) } From ab313adfd52bd04339684d4797580c9b9cb3c98f Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Fri, 15 Nov 2024 15:35:26 +0100 Subject: [PATCH 08/12] remove unused endpoint Signed-off-by: sowjanyakch --- app/src/main/java/com/nextcloud/talk/api/NcApi.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/api/NcApi.java b/app/src/main/java/com/nextcloud/talk/api/NcApi.java index 3082825c2b..6e294a0b9e 100644 --- a/app/src/main/java/com/nextcloud/talk/api/NcApi.java +++ b/app/src/main/java/com/nextcloud/talk/api/NcApi.java @@ -472,9 +472,6 @@ Observable sendLocation(@Header("Authorization") String authoriz @Field("objectId") String objectId, @Field("metaData") String metaData); - @DELETE - Observable clearChatHistory(@Header("Authorization") String authorization, @Url String url); - @FormUrlEncoded @POST Observable notificationCalls(@Header("Authorization") String authorization, From 452a4c72f4479ffe520b2f08933f4c262ab401ee Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Fri, 15 Nov 2024 17:52:34 +0100 Subject: [PATCH 09/12] convert rxjava to coroutines - set conversation read only Signed-off-by: sowjanyakch --- .../com/nextcloud/talk/api/NcApiCoroutines.kt | 9 ++- .../RenameConversationDialogFragment.kt | 7 +- .../repository/ConversationRepositoryImpl.kt | 2 - .../ConversationInfoActivity.kt | 30 +++---- .../viewmodel/ConversationInfoViewModel.kt | 80 ++++++++----------- .../ConversationInfoEditActivity.kt | 35 ++++---- .../data/ConversationInfoEditRepository.kt | 2 +- .../ConversationInfoEditRepositoryImpl.kt | 6 +- .../ConversationInfoEditViewModel.kt | 50 ++++++------ .../talk/dagger/modules/RepositoryModule.kt | 2 +- .../conversations/ConversationsRepository.kt | 4 +- .../ConversationsRepositoryImpl.kt | 7 +- 12 files changed, 110 insertions(+), 124 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt b/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt index 8c94e9a9b8..a35b175078 100644 --- a/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt +++ b/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt @@ -142,8 +142,13 @@ interface NcApiCoroutines { ): GenericOverall @DELETE - suspend fun clearChatHistory( + suspend fun clearChatHistory(@Header("Authorization") authorization: String, @Url url: String): GenericOverall + + @FormUrlEncoded + @PUT + suspend fun setConversationReadOnly( @Header("Authorization") authorization: String, - @Url url: String + @Url url: String, + @Field("state") state: Int ): GenericOverall } diff --git a/app/src/main/java/com/nextcloud/talk/conversation/RenameConversationDialogFragment.kt b/app/src/main/java/com/nextcloud/talk/conversation/RenameConversationDialogFragment.kt index 451016bfe7..8899febd20 100644 --- a/app/src/main/java/com/nextcloud/talk/conversation/RenameConversationDialogFragment.kt +++ b/app/src/main/java/com/nextcloud/talk/conversation/RenameConversationDialogFragment.kt @@ -171,13 +171,12 @@ class RenameConversationDialogFragment : DialogFragment() { private fun setupStateObserver() { viewModel.renameRoomUiState.observe(viewLifecycleOwner) { state -> when (state) { - is ConversationInfoEditViewModel.RenameRoomUiState.None ->{ - + is ConversationInfoEditViewModel.RenameRoomUiState.None -> { } - is ConversationInfoEditViewModel.RenameRoomUiState.Success ->{ + is ConversationInfoEditViewModel.RenameRoomUiState.Success -> { handleSuccess() } - is ConversationInfoEditViewModel.RenameRoomUiState.Error ->{ + is ConversationInfoEditViewModel.RenameRoomUiState.Error -> { showError() } } diff --git a/app/src/main/java/com/nextcloud/talk/conversation/repository/ConversationRepositoryImpl.kt b/app/src/main/java/com/nextcloud/talk/conversation/repository/ConversationRepositoryImpl.kt index 8f344f5e55..d7b3467ef6 100644 --- a/app/src/main/java/com/nextcloud/talk/conversation/repository/ConversationRepositoryImpl.kt +++ b/app/src/main/java/com/nextcloud/talk/conversation/repository/ConversationRepositoryImpl.kt @@ -23,8 +23,6 @@ class ConversationRepositoryImpl(private val ncApi: NcApi, currentUserProvider: val currentUser: User = currentUserProvider.currentUser.blockingGet() val credentials: String = ApiUtils.getCredentials(currentUser.username, currentUser.token)!! - - override fun createConversation( roomName: String, conversationType: ConversationEnums.ConversationType? 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 77ca78d558..8fa81c85c8 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt @@ -260,37 +260,33 @@ class ConversationInfoActivity : viewModel.getConversationReadOnlyState.observe(this) { state -> when (state) { - is ConversationInfoViewModel.SetConversationReadOnlySuccessState -> { + is ConversationInfoViewModel.SetConversationReadOnlyViewState.Success -> { } - is ConversationInfoViewModel.SetConversationReadOnlyErrorState -> { + is ConversationInfoViewModel.SetConversationReadOnlyViewState.Error -> { Snackbar.make(binding.root, R.string.conversation_read_only_failed, Snackbar.LENGTH_LONG).show() } - else -> { + is ConversationInfoViewModel.SetConversationReadOnlyViewState.None -> { + } } } - viewModel.clearChatHistoryViewState.observe(this){uiState -> - when(uiState){ - is ConversationInfoViewModel.ClearChatHistoryViewState.None ->{ - + viewModel.clearChatHistoryViewState.observe(this) { uiState -> + when (uiState) { + is ConversationInfoViewModel.ClearChatHistoryViewState.None -> { } - is ConversationInfoViewModel.ClearChatHistoryViewState.Success ->{ + is ConversationInfoViewModel.ClearChatHistoryViewState.Success -> { Snackbar.make( binding.root, context.getString(R.string.nc_clear_history_success), Snackbar.LENGTH_LONG ).show() - - } - is ConversationInfoViewModel.ClearChatHistoryViewState.Error ->{ + is ConversationInfoViewModel.ClearChatHistoryViewState.Error -> { Snackbar.make(binding.root, R.string.nc_common_error_sorry, Snackbar.LENGTH_LONG).show() Log.e(TAG, "failed to clear chat history", uiState.exception) - } } - } } @@ -747,7 +743,7 @@ class ConversationInfoActivity : private fun clearHistory() { val apiVersion = ApiUtils.getChatApiVersion(spreedCapabilities, intArrayOf(1)) - viewModel.clearChatHistory(apiVersion,conversationToken) + viewModel.clearChatHistory(apiVersion, conversationToken) } private fun deleteConversation() { @@ -842,7 +838,7 @@ class ConversationInfoActivity : binding.lockConversationSwitch.isChecked = !isLocked databaseStorageModule!!.saveBoolean("lock_switch", !isLocked) val state = if (isLocked) 0 else 1 - makeConversationReadOnly(conversationUser, conversationToken, state) + makeConversationReadOnly(conversationToken, state) } } else { binding.lockConversation.visibility = GONE @@ -922,8 +918,8 @@ class ConversationInfoActivity : } } - private fun makeConversationReadOnly(conversationUser: User, roomToken: String, state: Int) { - viewModel.setConversationReadOnly(conversationUser, roomToken, state) + private fun makeConversationReadOnly(roomToken: String, state: Int) { + 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 f24c994ed4..4dedfcb932 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 @@ -18,11 +18,9 @@ import com.nextcloud.talk.chat.data.network.ChatNetworkDataSource import com.nextcloud.talk.data.user.model.User import com.nextcloud.talk.models.domain.ConversationModel import com.nextcloud.talk.models.json.capabilities.SpreedCapability -import com.nextcloud.talk.models.json.generic.GenericMeta import com.nextcloud.talk.models.json.generic.GenericOverall import com.nextcloud.talk.models.json.participants.TalkBan import com.nextcloud.talk.repositories.conversations.ConversationsRepository -import com.nextcloud.talk.repositories.conversations.ConversationsRepositoryImpl.Companion.STATUS_CODE_OK import com.nextcloud.talk.utils.ApiUtils import io.reactivex.Observer import io.reactivex.android.schedulers.AndroidSchedulers @@ -81,13 +79,6 @@ class ConversationInfoViewModel @Inject constructor( val getUnBanActorState: LiveData get() = _getUnBanActorState - object SetConversationReadOnlySuccessState : ViewState - object SetConversationReadOnlyErrorState : ViewState - - private val _getConversationReadOnlyState: MutableLiveData = MutableLiveData() - val getConversationReadOnlyState: LiveData - get() = _getConversationReadOnlyState - object GetRoomStartState : ViewState object GetRoomErrorState : ViewState open class GetRoomSuccessState(val conversationModel: ConversationModel) : ViewState @@ -112,10 +103,16 @@ class ConversationInfoViewModel @Inject constructor( val getCapabilitiesViewState: LiveData get() = _getCapabilitiesViewState - private val _clearChatHistoryViewState:MutableLiveData = MutableLiveData(ClearChatHistoryViewState.None) - val clearChatHistoryViewState:LiveData + private val _clearChatHistoryViewState: MutableLiveData = + MutableLiveData(ClearChatHistoryViewState.None) + val clearChatHistoryViewState: LiveData get() = _clearChatHistoryViewState + private val _getConversationReadOnlyState: MutableLiveData = + MutableLiveData(SetConversationReadOnlyViewState.None) + val getConversationReadOnlyState: LiveData + get() = _getConversationReadOnlyState + fun getRoom(user: User, token: String) { _viewState.value = GetRoomStartState chatNetworkDataSource.getRoom(user, token) @@ -202,28 +199,15 @@ class ConversationInfoViewModel @Inject constructor( }) } - fun setConversationReadOnly(user: User, token: String, state: Int) { - val apiVersion = ApiUtils.getConversationApiVersion(user, intArrayOf(ApiUtils.API_V4, ApiUtils.API_V1)) - val url = ApiUtils.getUrlForConversationReadOnly(apiVersion, user.baseUrl!!, token) - conversationsRepository.setConversationReadOnly(user.getCredentials(), url, state) - .subscribeOn(Schedulers.io()) - ?.observeOn(AndroidSchedulers.mainThread()) - ?.subscribe(object : Observer { - override fun onSubscribe(p0: Disposable) { - } - - override fun onError(error: Throwable) { - _getConversationReadOnlyState.value = SetConversationReadOnlyErrorState - } - - override fun onComplete() { - // unused atm - } - - override fun onNext(p0: GenericOverall) { - _getConversationReadOnlyState.value = SetConversationReadOnlySuccessState - } - }) + fun setConversationReadOnly(roomToken: String, state: Int) { + viewModelScope.launch { + try { + conversationsRepository.setConversationReadOnly(roomToken, state) + _getConversationReadOnlyState.value = SetConversationReadOnlyViewState.Success + } catch (exception: Exception) { + _getConversationReadOnlyState.value = SetConversationReadOnlyViewState.Error(exception) + } + } } fun unbanActor(user: User, token: String, banId: Int) { @@ -285,16 +269,12 @@ class ConversationInfoViewModel @Inject constructor( conversationsRepository.unarchiveConversation(user.getCredentials(), url) } - fun clearChatHistory(apiVersion:Int,roomToken:String){ - viewModelScope.launch{ - try{ - val clearChatResult = conversationsRepository.clearChatHistory(apiVersion,roomToken) - val statusCode: GenericMeta? = clearChatResult.ocs?.meta - val result = statusCode?.statusCode == STATUS_CODE_OK - if (result) { - _clearChatHistoryViewState.value = ClearChatHistoryViewState.Success - } - }catch(exception:Exception){ + fun clearChatHistory(apiVersion: Int, roomToken: String) { + viewModelScope.launch { + try { + conversationsRepository.clearChatHistory(apiVersion, roomToken) + _clearChatHistoryViewState.value = ClearChatHistoryViewState.Success + } catch (exception: Exception) { _clearChatHistoryViewState.value = ClearChatHistoryViewState.Error(exception) } } @@ -323,10 +303,16 @@ class ConversationInfoViewModel @Inject constructor( private val TAG = ConversationInfoViewModel::class.simpleName } - sealed class ClearChatHistoryViewState{ - data object None: ClearChatHistoryViewState() - data object Success:ClearChatHistoryViewState() - data class Error(val exception:Exception):ClearChatHistoryViewState() + sealed class ClearChatHistoryViewState { + data object None : ClearChatHistoryViewState() + data object Success : ClearChatHistoryViewState() + data class Error(val exception: Exception) : ClearChatHistoryViewState() + } + + sealed class SetConversationReadOnlyViewState { + data object None : SetConversationReadOnlyViewState() + data object Success : SetConversationReadOnlyViewState() + data class Error(val exception: Exception) : SetConversationReadOnlyViewState() } sealed class AllowGuestsUIState { diff --git a/app/src/main/java/com/nextcloud/talk/conversationinfoedit/ConversationInfoEditActivity.kt b/app/src/main/java/com/nextcloud/talk/conversationinfoedit/ConversationInfoEditActivity.kt index 2f750368b5..43d7cb2b2b 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationinfoedit/ConversationInfoEditActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationinfoedit/ConversationInfoEditActivity.kt @@ -167,19 +167,18 @@ class ConversationInfoEditActivity : BaseActivity() { else -> {} } } - conversationInfoEditViewModel.renameRoomUiState.observe(this){uiState -> - when(uiState){ - is ConversationInfoEditViewModel.RenameRoomUiState.None ->{ - + conversationInfoEditViewModel.renameRoomUiState.observe(this) { uiState -> + when (uiState) { + is ConversationInfoEditViewModel.RenameRoomUiState.None -> { } - is ConversationInfoEditViewModel.RenameRoomUiState.Success ->{ + is ConversationInfoEditViewModel.RenameRoomUiState.Success -> { if (CapabilitiesUtil.isConversationDescriptionEndpointAvailable(spreedCapabilities)) { saveConversationDescription() } else { finish() } } - is ConversationInfoEditViewModel.RenameRoomUiState.Error ->{ + is ConversationInfoEditViewModel.RenameRoomUiState.Error -> { Snackbar.make( binding.root, context.getString(R.string.default_error_msg), @@ -190,27 +189,23 @@ class ConversationInfoEditActivity : BaseActivity() { } } - conversationInfoEditViewModel.setConversationDescriptionUiState.observe(this){ uiState -> - when(uiState){ - is ConversationInfoEditViewModel.SetConversationDescriptionUiState.None ->{ - + conversationInfoEditViewModel.setConversationDescriptionUiState.observe(this) { uiState -> + when (uiState) { + is ConversationInfoEditViewModel.SetConversationDescriptionUiState.None -> { } - is ConversationInfoEditViewModel.SetConversationDescriptionUiState.Success ->{ + is ConversationInfoEditViewModel.SetConversationDescriptionUiState.Success -> { finish() } - is ConversationInfoEditViewModel.SetConversationDescriptionUiState.Error ->{ + is ConversationInfoEditViewModel.SetConversationDescriptionUiState.Error -> { Snackbar.make( binding.root, context.getString(R.string.default_error_msg), Snackbar.LENGTH_LONG ).show() Log.e(TAG, "Error while saving conversation description", uiState.exception) - } } - } - } private fun setupAvatarOptions() { @@ -276,14 +271,14 @@ class ConversationInfoEditActivity : BaseActivity() { private fun saveConversationNameAndDescription() { val newRoomName = binding.conversationName.text.toString() - conversationInfoEditViewModel.renameRoom( - conversation!!.token, - newRoomName - ) + conversationInfoEditViewModel.renameRoom( + conversation!!.token, + newRoomName + ) } fun saveConversationDescription() { - val conversationDescription = binding.conversationDescription.text.toString() + val conversationDescription = binding.conversationDescription.text.toString() conversationInfoEditViewModel.setConversationDescription(conversation!!.token, conversationDescription) } diff --git a/app/src/main/java/com/nextcloud/talk/conversationinfoedit/data/ConversationInfoEditRepository.kt b/app/src/main/java/com/nextcloud/talk/conversationinfoedit/data/ConversationInfoEditRepository.kt index a705003265..7b3571b6f9 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationinfoedit/data/ConversationInfoEditRepository.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationinfoedit/data/ConversationInfoEditRepository.kt @@ -20,5 +20,5 @@ interface ConversationInfoEditRepository { suspend fun renameConversation(roomToken: String, roomNameNew: String): GenericOverall - suspend fun setConversationDescription(roomToken:String, conversationDescription:String?): GenericOverall + suspend fun setConversationDescription(roomToken: String, conversationDescription: String?): GenericOverall } diff --git a/app/src/main/java/com/nextcloud/talk/conversationinfoedit/data/ConversationInfoEditRepositoryImpl.kt b/app/src/main/java/com/nextcloud/talk/conversationinfoedit/data/ConversationInfoEditRepositoryImpl.kt index ee188f5887..a664419cc9 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationinfoedit/data/ConversationInfoEditRepositoryImpl.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationinfoedit/data/ConversationInfoEditRepositoryImpl.kt @@ -20,9 +20,11 @@ import okhttp3.MultipartBody import okhttp3.RequestBody.Companion.asRequestBody import java.io.File -class ConversationInfoEditRepositoryImpl(private val ncApi: NcApi, +class ConversationInfoEditRepositoryImpl( + private val ncApi: NcApi, private val ncApiCoroutines: NcApiCoroutines, - currentUserProvider: CurrentUserProviderNew) : + currentUserProvider: CurrentUserProviderNew +) : ConversationInfoEditRepository { val currentUser: User = currentUserProvider.currentUser.blockingGet() 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 8d4c8a7612..a7ddbf6059 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 @@ -47,11 +47,12 @@ class ConversationInfoEditViewModel @Inject constructor( get() = _viewState private val _renameRoomUiState = MutableLiveData(RenameRoomUiState.None) - val renameRoomUiState:LiveData + val renameRoomUiState: LiveData get() = _renameRoomUiState - private val _setConversationDescriptionUiState = MutableLiveData(SetConversationDescriptionUiState.None) - val setConversationDescriptionUiState:LiveData + private val _setConversationDescriptionUiState = + MutableLiveData(SetConversationDescriptionUiState.None) + val setConversationDescriptionUiState: LiveData get() = _setConversationDescriptionUiState fun getRoom(user: User, token: String) { @@ -76,31 +77,34 @@ class ConversationInfoEditViewModel @Inject constructor( ?.subscribe(DeleteConversationAvatarObserver()) } - fun renameRoom(roomToken:String, newRoomName:String){ - viewModelScope.launch{ - try{ + fun renameRoom(roomToken: String, newRoomName: String) { + viewModelScope.launch { + try { val renameRoomResult = conversationInfoEditRepository.renameConversation(roomToken, newRoomName) - val statusCode:GenericMeta? = renameRoomResult.ocs?.meta + val statusCode: GenericMeta? = renameRoomResult.ocs?.meta val result = statusCode?.statusCode == STATUS_CODE_OK - if(result){ + if (result) { _renameRoomUiState.value = RenameRoomUiState.Success(result) } - }catch(exception:Exception){ + } catch (exception: Exception) { _renameRoomUiState.value = RenameRoomUiState.Error(exception) } } } - fun setConversationDescription(roomToken:String, conversationDescription:String?){ - viewModelScope.launch{ - try{ - val setConversationDescriptionResult = conversationInfoEditRepository.setConversationDescription(roomToken, conversationDescription) + fun setConversationDescription(roomToken: String, conversationDescription: String?) { + viewModelScope.launch { + try { + val setConversationDescriptionResult = conversationInfoEditRepository.setConversationDescription( + roomToken, + conversationDescription + ) val statusCode: GenericMeta? = setConversationDescriptionResult.ocs?.meta val result = statusCode?.statusCode == STATUS_CODE_OK - if(result){ + if (result) { _setConversationDescriptionUiState.value = SetConversationDescriptionUiState.Success(result) } - }catch(exception:Exception){ + } catch (exception: Exception) { _setConversationDescriptionUiState.value = SetConversationDescriptionUiState.Error(exception) } } @@ -167,15 +171,15 @@ class ConversationInfoEditViewModel @Inject constructor( private val TAG = ConversationInfoEditViewModel::class.simpleName } - sealed class RenameRoomUiState{ - data object None: RenameRoomUiState() - data class Success(val result:Boolean): RenameRoomUiState() - data class Error(val exception:Exception): RenameRoomUiState() + sealed class RenameRoomUiState { + data object None : RenameRoomUiState() + data class Success(val result: Boolean) : RenameRoomUiState() + data class Error(val exception: Exception) : RenameRoomUiState() } - sealed class SetConversationDescriptionUiState{ - data object None: SetConversationDescriptionUiState() - data class Success(val result:Boolean):SetConversationDescriptionUiState() - data class Error(val exception:Exception):SetConversationDescriptionUiState() + sealed class SetConversationDescriptionUiState { + data object None : SetConversationDescriptionUiState() + data class Success(val result: Boolean) : SetConversationDescriptionUiState() + data class Error(val exception: Exception) : SetConversationDescriptionUiState() } } diff --git a/app/src/main/java/com/nextcloud/talk/dagger/modules/RepositoryModule.kt b/app/src/main/java/com/nextcloud/talk/dagger/modules/RepositoryModule.kt index 3529889600..b33c9ffbbe 100644 --- a/app/src/main/java/com/nextcloud/talk/dagger/modules/RepositoryModule.kt +++ b/app/src/main/java/com/nextcloud/talk/dagger/modules/RepositoryModule.kt @@ -162,7 +162,7 @@ class RepositoryModule { ncApiCoroutines: NcApiCoroutines, userProvider: CurrentUserProviderNew ): ConversationInfoEditRepository { - return ConversationInfoEditRepositoryImpl(ncApi, ncApiCoroutines,userProvider) + return ConversationInfoEditRepositoryImpl(ncApi, ncApiCoroutines, userProvider) } @Provides diff --git a/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepository.kt b/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepository.kt index c22e7f55f4..75d373dd69 100644 --- a/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepository.kt +++ b/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepository.kt @@ -25,7 +25,7 @@ interface ConversationsRepository { suspend fun setPassword(password: String, token: String): GenericOverall - fun setConversationReadOnly(credentials: String, url: String, state: Int): Observable + suspend fun setConversationReadOnly(roomToken: String, state: Int): GenericOverall - suspend fun clearChatHistory(apiVersion:Int,roomToken:String): GenericOverall + suspend fun clearChatHistory(apiVersion: Int, roomToken: String): GenericOverall } diff --git a/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepositoryImpl.kt b/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepositoryImpl.kt index 7e2ef91c5a..173269719c 100644 --- a/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepositoryImpl.kt +++ b/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepositoryImpl.kt @@ -74,8 +74,10 @@ class ConversationsRepositoryImpl( return coroutineApi.unarchiveConversation(credentials, url) } - override fun setConversationReadOnly(credentials: String, url: String, state: Int): Observable { - return api.setConversationReadOnly(credentials, url, state) + override suspend fun setConversationReadOnly(roomToken: String, state: Int): GenericOverall { + val apiVersion = ApiUtils.getConversationApiVersion(user, intArrayOf(ApiUtils.API_V4, ApiUtils.API_V1)) + val url = ApiUtils.getUrlForConversationReadOnly(apiVersion, user.baseUrl!!, roomToken) + return coroutineApi.setConversationReadOnly(credentials, url, state) } override suspend fun setPassword(password: String, token: String): GenericOverall { @@ -91,7 +93,6 @@ class ConversationsRepositoryImpl( return result } - override suspend fun clearChatHistory(roomToken:String): GenericOverall { override suspend fun clearChatHistory(apiVersion:Int,roomToken:String): GenericOverall { return coroutineApi.clearChatHistory( credentials, From 574791c1bc2e0a269d948bf9892e106975aca16a Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Fri, 15 Nov 2024 17:54:33 +0100 Subject: [PATCH 10/12] remove unused imports Signed-off-by: sowjanyakch --- app/src/main/java/com/nextcloud/talk/api/NcApi.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/api/NcApi.java b/app/src/main/java/com/nextcloud/talk/api/NcApi.java index 6e294a0b9e..b0f5199fb0 100644 --- a/app/src/main/java/com/nextcloud/talk/api/NcApi.java +++ b/app/src/main/java/com/nextcloud/talk/api/NcApi.java @@ -393,12 +393,6 @@ Observable setNotificationLevel(@Header("Authorization") String @Url String url, @Field("level") int level); - @FormUrlEncoded - @PUT - Observable setConversationReadOnly(@Header("Authorization") String authorization, - @Url String url, - @Field("state") int state); - @FormUrlEncoded @POST Observable createRemoteShare(@Nullable @Header("Authorization") String authorization, From a133c2a3b9b70011c3fddcacdd77f9bc3703981c Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Fri, 15 Nov 2024 18:06:23 +0100 Subject: [PATCH 11/12] 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 8fa81c85c8..da36a2d09c 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 4dedfcb932..b6b4ef2885 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 a7ddbf6059..29d171f05b 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() } } From 0db401de4aeffeb7cf71688aae1c1e40b91e1955 Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Tue, 19 Nov 2024 11:07:35 +0100 Subject: [PATCH 12/12] remove unused code Signed-off-by: sowjanyakch --- .../main/java/com/nextcloud/talk/api/NcApiCoroutines.kt | 8 -------- .../conversations/ConversationsRepositoryImpl.kt | 2 +- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt b/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt index a35b175078..f47978d99a 100644 --- a/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt +++ b/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt @@ -133,14 +133,6 @@ interface NcApiCoroutines { @Body body: RequestBody ): GenericOverall - @FormUrlEncoded - @PUT - suspend fun setPassword2( - @Header("Authorization") authorization: String, - @Url url: String, - @Field("password") password: String - ): GenericOverall - @DELETE suspend fun clearChatHistory(@Header("Authorization") authorization: String, @Url url: String): GenericOverall diff --git a/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepositoryImpl.kt b/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepositoryImpl.kt index 173269719c..2d7fa0609e 100644 --- a/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepositoryImpl.kt +++ b/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepositoryImpl.kt @@ -93,7 +93,7 @@ class ConversationsRepositoryImpl( return result } - override suspend fun clearChatHistory(apiVersion:Int,roomToken:String): GenericOverall { + override suspend fun clearChatHistory(apiVersion: Int, roomToken: String): GenericOverall { return coroutineApi.clearChatHistory( credentials, ApiUtils.getUrlForChat(apiVersion, user.baseUrl!!, roomToken)