diff options
author | fiaxh <git@mx.ax.lt> | 2017-12-04 18:40:40 +0100 |
---|---|---|
committer | fiaxh <git@mx.ax.lt> | 2017-12-05 15:07:15 +0100 |
commit | bbbfdf0551fdb03e793944243dcaaf811e8ac027 (patch) | |
tree | de06d11dab6da4f5d7d6aa5a0fe893a558d09f4d | |
parent | dc2dde5378b75743aa3110a00e47265cb440629b (diff) | |
download | dino-bbbfdf0551fdb03e793944243dcaaf811e8ac027.tar.gz dino-bbbfdf0551fdb03e793944243dcaaf811e8ac027.zip |
Match message with previously arrived marker
-rw-r--r-- | libdino/src/service/conversation_manager.vala | 16 | ||||
-rw-r--r-- | libdino/src/service/counterpart_interaction_manager.vala | 16 | ||||
-rw-r--r-- | libdino/src/service/message_processor.vala | 13 |
3 files changed, 30 insertions, 15 deletions
diff --git a/libdino/src/service/conversation_manager.vala b/libdino/src/service/conversation_manager.vala index 44b16d68..986cb0f1 100644 --- a/libdino/src/service/conversation_manager.vala +++ b/libdino/src/service/conversation_manager.vala @@ -27,8 +27,8 @@ public class ConversationManager : StreamInteractionModule, Object { stream_interactor.add_module(this); stream_interactor.account_added.connect(on_account_added); stream_interactor.get_module(MucManager.IDENTITY).joined.connect(on_groupchat_joined); - stream_interactor.get_module(MessageProcessor.IDENTITY).message_received.connect(on_message_received); - stream_interactor.get_module(MessageProcessor.IDENTITY).message_sent.connect(on_message_sent); + stream_interactor.get_module(MessageProcessor.IDENTITY).message_received.connect(handle_new_message); + stream_interactor.get_module(MessageProcessor.IDENTITY).message_sent.connect(handle_new_message); } public Conversation create_conversation(Jid jid, Account account, Conversation.Type? type = null) { @@ -117,13 +117,15 @@ public class ConversationManager : StreamInteractionModule, Object { } } - private void on_message_received(Entities.Message message, Conversation conversation) { + private void handle_new_message(Entities.Message message, Conversation conversation) { conversation.last_active = message.time; - start_conversation(conversation); - } - private void on_message_sent(Entities.Message message, Conversation conversation) { - conversation.last_active = message.time; + if (message.stanza != null) { + bool is_mam_message = Xep.MessageArchiveManagement.MessageFlag.get_flag(message.stanza) != null; + bool is_recent = message.local_time.compare(new DateTime.now_utc().add_hours(-24)) > 0; + if (is_mam_message && !is_recent) return; + } + start_conversation(conversation); } private void on_groupchat_joined(Account account, Jid jid, string nick) { diff --git a/libdino/src/service/counterpart_interaction_manager.vala b/libdino/src/service/counterpart_interaction_manager.vala index 0b989c35..bde60889 100644 --- a/libdino/src/service/counterpart_interaction_manager.vala +++ b/libdino/src/service/counterpart_interaction_manager.vala @@ -15,6 +15,7 @@ public class CounterpartInteractionManager : StreamInteractionModule, Object { private StreamInteractor stream_interactor; private HashMap<Jid, string> chat_states = new HashMap<Jid, string>(Jid.hash_bare_func, Jid.equals_bare_func); + private HashMap<string, string> marker_wo_message = new HashMap<string, string>(); public static void start(StreamInteractor stream_interactor) { CounterpartInteractionManager m = new CounterpartInteractionManager(stream_interactor); @@ -25,6 +26,7 @@ public class CounterpartInteractionManager : StreamInteractionModule, Object { this.stream_interactor = stream_interactor; stream_interactor.account_added.connect(on_account_added); stream_interactor.get_module(MessageProcessor.IDENTITY).message_received.connect(on_message_received); + stream_interactor.get_module(MessageProcessor.IDENTITY).message_sent.connect(check_if_got_marker); } public string? get_chat_state(Account account, Jid jid) { @@ -67,10 +69,23 @@ public class CounterpartInteractionManager : StreamInteractionModule, Object { message.marked = Entities.Message.Marked.READ; break; } + } else { + if (marker_wo_message.has_key(stanza_id) && + marker_wo_message[stanza_id] == Xep.ChatMarkers.MARKER_DISPLAYED && marker == Xep.ChatMarkers.MARKER_RECEIVED) { + return; + } + marker_wo_message[stanza_id] = marker; } } } + private void check_if_got_marker(Entities.Message message, Conversation conversation) { + if (marker_wo_message.has_key(message.stanza_id)) { + on_chat_marker_received(conversation.account, conversation.counterpart, marker_wo_message[message.stanza_id], message.stanza_id); + marker_wo_message.unset(message.stanza_id); + } + } + private void on_message_received(Entities.Message message, Conversation conversation) { on_chat_state_received(conversation.account, conversation.counterpart, Xep.ChatStateNotifications.STATE_ACTIVE); } @@ -79,4 +94,5 @@ public class CounterpartInteractionManager : StreamInteractionModule, Object { on_chat_marker_received(account, jid, Xep.ChatMarkers.MARKER_RECEIVED, id); } } + } diff --git a/libdino/src/service/message_processor.vala b/libdino/src/service/message_processor.vala index 757a0e1f..1a9b1872 100644 --- a/libdino/src/service/message_processor.vala +++ b/libdino/src/service/message_processor.vala @@ -104,16 +104,13 @@ public class MessageProcessor : StreamInteractionModule, Object { (!is_uuid && !db.contains_message(new_message, conversation.account))) { stream_interactor.get_module(MessageStorage.IDENTITY).add_message(new_message, conversation); - bool is_mam_message = Xep.MessageArchiveManagement.MessageFlag.get_flag(stanza) != null; - bool is_recent = new_message.local_time.compare(new DateTime.now_utc().add_hours(-24)) > 0; - if (!is_mam_message || is_recent) { - if (new_message.direction == Entities.Message.DIRECTION_SENT) { - message_sent(new_message, conversation); - } else { - message_received(new_message, conversation); - } + if (new_message.direction == Entities.Message.DIRECTION_SENT) { + message_sent(new_message, conversation); + } else { + message_received(new_message, conversation); } + bool is_mam_message = Xep.MessageArchiveManagement.MessageFlag.get_flag(stanza) != null; Core.XmppStream? stream = stream_interactor.get_stream(conversation.account); Xep.MessageArchiveManagement.Flag? mam_flag = stream != null ? stream.get_flag(Xep.MessageArchiveManagement.Flag.IDENTITY) : null; if (is_mam_message || (mam_flag != null && mam_flag.cought_up == true)) { |