From 2d5facc9056a22d7efe9aed7bb064db8aab37917 Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Wed, 13 Nov 2024 17:48:27 +0100 Subject: [PATCH 01/11] remove setPassword from NcApi Signed-off-by: sowjanyakch --- app/src/main/java/com/nextcloud/talk/api/NcApi.java | 5 ----- 1 file changed, 5 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 297bba392..760af3b3d 100644 --- a/app/src/main/java/com/nextcloud/talk/api/NcApi.java +++ b/app/src/main/java/com/nextcloud/talk/api/NcApi.java @@ -341,11 +341,6 @@ public interface NcApi { Observable unregisterDeviceForNotificationsWithProxy(@Url String url, @QueryMap Map fields); - @FormUrlEncoded - @PUT - Observable setPassword(@Header("Authorization") String authorization, - @Url String url, - @Field("password") String password); @FormUrlEncoded @PUT From af9b2b29c72b04498aad3e3a902fb8229c104d66 Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Wed, 13 Nov 2024 20:52:24 +0100 Subject: [PATCH 02/11] convert rxjava to coroutines Signed-off-by: sowjanyakch --- .../com/nextcloud/talk/api/NcApiCoroutines.kt | 4 +- .../ConversationCreationRepositoryImpl.kt | 5 +- .../ConversationInfoActivity.kt | 4 +- .../conversationinfo/GuestAccessHelper.kt | 59 ++++++++----------- .../viewmodel/ConversationInfoViewModel.kt | 36 +++++++++++ .../conversations/ConversationsRepository.kt | 6 +- .../ConversationsRepositoryImpl.kt | 22 +++---- 7 files changed, 81 insertions(+), 55 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 5707ae397..a84b2ca6d 100644 --- a/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt +++ b/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt @@ -89,10 +89,10 @@ interface NcApiCoroutines { ): AddParticipantOverall @POST - suspend fun makeRoomPublic(@Header("Authorization") authorization: String?, @Url url: String): GenericOverall + suspend fun makeRoomPublic(@Header("Authorization") authorization: String, @Url url: String): GenericOverall @DELETE - suspend fun makeRoomPrivate(@Header("Authorization") authorization: String?, @Url url: String): GenericOverall + suspend fun makeRoomPrivate(@Header("Authorization") authorization: String, @Url url: String): GenericOverall @FormUrlEncoded @PUT diff --git a/app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationRepositoryImpl.kt b/app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationRepositoryImpl.kt index 1f804e3ad..37f7d1d38 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationRepositoryImpl.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationRepositoryImpl.kt @@ -168,16 +168,15 @@ class ConversationCreationRepositoryImpl( val result: GenericOverall = if (allow) { ncApiCoroutines.makeRoomPublic( - credentials, + credentials!!, url ) } else { ncApiCoroutines.makeRoomPrivate( - credentials, + credentials!!, url ) } - return result } } 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 f0bae76ee..9d40b112d 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt @@ -916,7 +916,9 @@ class ConversationInfoActivity : it, conversation!!, spreedCapabilities, - conversationUser + conversationUser, + viewModel, + this ).setupGuestAccess() } if (ConversationUtils.isNoteToSelfConversation(conversation!!)) { diff --git a/app/src/main/java/com/nextcloud/talk/conversationinfo/GuestAccessHelper.kt b/app/src/main/java/com/nextcloud/talk/conversationinfo/GuestAccessHelper.kt index 43b1a8817..414d2a089 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationinfo/GuestAccessHelper.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationinfo/GuestAccessHelper.kt @@ -12,9 +12,11 @@ import android.util.Log import android.view.LayoutInflater import android.view.View import androidx.appcompat.app.AlertDialog +import androidx.lifecycle.LifecycleOwner import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.snackbar.Snackbar import com.nextcloud.talk.R +import com.nextcloud.talk.conversationinfo.viewmodel.ConversationInfoViewModel import com.nextcloud.talk.data.user.model.User import com.nextcloud.talk.databinding.ActivityConversationInfoBinding import com.nextcloud.talk.databinding.DialogPasswordBinding @@ -33,9 +35,10 @@ class GuestAccessHelper( private val binding: ActivityConversationInfoBinding, private val conversation: ConversationModel, private val spreedCapabilities: SpreedCapability, - private val conversationUser: User + private val conversationUser: User, + private val viewModel: ConversationInfoViewModel, + private val lifecycleOwner: LifecycleOwner ) { - private val conversationsRepository = activity.conversationsRepository private val viewThemeUtils = activity.viewThemeUtils private val context = activity.context @@ -61,11 +64,27 @@ class GuestAccessHelper( binding.guestAccessView.guestAccessSettingsAllowGuest.setOnClickListener { val isChecked = binding.guestAccessView.allowGuestsSwitch.isChecked binding.guestAccessView.allowGuestsSwitch.isChecked = !isChecked - conversationsRepository.allowGuests( - conversation.token!!, - !isChecked - ).subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()).subscribe(AllowGuestsResultObserver()) + viewModel.allowGuests(conversation.token, !isChecked) + viewModel.allowGuestsViewState.observe(lifecycleOwner){uiState -> + when(uiState){ + is ConversationInfoViewModel.AllowGuestsUIState.Success ->{ + if(uiState.result){ + showAllOptions() + }else{ + hideAllOptions() + } + } + is ConversationInfoViewModel.AllowGuestsUIState.Error ->{ + val exception = uiState.message + val message = context.getString(R.string.nc_guest_access_allow_failed) + Snackbar.make(binding.root, message, Snackbar.LENGTH_LONG).show() + Log.e(TAG, exception) + } + ConversationInfoViewModel.AllowGuestsUIState.None ->{ + //unused atm + } + } + } } binding.guestAccessView.guestAccessSettingsPasswordProtection.setOnClickListener { @@ -143,32 +162,6 @@ class GuestAccessHelper( } } - inner class AllowGuestsResultObserver : Observer { - - private lateinit var allowGuestsResult: ConversationsRepository.AllowGuestsResult - - override fun onNext(t: ConversationsRepository.AllowGuestsResult) { - allowGuestsResult = t - } - - override fun onError(e: Throwable) { - val message = context.getString(R.string.nc_guest_access_allow_failed) - Snackbar.make(binding.root, message, Snackbar.LENGTH_LONG).show() - Log.e(TAG, message, e) - } - - override fun onComplete() { - binding.guestAccessView.allowGuestsSwitch.isChecked = allowGuestsResult.allow - if (allowGuestsResult.allow) { - showAllOptions() - } else { - hideAllOptions() - } - } - - override fun onSubscribe(d: Disposable) = Unit - } - private fun showAllOptions() { binding.guestAccessView.guestAccessSettingsPasswordProtection.visibility = View.VISIBLE if (conversationUser.capabilities?.spreedCapability?.features?.contains("sip-support") == true) { 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 68e278a99..2ff5c3369 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 @@ -12,18 +12,27 @@ import androidx.lifecycle.LifecycleOwner 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.conversationcreation.AllowGuestsUiState +import com.nextcloud.talk.conversationcreation.RoomUIState 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.conversations.Conversation +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 import io.reactivex.disposables.Disposable import io.reactivex.schedulers.Schedulers +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.launch import javax.inject.Inject class ConversationInfoViewModel @Inject constructor( @@ -95,6 +104,10 @@ class ConversationInfoViewModel @Inject constructor( object GetCapabilitiesErrorState : ViewState open class GetCapabilitiesSuccessState(val spreedCapabilities: SpreedCapability) : ViewState + private val _allowGuestsViewState = MutableLiveData(AllowGuestsUIState.None) + val allowGuestsViewState: LiveData + get() = _allowGuestsViewState + private val _getCapabilitiesViewState: MutableLiveData = MutableLiveData(GetCapabilitiesStartState) val getCapabilitiesViewState: LiveData get() = _getCapabilitiesViewState @@ -233,6 +246,23 @@ class ConversationInfoViewModel @Inject constructor( }) } + + fun allowGuests(token:String,allow:Boolean){ + viewModelScope.launch{ + try{ + val allowGuestsResult = conversationsRepository.allowGuests(token,allow) + val statusCode: GenericMeta? = allowGuestsResult.ocs?.meta + val result = (statusCode?.statusCode == STATUS_CODE_OK) + if (result) { + _allowGuestsViewState.value = AllowGuestsUIState.Success(result) + } + }catch(exception:Exception){ + _allowGuestsViewState.value = AllowGuestsUIState.Error(exception.message?: "") + + } + } + } + suspend fun archiveConversation(user: User, token: String) { val apiVersion = ApiUtils.getConversationApiVersion(user, intArrayOf(ApiUtils.API_V4, ApiUtils.API_V1)) val url = ApiUtils.getUrlForArchive(apiVersion, user.baseUrl, token) @@ -267,4 +297,10 @@ class ConversationInfoViewModel @Inject constructor( companion object { private val TAG = ConversationInfoViewModel::class.simpleName } + + sealed class AllowGuestsUIState { + data object None : AllowGuestsUIState() + data class Success(val result: Boolean) : AllowGuestsUIState() + data class Error(val message: String) : 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 941592732..4a858a62d 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 @@ -12,11 +12,7 @@ import io.reactivex.Observable interface ConversationsRepository { - data class AllowGuestsResult( - val allow: Boolean - ) - - fun allowGuests(token: String, allow: Boolean): Observable + suspend fun allowGuests(token: String, allow: Boolean): GenericOverall data class PasswordResult( val passwordSet: Boolean, 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 458b97efe..4967f1051 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 @@ -13,7 +13,6 @@ import com.nextcloud.talk.api.NcApiCoroutines import com.nextcloud.talk.data.user.model.User import com.nextcloud.talk.models.json.conversations.password.PasswordOverall import com.nextcloud.talk.models.json.generic.GenericOverall -import com.nextcloud.talk.repositories.conversations.ConversationsRepository.AllowGuestsResult import com.nextcloud.talk.repositories.conversations.ConversationsRepository.PasswordResult import com.nextcloud.talk.repositories.conversations.ConversationsRepository.ResendInvitationsResult import com.nextcloud.talk.utils.ApiUtils @@ -24,8 +23,7 @@ class ConversationsRepositoryImpl( private val api: NcApi, private val coroutineApi: NcApiCoroutines, private val userProvider: CurrentUserProviderNew -) : - ConversationsRepository { +) : ConversationsRepository { private val user: User get() = userProvider.currentUser.blockingGet() @@ -33,29 +31,31 @@ class ConversationsRepositoryImpl( private val credentials: String get() = ApiUtils.getCredentials(user.username, user.token)!! - override fun allowGuests(token: String, allow: Boolean): Observable { + val apiVersion = ApiUtils.getConversationApiVersion(user, intArrayOf(ApiUtils.API_V4, ApiUtils.API_V1)) + + override suspend fun allowGuests(token: String, allow: Boolean): GenericOverall { val url = ApiUtils.getUrlForRoomPublic( - apiVersion(), + apiVersion, user.baseUrl!!, token ) - val apiObservable = if (allow) { - api.makeRoomPublic( + val result: GenericOverall = if (allow) { + coroutineApi.makeRoomPublic( credentials, url ) } else { - api.makeRoomPrivate( + coroutineApi.makeRoomPrivate( credentials, url ) } - - return apiObservable.map { AllowGuestsResult(it.ocs!!.meta!!.statusCode == STATUS_CODE_OK && allow) } + return result } - override fun password(password: String, token: String): Observable { + +override fun password(password: String, token: String): Observable { val apiObservable = api.setPassword2( credentials, ApiUtils.getUrlForRoomPassword( From c03c5a5d50d0f04c12cdbf40c92c8784e839b73a Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Wed, 13 Nov 2024 20:52:51 +0100 Subject: [PATCH 03/11] remove unused imports Signed-off-by: sowjanyakch --- .../conversationinfo/viewmodel/ConversationInfoViewModel.kt | 5 ----- 1 file changed, 5 deletions(-) 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 2ff5c3369..aad7bcb57 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 @@ -14,12 +14,9 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.nextcloud.talk.chat.data.network.ChatNetworkDataSource -import com.nextcloud.talk.conversationcreation.AllowGuestsUiState -import com.nextcloud.talk.conversationcreation.RoomUIState 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.conversations.Conversation import com.nextcloud.talk.models.json.generic.GenericMeta import com.nextcloud.talk.models.json.generic.GenericOverall import com.nextcloud.talk.models.json.participants.TalkBan @@ -30,8 +27,6 @@ import io.reactivex.Observer import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.Disposable import io.reactivex.schedulers.Schedulers -import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.launch import javax.inject.Inject From 79dfac6ac0dc5c969222578398b44cbf948799b6 Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Wed, 13 Nov 2024 20:55:16 +0100 Subject: [PATCH 04/11] remove endpoints from NcApi Signed-off-by: sowjanyakch --- app/src/main/java/com/nextcloud/talk/api/NcApi.java | 12 ------------ 1 file changed, 12 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 760af3b3d..af11d231f 100644 --- a/app/src/main/java/com/nextcloud/talk/api/NcApi.java +++ b/app/src/main/java/com/nextcloud/talk/api/NcApi.java @@ -195,18 +195,6 @@ public interface NcApi { @DELETE Observable removeSelfFromRoom(@Header("Authorization") String authorization, @Url String url); - /* - Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /room/roomToken/public - */ - @POST - Observable makeRoomPublic(@Header("Authorization") String authorization, @Url String url); - - /* - Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /room/roomToken/public - */ - @DELETE - Observable makeRoomPrivate(@Header("Authorization") String authorization, @Url String url); - @DELETE Observable deleteRoom(@Header("Authorization") String authorization, @Url String url); From 228c73ce609a25d4ac770848088fd81655b77339 Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Thu, 14 Nov 2024 07:38:46 +0100 Subject: [PATCH 05/11] test coroutines Signed-off-by: sowjanyakch --- .../java/com/nextcloud/talk/api/NcApi.java | 2 +- .../com/nextcloud/talk/api/NcApiCoroutines.kt | 8 ++++ .../conversationinfo/GuestAccessHelper.kt | 44 ++++++++++++++++--- .../viewmodel/ConversationInfoViewModel.kt | 31 ++++++++++++- .../conversations/ConversationsRepository.kt | 4 +- .../ConversationsRepositoryImpl.kt | 38 ++++++---------- app/src/main/res/values/strings.xml | 1 + 7 files changed, 91 insertions(+), 37 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 af11d231f..165171fd4 100644 --- a/app/src/main/java/com/nextcloud/talk/api/NcApi.java +++ b/app/src/main/java/com/nextcloud/talk/api/NcApi.java @@ -332,7 +332,7 @@ public interface NcApi { @FormUrlEncoded @PUT - Observable> setPassword2(@Header("Authorization") String authorization, + Observable setPassword2(@Header("Authorization") String authorization, @Url String url, @Field("password") String password); 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 a84b2ca6d..cee5671f6 100644 --- a/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt +++ b/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt @@ -132,4 +132,12 @@ interface NcApiCoroutines { @Url url: String, @Body body: RequestBody ): GenericOverall + + @FormUrlEncoded + @PUT + suspend fun setPassword2( + @Header("Authorization") authorization: String, + @Url url: String, + @Field("password") password: String + ): GenericOverall } diff --git a/app/src/main/java/com/nextcloud/talk/conversationinfo/GuestAccessHelper.kt b/app/src/main/java/com/nextcloud/talk/conversationinfo/GuestAccessHelper.kt index 414d2a089..cb1a91def 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationinfo/GuestAccessHelper.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationinfo/GuestAccessHelper.kt @@ -68,7 +68,7 @@ class GuestAccessHelper( viewModel.allowGuestsViewState.observe(lifecycleOwner){uiState -> when(uiState){ is ConversationInfoViewModel.AllowGuestsUIState.Success ->{ - if(uiState.result){ + if(uiState.allow){ showAllOptions() }else{ hideAllOptions() @@ -91,8 +91,8 @@ class GuestAccessHelper( val isChecked = binding.guestAccessView.passwordProtectionSwitch.isChecked binding.guestAccessView.passwordProtectionSwitch.isChecked = !isChecked if (isChecked) { - conversationsRepository.password("", conversation.token!!).subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()).subscribe(PasswordResultObserver(false)) + viewModel.setPassword("",conversation.token) + passwordObserver(false,"") } else { showPasswordDialog() } @@ -104,6 +104,38 @@ class GuestAccessHelper( } } + private fun passwordObserver(passwordSet:Boolean, password:String){ + viewModel.passwordViewState.observe(lifecycleOwner){uiState -> + when(uiState){ + is ConversationInfoViewModel.PasswordUiState.Success ->{ + val weakPassword = password.trim().length < 8 + binding.guestAccessView.passwordProtectionSwitch.isChecked = passwordSet && weakPassword + if (weakPassword && passwordSet) { + val builder = MaterialAlertDialogBuilder(activity) + builder.apply { + setTitle(R.string.nc_guest_access_password_weak_alert_title) + setMessage(R.string.nc_weak_password) + setPositiveButton("OK") { _, _ -> + } + } + createDialog(builder) + } + } + is ConversationInfoViewModel.PasswordUiState.Error ->{ + val exception = uiState.message + val message = context.getString(R.string.nc_guest_access_password_failed) + Snackbar.make(binding.root, message, Snackbar.LENGTH_LONG).show() + Log.e(TAG, exception) + + } + is ConversationInfoViewModel.PasswordUiState.None ->{ + //unused atm + } + } + } + + } + private fun showPasswordDialog() { val builder = MaterialAlertDialogBuilder(activity) builder.apply { @@ -113,10 +145,8 @@ class GuestAccessHelper( setTitle(R.string.nc_guest_access_password_dialog_title) setPositiveButton(R.string.nc_ok) { _, _ -> val password = dialogPassword.password.text.toString() - conversationsRepository.password(password, conversation.token!!) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(PasswordResultObserver(true)) + viewModel.setPassword(password, conversation.token) + passwordObserver(true, password) } setNegativeButton(R.string.nc_cancel) { _, _ -> binding.guestAccessView.passwordProtectionSwitch.isChecked = false 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 aad7bcb57..4ba0d0160 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 @@ -6,6 +6,7 @@ */ package com.nextcloud.talk.conversationinfo.viewmodel +import android.annotation.SuppressLint import android.util.Log import androidx.lifecycle.DefaultLifecycleObserver import androidx.lifecycle.LifecycleOwner @@ -103,6 +104,10 @@ class ConversationInfoViewModel @Inject constructor( val allowGuestsViewState: LiveData get() = _allowGuestsViewState + private val _passwordViewState = MutableLiveData(PasswordUiState.None) + val passwordViewState: LiveData + get() = _passwordViewState + private val _getCapabilitiesViewState: MutableLiveData = MutableLiveData(GetCapabilitiesStartState) val getCapabilitiesViewState: LiveData get() = _getCapabilitiesViewState @@ -249,7 +254,7 @@ class ConversationInfoViewModel @Inject constructor( val statusCode: GenericMeta? = allowGuestsResult.ocs?.meta val result = (statusCode?.statusCode == STATUS_CODE_OK) if (result) { - _allowGuestsViewState.value = AllowGuestsUIState.Success(result) + _allowGuestsViewState.value = AllowGuestsUIState.Success(allow) } }catch(exception:Exception){ _allowGuestsViewState.value = AllowGuestsUIState.Error(exception.message?: "") @@ -258,6 +263,22 @@ class ConversationInfoViewModel @Inject constructor( } } + + fun setPassword(password:String, token:String){ + viewModelScope.launch{ + try{ + val setPasswordResult = conversationsRepository.setPassword(password,token) + val statusCode: GenericMeta? = setPasswordResult.ocs?.meta + val result = (statusCode?.statusCode == STATUS_CODE_OK) + if(result){ + _passwordViewState.value = PasswordUiState.Success(result) + } + }catch(exception:Exception){ + _passwordViewState.value = PasswordUiState.Error(exception.message?:"") + } + } + } + suspend fun archiveConversation(user: User, token: String) { val apiVersion = ApiUtils.getConversationApiVersion(user, intArrayOf(ApiUtils.API_V4, ApiUtils.API_V1)) val url = ApiUtils.getUrlForArchive(apiVersion, user.baseUrl, token) @@ -295,7 +316,13 @@ class ConversationInfoViewModel @Inject constructor( sealed class AllowGuestsUIState { data object None : AllowGuestsUIState() - data class Success(val result: Boolean) : AllowGuestsUIState() + data class Success(val allow:Boolean) : AllowGuestsUIState() data class Error(val message: String) : AllowGuestsUIState() } + + sealed class PasswordUiState{ + data object None:PasswordUiState() + data class Success(val result:Boolean): PasswordUiState() + data class Error(val message:String): PasswordUiState() + } } 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 4a858a62d..d4ca0f490 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 @@ -20,8 +20,6 @@ interface ConversationsRepository { val message: String ) - fun password(password: String, token: String): Observable - data class ResendInvitationsResult( val successful: Boolean ) @@ -31,5 +29,7 @@ interface ConversationsRepository { suspend fun unarchiveConversation(credentials: String, url: String): GenericOverall + suspend fun setPassword(password: String, token: String): GenericOverall + fun setConversationReadOnly(credentials: String, url: String, state: Int): Observable } 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 4967f1051..db29492eb 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 @@ -7,13 +7,10 @@ */ package com.nextcloud.talk.repositories.conversations -import com.bluelinelabs.logansquare.LoganSquare 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.json.conversations.password.PasswordOverall import com.nextcloud.talk.models.json.generic.GenericOverall -import com.nextcloud.talk.repositories.conversations.ConversationsRepository.PasswordResult import com.nextcloud.talk.repositories.conversations.ConversationsRepository.ResendInvitationsResult import com.nextcloud.talk.utils.ApiUtils import com.nextcloud.talk.utils.database.user.CurrentUserProviderNew @@ -55,28 +52,6 @@ class ConversationsRepositoryImpl( } -override fun password(password: String, token: String): Observable { - val apiObservable = api.setPassword2( - credentials, - ApiUtils.getUrlForRoomPassword( - apiVersion(), - user.baseUrl!!, - token - ), - password - ) - return apiObservable.map { - val passwordPolicyMessage = if (it.code() == STATUS_CODE_BAD_REQUEST) { - LoganSquare.parse(it.errorBody()!!.string(), PasswordOverall::class.java).ocs!!.data!! - .message!! - } else { - "" - } - - PasswordResult(it.isSuccessful, passwordPolicyMessage.isNotEmpty(), passwordPolicyMessage) - } - } - override fun resendInvitations(token: String): Observable { val apiObservable = api.resendParticipantInvitations( credentials, @@ -104,6 +79,19 @@ override fun password(password: String, token: String): ObservableInvitations were sent out again. Invitations were not send due to an error. Share link + Password must be atleast 8 characters length Send message From 51330cbc7664ef5e98efb993151988a97bbb0491 Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Thu, 14 Nov 2024 07:40:25 +0100 Subject: [PATCH 06/11] remove unused imports Signed-off-by: sowjanyakch --- .../conversationinfo/viewmodel/ConversationInfoViewModel.kt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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 4ba0d0160..3dcd8dd75 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 @@ -6,7 +6,6 @@ */ package com.nextcloud.talk.conversationinfo.viewmodel -import android.annotation.SuppressLint import android.util.Log import androidx.lifecycle.DefaultLifecycleObserver import androidx.lifecycle.LifecycleOwner @@ -252,7 +251,7 @@ class ConversationInfoViewModel @Inject constructor( try{ val allowGuestsResult = conversationsRepository.allowGuests(token,allow) val statusCode: GenericMeta? = allowGuestsResult.ocs?.meta - val result = (statusCode?.statusCode == STATUS_CODE_OK) + val result = statusCode?.statusCode == STATUS_CODE_OK if (result) { _allowGuestsViewState.value = AllowGuestsUIState.Success(allow) } @@ -269,7 +268,7 @@ class ConversationInfoViewModel @Inject constructor( try{ val setPasswordResult = conversationsRepository.setPassword(password,token) val statusCode: GenericMeta? = setPasswordResult.ocs?.meta - val result = (statusCode?.statusCode == STATUS_CODE_OK) + val result = statusCode?.statusCode == STATUS_CODE_OK if(result){ _passwordViewState.value = PasswordUiState.Success(result) } From e0b2174fc73e74b4193bdce169d11b8f4cbf968a Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Thu, 14 Nov 2024 09:20:28 +0100 Subject: [PATCH 07/11] use one endpoint instead of two Signed-off-by: sowjanyakch --- .../java/com/nextcloud/talk/api/NcApi.java | 7 -- .../conversationinfo/GuestAccessHelper.kt | 84 +++++-------------- .../viewmodel/ConversationInfoViewModel.kt | 57 +++++++------ .../ConversationsRepositoryImpl.kt | 6 +- 4 files changed, 50 insertions(+), 104 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 165171fd4..2e39a926c 100644 --- a/app/src/main/java/com/nextcloud/talk/api/NcApi.java +++ b/app/src/main/java/com/nextcloud/talk/api/NcApi.java @@ -329,13 +329,6 @@ public interface NcApi { Observable unregisterDeviceForNotificationsWithProxy(@Url String url, @QueryMap Map fields); - - @FormUrlEncoded - @PUT - Observable setPassword2(@Header("Authorization") String authorization, - @Url String url, - @Field("password") String password); - @GET Observable getCapabilities(@Header("Authorization") String authorization, @Url String url); diff --git a/app/src/main/java/com/nextcloud/talk/conversationinfo/GuestAccessHelper.kt b/app/src/main/java/com/nextcloud/talk/conversationinfo/GuestAccessHelper.kt index cb1a91def..51ce20972 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationinfo/GuestAccessHelper.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationinfo/GuestAccessHelper.kt @@ -65,23 +65,23 @@ class GuestAccessHelper( val isChecked = binding.guestAccessView.allowGuestsSwitch.isChecked binding.guestAccessView.allowGuestsSwitch.isChecked = !isChecked viewModel.allowGuests(conversation.token, !isChecked) - viewModel.allowGuestsViewState.observe(lifecycleOwner){uiState -> - when(uiState){ - is ConversationInfoViewModel.AllowGuestsUIState.Success ->{ - if(uiState.allow){ + viewModel.allowGuestsViewState.observe(lifecycleOwner) { uiState -> + when (uiState) { + is ConversationInfoViewModel.AllowGuestsUIState.Success -> { + binding.guestAccessView.allowGuestsSwitch.isChecked = uiState.allow + if (uiState.allow) { showAllOptions() - }else{ + } else { hideAllOptions() } } - is ConversationInfoViewModel.AllowGuestsUIState.Error ->{ + is ConversationInfoViewModel.AllowGuestsUIState.Error -> { val exception = uiState.message val message = context.getString(R.string.nc_guest_access_allow_failed) Snackbar.make(binding.root, message, Snackbar.LENGTH_LONG).show() Log.e(TAG, exception) } - ConversationInfoViewModel.AllowGuestsUIState.None ->{ - //unused atm + ConversationInfoViewModel.AllowGuestsUIState.None -> { } } } @@ -91,8 +91,8 @@ class GuestAccessHelper( val isChecked = binding.guestAccessView.passwordProtectionSwitch.isChecked binding.guestAccessView.passwordProtectionSwitch.isChecked = !isChecked if (isChecked) { - viewModel.setPassword("",conversation.token) - passwordObserver(false,"") + viewModel.setPassword("", conversation.token) + passwordObserver() } else { showPasswordDialog() } @@ -104,36 +104,23 @@ class GuestAccessHelper( } } - private fun passwordObserver(passwordSet:Boolean, password:String){ - viewModel.passwordViewState.observe(lifecycleOwner){uiState -> - when(uiState){ - is ConversationInfoViewModel.PasswordUiState.Success ->{ - val weakPassword = password.trim().length < 8 - binding.guestAccessView.passwordProtectionSwitch.isChecked = passwordSet && weakPassword - if (weakPassword && passwordSet) { - val builder = MaterialAlertDialogBuilder(activity) - builder.apply { - setTitle(R.string.nc_guest_access_password_weak_alert_title) - setMessage(R.string.nc_weak_password) - setPositiveButton("OK") { _, _ -> - } - } - createDialog(builder) - } + private fun passwordObserver() { + viewModel.passwordViewState.observe(lifecycleOwner) { uiState -> + when (uiState) { + is ConversationInfoViewModel.PasswordUiState.Success -> { + // unused atm } - is ConversationInfoViewModel.PasswordUiState.Error ->{ + is ConversationInfoViewModel.PasswordUiState.Error -> { val exception = uiState.message val message = context.getString(R.string.nc_guest_access_password_failed) Snackbar.make(binding.root, message, Snackbar.LENGTH_LONG).show() Log.e(TAG, exception) - } - is ConversationInfoViewModel.PasswordUiState.None ->{ - //unused atm + is ConversationInfoViewModel.PasswordUiState.None -> { + // unused atm } } } - } private fun showPasswordDialog() { @@ -145,14 +132,14 @@ class GuestAccessHelper( setTitle(R.string.nc_guest_access_password_dialog_title) setPositiveButton(R.string.nc_ok) { _, _ -> val password = dialogPassword.password.text.toString() - viewModel.setPassword(password, conversation.token) - passwordObserver(true, password) + viewModel.setPassword(password, conversation.token) } setNegativeButton(R.string.nc_cancel) { _, _ -> binding.guestAccessView.passwordProtectionSwitch.isChecked = false } } createDialog(builder) + passwordObserver() } private fun createDialog(builder: MaterialAlertDialogBuilder) { @@ -204,37 +191,6 @@ class GuestAccessHelper( binding.guestAccessView.resendInvitationsButton.visibility = View.GONE } - inner class PasswordResultObserver(private val setPassword: Boolean) : - Observer { - - private lateinit var passwordResult: ConversationsRepository.PasswordResult - - override fun onSubscribe(d: Disposable) = Unit - - override fun onNext(t: ConversationsRepository.PasswordResult) { - passwordResult = t - } - - override fun onError(e: Throwable) { - val message = context.getString(R.string.nc_guest_access_password_failed) - Snackbar.make(binding.root, message, Snackbar.LENGTH_LONG).show() - Log.e(TAG, message, e) - } - - override fun onComplete() { - binding.guestAccessView.passwordProtectionSwitch.isChecked = passwordResult.passwordSet && setPassword - if (passwordResult.passwordIsWeak) { - val builder = MaterialAlertDialogBuilder(activity) - builder.apply { - setTitle(R.string.nc_guest_access_password_weak_alert_title) - setMessage(passwordResult.message) - setPositiveButton("OK") { _, _ -> } - } - createDialog(builder) - } - } - } - companion object { private val TAG = GuestAccessHelper::class.simpleName } 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 3dcd8dd75..c281ba4c9 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 @@ -6,6 +6,7 @@ */ package com.nextcloud.talk.conversationinfo.viewmodel +import android.annotation.SuppressLint import android.util.Log import androidx.lifecycle.DefaultLifecycleObserver import androidx.lifecycle.LifecycleOwner @@ -245,35 +246,33 @@ class ConversationInfoViewModel @Inject constructor( }) } - - fun allowGuests(token:String,allow:Boolean){ - viewModelScope.launch{ - try{ - val allowGuestsResult = conversationsRepository.allowGuests(token,allow) - val statusCode: GenericMeta? = allowGuestsResult.ocs?.meta - val result = statusCode?.statusCode == STATUS_CODE_OK - if (result) { - _allowGuestsViewState.value = AllowGuestsUIState.Success(allow) - } - }catch(exception:Exception){ - _allowGuestsViewState.value = AllowGuestsUIState.Error(exception.message?: "") - - } + fun allowGuests(token: String, allow: Boolean) { + viewModelScope.launch { + try { + val allowGuestsResult = conversationsRepository.allowGuests(token, allow) + val statusCode: GenericMeta? = allowGuestsResult.ocs?.meta + val result = statusCode?.statusCode == STATUS_CODE_OK + if (result) { + _allowGuestsViewState.value = AllowGuestsUIState.Success(allow) + } + } catch (exception: Exception) { + _allowGuestsViewState.value = AllowGuestsUIState.Error(exception.message ?: "") + } } } - - fun setPassword(password:String, token:String){ - viewModelScope.launch{ - try{ - val setPasswordResult = conversationsRepository.setPassword(password,token) + @SuppressLint("SuspiciousIndentation") + fun setPassword(password: String, token: String) { + viewModelScope.launch { + try { + val setPasswordResult = conversationsRepository.setPassword(password, token) val statusCode: GenericMeta? = setPasswordResult.ocs?.meta val result = statusCode?.statusCode == STATUS_CODE_OK - if(result){ - _passwordViewState.value = PasswordUiState.Success(result) - } - }catch(exception:Exception){ - _passwordViewState.value = PasswordUiState.Error(exception.message?:"") + if (result) { + _passwordViewState.value = PasswordUiState.Success(result) + } + } catch (exception: Exception) { + _passwordViewState.value = PasswordUiState.Error(exception.message ?: "") } } } @@ -315,13 +314,13 @@ class ConversationInfoViewModel @Inject constructor( sealed class AllowGuestsUIState { data object None : AllowGuestsUIState() - data class Success(val allow:Boolean) : AllowGuestsUIState() + data class Success(val allow: Boolean) : AllowGuestsUIState() data class Error(val message: String) : AllowGuestsUIState() } - sealed class PasswordUiState{ - data object None:PasswordUiState() - data class Success(val result:Boolean): PasswordUiState() - data class Error(val message:String): PasswordUiState() + sealed class PasswordUiState { + data object None : PasswordUiState() + data class Success(val result: Boolean) : PasswordUiState() + data class Error(val message: String) : PasswordUiState() } } 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 db29492eb..254f0e4f7 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 @@ -38,7 +38,7 @@ class ConversationsRepositoryImpl( ) val result: GenericOverall = if (allow) { - coroutineApi.makeRoomPublic( + coroutineApi.makeRoomPublic( credentials, url ) @@ -51,7 +51,6 @@ class ConversationsRepositoryImpl( return result } - override fun resendInvitations(token: String): Observable { val apiObservable = api.resendParticipantInvitations( credentials, @@ -80,7 +79,7 @@ class ConversationsRepositoryImpl( } override suspend fun setPassword(password: String, token: String): GenericOverall { - val result = coroutineApi.setPassword2( + val result = coroutineApi.setPassword( credentials, ApiUtils.getUrlForRoomPassword( apiVersion, @@ -98,6 +97,5 @@ class ConversationsRepositoryImpl( companion object { const val STATUS_CODE_OK = 200 - const val STATUS_CODE_BAD_REQUEST = 400 } } From 03c4402630eb30c172c231808c1eea19d8feabe9 Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Thu, 14 Nov 2024 09:27:48 +0100 Subject: [PATCH 08/11] remove unused string Signed-off-by: sowjanyakch --- app/src/main/res/values/strings.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 29b9af894..ca4c364cf 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -455,7 +455,6 @@ How to translate with transifex: Invitations were sent out again. Invitations were not send due to an error. Share link - Password must be atleast 8 characters length Send message From 3de36ebec386429e71bff87ab239c95cabaf01aa Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Thu, 14 Nov 2024 09:28:48 +0100 Subject: [PATCH 09/11] ktlintFormat Signed-off-by: sowjanyakch --- .../com/nextcloud/talk/conversationinfo/GuestAccessHelper.kt | 2 +- .../conversationinfo/viewmodel/ConversationInfoViewModel.kt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/conversationinfo/GuestAccessHelper.kt b/app/src/main/java/com/nextcloud/talk/conversationinfo/GuestAccessHelper.kt index 51ce20972..9174ea5d8 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationinfo/GuestAccessHelper.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationinfo/GuestAccessHelper.kt @@ -104,7 +104,7 @@ class GuestAccessHelper( } } - private fun passwordObserver() { + private fun passwordObserver() { viewModel.passwordViewState.observe(lifecycleOwner) { uiState -> when (uiState) { is ConversationInfoViewModel.PasswordUiState.Success -> { 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 c281ba4c9..197402816 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 @@ -246,7 +246,7 @@ class ConversationInfoViewModel @Inject constructor( }) } - fun allowGuests(token: String, allow: Boolean) { + fun allowGuests(token: String, allow: Boolean) { viewModelScope.launch { try { val allowGuestsResult = conversationsRepository.allowGuests(token, allow) @@ -262,7 +262,7 @@ class ConversationInfoViewModel @Inject constructor( } @SuppressLint("SuspiciousIndentation") - fun setPassword(password: String, token: String) { + fun setPassword(password: String, token: String) { viewModelScope.launch { try { val setPasswordResult = conversationsRepository.setPassword(password, token) From 013195465cc2da1b64e4e24409dd29c21da96e9c Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Sun, 17 Nov 2024 22:02:56 +0100 Subject: [PATCH 10/11] refactoring Signed-off-by: sowjanyakch --- .../conversationinfo/GuestAccessHelper.kt | 8 +++--- .../viewmodel/ConversationInfoViewModel.kt | 28 ++++++------------- 2 files changed, 13 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/conversationinfo/GuestAccessHelper.kt b/app/src/main/java/com/nextcloud/talk/conversationinfo/GuestAccessHelper.kt index 9174ea5d8..875611144 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationinfo/GuestAccessHelper.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationinfo/GuestAccessHelper.kt @@ -76,10 +76,10 @@ class GuestAccessHelper( } } is ConversationInfoViewModel.AllowGuestsUIState.Error -> { - val exception = uiState.message + val exception = uiState.exception val message = context.getString(R.string.nc_guest_access_allow_failed) Snackbar.make(binding.root, message, Snackbar.LENGTH_LONG).show() - Log.e(TAG, exception) + Log.e(TAG, message, exception) } ConversationInfoViewModel.AllowGuestsUIState.None -> { } @@ -111,10 +111,10 @@ class GuestAccessHelper( // unused atm } is ConversationInfoViewModel.PasswordUiState.Error -> { - val exception = uiState.message + val exception = uiState.exception val message = context.getString(R.string.nc_guest_access_password_failed) Snackbar.make(binding.root, message, Snackbar.LENGTH_LONG).show() - Log.e(TAG, exception) + Log.e(TAG, message, exception) } is ConversationInfoViewModel.PasswordUiState.None -> { // unused atm 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 197402816..efad9cfc4 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 @@ -249,14 +247,10 @@ class ConversationInfoViewModel @Inject constructor( fun allowGuests(token: String, allow: Boolean) { viewModelScope.launch { try { - val allowGuestsResult = conversationsRepository.allowGuests(token, allow) - val statusCode: GenericMeta? = allowGuestsResult.ocs?.meta - val result = statusCode?.statusCode == STATUS_CODE_OK - if (result) { - _allowGuestsViewState.value = AllowGuestsUIState.Success(allow) - } + conversationsRepository.allowGuests(token, allow) + _allowGuestsViewState.value = AllowGuestsUIState.Success(allow) } catch (exception: Exception) { - _allowGuestsViewState.value = AllowGuestsUIState.Error(exception.message ?: "") + _allowGuestsViewState.value = AllowGuestsUIState.Error(exception) } } } @@ -265,14 +259,10 @@ class ConversationInfoViewModel @Inject constructor( fun setPassword(password: String, token: String) { viewModelScope.launch { try { - val setPasswordResult = conversationsRepository.setPassword(password, token) - val statusCode: GenericMeta? = setPasswordResult.ocs?.meta - val result = statusCode?.statusCode == STATUS_CODE_OK - if (result) { - _passwordViewState.value = PasswordUiState.Success(result) - } + conversationsRepository.setPassword(password, token) + _passwordViewState.value = PasswordUiState.Success } catch (exception: Exception) { - _passwordViewState.value = PasswordUiState.Error(exception.message ?: "") + _passwordViewState.value = PasswordUiState.Error(exception) } } } @@ -315,12 +305,12 @@ class ConversationInfoViewModel @Inject constructor( sealed class AllowGuestsUIState { data object None : AllowGuestsUIState() data class Success(val allow: Boolean) : AllowGuestsUIState() - data class Error(val message: String) : AllowGuestsUIState() + data class Error(val exception: Exception) : AllowGuestsUIState() } sealed class PasswordUiState { data object None : PasswordUiState() - data class Success(val result: Boolean) : PasswordUiState() - data class Error(val message: String) : PasswordUiState() + data object Success : PasswordUiState() + data class Error(val exception: Exception) : PasswordUiState() } } From e5802d70f371148ccdcc6eaa12744cd288f2cff6 Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Mon, 18 Nov 2024 10:22:51 +0100 Subject: [PATCH 11/11] remove unused code Signed-off-by: sowjanyakch --- .../repositories/conversations/ConversationsRepository.kt | 6 ------ 1 file changed, 6 deletions(-) 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 d4ca0f490..e4114bfaf 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 @@ -14,12 +14,6 @@ interface ConversationsRepository { suspend fun allowGuests(token: String, allow: Boolean): GenericOverall - data class PasswordResult( - val passwordSet: Boolean, - val passwordIsWeak: Boolean, - val message: String - ) - data class ResendInvitationsResult( val successful: Boolean )