mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-11-21 12:35:30 +03:00
use one endpoint instead of two
Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
This commit is contained in:
parent
51330cbc76
commit
e0b2174fc7
4 changed files with 50 additions and 104 deletions
|
@ -329,13 +329,6 @@ public interface NcApi {
|
|||
Observable<Void> unregisterDeviceForNotificationsWithProxy(@Url String url,
|
||||
@QueryMap Map<String, String> fields);
|
||||
|
||||
|
||||
@FormUrlEncoded
|
||||
@PUT
|
||||
Observable<GenericOverall> setPassword2(@Header("Authorization") String authorization,
|
||||
@Url String url,
|
||||
@Field("password") String password);
|
||||
|
||||
@GET
|
||||
Observable<CapabilitiesOverall> getCapabilities(@Header("Authorization") String authorization, @Url String url);
|
||||
|
||||
|
|
|
@ -68,6 +68,7 @@ class GuestAccessHelper(
|
|||
viewModel.allowGuestsViewState.observe(lifecycleOwner) { uiState ->
|
||||
when (uiState) {
|
||||
is ConversationInfoViewModel.AllowGuestsUIState.Success -> {
|
||||
binding.guestAccessView.allowGuestsSwitch.isChecked = uiState.allow
|
||||
if (uiState.allow) {
|
||||
showAllOptions()
|
||||
} else {
|
||||
|
@ -81,7 +82,6 @@ class GuestAccessHelper(
|
|||
Log.e(TAG, exception)
|
||||
}
|
||||
ConversationInfoViewModel.AllowGuestsUIState.None -> {
|
||||
//unused atm
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ class GuestAccessHelper(
|
|||
binding.guestAccessView.passwordProtectionSwitch.isChecked = !isChecked
|
||||
if (isChecked) {
|
||||
viewModel.setPassword("", conversation.token)
|
||||
passwordObserver(false,"")
|
||||
passwordObserver()
|
||||
} else {
|
||||
showPasswordDialog()
|
||||
}
|
||||
|
@ -104,36 +104,23 @@ class GuestAccessHelper(
|
|||
}
|
||||
}
|
||||
|
||||
private fun passwordObserver(passwordSet:Boolean, password:String){
|
||||
private fun passwordObserver() {
|
||||
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)
|
||||
}
|
||||
// unused atm
|
||||
}
|
||||
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() {
|
||||
|
@ -146,13 +133,13 @@ class GuestAccessHelper(
|
|||
setPositiveButton(R.string.nc_ok) { _, _ ->
|
||||
val password = dialogPassword.password.text.toString()
|
||||
viewModel.setPassword(password, conversation.token)
|
||||
passwordObserver(true, password)
|
||||
}
|
||||
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<ConversationsRepository.PasswordResult> {
|
||||
|
||||
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
|
||||
}
|
||||
|
|
|
@ -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,7 +246,6 @@ class ConversationInfoViewModel @Inject constructor(
|
|||
})
|
||||
}
|
||||
|
||||
|
||||
fun allowGuests(token: String, allow: Boolean) {
|
||||
viewModelScope.launch {
|
||||
try {
|
||||
|
@ -257,12 +257,11 @@ class ConversationInfoViewModel @Inject constructor(
|
|||
}
|
||||
} catch (exception: Exception) {
|
||||
_allowGuestsViewState.value = AllowGuestsUIState.Error(exception.message ?: "")
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SuppressLint("SuspiciousIndentation")
|
||||
fun setPassword(password: String, token: String) {
|
||||
viewModelScope.launch {
|
||||
try {
|
||||
|
|
|
@ -51,7 +51,6 @@ class ConversationsRepositoryImpl(
|
|||
return result
|
||||
}
|
||||
|
||||
|
||||
override fun resendInvitations(token: String): Observable<ResendInvitationsResult> {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue