diff --git a/mastodon/src/main/java/org/joinmastodon/android/api/requests/statuses/SetStatusConversationMuted.java b/mastodon/src/main/java/org/joinmastodon/android/api/requests/statuses/SetStatusConversationMuted.java new file mode 100644 index 00000000..cc523663 --- /dev/null +++ b/mastodon/src/main/java/org/joinmastodon/android/api/requests/statuses/SetStatusConversationMuted.java @@ -0,0 +1,11 @@ +package org.joinmastodon.android.api.requests.statuses; + +import org.joinmastodon.android.api.MastodonAPIRequest; +import org.joinmastodon.android.model.Status; + +public class SetStatusConversationMuted extends MastodonAPIRequest{ + public SetStatusConversationMuted(String id, boolean muted){ + super(HttpMethod.POST, "/statuses/"+id+(muted ? "/mute" : "/unmute"), Status.class); + setRequestBody(new Object()); + } +} diff --git a/mastodon/src/main/java/org/joinmastodon/android/model/Status.java b/mastodon/src/main/java/org/joinmastodon/android/model/Status.java index 955f5c9c..2d7c3d82 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/model/Status.java +++ b/mastodon/src/main/java/org/joinmastodon/android/model/Status.java @@ -58,7 +58,7 @@ public class Status extends BaseModel implements DisplayItemsParent{ public boolean favourited; public boolean reblogged; - public boolean muted; + public Boolean muted; public boolean bookmarked; public Boolean pinned; diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/HeaderStatusDisplayItem.java b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/HeaderStatusDisplayItem.java index d4d5b49f..8b2a056c 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/HeaderStatusDisplayItem.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/HeaderStatusDisplayItem.java @@ -25,11 +25,13 @@ import org.joinmastodon.android.GlobalUserPreferences; import org.joinmastodon.android.R; import org.joinmastodon.android.api.requests.accounts.GetAccountRelationships; import org.joinmastodon.android.api.requests.statuses.GetStatusSourceText; +import org.joinmastodon.android.api.requests.statuses.SetStatusConversationMuted; import org.joinmastodon.android.api.requests.statuses.SetStatusPinned; import org.joinmastodon.android.api.session.AccountSessionManager; import org.joinmastodon.android.fragments.AddAccountToListsFragment; import org.joinmastodon.android.fragments.BaseStatusListFragment; import org.joinmastodon.android.fragments.ComposeFragment; +import org.joinmastodon.android.fragments.NotificationsListFragment; import org.joinmastodon.android.fragments.ProfileFragment; import org.joinmastodon.android.fragments.report.ReportReasonChoiceFragment; import org.joinmastodon.android.model.Account; @@ -228,6 +230,22 @@ public class HeaderStatusDisplayItem extends StatusDisplayItem{ }) .wrapProgress(activity, R.string.loading, true) .exec(item.accountID); + }else if(id==R.id.mute_conversation){ + new SetStatusConversationMuted(item.status.id, !item.status.muted) + .setCallback(new Callback<>(){ + @Override + public void onSuccess(Status result){ + // TODO snackbar? + item.status.muted=result.muted; + } + + @Override + public void onError(ErrorResponse error){ + error.showToast(activity); + } + }) + .wrapProgress(activity, R.string.loading, true) + .exec(item.accountID); } return true; }); @@ -314,6 +332,7 @@ public class HeaderStatusDisplayItem extends StatusDisplayItem{ MenuItem follow=menu.findItem(R.id.follow); MenuItem bookmark=menu.findItem(R.id.bookmark); MenuItem pin=menu.findItem(R.id.pin); + MenuItem muteConversation=menu.findItem(R.id.mute_conversation); if(item.status!=null){ bookmark.setVisible(true); bookmark.setTitle(item.status.bookmarked ? R.string.remove_bookmark : R.string.add_bookmark); @@ -340,6 +359,12 @@ public class HeaderStatusDisplayItem extends StatusDisplayItem{ report.setTitle(item.parentFragment.getString(R.string.report_user, account.displayName)); follow.setTitle(item.parentFragment.getString(relationship!=null && relationship.following ? R.string.unfollow_user : R.string.follow_user, account.displayName)); } + if(item.status.muted!=null){ + muteConversation.setVisible(isOwnPost || item.parentFragment instanceof NotificationsListFragment); + muteConversation.setTitle(item.status.muted ? R.string.unmute_conversation : R.string.mute_conversation); + }else{ + muteConversation.setVisible(false); + } menu.findItem(R.id.add_to_list).setVisible(relationship!=null && relationship.following); } } diff --git a/mastodon/src/main/res/menu/post.xml b/mastodon/src/main/res/menu/post.xml index 628150d9..85689835 100644 --- a/mastodon/src/main/res/menu/post.xml +++ b/mastodon/src/main/res/menu/post.xml @@ -9,6 +9,7 @@ + diff --git a/mastodon/src/main/res/values/strings.xml b/mastodon/src/main/res/values/strings.xml index 43dfa0c9..09181664 100644 --- a/mastodon/src/main/res/values/strings.xml +++ b/mastodon/src/main/res/values/strings.xml @@ -725,4 +725,6 @@ Stop notifying me when %s posts You’ll get notifications for new posts. You’ll no longer get notifications for new posts. + Mute conversation + Unmute conversation \ No newline at end of file