Remove rxjava from API calls used by AccountViewModel::changeRelationship() (#3008)
* 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. * Emit log messages with the correct tag * Add another log tag, and lint * Move viewModelScope.launch in to changeRelationshop()
This commit is contained in:
parent
68f20e03c4
commit
a21f2fadf9
7 changed files with 145 additions and 142 deletions
|
|
@ -33,7 +33,6 @@ import com.keylesspalace.tusky.network.MastodonApi
|
|||
import com.keylesspalace.tusky.util.getServerErrorMessage
|
||||
import io.reactivex.rxjava3.core.Single
|
||||
import io.reactivex.rxjava3.disposables.CompositeDisposable
|
||||
import io.reactivex.rxjava3.kotlin.addTo
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
|
|
@ -95,30 +94,22 @@ class TimelineCases @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
fun mute(statusId: String, notifications: Boolean, duration: Int?) {
|
||||
mastodonApi.muteAccount(statusId, notifications, duration)
|
||||
.subscribe(
|
||||
{
|
||||
eventHub.dispatch(MuteEvent(statusId))
|
||||
},
|
||||
{ t ->
|
||||
Log.w("Failed to mute account", t)
|
||||
}
|
||||
)
|
||||
.addTo(cancelDisposable)
|
||||
suspend fun mute(statusId: String, notifications: Boolean, duration: Int?) {
|
||||
try {
|
||||
mastodonApi.muteAccount(statusId, notifications, duration)
|
||||
eventHub.dispatch(MuteEvent(statusId))
|
||||
} catch (t: Throwable) {
|
||||
Log.w(TAG, "Failed to mute account", t)
|
||||
}
|
||||
}
|
||||
|
||||
fun block(statusId: String) {
|
||||
mastodonApi.blockAccount(statusId)
|
||||
.subscribe(
|
||||
{
|
||||
eventHub.dispatch(BlockEvent(statusId))
|
||||
},
|
||||
{ t ->
|
||||
Log.w("Failed to block account", t)
|
||||
}
|
||||
)
|
||||
.addTo(cancelDisposable)
|
||||
suspend fun block(statusId: String) {
|
||||
try {
|
||||
mastodonApi.blockAccount(statusId)
|
||||
eventHub.dispatch(BlockEvent(statusId))
|
||||
} catch (t: Throwable) {
|
||||
Log.w(TAG, "Failed to block account", t)
|
||||
}
|
||||
}
|
||||
|
||||
fun delete(statusId: String): Single<DeletedStatus> {
|
||||
|
|
@ -132,7 +123,7 @@ class TimelineCases @Inject constructor(
|
|||
// Replace with extension method if we use RxKotlin
|
||||
return (if (pin) mastodonApi.pinStatus(statusId) else mastodonApi.unpinStatus(statusId))
|
||||
.doOnError { e ->
|
||||
Log.w("Failed to change pin state", e)
|
||||
Log.w(TAG, "Failed to change pin state", e)
|
||||
}
|
||||
.onErrorResumeNext(::convertError)
|
||||
.doAfterSuccess {
|
||||
|
|
@ -153,6 +144,10 @@ class TimelineCases @Inject constructor(
|
|||
private fun <T : Any> convertError(e: Throwable): Single<T> {
|
||||
return Single.error(TimelineError(e.getServerErrorMessage()))
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TAG = "TimelineCases"
|
||||
}
|
||||
}
|
||||
|
||||
class TimelineError(message: String?) : RuntimeException(message)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue