From 4141030d2e2bfc03b63bf3d70993db27298a05f8 Mon Sep 17 00:00:00 2001 From: a1batross Date: Tue, 28 Apr 2020 04:01:19 +0200 Subject: [PATCH] filters: represent POST as json becausr booleans cannot be represented in urlencoded as Pleroma thinks --- .../keylesspalace/tusky/FiltersActivity.kt | 7 +++--- .../tusky/network/MastodonApi.kt | 24 ++++++++----------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/FiltersActivity.kt b/app/src/main/java/com/keylesspalace/tusky/FiltersActivity.kt index 5adce8ed..55a856c2 100644 --- a/app/src/main/java/com/keylesspalace/tusky/FiltersActivity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/FiltersActivity.kt @@ -39,7 +39,7 @@ class FiltersActivity: BaseActivity() { } private fun updateFilter(filter: Filter, itemIndex: Int) { - api.updateFilter(filter.id, filter.phrase, filter.context, filter.irreversible, filter.wholeWord, filter.expiresAt) + api.updateFilter(filter.id, MastodonApi.PostFilter(filter.phrase, filter.context, filter.irreversible, filter.wholeWord, filter.expiresAt)) .enqueue(object: Callback{ override fun onFailure(call: Call, t: Throwable) { Toast.makeText(this@FiltersActivity, "Error updating filter '${filter.phrase}'", Toast.LENGTH_SHORT).show() @@ -83,7 +83,8 @@ class FiltersActivity: BaseActivity() { } private fun createFilter(phrase: String, wholeWord: Boolean) { - api.createFilter(phrase, listOf(context), false, wholeWord, "").enqueue(object: Callback { + api.createFilter(MastodonApi.PostFilter(phrase, listOf(context), false, wholeWord, "")) + .enqueue(object: Callback { override fun onResponse(call: Call, response: Response) { val filterResponse = response.body() if(response.isSuccessful && filterResponse != null) { @@ -215,4 +216,4 @@ class FiltersActivity: BaseActivity() { } return super.onOptionsItemSelected(item) } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/keylesspalace/tusky/network/MastodonApi.kt b/app/src/main/java/com/keylesspalace/tusky/network/MastodonApi.kt index 119867fb..7cdc93a9 100644 --- a/app/src/main/java/com/keylesspalace/tusky/network/MastodonApi.kt +++ b/app/src/main/java/com/keylesspalace/tusky/network/MastodonApi.kt @@ -479,25 +479,21 @@ interface MastodonApi { @Query("limit") limit: Int ): Call> - @FormUrlEncoded + data class PostFilter( + val phrase: String, + val context: List, + val irreversible: Boolean?, + val whole_word: Boolean?, + val expires_in: String? + ); + @POST("api/v1/filters") - fun createFilter( - @Field("phrase") phrase: String, - @Field("context[]") context: List, - @Field("irreversible") irreversible: Boolean?, - @Field("whole_word") wholeWord: Boolean?, - @Field("expires_in") expiresIn: String? - ): Call + fun createFilter(@Body body: PostFilter): Call - @FormUrlEncoded @PUT("api/v1/filters/{id}") fun updateFilter( @Path("id") id: String, - @Field("phrase") phrase: String, - @Field("context[]") context: List, - @Field("irreversible") irreversible: Boolean?, - @Field("whole_word") wholeWord: Boolean?, - @Field("expires_in") expiresIn: String? + @Body body: PostFilter ): Call @DELETE("api/v1/filters/{id}")