Personal account notes (#1978)

* add personal notes to AccountActivity

* use RxJava instead of plain okhttp calls

* make AccountViewModel rx aware

* hide note input until data is loaded
This commit is contained in:
Konrad Pozniak 2020-11-17 20:10:54 +01:00 committed by GitHub
commit ce973ea7e7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 181 additions and 213 deletions

View file

@ -269,7 +269,7 @@ interface MastodonApi {
@GET("api/v1/accounts/{id}")
fun account(
@Path("id") accountId: String
): Call<Account>
): Single<Account>
/**
* Method to fetch statuses for the specified account.
@ -308,44 +308,44 @@ interface MastodonApi {
fun followAccount(
@Path("id") accountId: String,
@Field("reblogs") showReblogs: Boolean
): Call<Relationship>
): Single<Relationship>
@POST("api/v1/accounts/{id}/unfollow")
fun unfollowAccount(
@Path("id") accountId: String
): Call<Relationship>
): Single<Relationship>
@POST("api/v1/accounts/{id}/block")
fun blockAccount(
@Path("id") accountId: String
): Call<Relationship>
): Single<Relationship>
@POST("api/v1/accounts/{id}/unblock")
fun unblockAccount(
@Path("id") accountId: String
): Call<Relationship>
): Single<Relationship>
@FormUrlEncoded
@POST("api/v1/accounts/{id}/mute")
fun muteAccount(
@Path("id") accountId: String,
@Field("notifications") notifications: Boolean
): Call<Relationship>
@Field("notifications") notifications: Boolean? = null
): Single<Relationship>
@POST("api/v1/accounts/{id}/unmute")
fun unmuteAccount(
@Path("id") accountId: String
): Call<Relationship>
): Single<Relationship>
@GET("api/v1/accounts/relationships")
fun relationships(
@Query("id[]") accountIds: List<String>
): Call<List<Relationship>>
): Single<List<Relationship>>
@GET("api/v1/accounts/{id}/identity_proofs")
fun identityProofs(
@Path("id") accountId: String
): Call<List<IdentityProof>>
): Single<List<IdentityProof>>
@GET("api/v1/blocks")
fun blocks(
@ -513,31 +513,6 @@ interface MastodonApi {
@Field("choices[]") choices: List<Int>
): Single<Poll>
@POST("api/v1/accounts/{id}/block")
fun blockAccountObservable(
@Path("id") accountId: String
): Single<Relationship>
@POST("api/v1/accounts/{id}/unblock")
fun unblockAccountObservable(
@Path("id") accountId: String
): Single<Relationship>
@POST("api/v1/accounts/{id}/mute")
fun muteAccountObservable(
@Path("id") accountId: String
): Single<Relationship>
@POST("api/v1/accounts/{id}/unmute")
fun unmuteAccountObservable(
@Path("id") accountId: String
): Single<Relationship>
@GET("api/v1/accounts/relationships")
fun relationshipsObservable(
@Query("id[]") accountIds: List<String>
): Single<List<Relationship>>
@FormUrlEncoded
@POST("api/v1/reports")
fun reportObservable(
@ -571,4 +546,11 @@ interface MastodonApi {
@Query("following") following: Boolean? = null
): Single<SearchResult>
@FormUrlEncoded
@POST("api/v1/accounts/{id}/note")
fun updateAccountNote(
@Path("id") accountId: String,
@Field("comment") note: String
): Single<Relationship>
}

View file

@ -15,17 +15,14 @@
package com.keylesspalace.tusky.network
import android.util.Log
import com.keylesspalace.tusky.appstore.*
import com.keylesspalace.tusky.entity.DeletedStatus
import com.keylesspalace.tusky.entity.Poll
import com.keylesspalace.tusky.entity.Relationship
import com.keylesspalace.tusky.entity.Status
import io.reactivex.Single
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.rxkotlin.addTo
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
import java.lang.IllegalStateException
/**
@ -108,24 +105,23 @@ class TimelineCasesImpl(
}
override fun mute(id: String, notifications: Boolean) {
val call = mastodonApi.muteAccount(id, notifications)
call.enqueue(object : Callback<Relationship> {
override fun onResponse(call: Call<Relationship>, response: Response<Relationship>) {}
override fun onFailure(call: Call<Relationship>, t: Throwable) {}
})
eventHub.dispatch(MuteEvent(id))
mastodonApi.muteAccount(id, notifications)
.subscribe({
eventHub.dispatch(MuteEvent(id))
}, { t ->
Log.w("Failed to mute account", t)
})
.addTo(cancelDisposable)
}
override fun block(id: String) {
val call = mastodonApi.blockAccount(id)
call.enqueue(object : Callback<Relationship> {
override fun onResponse(call: Call<Relationship>, response: Response<Relationship>) {}
override fun onFailure(call: Call<Relationship>, t: Throwable) {}
})
eventHub.dispatch(BlockEvent(id))
mastodonApi.blockAccount(id)
.subscribe({
eventHub.dispatch(BlockEvent(id))
}, { t ->
Log.w("Failed to block account", t)
})
.addTo(cancelDisposable)
}
override fun delete(id: String): Single<DeletedStatus> {