From b104be4842c4f5c309055052bd7b9d2fc9337113 Mon Sep 17 00:00:00 2001 From: fiaxh Date: Mon, 6 Jul 2020 19:32:16 +0200 Subject: [PATCH] Don't create a second message object for each typing notification --- libdino/src/service/conversation_manager.vala | 11 +++++++++++ .../src/service/counterpart_interaction_manager.vala | 6 ++---- libdino/src/service/message_processor.vala | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/libdino/src/service/conversation_manager.vala b/libdino/src/service/conversation_manager.vala index 18a362c6..dcb0ced4 100644 --- a/libdino/src/service/conversation_manager.vala +++ b/libdino/src/service/conversation_manager.vala @@ -84,6 +84,17 @@ public class ConversationManager : StreamInteractionModule, Object { return null; } + public Conversation? approx_conversation_for_stanza(Jid jid, Account account, string msg_ty) { + if (msg_ty == Xmpp.MessageStanza.TYPE_GROUPCHAT) { + return get_conversation(jid.bare_jid, account, Conversation.Type.GROUPCHAT); + } else if (msg_ty == Xmpp.MessageStanza.TYPE_CHAT && jid.is_full() && + get_conversation(jid.bare_jid, account, Conversation.Type.GROUPCHAT) != null) { + var pm = get_conversation(jid, account, Conversation.Type.GROUPCHAT_PM); + if (pm != null) return pm; + } + return get_conversation(jid.bare_jid, account, Conversation.Type.CHAT); + } + public Conversation? get_conversation_by_id(int id) { foreach (HashMap> hm in conversations.values) { foreach (Gee.List hm2 in hm.values) { diff --git a/libdino/src/service/counterpart_interaction_manager.vala b/libdino/src/service/counterpart_interaction_manager.vala index 7a98f0ff..7776b885 100644 --- a/libdino/src/service/counterpart_interaction_manager.vala +++ b/libdino/src/service/counterpart_interaction_manager.vala @@ -95,8 +95,7 @@ public class CounterpartInteractionManager : StreamInteractionModule, Object { // Don't show our own (other devices) typing notification if (jid.equals_bare(account.bare_jid)) return; - Message message = yield stream_interactor.get_module(MessageProcessor.IDENTITY).parse_message_stanza(account, stanza); - Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation_for_message(message); + Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).approx_conversation_for_stanza(jid, account, stanza.type_); if (conversation == null) return; // Don't show our own typing notification in MUCs @@ -119,8 +118,7 @@ public class CounterpartInteractionManager : StreamInteractionModule, Object { } private async void on_chat_marker_received(Account account, Jid jid, string marker, string stanza_id, MessageStanza message_stanza) { - Message message = yield stream_interactor.get_module(MessageProcessor.IDENTITY).parse_message_stanza(account, message_stanza); - Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation_for_message(message); + Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).approx_conversation_for_stanza(jid, account, message_stanza.type_); if (conversation == null) return; handle_chat_marker(conversation, jid, marker, stanza_id); } diff --git a/libdino/src/service/message_processor.vala b/libdino/src/service/message_processor.vala index e65d45ac..aedc0147 100644 --- a/libdino/src/service/message_processor.vala +++ b/libdino/src/service/message_processor.vala @@ -341,7 +341,7 @@ public class MessageProcessor : StreamInteractionModule, Object { message_sent_or_received(message, conversation); } - public async Entities.Message parse_message_stanza(Account account, Xmpp.MessageStanza message) { + private async Entities.Message parse_message_stanza(Account account, Xmpp.MessageStanza message) { string? body = message.body; if (body != null) body = body.strip(); Entities.Message new_message = new Entities.Message(body);