diff options
author | fiaxh <git@lightrise.org> | 2023-01-29 23:06:01 +0100 |
---|---|---|
committer | fiaxh <git@lightrise.org> | 2023-01-30 22:54:55 +0100 |
commit | b0b81b88c6948dcfd2b1b82a9fe7357316a3af1f (patch) | |
tree | ea44aed7431b955ef8b1636f74c8ebe42bacb099 /main | |
parent | 10a2bce5122dcd1e6fef037633a26568bf27d4d1 (diff) | |
download | dino-b0b81b88c6948dcfd2b1b82a9fe7357316a3af1f.tar.gz dino-b0b81b88c6948dcfd2b1b82a9fe7357316a3af1f.zip |
Always display reaction+reply buttons, disable if not possible
Diffstat (limited to 'main')
-rw-r--r-- | main/CMakeLists.txt | 1 | ||||
-rw-r--r-- | main/src/ui/conversation_content_view/conversation_view.vala | 19 | ||||
-rw-r--r-- | main/src/ui/conversation_content_view/file_widget.vala | 17 | ||||
-rw-r--r-- | main/src/ui/conversation_content_view/item_actions.vala | 50 | ||||
-rw-r--r-- | main/src/ui/conversation_content_view/message_widget.vala | 29 |
5 files changed, 65 insertions, 51 deletions
diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index b8f9d942..301e1d95 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -165,6 +165,7 @@ SOURCES src/ui/conversation_content_view/file_default_widget.vala src/ui/conversation_content_view/file_image_widget.vala src/ui/conversation_content_view/file_widget.vala + src/ui/conversation_content_view/item_actions.vala src/ui/conversation_content_view/message_widget.vala src/ui/conversation_content_view/quote_widget.vala src/ui/conversation_content_view/reactions_widget.vala diff --git a/main/src/ui/conversation_content_view/conversation_view.vala b/main/src/ui/conversation_content_view/conversation_view.vala index 4d978132..36e19474 100644 --- a/main/src/ui/conversation_content_view/conversation_view.vala +++ b/main/src/ui/conversation_content_view/conversation_view.vala @@ -203,23 +203,22 @@ public class ConversationView : Widget, Plugins.ConversationItemCollection, Plug message_menu_box.visible = true; // Configure as many buttons as we need with the actions for the current meta item - for (int i = 0; i < message_actions.size; i++) { - if (message_actions[i].popover != null) { + foreach (var message_action in message_actions) { + if (message_action.popover != null) { MenuButton button = new MenuButton(); - button.icon_name = message_actions[i].icon_name; - button.set_popover(message_actions[i].popover as Popover); - button.tooltip_text = Util.string_if_tooltips_active(message_actions[i].tooltip); + button.sensitive = message_action.sensitive; + button.icon_name = message_action.icon_name; + button.set_popover(message_action.popover as Popover); + button.tooltip_text = Util.string_if_tooltips_active(message_action.tooltip); action_buttons.add(button); - } - - if (message_actions[i].callback != null) { - var message_action = message_actions[i]; + } else if (message_action.callback != null) { Button button = new Button(); + button.sensitive = message_action.sensitive; button.icon_name = message_action.icon_name; button.clicked.connect(() => { message_action.callback(button, current_meta_item, currently_highlighted); }); - button.tooltip_text = Util.string_if_tooltips_active(message_actions[i].tooltip); + button.tooltip_text = Util.string_if_tooltips_active(message_action.tooltip); action_buttons.add(button); } } diff --git a/main/src/ui/conversation_content_view/file_widget.vala b/main/src/ui/conversation_content_view/file_widget.vala index 8c36475a..543eb169 100644 --- a/main/src/ui/conversation_content_view/file_widget.vala +++ b/main/src/ui/conversation_content_view/file_widget.vala @@ -32,21 +32,8 @@ public class FileMetaItem : ConversationSummary.ContentMetaItem { Gee.List<Plugins.MessageAction> actions = new ArrayList<Plugins.MessageAction>(); if (stream_interactor.get_module(ContentItemStore.IDENTITY).get_message_id_for_content_item(file_item.conversation, content_item) != null) { - Plugins.MessageAction reply_action = new Plugins.MessageAction(); - reply_action.icon_name = "mail-reply-sender-symbolic"; - reply_action.callback = (button, content_meta_item_activated, widget) => { - GLib.Application.get_default().activate_action("quote", new GLib.Variant.tuple(new GLib.Variant[] { new GLib.Variant.int32(file_item.conversation.id), new GLib.Variant.int32(content_item.id) })); - }; - actions.add(reply_action); - - Plugins.MessageAction action2 = new Plugins.MessageAction(); - action2.icon_name = "dino-emoticon-add-symbolic"; - EmojiChooser chooser = new EmojiChooser(); - chooser.emoji_picked.connect((emoji) => { - stream_interactor.get_module(Reactions.IDENTITY).add_reaction(file_item.conversation, content_item, emoji); - }); - action2.popover = chooser; - actions.add(action2); + actions.add(get_reply_action(content_item, file_item.conversation, stream_interactor)); + actions.add(get_reaction_action(content_item, file_item.conversation, stream_interactor)); } return actions; } diff --git a/main/src/ui/conversation_content_view/item_actions.vala b/main/src/ui/conversation_content_view/item_actions.vala new file mode 100644 index 00000000..2cca7565 --- /dev/null +++ b/main/src/ui/conversation_content_view/item_actions.vala @@ -0,0 +1,50 @@ +using Dino.Entities; +using Gtk; + +namespace Dino.Ui { + public Plugins.MessageAction get_reaction_action(ContentItem content_item, Conversation conversation, StreamInteractor stream_interactor) { + Plugins.MessageAction action = new Plugins.MessageAction(); + action.icon_name = "dino-emoticon-add-symbolic"; + action.tooltip = _("Add reaction"); + + EmojiChooser chooser = new EmojiChooser(); + chooser.emoji_picked.connect((emoji) => { + stream_interactor.get_module(Reactions.IDENTITY).add_reaction(conversation, content_item, emoji); + }); + action.popover = chooser; + + // Disable the button if reaction aren't possible. + bool supports_reactions = stream_interactor.get_module(Reactions.IDENTITY).conversation_supports_reactions(conversation); + string? message_id = stream_interactor.get_module(ContentItemStore.IDENTITY).get_message_id_for_content_item(conversation, content_item); + + if (!supports_reactions) { + action.tooltip = _("This conversation does not support reactions."); + action.sensitive = false; + } else if (message_id == null) { + action.tooltip = "This message does not support reactions."; + action.sensitive = false; + } + return action; + } + + public Plugins.MessageAction get_reply_action(ContentItem content_item, Conversation conversation, StreamInteractor stream_interactor) { + Plugins.MessageAction action = new Plugins.MessageAction(); + action.icon_name = "mail-reply-sender-symbolic"; + action.tooltip = _("Reply"); + action.callback = (button, content_meta_item_activated, widget) => { + GLib.Application.get_default().activate_action("quote", new GLib.Variant.tuple(new GLib.Variant[] { new GLib.Variant.int32(conversation.id), new GLib.Variant.int32(content_item.id) })); + }; + + // Disable the button if replies aren't possible. + string? message_id = stream_interactor.get_module(ContentItemStore.IDENTITY).get_message_id_for_content_item(conversation, content_item); + if (message_id == null) { + action.sensitive = false; + if (conversation.type_.is_muc_semantic()) { + action.tooltip = _("This conversation does not support replies."); + } else { + action.tooltip = "This message does not support replies."; + } + } + return action; + } +}
\ No newline at end of file diff --git a/main/src/ui/conversation_content_view/message_widget.vala b/main/src/ui/conversation_content_view/message_widget.vala index 900525fe..b05fe850 100644 --- a/main/src/ui/conversation_content_view/message_widget.vala +++ b/main/src/ui/conversation_content_view/message_widget.vala @@ -22,7 +22,6 @@ public class MessageMetaItem : ContentMetaItem { MessageItemEditMode? edit_mode = null; ChatTextViewController? controller = null; - private bool supports_reaction = false; AdditionalInfo additional_info = AdditionalInfo.NONE; ulong realize_id = -1; @@ -36,8 +35,6 @@ public class MessageMetaItem : ContentMetaItem { message_item = content_item as MessageItem; this.stream_interactor = stream_interactor; - init.begin(); - label.activate_link.connect(on_label_activate_link); Message message = ((MessageItem) content_item).message; @@ -71,10 +68,6 @@ public class MessageMetaItem : ContentMetaItem { update_label(); } - private async void init() { - supports_reaction = yield stream_interactor.get_module(Reactions.IDENTITY).conversation_supports_reactions(message_item.conversation); - } - private string generate_markup_text(ContentItem item) { MessageItem message_item = item as MessageItem; Conversation conversation = message_item.conversation; @@ -224,25 +217,9 @@ public class MessageMetaItem : ContentMetaItem { actions.add(action1); } - Plugins.MessageAction reply_action = new Plugins.MessageAction(); - reply_action.icon_name = "mail-reply-sender-symbolic"; - reply_action.tooltip = _("Reply"); - reply_action.callback = (button, content_meta_item_activated, widget) => { - GLib.Application.get_default().activate_action("quote", new GLib.Variant.tuple(new GLib.Variant[] { new GLib.Variant.int32(message_item.conversation.id), new GLib.Variant.int32(content_item.id) })); - }; - actions.add(reply_action); - - if (supports_reaction) { - Plugins.MessageAction action2 = new Plugins.MessageAction(); - action2.icon_name = "dino-emoticon-add-symbolic"; - action2.tooltip = _("Add reaction"); - EmojiChooser chooser = new EmojiChooser(); - chooser.emoji_picked.connect((emoji) => { - stream_interactor.get_module(Reactions.IDENTITY).add_reaction(message_item.conversation, message_item, emoji); - }); - action2.popover = chooser; - actions.add(action2); - } + actions.add(get_reply_action(content_item, message_item.conversation, stream_interactor)); + actions.add(get_reaction_action(content_item, message_item.conversation, stream_interactor)); + return actions; } |