filters: represent POST as json becausr booleans cannot be represented in urlencoded as Pleroma thinks

main
a1batross 5 years ago
parent 645098c3c7
commit 4141030d2e
  1. 7
      app/src/main/java/com/keylesspalace/tusky/FiltersActivity.kt
  2. 24
      app/src/main/java/com/keylesspalace/tusky/network/MastodonApi.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<Filter>{
override fun onFailure(call: Call<Filter>, 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<Filter> {
api.createFilter(MastodonApi.PostFilter(phrase, listOf(context), false, wholeWord, ""))
.enqueue(object: Callback<Filter> {
override fun onResponse(call: Call<Filter>, response: Response<Filter>) {
val filterResponse = response.body()
if(response.isSuccessful && filterResponse != null) {
@ -215,4 +216,4 @@ class FiltersActivity: BaseActivity() {
}
return super.onOptionsItemSelected(item)
}
}
}

@ -479,25 +479,21 @@ interface MastodonApi {
@Query("limit") limit: Int
): Call<List<Conversation>>
@FormUrlEncoded
data class PostFilter(
val phrase: String,
val context: List<String>,
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<String>,
@Field("irreversible") irreversible: Boolean?,
@Field("whole_word") wholeWord: Boolean?,
@Field("expires_in") expiresIn: String?
): Call<Filter>
fun createFilter(@Body body: PostFilter): Call<Filter>
@FormUrlEncoded
@PUT("api/v1/filters/{id}")
fun updateFilter(
@Path("id") id: String,
@Field("phrase") phrase: String,
@Field("context[]") context: List<String>,
@Field("irreversible") irreversible: Boolean?,
@Field("whole_word") wholeWord: Boolean?,
@Field("expires_in") expiresIn: String?
@Body body: PostFilter
): Call<Filter>
@DELETE("api/v1/filters/{id}")

Loading…
Cancel
Save