Add support for muting conversations (#1732)
* Add support for muting conversations Implements #1731 * Fix CI * Apply code review feedback
This commit is contained in:
parent
8e54e4ae16
commit
8cb83050ac
21 changed files with 904 additions and 19 deletions
|
@ -185,11 +185,8 @@ public abstract class SFragment extends BaseFragment implements Injectable {
|
|||
|
||||
PopupMenu popup = new PopupMenu(getContext(), view);
|
||||
// Give a different menu depending on whether this is the user's own toot or not.
|
||||
if (loggedInAccountId == null || !loggedInAccountId.equals(accountId)) {
|
||||
popup.inflate(R.menu.status_more);
|
||||
Menu menu = popup.getMenu();
|
||||
menu.findItem(R.id.status_download_media).setVisible(!status.getAttachments().isEmpty());
|
||||
} else {
|
||||
boolean statusIsByCurrentUser = loggedInAccountId != null && loggedInAccountId.equals(accountId);
|
||||
if (statusIsByCurrentUser) {
|
||||
popup.inflate(R.menu.status_more_for_user);
|
||||
Menu menu = popup.getMenu();
|
||||
switch (status.getVisibility()) {
|
||||
|
@ -208,6 +205,10 @@ public abstract class SFragment extends BaseFragment implements Injectable {
|
|||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
popup.inflate(R.menu.status_more);
|
||||
Menu menu = popup.getMenu();
|
||||
menu.findItem(R.id.status_download_media).setVisible(!status.getAttachments().isEmpty());
|
||||
}
|
||||
|
||||
Menu menu = popup.getMenu();
|
||||
|
@ -231,6 +232,15 @@ public abstract class SFragment extends BaseFragment implements Injectable {
|
|||
}
|
||||
openAsItem.setTitle(openAsTitle);
|
||||
|
||||
MenuItem muteConversationItem = menu.findItem(R.id.status_mute_conversation);
|
||||
boolean mutable = statusIsByCurrentUser || accountIsInMentions(activeAccount, status.getMentions());
|
||||
muteConversationItem.setVisible(mutable);
|
||||
if (mutable) {
|
||||
muteConversationItem.setTitle((status.getMuted() == null || !status.getMuted()) ?
|
||||
R.string.action_mute_conversation :
|
||||
R.string.action_unmute_conversation);
|
||||
}
|
||||
|
||||
popup.setOnMenuItemClickListener(item -> {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.status_share_content: {
|
||||
|
@ -305,12 +315,35 @@ public abstract class SFragment extends BaseFragment implements Injectable {
|
|||
timelineCases.pin(status, !status.isPinned());
|
||||
return true;
|
||||
}
|
||||
case R.id.status_mute_conversation: {
|
||||
timelineCases.muteConversation(status, status.getMuted() == null || !status.getMuted())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.as(autoDisposable(from(this, Lifecycle.Event.ON_DESTROY)))
|
||||
.subscribe();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
popup.show();
|
||||
}
|
||||
|
||||
private static boolean accountIsInMentions(AccountEntity account, Status.Mention[] mentions) {
|
||||
if (account == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (Status.Mention mention : mentions) {
|
||||
if (account.getUsername().equals(mention.getUsername())) {
|
||||
Uri uri = Uri.parse(mention.getUrl());
|
||||
if (uri != null && account.getDomain().equals(uri.getHost())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void viewMedia(int urlIndex, Status status, @Nullable View view) {
|
||||
final Status actionable = status.getActionableStatus();
|
||||
final Attachment active = actionable.getAttachments().get(urlIndex);
|
||||
|
|
|
@ -53,6 +53,7 @@ import com.keylesspalace.tusky.appstore.BookmarkEvent;
|
|||
import com.keylesspalace.tusky.appstore.DomainMuteEvent;
|
||||
import com.keylesspalace.tusky.appstore.EventHub;
|
||||
import com.keylesspalace.tusky.appstore.FavoriteEvent;
|
||||
import com.keylesspalace.tusky.appstore.MuteConversationEvent;
|
||||
import com.keylesspalace.tusky.appstore.MuteEvent;
|
||||
import com.keylesspalace.tusky.appstore.PreferenceChangedEvent;
|
||||
import com.keylesspalace.tusky.appstore.ReblogEvent;
|
||||
|
@ -503,6 +504,9 @@ public class TimelineFragment extends SFragment implements
|
|||
} else if (event instanceof BookmarkEvent) {
|
||||
BookmarkEvent bookmarkEvent = (BookmarkEvent) event;
|
||||
handleBookmarkEvent(bookmarkEvent);
|
||||
} else if (event instanceof MuteConversationEvent) {
|
||||
MuteConversationEvent muteEvent = (MuteConversationEvent) event;
|
||||
handleMuteConversationEvent(muteEvent);
|
||||
} else if (event instanceof UnfollowEvent) {
|
||||
if (kind == Kind.HOME) {
|
||||
String id = ((UnfollowEvent) event).getAccountId();
|
||||
|
@ -1313,6 +1317,10 @@ public class TimelineFragment extends SFragment implements
|
|||
setBookmarkForStatus(pos, status, bookmarkEvent.getBookmark());
|
||||
}
|
||||
|
||||
private void handleMuteConversationEvent(@NonNull MuteConversationEvent event) {
|
||||
fullyRefresh();
|
||||
}
|
||||
|
||||
private void handleStatusComposeEvent(@NonNull Status status) {
|
||||
switch (kind) {
|
||||
case HOME:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue