check for capability before reverting status

Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
This commit is contained in:
sowjanyakch 2024-11-06 18:27:03 +01:00
parent 7a63a645fe
commit c4f4c857d3
No known key found for this signature in database
GPG key ID: F7AA2A8B65B50220
2 changed files with 35 additions and 33 deletions

View file

@ -283,41 +283,43 @@ class SetStatusDialogFragment :
} }
} }
override fun revertStatus() { override fun revertStatus() {
ncApi.revertStatus( if (isRestoreStatusAvailable(currentUser!!)) {
credentials, ncApi.revertStatus(
ApiUtils.getUrlForRevertStatus(currentUser?.baseUrl!!, currentStatus?.messageId) credentials,
) ApiUtils.getUrlForRevertStatus(currentUser?.baseUrl!!, currentStatus?.messageId)
.subscribeOn(Schedulers.io()) )
.observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io())
.subscribe(object : Observer<GenericOverall> { .observeOn(AndroidSchedulers.mainThread())
.subscribe(object : Observer<GenericOverall> {
override fun onSubscribe(d: Disposable) { 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 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() { private fun setupGeneralStatusOptions() {

View file

@ -487,7 +487,7 @@ object ApiUtils {
return "$baseUrl$OCS_API_VERSION/apps/user_status/api/v1/statuses/_$userId" 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" return "$baseUrl$OCS_API_VERSION/apps/user_status/api/v1/user_status/revert/$messageId"
} }