mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-11-23 21:45:42 +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);
|
||||
|
||||
|
|
|
@ -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<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,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()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<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