Support "replies policy" for lists (#4072)

This commit is contained in:
Levi Bard 2023-10-26 11:21:04 +02:00 committed by GitHub
commit 55ed6841ff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 74 additions and 14 deletions

View file

@ -124,7 +124,9 @@ class ListsActivity : BaseActivity(), Injectable, HasAndroidInjector {
}
private fun showlistNameDialog(list: MastoList?) {
val binding = DialogListBinding.inflate(layoutInflater)
val binding = DialogListBinding.inflate(layoutInflater).apply {
replyPolicySpinner.setSelection(MastoList.ReplyPolicy.from(list?.repliesPolicy).ordinal)
}
val dialog = AlertDialog.Builder(this)
.setView(binding.root)
.setPositiveButton(
@ -134,7 +136,12 @@ class ListsActivity : BaseActivity(), Injectable, HasAndroidInjector {
R.string.action_rename_list
}
) { _, _ ->
onPickedDialogName(binding.nameText.text.toString(), list?.id, binding.exclusiveCheckbox.isChecked)
onPickedDialogName(
binding.nameText.text.toString(),
list?.id,
binding.exclusiveCheckbox.isChecked,
MastoList.ReplyPolicy.entries[binding.replyPolicySpinner.selectedItemPosition].policy
)
}
.setNegativeButton(android.R.string.cancel, null)
.show()
@ -288,11 +295,11 @@ class ListsActivity : BaseActivity(), Injectable, HasAndroidInjector {
}
}
private fun onPickedDialogName(name: String, listId: String?, exclusive: Boolean) {
private fun onPickedDialogName(name: String, listId: String?, exclusive: Boolean, replyPolicy: String) {
if (listId == null) {
viewModel.createNewList(name, exclusive)
viewModel.createNewList(name, exclusive, replyPolicy)
} else {
viewModel.updateList(listId, name, exclusive)
viewModel.updateList(listId, name, exclusive, replyPolicy)
}
}

View file

@ -16,6 +16,8 @@
package com.keylesspalace.tusky.entity
import com.google.gson.annotations.SerializedName
/**
* Created by charlag on 1/4/18.
*/
@ -23,5 +25,16 @@ package com.keylesspalace.tusky.entity
data class MastoList(
val id: String,
val title: String,
val exclusive: Boolean?
)
val exclusive: Boolean?,
@SerializedName("replies_policy") val repliesPolicy: String?,
) {
enum class ReplyPolicy(val policy: String) {
NONE("none"),
LIST("list"),
FOLLOWED("followed");
companion object {
fun from(policy: String?): ReplyPolicy = values().firstOrNull { it.policy == policy } ?: LIST
}
}
}

View file

@ -599,7 +599,8 @@ interface MastodonApi {
@POST("api/v1/lists")
suspend fun createList(
@Field("title") title: String,
@Field("exclusive") exclusive: Boolean?
@Field("exclusive") exclusive: Boolean?,
@Field("replies_policy") replyPolicy: String,
): NetworkResult<MastoList>
@FormUrlEncoded
@ -607,7 +608,8 @@ interface MastodonApi {
suspend fun updateList(
@Path("listId") listId: String,
@Field("title") title: String,
@Field("exclusive") exclusive: Boolean?
@Field("exclusive") exclusive: Boolean?,
@Field("replies_policy") replyPolicy: String,
): NetworkResult<MastoList>
@DELETE("api/v1/lists/{listId}")

View file

@ -84,9 +84,9 @@ internal class ListsViewModel @Inject constructor(private val api: MastodonApi)
}
}
fun createNewList(listName: String, exclusive: Boolean) {
fun createNewList(listName: String, exclusive: Boolean, replyPolicy: String) {
viewModelScope.launch {
api.createList(listName, exclusive).fold(
api.createList(listName, exclusive, replyPolicy).fold(
{ list ->
updateState {
copy(lists = lists + list)
@ -99,9 +99,9 @@ internal class ListsViewModel @Inject constructor(private val api: MastodonApi)
}
}
fun updateList(listId: String, listName: String, exclusive: Boolean) {
fun updateList(listId: String, listName: String, exclusive: Boolean, replyPolicy: String) {
viewModelScope.launch {
api.updateList(listId, listName, exclusive).fold(
api.updateList(listId, listName, exclusive, replyPolicy).fold(
{ list ->
updateState {
copy(lists = lists.replacedFirstWhich(list) { it.id == listId })