diff --git a/app/src/main/java/com/nextcloud/talk/ui/dialog/SetStatusDialogFragment.kt b/app/src/main/java/com/nextcloud/talk/ui/dialog/SetStatusDialogFragment.kt index 764029366..77cab2606 100644 --- a/app/src/main/java/com/nextcloud/talk/ui/dialog/SetStatusDialogFragment.kt +++ b/app/src/main/java/com/nextcloud/talk/ui/dialog/SetStatusDialogFragment.kt @@ -283,41 +283,43 @@ class SetStatusDialogFragment : } } - override fun revertStatus() { - ncApi.revertStatus( - credentials, - ApiUtils.getUrlForRevertStatus(currentUser?.baseUrl!!, currentStatus?.messageId) - ) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(object : Observer { + override fun revertStatus() { + if (isRestoreStatusAvailable(currentUser!!)) { + ncApi.revertStatus( + credentials, + ApiUtils.getUrlForRevertStatus(currentUser?.baseUrl!!, currentStatus?.messageId) + ) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(object : Observer { - override fun onSubscribe(d: Disposable) { - } - - @SuppressLint("NotifyDataSetChanged") - override fun onNext(genericOverall: GenericOverall) { - Log.d(TAG, "$genericOverall") - if (genericOverall.ocs?.meta?.statusCode == 200) { - Snackbar.make( - binding.root, - R.string.status_reverted, - Snackbar.LENGTH_LONG - ).show() - adapter.isBackupStatusAvailable = false - predefinedStatusesList.removeAt(0) - adapter.notifyDataSetChanged() - currentStatus = backupStatus - setupCurrentStatus() + override fun onSubscribe(d: Disposable) { } - } - override fun onError(e: Throwable) { - Log.e(TAG, "Error while fetching predefined statuses", e) - } - override fun onComplete() { - } - }) + @SuppressLint("NotifyDataSetChanged") + override fun onNext(genericOverall: GenericOverall) { + Log.d(TAG, "$genericOverall") + if (genericOverall.ocs?.meta?.statusCode == 200) { + Snackbar.make( + binding.root, + R.string.status_reverted, + Snackbar.LENGTH_LONG + ).show() + adapter.isBackupStatusAvailable = false + predefinedStatusesList.removeAt(0) + adapter.notifyDataSetChanged() + currentStatus = backupStatus + setupCurrentStatus() + } + } + override fun onError(e: Throwable) { + Log.e(TAG, "Error while fetching predefined statuses", e) + } + + override fun onComplete() { + } + }) + } } private fun setupGeneralStatusOptions() { diff --git a/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.kt b/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.kt index aa4023a79..5440e6bb1 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.kt +++ b/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.kt @@ -487,7 +487,7 @@ object ApiUtils { return "$baseUrl$OCS_API_VERSION/apps/user_status/api/v1/statuses/_$userId" } - fun getUrlForRevertStatus(baseUrl: String, messageId: String?): String { + fun getUrlForRevertStatus(baseUrl: String, messageId: String?): String { return "$baseUrl$OCS_API_VERSION/apps/user_status/api/v1/user_status/revert/$messageId" }