diff options
author | fiaxh <git@lightrise.org> | 2023-01-06 13:19:42 +0100 |
---|---|---|
committer | fiaxh <git@lightrise.org> | 2023-01-06 14:03:54 +0100 |
commit | dc52e7595cca06d0a2da7d11b3c88cb2f7ce529c (patch) | |
tree | 111f4a86a8541ce51bba7ec56f5b32197fcefc83 /main/src/ui/chat_input | |
parent | 4d7809bb12199a598b531ca3ca019a4bb5a867f7 (diff) | |
download | dino-dc52e7595cca06d0a2da7d11b3c88cb2f7ce529c.tar.gz dino-dc52e7595cca06d0a2da7d11b3c88cb2f7ce529c.zip |
Add support for XEP-0461 replies (with fallback)
Diffstat (limited to 'main/src/ui/chat_input')
-rw-r--r-- | main/src/ui/chat_input/chat_input_controller.vala | 37 | ||||
-rw-r--r-- | main/src/ui/chat_input/view.vala | 15 |
2 files changed, 48 insertions, 4 deletions
diff --git a/main/src/ui/chat_input/chat_input_controller.vala b/main/src/ui/chat_input/chat_input_controller.vala index 7b260695..de75cdf8 100644 --- a/main/src/ui/chat_input/chat_input_controller.vala +++ b/main/src/ui/chat_input/chat_input_controller.vala @@ -24,6 +24,8 @@ public class ChatInputController : Object { private Plugins.InputFieldStatus input_field_status; private ChatTextViewController chat_text_view_controller; + private ContentItem? quoted_content_item = null; + public ChatInputController(ChatInput.View chat_input, StreamInteractor stream_interactor) { this.chat_input = chat_input; this.status_description_label = chat_input.chat_input_status; @@ -58,12 +60,34 @@ public class ChatInputController : Object { } return true; }); + + SimpleAction quote_action = new SimpleAction("quote", new VariantType.tuple(new VariantType[]{VariantType.INT32, VariantType.INT32})); + quote_action.activate.connect((variant) => { + int conversation_id = variant.get_child_value(0).get_int32(); + Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation_by_id(conversation_id); + if (conversation == null || !this.conversation.equals(conversation)) return; + + int content_item_id = variant.get_child_value(1).get_int32(); + ContentItem? content_item = stream_interactor.get_module(ContentItemStore.IDENTITY).get_item_by_id(conversation, content_item_id); + if (content_item == null) return; + + quoted_content_item = content_item; + var quote_model = new Quote.Model.from_content_item(content_item, conversation, stream_interactor) { can_abort = true }; + quote_model.aborted.connect(() => { + content_item = null; + chat_input.unset_quoted_message(); + }); + chat_input.set_quoted_message(Quote.get_widget(quote_model)); + }); + GLib.Application.get_default().add_action(quote_action); } public void set_conversation(Conversation conversation) { - this.conversation = conversation; - + this.quoted_content_item = null; reset_input_field_status(); + chat_input.unset_quoted_message(); + + this.conversation = conversation; chat_input.encryption_widget.set_conversation(conversation); @@ -111,7 +135,10 @@ public class ChatInputController : Object { } string text = chat_input.chat_text_view.text_view.buffer.text; + chat_input.chat_text_view.text_view.buffer.text = ""; + chat_input.unset_quoted_message(); + if (text.has_prefix("/")) { string[] token = text.split(" ", 2); switch(token[0]) { @@ -164,7 +191,11 @@ public class ChatInputController : Object { break; } } - stream_interactor.get_module(MessageProcessor.IDENTITY).send_text(text, conversation); + Message out_message = stream_interactor.get_module(MessageProcessor.IDENTITY).create_out_message(text, conversation); + if (quoted_content_item != null) { + stream_interactor.get_module(Replies.IDENTITY).set_message_is_reply_to(out_message, quoted_content_item); + } + stream_interactor.get_module(MessageProcessor.IDENTITY).send_message(out_message, conversation); } private void on_text_input_changed() { diff --git a/main/src/ui/chat_input/view.vala b/main/src/ui/chat_input/view.vala index 4be4455b..e16b4085 100644 --- a/main/src/ui/chat_input/view.vala +++ b/main/src/ui/chat_input/view.vala @@ -20,8 +20,8 @@ public class View : Box { private HashMap<Conversation, string> entry_cache = new HashMap<Conversation, string>(Conversation.hash_func, Conversation.equals_func); [GtkChild] public unowned Frame frame; + [GtkChild] public unowned Box quote_box; [GtkChild] public unowned ChatTextView chat_text_view; - [GtkChild] public unowned Box outer_box; [GtkChild] public unowned Button file_button; [GtkChild] public unowned MenuButton emoji_button; [GtkChild] public unowned MenuButton encryption_button; @@ -94,6 +94,19 @@ public class View : Box { }); } + public void set_quoted_message(Widget quote_widget) { + Widget? quote_box_child = quote_box.get_first_child(); + if (quote_box_child != null) quote_box.remove(quote_box_child); + quote_box.append(quote_widget); + quote_box.visible = true; + } + + public void unset_quoted_message() { + Widget? quote_box_child = quote_box.get_first_child(); + if (quote_box_child != null) quote_box.remove(quote_box_child); + quote_box.visible = false; + } + public void do_focus() { chat_text_view.text_view.grab_focus(); } |