Skip to content

Commit

Permalink
feat(Status): allow muting if only mentioned (#1292)
Browse files Browse the repository at this point in the history
  • Loading branch information
GeopJr authored Dec 20, 2024
1 parent 9e39da8 commit 3b5751f
Showing 1 changed file with 42 additions and 21 deletions.
63 changes: 42 additions & 21 deletions src/Widgets/Status.vala
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@
private SimpleAction toggle_pinned_simple_action;
private SimpleAction translate_simple_action;
private SimpleAction show_original_simple_action;
private SimpleAction mute_conversation_action;
private SimpleAction unmute_conversation_action;
private SimpleAction? mute_conversation_action = null;
private SimpleAction? unmute_conversation_action = null;

void settings_updated () {
Tuba.toggle_css (this, settings.larger_font_size, "ttl-status-font-large");
Expand Down Expand Up @@ -263,6 +263,14 @@
protected void create_actions () {
create_context_menu ();

mute_conversation_action = new SimpleAction ("mute-conversation", null);
mute_conversation_action.activate.connect (toggle_mute_conversation);
action_group.add_action (mute_conversation_action);

unmute_conversation_action = new SimpleAction ("unmute-conversation", null);
unmute_conversation_action.activate.connect (toggle_mute_conversation);
action_group.add_action (unmute_conversation_action);

if (status.formal.account.is_self ()) {
if (status.formal.visibility != "direct") {
toggle_pinned_simple_action = new SimpleAction ("toggle-pinned", null);
Expand All @@ -271,16 +279,6 @@
action_group.add_action (toggle_pinned_simple_action);
}

mute_conversation_action = new SimpleAction ("mute-conversation", null);
mute_conversation_action.activate.connect (toggle_mute_conversation);
action_group.add_action (mute_conversation_action);

unmute_conversation_action = new SimpleAction ("unmute-conversation", null);
unmute_conversation_action.activate.connect (toggle_mute_conversation);
action_group.add_action (unmute_conversation_action);

update_mute_conversation_actions_enabled_status ();

var edit_status_simple_action = new SimpleAction ("edit-status", null);
edit_status_simple_action.activate.connect (edit_status);
action_group.add_action (edit_status_simple_action);
Expand All @@ -300,6 +298,8 @@
action_group.add_action (translate_simple_action);
action_group.add_action (show_original_simple_action);
}

update_mute_conversation_actions_enabled_status ();
}

private GLib.MenuItem pin_menu_item;
Expand All @@ -317,24 +317,27 @@
edit_history_menu_item.set_attribute_value ("hidden-when", "action-disabled");
menu_model.append_item (edit_history_menu_item);

var mute_menu_item = new GLib.MenuItem (_("Mute"), "status.mute-conversation");
mute_menu_item.set_attribute_value ("hidden-when", "action-disabled");

var unmute_menu_item = new GLib.MenuItem (_("Unmute"), "status.unmute-conversation");
unmute_menu_item.set_attribute_value ("hidden-when", "action-disabled");

if (status.formal.account.is_self ()) {
pin_menu_item = new GLib.MenuItem (_("Pin"), "status.toggle-pinned");
update_toggle_pinned_label ();
pin_menu_item.set_attribute_value ("hidden-when", "action-disabled");

var mute_menu_item = new GLib.MenuItem (_("Mute"), "status.mute-conversation");
mute_menu_item.set_attribute_value ("hidden-when", "action-disabled");

var unmute_menu_item = new GLib.MenuItem (_("Unmute"), "status.unmute-conversation");
unmute_menu_item.set_attribute_value ("hidden-when", "action-disabled");

menu_model.append_item (pin_menu_item);
menu_model.append_item (mute_menu_item);
menu_model.append_item (unmute_menu_item);

menu_model.append (_("Edit"), "status.edit-status");
menu_model.append (_("Delete"), "status.delete-status");
} else {
menu_model.append_item (mute_menu_item);
menu_model.append_item (unmute_menu_item);

if (
accounts.active.instance_info != null
&& accounts.active.instance_info.tuba_can_translate
Expand Down Expand Up @@ -485,7 +488,7 @@
string api_action = status.formal.muted ? "unmute" : "mute";
new Request.POST (@"/api/v1/statuses/$(status.formal.id)/$api_action")
.with_account (accounts.active)
.then ((in_stream) => {
.then (() => {
status.formal.muted = !status.formal.muted;
update_mute_conversation_actions_enabled_status ();
})
Expand All @@ -503,8 +506,25 @@
}

private void update_mute_conversation_actions_enabled_status () {
mute_conversation_action.set_enabled (!status.formal.muted);
unmute_conversation_action.set_enabled (status.formal.muted);
if (mute_conversation_action == null || unmute_conversation_action == null) return;

bool can_mute_convo = status.formal.account.is_self ();
if (!can_mute_convo && status.formal.mentions != null && status.formal.mentions.size > 0) {
foreach (var mention in status.formal.mentions) {
if (mention.id == accounts.active.id) {
can_mute_convo = true;
break;
}
}
}

if (can_mute_convo) {
mute_conversation_action.set_enabled (!status.formal.muted);
unmute_conversation_action.set_enabled (status.formal.muted);
} else {
mute_conversation_action.set_enabled (false);
unmute_conversation_action.set_enabled (false);
}
}

private void translate () {
Expand Down Expand Up @@ -1131,6 +1151,7 @@
formal_handler_ids += status.formal.notify["tuba-spoiler-revealed"].connect (update_spoiler_status);

aria_describe_status ();
update_mute_conversation_actions_enabled_status ();
}

public void soft_unbind () {
Expand Down

0 comments on commit 3b5751f

Please sign in to comment.