mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-19 19:49:33 +01:00
use one endpoint instead of two
Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
This commit is contained in:
parent
51330cbc76
commit
e0b2174fc7
@ -329,13 +329,6 @@ public interface NcApi {
|
|||||||
Observable<Void> unregisterDeviceForNotificationsWithProxy(@Url String url,
|
Observable<Void> unregisterDeviceForNotificationsWithProxy(@Url String url,
|
||||||
@QueryMap Map<String, String> fields);
|
@QueryMap Map<String, String> fields);
|
||||||
|
|
||||||
|
|
||||||
@FormUrlEncoded
|
|
||||||
@PUT
|
|
||||||
Observable<GenericOverall> setPassword2(@Header("Authorization") String authorization,
|
|
||||||
@Url String url,
|
|
||||||
@Field("password") String password);
|
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
Observable<CapabilitiesOverall> getCapabilities(@Header("Authorization") String authorization, @Url String url);
|
Observable<CapabilitiesOverall> getCapabilities(@Header("Authorization") String authorization, @Url String url);
|
||||||
|
|
||||||
|
@ -68,6 +68,7 @@ class GuestAccessHelper(
|
|||||||
viewModel.allowGuestsViewState.observe(lifecycleOwner) { uiState ->
|
viewModel.allowGuestsViewState.observe(lifecycleOwner) { uiState ->
|
||||||
when (uiState) {
|
when (uiState) {
|
||||||
is ConversationInfoViewModel.AllowGuestsUIState.Success -> {
|
is ConversationInfoViewModel.AllowGuestsUIState.Success -> {
|
||||||
|
binding.guestAccessView.allowGuestsSwitch.isChecked = uiState.allow
|
||||||
if (uiState.allow) {
|
if (uiState.allow) {
|
||||||
showAllOptions()
|
showAllOptions()
|
||||||
} else {
|
} else {
|
||||||
@ -81,7 +82,6 @@ class GuestAccessHelper(
|
|||||||
Log.e(TAG, exception)
|
Log.e(TAG, exception)
|
||||||
}
|
}
|
||||||
ConversationInfoViewModel.AllowGuestsUIState.None -> {
|
ConversationInfoViewModel.AllowGuestsUIState.None -> {
|
||||||
//unused atm
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -92,7 +92,7 @@ class GuestAccessHelper(
|
|||||||
binding.guestAccessView.passwordProtectionSwitch.isChecked = !isChecked
|
binding.guestAccessView.passwordProtectionSwitch.isChecked = !isChecked
|
||||||
if (isChecked) {
|
if (isChecked) {
|
||||||
viewModel.setPassword("", conversation.token)
|
viewModel.setPassword("", conversation.token)
|
||||||
passwordObserver(false,"")
|
passwordObserver()
|
||||||
} else {
|
} else {
|
||||||
showPasswordDialog()
|
showPasswordDialog()
|
||||||
}
|
}
|
||||||
@ -104,36 +104,23 @@ class GuestAccessHelper(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun passwordObserver(passwordSet:Boolean, password:String){
|
private fun passwordObserver() {
|
||||||
viewModel.passwordViewState.observe(lifecycleOwner) { uiState ->
|
viewModel.passwordViewState.observe(lifecycleOwner) { uiState ->
|
||||||
when (uiState) {
|
when (uiState) {
|
||||||
is ConversationInfoViewModel.PasswordUiState.Success -> {
|
is ConversationInfoViewModel.PasswordUiState.Success -> {
|
||||||
val weakPassword = password.trim().length < 8
|
// unused atm
|
||||||
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 -> {
|
is ConversationInfoViewModel.PasswordUiState.Error -> {
|
||||||
val exception = uiState.message
|
val exception = uiState.message
|
||||||
val message = context.getString(R.string.nc_guest_access_password_failed)
|
val message = context.getString(R.string.nc_guest_access_password_failed)
|
||||||
Snackbar.make(binding.root, message, Snackbar.LENGTH_LONG).show()
|
Snackbar.make(binding.root, message, Snackbar.LENGTH_LONG).show()
|
||||||
Log.e(TAG, exception)
|
Log.e(TAG, exception)
|
||||||
|
|
||||||
}
|
}
|
||||||
is ConversationInfoViewModel.PasswordUiState.None -> {
|
is ConversationInfoViewModel.PasswordUiState.None -> {
|
||||||
// unused atm
|
// unused atm
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showPasswordDialog() {
|
private fun showPasswordDialog() {
|
||||||
@ -146,13 +133,13 @@ class GuestAccessHelper(
|
|||||||
setPositiveButton(R.string.nc_ok) { _, _ ->
|
setPositiveButton(R.string.nc_ok) { _, _ ->
|
||||||
val password = dialogPassword.password.text.toString()
|
val password = dialogPassword.password.text.toString()
|
||||||
viewModel.setPassword(password, conversation.token)
|
viewModel.setPassword(password, conversation.token)
|
||||||
passwordObserver(true, password)
|
|
||||||
}
|
}
|
||||||
setNegativeButton(R.string.nc_cancel) { _, _ ->
|
setNegativeButton(R.string.nc_cancel) { _, _ ->
|
||||||
binding.guestAccessView.passwordProtectionSwitch.isChecked = false
|
binding.guestAccessView.passwordProtectionSwitch.isChecked = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
createDialog(builder)
|
createDialog(builder)
|
||||||
|
passwordObserver()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createDialog(builder: MaterialAlertDialogBuilder) {
|
private fun createDialog(builder: MaterialAlertDialogBuilder) {
|
||||||
@ -204,37 +191,6 @@ class GuestAccessHelper(
|
|||||||
binding.guestAccessView.resendInvitationsButton.visibility = View.GONE
|
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 {
|
companion object {
|
||||||
private val TAG = GuestAccessHelper::class.simpleName
|
private val TAG = GuestAccessHelper::class.simpleName
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.nextcloud.talk.conversationinfo.viewmodel
|
package com.nextcloud.talk.conversationinfo.viewmodel
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.lifecycle.DefaultLifecycleObserver
|
import androidx.lifecycle.DefaultLifecycleObserver
|
||||||
import androidx.lifecycle.LifecycleOwner
|
import androidx.lifecycle.LifecycleOwner
|
||||||
@ -245,7 +246,6 @@ class ConversationInfoViewModel @Inject constructor(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun allowGuests(token: String, allow: Boolean) {
|
fun allowGuests(token: String, allow: Boolean) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
try {
|
try {
|
||||||
@ -257,12 +257,11 @@ class ConversationInfoViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
} catch (exception: Exception) {
|
} catch (exception: Exception) {
|
||||||
_allowGuestsViewState.value = AllowGuestsUIState.Error(exception.message ?: "")
|
_allowGuestsViewState.value = AllowGuestsUIState.Error(exception.message ?: "")
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("SuspiciousIndentation")
|
||||||
fun setPassword(password: String, token: String) {
|
fun setPassword(password: String, token: String) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
try {
|
try {
|
||||||
|
@ -51,7 +51,6 @@ class ConversationsRepositoryImpl(
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun resendInvitations(token: String): Observable<ResendInvitationsResult> {
|
override fun resendInvitations(token: String): Observable<ResendInvitationsResult> {
|
||||||
val apiObservable = api.resendParticipantInvitations(
|
val apiObservable = api.resendParticipantInvitations(
|
||||||
credentials,
|
credentials,
|
||||||
@ -80,7 +79,7 @@ class ConversationsRepositoryImpl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun setPassword(password: String, token: String): GenericOverall {
|
override suspend fun setPassword(password: String, token: String): GenericOverall {
|
||||||
val result = coroutineApi.setPassword2(
|
val result = coroutineApi.setPassword(
|
||||||
credentials,
|
credentials,
|
||||||
ApiUtils.getUrlForRoomPassword(
|
ApiUtils.getUrlForRoomPassword(
|
||||||
apiVersion,
|
apiVersion,
|
||||||
@ -98,6 +97,5 @@ class ConversationsRepositoryImpl(
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val STATUS_CODE_OK = 200
|
const val STATUS_CODE_OK = 200
|
||||||
const val STATUS_CODE_BAD_REQUEST = 400
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user