diff options
author | fiaxh <git@lightrise.org> | 2024-08-18 22:02:33 +0200 |
---|---|---|
committer | fiaxh <fiaxh@users.noreply.github.com> | 2024-08-19 11:36:17 +0200 |
commit | 88376cd6f75d5057caa6582d0a82fc76bb7b388f (patch) | |
tree | 72bf7aef70340bd47247d193180691108cb5c60d | |
parent | 8e7dedcaa62a49373c22dfc54bf1bb8b261bcb61 (diff) | |
download | dino-88376cd6f75d5057caa6582d0a82fc76bb7b388f.tar.gz dino-88376cd6f75d5057caa6582d0a82fc76bb7b388f.zip |
Conversation details: Make block button a stateful menu button
-rw-r--r-- | main/data/conversation_details.ui | 19 | ||||
-rw-r--r-- | main/src/ui/conversation_details.vala | 30 | ||||
-rw-r--r-- | main/src/view_model/conversation_details.vala | 10 | ||||
-rw-r--r-- | main/src/windows/conversation_details.vala | 55 |
4 files changed, 54 insertions, 60 deletions
diff --git a/main/data/conversation_details.ui b/main/data/conversation_details.ui index c34124a3..5ee156bb 100644 --- a/main/data/conversation_details.ui +++ b/main/data/conversation_details.ui @@ -122,8 +122,7 @@ </object> </child> <child> - <object class="AdwSplitButton" id="block_button"> - <property name="menu_model">block_menu_model</property> + <object class="GtkMenuButton" id="block_button"> <property name="visible" bind-source="model" bind-property="show-blocked" bind-flags="sync-create"/> <child> <object class="AdwButtonContent" id="block_button_content"> @@ -204,20 +203,4 @@ </item> </section> </menu> - <menu id="block_menu_model"> - <section> - <item> - <attribute name="label" translatable="1">Block user</attribute> - <attribute name="action">do.block</attribute> - </item> - <item> - <attribute name="label" translatable="1">Block entire domain</attribute> - <attribute name="action">do.block_domain</attribute> - </item> - <item> - <attribute name="label" translatable="1">Unblock</attribute> - <attribute name="action">do.unblock</attribute> - </item> - </section> - </menu> </interface> diff --git a/main/src/ui/conversation_details.vala b/main/src/ui/conversation_details.vala index 90aa9244..4c6a0481 100644 --- a/main/src/ui/conversation_details.vala +++ b/main/src/ui/conversation_details.vala @@ -25,6 +25,14 @@ namespace Dino.Ui.ConversationDetails { view_model.avatar = new ViewModel.CompatAvatarPictureModel(stream_interactor).set_conversation(model.conversation); view_model.show_blocked = model.conversation.type_ == Conversation.Type.CHAT && stream_interactor.get_module(BlockingManager.IDENTITY).is_supported(model.conversation.account); + if (model.domain_blocked) { + view_model.blocked = DOMAIN; + } else if (model.blocked) { + view_model.blocked = USER; + } else { + view_model.blocked = UNBLOCK; + } + model.display_name.bind_property("display-name", view_model, "name", BindingFlags.SYNC_CREATE); model.conversation.bind_property("notify-setting", view_model, "notification", BindingFlags.SYNC_CREATE, (_, from, ref to) => { switch (model.conversation.get_notification_setting(stream_interactor)) { @@ -58,8 +66,6 @@ namespace Dino.Ui.ConversationDetails { to = ty == Conversation.Type.GROUPCHAT ? ViewModel.ConversationDetails.NotificationOptions.ON_HIGHLIGHT_OFF : ViewModel.ConversationDetails.NotificationOptions.ON_OFF; return true; }); - model.bind_property("blocked", view_model, "blocked", BindingFlags.SYNC_CREATE); - model.bind_property("domain_blocked", view_model, "domain_blocked", BindingFlags.SYNC_CREATE); model.bind_property("data-form", view_model, "room-configuration-rows", BindingFlags.SYNC_CREATE, (_, from, ref to) => { var data_form = (DataForms.DataForm) from; if (data_form == null) return true; @@ -83,33 +89,17 @@ namespace Dino.Ui.ConversationDetails { switch (action) { case USER: stream_interactor.get_module(BlockingManager.IDENTITY).block(model.conversation.account, model.conversation.counterpart); - view_model.blocked = true; + stream_interactor.get_module(BlockingManager.IDENTITY).unblock(model.conversation.account, model.conversation.counterpart.domain_jid); break; case DOMAIN: stream_interactor.get_module(BlockingManager.IDENTITY).block(model.conversation.account, model.conversation.counterpart.domain_jid); - view_model.blocked = true; - view_model.domain_blocked = true; break; case UNBLOCK: stream_interactor.get_module(BlockingManager.IDENTITY).unblock(model.conversation.account, model.conversation.counterpart); stream_interactor.get_module(BlockingManager.IDENTITY).unblock(model.conversation.account, model.conversation.counterpart.domain_jid); - view_model.blocked = false; - view_model.domain_blocked = false; - break; - case TOGGLE: - if (view_model.blocked) { - view_model.block_changed(UNBLOCK); - } - else { - view_model.block_changed(USER); - } - if (view_model.domain_blocked) { - view_model.block_changed(UNBLOCK); - } - break; - default: break; } + view_model.blocked = action; }); view_model.notification_changed.connect((setting) => { switch (setting) { diff --git a/main/src/view_model/conversation_details.vala b/main/src/view_model/conversation_details.vala index 9a34be78..75fc9669 100644 --- a/main/src/view_model/conversation_details.vala +++ b/main/src/view_model/conversation_details.vala @@ -6,15 +6,14 @@ using Gtk; public class Dino.Ui.ViewModel.ConversationDetails : Object { public signal void pin_changed(); - public signal void block_changed(BlockActions action); + public signal void block_changed(BlockState action); public signal void notification_flipped(); public signal void notification_changed(NotificationSetting setting); - public enum BlockActions { + public enum BlockState { USER, DOMAIN, - UNBLOCK, - TOGGLE + UNBLOCK } public enum NotificationOptions { @@ -38,8 +37,7 @@ public class Dino.Ui.ViewModel.ConversationDetails : Object { public bool notification_is_default { get; set; } public bool show_blocked { get; set; } - public bool blocked { get; set; } - public bool domain_blocked { get; set; } + public BlockState blocked { get; set; } public GLib.ListStore preferences_rows = new GLib.ListStore(typeof(PreferencesRow.Any)); public GLib.ListStore about_rows = new GLib.ListStore(typeof(PreferencesRow.Any)); diff --git a/main/src/windows/conversation_details.vala b/main/src/windows/conversation_details.vala index b2b33fa3..7ffa01f1 100644 --- a/main/src/windows/conversation_details.vala +++ b/main/src/windows/conversation_details.vala @@ -11,7 +11,7 @@ namespace Dino.Ui.ConversationDetails { [GtkChild] public unowned Box about_box; [GtkChild] public unowned Button pin_button; [GtkChild] public unowned Adw.ButtonContent pin_button_content; - [GtkChild] public unowned Adw.SplitButton block_button; + [GtkChild] public unowned MenuButton block_button; [GtkChild] public unowned Adw.ButtonContent block_button_content; [GtkChild] public unowned Button notification_button_toggle; [GtkChild] public unowned Adw.ButtonContent notification_button_toggle_content; @@ -22,25 +22,22 @@ namespace Dino.Ui.ConversationDetails { [GtkChild] public unowned ViewModel.ConversationDetails model { get; } + private SimpleAction block_action = new SimpleAction.stateful("block", VariantType.INT32, new Variant.int32(ViewModel.ConversationDetails.BlockState.UNBLOCK)); + class construct { install_action("notification.on", null, (widget, action_name) => { ((Dialog) widget).model.notification_changed(ViewModel.ConversationDetails.NotificationSetting.ON); } ); install_action("notification.off", null, (widget, action_name) => { ((Dialog) widget).model.notification_changed(ViewModel.ConversationDetails.NotificationSetting.OFF); } ); install_action("notification.highlight", null, (widget, action_name) => { ((Dialog) widget).model.notification_changed(ViewModel.ConversationDetails.NotificationSetting.HIGHLIGHT); } ); install_action("notification.default", null, (widget, action_name) => { ((Dialog) widget).model.notification_changed(ViewModel.ConversationDetails.NotificationSetting.DEFAULT); } ); - install_action("do.block", null, (widget, action_name) => { ((Dialog) widget).model.block_changed(ViewModel.ConversationDetails.BlockActions.USER); } ); - install_action("do.block_domain", null, (widget, action_name) => { ((Dialog) widget).model.block_changed(ViewModel.ConversationDetails.BlockActions.DOMAIN); } ); - install_action("do.unblock", null, (widget, action_name) => { ((Dialog) widget).model.block_changed(ViewModel.ConversationDetails.BlockActions.UNBLOCK); } ); } construct { pin_button.clicked.connect(() => { model.pin_changed(); }); - block_button.clicked.connect(() => { model.block_changed(ViewModel.ConversationDetails.BlockActions.TOGGLE); }); notification_button_toggle.clicked.connect(() => { model.notification_flipped(); }); notification_button_split.clicked.connect(() => { model.notification_flipped(); }); model.notify["pinned"].connect(update_pinned_button); model.notify["blocked"].connect(update_blocked_button); - model.notify["domain-blocked"].connect(update_blocked_button); model.notify["notification"].connect(update_notification_button); model.notify["notification"].connect(update_notification_button_state); model.notify["notification-options"].connect(update_notification_button_visibility); @@ -51,10 +48,32 @@ namespace Dino.Ui.ConversationDetails { model.settings_rows.items_changed.connect(create_preferences_rows); model.notify["room-configuration-rows"].connect(create_preferences_rows); + // Create block action + SimpleActionGroup block_action_group = new SimpleActionGroup(); + block_action = new SimpleAction.stateful("block", VariantType.INT32, new Variant.int32(0)); + block_action.activate.connect((parameter) => { + block_action.set_state(parameter); + model.block_changed((ViewModel.ConversationDetails.BlockState) parameter.get_int32()); + }); + block_action_group.insert(block_action); + this.insert_action_group("block", block_action_group); + + // Create block menu model + Menu block_menu_model = new Menu(); + string[] menu_labels = new string[] { _("Block user"), _("Block entire domain"), _("Unblock") }; + ViewModel.ConversationDetails.BlockState[] menu_states = new ViewModel.ConversationDetails.BlockState[] { ViewModel.ConversationDetails.BlockState.USER, ViewModel.ConversationDetails.BlockState.DOMAIN, ViewModel.ConversationDetails.BlockState.UNBLOCK }; + for (int i = 0; i < menu_labels.length; i++) { + MenuItem item = new MenuItem(menu_labels[i], null); + item.set_action_and_target_value("block.block", new Variant.int32(menu_states[i])); + block_menu_model.append_item(item); + } + block_button.menu_model = block_menu_model; + #if Adw_1_4 // TODO: replace with putting buttons in new line on small screens notification_button_menu_content.can_shrink = true; #endif + update_blocked_button(); } private void update_pinned_button() { @@ -68,18 +87,22 @@ namespace Dino.Ui.ConversationDetails { } private void update_blocked_button() { - if (model.blocked) { - block_button_content.label = _("Blocked"); - block_button.add_css_class("error"); - } else { - block_button_content.label = _("Block"); - block_button.remove_css_class("error"); + switch (model.blocked) { + case USER: + block_button_content.label = _("Blocked"); + block_button.add_css_class("error"); + break; + case DOMAIN: + block_button_content.label = _("Domain blocked"); + block_button.add_css_class("error"); + break; + case UNBLOCK: + block_button_content.label = _("Block"); + block_button.remove_css_class("error"); + break; } - if (model.domain_blocked) { - block_button_content.label = _("Domain blocked"); - block_button.add_css_class("error"); - } + block_action.set_state(new Variant.int32(model.blocked)); } private void update_notification_button() { |