From b156be6ded3a79d4448706aeb60adbe5d5569cef Mon Sep 17 00:00:00 2001 From: Konrad Pozniak Date: Sun, 9 May 2021 18:37:41 +0200 Subject: [PATCH] work around mastodon mute bug (#2150) --- .../tusky/components/search/SearchViewModel.kt | 2 +- .../keylesspalace/tusky/network/TimelineCases.kt | 4 ++-- .../keylesspalace/tusky/view/MuteAccountDialog.kt | 13 +++++++++++-- .../tusky/viewmodel/AccountViewModel.kt | 2 +- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/components/search/SearchViewModel.kt b/app/src/main/java/com/keylesspalace/tusky/components/search/SearchViewModel.kt index 08afe44d..57c78ef8 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/search/SearchViewModel.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/search/SearchViewModel.kt @@ -193,7 +193,7 @@ class SearchViewModel @Inject constructor( return accountManager.getAllAccountsOrderedByActive() } - fun muteAccount(accountId: String, notifications: Boolean, duration: Int) { + fun muteAccount(accountId: String, notifications: Boolean, duration: Int?) { timelineCases.mute(accountId, notifications, duration) } diff --git a/app/src/main/java/com/keylesspalace/tusky/network/TimelineCases.kt b/app/src/main/java/com/keylesspalace/tusky/network/TimelineCases.kt index 8cf2b688..6e79f075 100644 --- a/app/src/main/java/com/keylesspalace/tusky/network/TimelineCases.kt +++ b/app/src/main/java/com/keylesspalace/tusky/network/TimelineCases.kt @@ -33,7 +33,7 @@ interface TimelineCases { fun reblog(status: Status, reblog: Boolean): Single fun favourite(status: Status, favourite: Boolean): Single fun bookmark(status: Status, bookmark: Boolean): Single - fun mute(id: String, notifications: Boolean, duration: Int) + fun mute(id: String, notifications: Boolean, duration: Int?) fun block(id: String) fun delete(id: String): Single fun pin(status: Status, pin: Boolean) @@ -104,7 +104,7 @@ class TimelineCasesImpl( } } - override fun mute(id: String, notifications: Boolean, duration: Int) { + override fun mute(id: String, notifications: Boolean, duration: Int?) { mastodonApi.muteAccount(id, notifications, duration) .subscribe({ eventHub.dispatch(MuteEvent(id)) diff --git a/app/src/main/java/com/keylesspalace/tusky/view/MuteAccountDialog.kt b/app/src/main/java/com/keylesspalace/tusky/view/MuteAccountDialog.kt index da5e7987..022927e6 100644 --- a/app/src/main/java/com/keylesspalace/tusky/view/MuteAccountDialog.kt +++ b/app/src/main/java/com/keylesspalace/tusky/view/MuteAccountDialog.kt @@ -10,7 +10,7 @@ import com.keylesspalace.tusky.databinding.DialogMuteAccountBinding fun showMuteAccountDialog( activity: Activity, accountUsername: String, - onOk: (notifications: Boolean, duration: Int) -> Unit + onOk: (notifications: Boolean, duration: Int?) -> Unit ) { val binding = DialogMuteAccountBinding.inflate(activity.layoutInflater) binding.warning.text = activity.getString(R.string.dialog_mute_warning, accountUsername) @@ -20,7 +20,16 @@ fun showMuteAccountDialog( .setView(binding.root) .setPositiveButton(android.R.string.ok) { _, _ -> val durationValues = activity.resources.getIntArray(R.array.mute_duration_values) - onOk(binding.checkbox.isChecked, durationValues[binding.duration.selectedItemPosition]) + + // workaround to make indefinite muting work with Mastodon 3.3.0 + // https://github.com/tuskyapp/Tusky/issues/2107 + val duration = if(binding.duration.selectedItemPosition == 0) { + null + } else { + durationValues[binding.duration.selectedItemPosition] + } + + onOk(binding.checkbox.isChecked, duration) } .setNegativeButton(android.R.string.cancel, null) .show() diff --git a/app/src/main/java/com/keylesspalace/tusky/viewmodel/AccountViewModel.kt b/app/src/main/java/com/keylesspalace/tusky/viewmodel/AccountViewModel.kt index a0f0ed68..1837652e 100644 --- a/app/src/main/java/com/keylesspalace/tusky/viewmodel/AccountViewModel.kt +++ b/app/src/main/java/com/keylesspalace/tusky/viewmodel/AccountViewModel.kt @@ -119,7 +119,7 @@ class AccountViewModel @Inject constructor( } } - fun muteAccount(notifications: Boolean, duration: Int) { + fun muteAccount(notifications: Boolean, duration: Int?) { changeRelationship(RelationShipAction.MUTE, notifications, duration) }