Implement timed mutes. (#2035)

Fixes #2033
main
Levi Bard 4 years ago committed by Alibek Omarov
parent d7ec778fd9
commit fc47d1d94a
  1. 4
      app/src/main/java/com/keylesspalace/tusky/AccountActivity.kt
  2. 4
      app/src/main/java/com/keylesspalace/tusky/components/search/SearchViewModel.kt
  3. 7
      app/src/main/java/com/keylesspalace/tusky/components/search/fragments/SearchStatusesFragment.kt
  4. 4
      app/src/main/java/com/keylesspalace/tusky/fragment/SFragment.java
  5. 3
      app/src/main/java/com/keylesspalace/tusky/network/MastodonApi.kt
  6. 6
      app/src/main/java/com/keylesspalace/tusky/network/TimelineCases.kt
  7. 9
      app/src/main/java/com/keylesspalace/tusky/view/MuteAccountDialog.kt
  8. 8
      app/src/main/java/com/keylesspalace/tusky/viewmodel/AccountViewModel.kt
  9. 15
      app/src/main/res/layout/dialog_mute_account.xml

@ -866,8 +866,8 @@ class AccountActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidI
showMuteAccountDialog(
this,
it.username
) { notifications ->
viewModel.muteAccount(notifications)
) { notifications, duration ->
viewModel.muteAccount(notifications, duration)
}
}
} else {

@ -194,8 +194,8 @@ class SearchViewModel @Inject constructor(
return accountManager.getAllAccountsOrderedByActive()
}
fun muteAccount(accountId: String, notifications: Boolean) {
timelineCases.mute(accountId, notifications)
fun muteAccount(accountId: String, notifications: Boolean, duration: Int) {
timelineCases.mute(accountId, notifications, duration)
}
fun muteConversation(status: Status, isMute: Boolean) {

@ -373,9 +373,10 @@ class SearchStatusesFragment : SearchFragment<Pair<Status, StatusViewData.Concre
private fun onMute(accountId: String, accountUsername: String) {
showMuteAccountDialog(
this.requireActivity(),
accountUsername,
{ notifications -> viewModel.muteAccount(accountId, notifications) }
)
accountUsername
) { notifications, duration ->
viewModel.muteAccount(accountId, notifications, duration)
}
}
private fun accountIsInMentions(account: AccountEntity?, mentions: Array<Mention>): Boolean {

@ -382,8 +382,8 @@ public abstract class SFragment extends BaseFragment implements Injectable {
MuteAccountDialog.showMuteAccountDialog(
this.getActivity(),
accountUsername,
(notifications) -> {
timelineCases.mute(accountId, notifications);
(notifications, duration) -> {
timelineCases.mute(accountId, notifications, duration);
return Unit.INSTANCE;
}
);

@ -332,7 +332,8 @@ interface MastodonApi {
@POST("api/v1/accounts/{id}/mute")
fun muteAccount(
@Path("id") accountId: String,
@Field("notifications") notifications: Boolean? = null
@Field("notifications") notifications: Boolean? = null,
@Field("duration") duration: Int? = null
): Single<Relationship>
@POST("api/v1/accounts/{id}/unmute")

@ -34,7 +34,7 @@ interface TimelineCases {
fun favourite(status: Status, favourite: Boolean): Single<Status>
fun bookmark(status: Status, bookmark: Boolean): Single<Status>
fun muteConversation(status: Status, mute: Boolean)
fun mute(id: String, notifications: Boolean)
fun mute(id: String, notifications: Boolean, duration: Int)
fun block(id: String)
fun delete(id: String): Single<DeletedStatus>
fun pin(status: Status, pin: Boolean)
@ -107,8 +107,8 @@ class TimelineCasesImpl(
.addTo(cancelDisposable)
}
override fun mute(id: String, notifications: Boolean) {
mastodonApi.muteAccount(id, notifications)
override fun mute(id: String, notifications: Boolean, duration: Int) {
mastodonApi.muteAccount(id, notifications, duration)
.subscribe({
eventHub.dispatch(MuteEvent(id, true))
}, { t ->

@ -4,6 +4,7 @@ package com.keylesspalace.tusky.view
import android.app.Activity
import android.widget.CheckBox
import android.widget.Spinner
import android.widget.TextView
import androidx.appcompat.app.AlertDialog
import com.keylesspalace.tusky.R
@ -11,7 +12,7 @@ import com.keylesspalace.tusky.R
fun showMuteAccountDialog(
activity: Activity,
accountUsername: String,
onOk: (notifications: Boolean) -> Unit
onOk: (notifications: Boolean, duration: Int) -> Unit
) {
val view = activity.layoutInflater.inflate(R.layout.dialog_mute_account, null)
(view.findViewById(R.id.warning) as TextView).text =
@ -21,7 +22,11 @@ fun showMuteAccountDialog(
AlertDialog.Builder(activity)
.setView(view)
.setPositiveButton(android.R.string.ok) { _, _ -> onOk(checkbox.isChecked) }
.setPositiveButton(android.R.string.ok) { _, _ ->
val spinner: Spinner = view.findViewById(R.id.duration)
val durationValues = activity.resources.getIntArray(R.array.mute_duration_values)
onOk(checkbox.isChecked, durationValues[spinner.selectedItemPosition])
}
.setNegativeButton(android.R.string.cancel, null)
.show()
}

@ -119,8 +119,8 @@ class AccountViewModel @Inject constructor(
}
}
fun muteAccount(notifications: Boolean) {
changeRelationship(RelationShipAction.MUTE, notifications)
fun muteAccount(notifications: Boolean, duration: Int) {
changeRelationship(RelationShipAction.MUTE, notifications, duration)
}
fun unmuteAccount() {
@ -187,7 +187,7 @@ class AccountViewModel @Inject constructor(
/**
* @param parameter showReblogs if RelationShipAction.FOLLOW, notifications if MUTE
*/
private fun changeRelationship(relationshipAction: RelationShipAction, parameter: Boolean? = null) {
private fun changeRelationship(relationshipAction: RelationShipAction, parameter: Boolean? = null, duration: Int? = null) {
val relation = relationshipData.value?.data
val account = accountData.value?.data
val isMastodon = relationshipData.value?.data?.notifying != null
@ -227,7 +227,7 @@ class AccountViewModel @Inject constructor(
RelationShipAction.UNFOLLOW -> mastodonApi.unfollowAccount(accountId)
RelationShipAction.BLOCK -> mastodonApi.blockAccount(accountId)
RelationShipAction.UNBLOCK -> mastodonApi.unblockAccount(accountId)
RelationShipAction.MUTE -> mastodonApi.muteAccount(accountId, parameter ?: true)
RelationShipAction.MUTE -> mastodonApi.muteAccount(accountId, parameter ?: true, duration)
RelationShipAction.UNMUTE -> mastodonApi.unmuteAccount(accountId)
RelationShipAction.SUBSCRIBE -> {
if(isMastodon)

@ -22,4 +22,17 @@
app:buttonTint="@color/compound_button_color"
android:text="@string/dialog_mute_hide_notifications"/>
</LinearLayout>
<TextView
android:id="@+id/duration_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="20dp"
android:text="@string/label_duration" />
<Spinner
android:id="@+id/duration"
android:entries="@array/mute_duration_names"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>

Loading…
Cancel
Save