Remove rxjava from deletestatus API (#3041)

* Remove rxjava from API calls used by AccountListFragment

* Remove rxjava from API calls used by AccountViewModel::changeRelationship()

The affected API functions are also called from

- ReportViewModel.kt
- SearchViewModel.kt
- AccountListFragment.kt
- SFragment.java
- TimelineCases.kt

so they have also been updated.

This change requires bridging from Java code to Kotlin `suspend` functions,
by creating wrappers for the `mute` and `block` functions that can be
called from Java and create a coroutine scope.

I've deliberately made this fairly ugly so that it sticks out and can be
removed later.

* Use "Throwable" type and name

* Delete 46.json

Not sure where this came from.

* Remove rxjava from the deleteStatus call path

* Emit log messages with the correct tag

* Add another log tag, and lint

* Use TAG in log messages now it's present

* Lint

* Move viewModelScope.launch in to changeRelationshop()

* Use onSuccess/onFailure pair instead of fold

* Return Deferred when deleting statuses
This commit is contained in:
Nik Clayton 2023-01-10 21:20:00 +01:00 committed by GitHub
commit 561eda8482
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 45 additions and 50 deletions

View file

@ -16,6 +16,9 @@
package com.keylesspalace.tusky.usecase
import android.util.Log
import at.connyduck.calladapter.networkresult.NetworkResult
import at.connyduck.calladapter.networkresult.onFailure
import at.connyduck.calladapter.networkresult.onSuccess
import com.keylesspalace.tusky.appstore.BlockEvent
import com.keylesspalace.tusky.appstore.BookmarkEvent
import com.keylesspalace.tusky.appstore.EventHub
@ -112,11 +115,10 @@ class TimelineCases @Inject constructor(
}
}
fun delete(statusId: String): Single<DeletedStatus> {
suspend fun delete(statusId: String): NetworkResult<DeletedStatus> {
return mastodonApi.deleteStatus(statusId)
.doAfterSuccess {
eventHub.dispatch(StatusDeletedEvent(statusId))
}
.onSuccess { eventHub.dispatch(StatusDeletedEvent(statusId)) }
.onFailure { Log.w(TAG, "Failed to delete status", it) }
}
fun pin(statusId: String, pin: Boolean): Single<Status> {