diff options
Diffstat (limited to 'libdino/src/service/message_processor.vala')
-rw-r--r-- | libdino/src/service/message_processor.vala | 70 |
1 files changed, 36 insertions, 34 deletions
diff --git a/libdino/src/service/message_processor.vala b/libdino/src/service/message_processor.vala index baab37ce..d8ea3e2d 100644 --- a/libdino/src/service/message_processor.vala +++ b/libdino/src/service/message_processor.vala @@ -38,6 +38,7 @@ public class MessageProcessor : StreamInteractionModule, Object { received_pipeline.connect(new FilterMessageListener()); received_pipeline.connect(new StoreMessageListener(this, stream_interactor)); received_pipeline.connect(new StoreContentItemListener(stream_interactor)); + received_pipeline.connect(new MarkupListener(stream_interactor)); stream_interactor.account_added.connect(on_account_added); @@ -45,18 +46,6 @@ public class MessageProcessor : StreamInteractionModule, Object { stream_interactor.stream_resumed.connect(send_unsent_chat_messages); } - public Entities.Message send_text(string text, Conversation conversation) { - Entities.Message message = create_out_message(text, conversation); - return send_message(message, conversation); - } - - public Entities.Message send_message(Entities.Message message, Conversation conversation) { - stream_interactor.get_module(ContentItemStore.IDENTITY).insert_message(message, conversation); - send_xmpp_message(message, conversation); - message_sent(message, conversation); - return message; - } - private void convert_sending_to_unsent_msgs(Account account) { db.message.update() .with(db.message.account_id, "=", account.id) @@ -344,6 +333,25 @@ public class MessageProcessor : StreamInteractionModule, Object { } } + private class MarkupListener : MessageListener { + + public string[] after_actions_const = new string[]{ "STORE" }; + public override string action_group { get { return "Markup"; } } + public override string[] after_actions { get { return after_actions_const; } } + + private StreamInteractor stream_interactor; + + public MarkupListener(StreamInteractor stream_interactor) { + this.stream_interactor = stream_interactor; + } + + public override async bool run(Entities.Message message, Xmpp.MessageStanza stanza, Conversation conversation) { + Gee.List<MessageMarkup.Span> markups = MessageMarkup.get_spans(stanza); + message.persist_markups(markups, message.id); + return false; + } + } + private class StoreContentItemListener : MessageListener { public string[] after_actions_const = new string[]{ "DEDUPLICATE", "DECRYPT", "FILTER_EMPTY", "STORE", "CORRECTION", "MESSAGE_REINTERPRETING" }; @@ -406,8 +414,22 @@ public class MessageProcessor : StreamInteractionModule, Object { new_message.type_ = MessageStanza.TYPE_CHAT; } - string? fallback = get_fallback_body_set_infos(message, new_message, conversation); - new_message.body = fallback == null ? message.body : fallback + message.body; + if (message.quoted_item_id != 0) { + ContentItem? quoted_content_item = stream_interactor.get_module(ContentItemStore.IDENTITY).get_item_by_id(conversation, message.quoted_item_id); + if (quoted_content_item != null) { + Jid? quoted_sender = message.from; + string? quoted_stanza_id = stream_interactor.get_module(ContentItemStore.IDENTITY).get_message_id_for_content_item(conversation, quoted_content_item); + if (quoted_sender != null && quoted_stanza_id != null) { + Xep.Replies.set_reply_to(new_message, new Xep.Replies.ReplyTo(quoted_sender, quoted_stanza_id)); + } + + foreach (var fallback in message.get_fallbacks()) { + Xep.FallbackIndication.set_fallback(new_message, fallback); + } + } + } + + MessageMarkup.add_spans(new_message, message.get_markups()); build_message_stanza(message, new_message, conversation); pre_message_send(message, new_message, conversation); @@ -456,26 +478,6 @@ public class MessageProcessor : StreamInteractionModule, Object { } }); } - - public string? get_fallback_body_set_infos(Entities.Message message, MessageStanza new_stanza, Conversation conversation) { - if (message.quoted_item_id == 0) return null; - - ContentItem? content_item = stream_interactor.get_module(ContentItemStore.IDENTITY).get_item_by_id(conversation, message.quoted_item_id); - if (content_item == null) return null; - - Jid? quoted_sender = stream_interactor.get_module(ContentItemStore.IDENTITY).get_message_sender_for_content_item(conversation, content_item); - string? quoted_stanza_id = stream_interactor.get_module(ContentItemStore.IDENTITY).get_message_id_for_content_item(conversation, content_item); - if (quoted_sender != null && quoted_stanza_id != null) { - Xep.Replies.set_reply_to(new_stanza, new Xep.Replies.ReplyTo(quoted_sender, quoted_stanza_id)); - } - - string fallback = FallbackBody.get_quoted_fallback_body(content_item); - - var fallback_location = new Xep.FallbackIndication.FallbackLocation(0, (int)fallback.char_count()); - Xep.FallbackIndication.set_fallback(new_stanza, new Xep.FallbackIndication.Fallback(Xep.Replies.NS_URI, new Xep.FallbackIndication.FallbackLocation[] { fallback_location })); - - return fallback; - } } public abstract class MessageListener : Xmpp.OrderedListener { |