diff options
author | fiaxh <git@mx.ax.lt> | 2017-08-18 00:46:40 +0200 |
---|---|---|
committer | fiaxh <git@mx.ax.lt> | 2017-08-19 00:31:44 +0200 |
commit | dff8e08669996936cb58884c71b5ecd6ad7b1f76 (patch) | |
tree | 1bed7be48a042ca788f466a149ab0f434a53c34f /libdino/src | |
parent | 299f52df3af8bc7dafcd9a5a6e12d31042734357 (diff) | |
download | dino-dff8e08669996936cb58884c71b5ecd6ad7b1f76.tar.gz dino-dff8e08669996936cb58884c71b5ecd6ad7b1f76.zip |
MAM fixes
- don't send first request for timestamp -60
- only open conversation for messages within last 24h
- always show latest message in conversation tabs
Diffstat (limited to 'libdino/src')
-rw-r--r-- | libdino/src/service/conversation_manager.vala | 6 | ||||
-rw-r--r-- | libdino/src/service/message_processor.vala | 19 | ||||
-rw-r--r-- | libdino/src/service/message_storage.vala | 22 |
3 files changed, 29 insertions, 18 deletions
diff --git a/libdino/src/service/conversation_manager.vala b/libdino/src/service/conversation_manager.vala index 6e58ba8a..81d846e0 100644 --- a/libdino/src/service/conversation_manager.vala +++ b/libdino/src/service/conversation_manager.vala @@ -27,7 +27,7 @@ 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).pre_message_received.connect(on_message_received); + stream_interactor.get_module(MessageProcessor.IDENTITY).message_received.connect(on_message_received); stream_interactor.get_module(MessageProcessor.IDENTITY).message_sent.connect(on_message_sent); } @@ -107,7 +107,7 @@ public class ConversationManager : StreamInteractionModule, Object { } } - private void on_message_received(Entities.Message message, Xmpp.Message.Stanza message_stanza, Conversation conversation) { + private void on_message_received(Entities.Message message, Conversation conversation) { conversation.last_active = message.time; start_conversation(conversation); } @@ -129,4 +129,4 @@ public class ConversationManager : StreamInteractionModule, Object { } } -}
\ No newline at end of file +} diff --git a/libdino/src/service/message_processor.vala b/libdino/src/service/message_processor.vala index 14d4ef28..d1490aa0 100644 --- a/libdino/src/service/message_processor.vala +++ b/libdino/src/service/message_processor.vala @@ -45,7 +45,8 @@ public class MessageProcessor : StreamInteractionModule, Object { on_message_received(account, message); }); stream_interactor.module_manager.get_module(account, Xmpp.Xep.MessageArchiveManagement.Module.IDENTITY).feature_available.connect( (stream) => { - stream.get_module(Xep.MessageArchiveManagement.Module.IDENTITY).query_archive(stream, null, account.mam_earliest_synced.add_minutes(-1), null); + DateTime start_time = account.mam_earliest_synced.to_unix() > 60 ? account.mam_earliest_synced.add_minutes(-1) : account.mam_earliest_synced; + stream.get_module(Xep.MessageArchiveManagement.Module.IDENTITY).query_archive(stream, null, start_time, null); }); } @@ -102,15 +103,21 @@ public class MessageProcessor : StreamInteractionModule, Object { if ((is_uuid && !db.contains_message_by_stanza_id(new_message.stanza_id, conversation.account)) || (!is_uuid && !db.contains_message(new_message, conversation.account))) { stream_interactor.get_module(MessageStorage.IDENTITY).add_message(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; + bool is_recent = new_message.local_time.compare(new DateTime.now_utc().add_hours(-24)) > 0; + if (!is_mam_message || is_recent) { + print(new_message.local_time.to_string() + "\n"); + if (new_message.direction == Entities.Message.DIRECTION_SENT) { + message_sent(new_message, conversation); + } else { + message_received(new_message, conversation); + } } 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 (Xep.MessageArchiveManagement.MessageFlag.get_flag(stanza) != null || (mam_flag != null && mam_flag.cought_up == true)) { + if (is_mam_message || (mam_flag != null && mam_flag.cought_up == true)) { conversation.account.mam_earliest_synced = new_message.local_time; } } diff --git a/libdino/src/service/message_storage.vala b/libdino/src/service/message_storage.vala index 8812d950..1cde1a95 100644 --- a/libdino/src/service/message_storage.vala +++ b/libdino/src/service/message_storage.vala @@ -11,7 +11,7 @@ public class MessageStorage : StreamInteractionModule, Object { private StreamInteractor stream_interactor; private Database db; - private HashMap<Conversation, Gee.List<Message>> messages = new HashMap<Conversation, Gee.List<Entities.Message>>(Conversation.hash_func, Conversation.equals_func); + private HashMap<Conversation, Gee.TreeSet<Message>> messages = new HashMap<Conversation, Gee.TreeSet<Message>>(Conversation.hash_func, Conversation.equals_func); public static void start(StreamInteractor stream_interactor, Database db) { MessageStorage m = new MessageStorage(stream_interactor, db); @@ -31,16 +31,18 @@ public class MessageStorage : StreamInteractionModule, Object { public Gee.List<Message> get_messages(Conversation conversation, int count = 50) { init_conversation(conversation); - if (messages[conversation].size > 0) { - return messages[conversation][int.max(messages[conversation].size - count - 1, 0) : messages[conversation].size]; + Gee.List<Message> ret = new ArrayList<Message>(Message.equals_func); + foreach (Message message in messages[conversation]) { + if (ret.size >= count) break; + ret.add(message); } - return new ArrayList<Message>(); + return ret; } public Message? get_last_message(Conversation conversation) { init_conversation(conversation); if (messages[conversation].size > 0) { - return messages[conversation][messages[conversation].size - 1]; + return messages[conversation].first(); } return null; } @@ -52,17 +54,19 @@ public class MessageStorage : StreamInteractionModule, Object { public Message? get_message_by_id(string stanza_id, Conversation conversation) { init_conversation(conversation); - for (int i = messages[conversation].size - 1; i > 0; i--) { - if (messages[conversation][i].stanza_id == stanza_id) return messages[conversation][i]; + foreach (Message message in messages[conversation]) { + if (message.stanza_id == stanza_id) return message; } return null; } private void init_conversation(Conversation conversation) { if (!messages.has_key(conversation)) { - messages[conversation] = db.get_messages(conversation.counterpart, conversation.account, Util.get_message_type_for_conversation(conversation), 50, null); + messages[conversation] = new Gee.TreeSet<Message>((a, b) => { return -1 * a.local_time.compare(b.local_time); }); + Gee.List<Message> db_messages = db.get_messages(conversation.counterpart, conversation.account, Util.get_message_type_for_conversation(conversation), 50, null); + messages[conversation].add_all(db_messages); } } } -}
\ No newline at end of file +} |