diff options
| author | fiaxh <git@lightrise.org> | 2022-07-08 16:33:40 +0200 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2023-10-01 21:28:29 +0200 |
| commit | b0534dcf07e33ed8533f91dc47955b23a2c2a90d (patch) | |
| tree | 4d3daaebd96e6624f914a5c9e15dd48e33a69df9 /libdino/src/service/muc_manager.vala | |
| parent | b731e62e402c200398ef9dd8980c140a530b287d (diff) | |
| download | dino-b0534dcf07e33ed8533f91dc47955b23a2c2a90d.tar.gz | |
Rewrite MAM logic and add MUC MAM
Diffstat (limited to 'libdino/src/service/muc_manager.vala')
| -rw-r--r-- | libdino/src/service/muc_manager.vala | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/libdino/src/service/muc_manager.vala b/libdino/src/service/muc_manager.vala index 5cfe5528..17787387 100644 --- a/libdino/src/service/muc_manager.vala +++ b/libdino/src/service/muc_manager.vala @@ -68,6 +68,15 @@ public class MucManager : StreamInteractionModule, Object { if (last_message != null) history_since = last_message.time; } + bool receive_history = true; + EntityInfo entity_info = stream_interactor.get_module(EntityInfo.IDENTITY); + bool can_do_mam = yield entity_info.has_feature(account, jid, Xmpp.MessageArchiveManagement.NS_URI_2); + print(@"$(jid) $can_do_mam\n"); + if (can_do_mam) { + receive_history = false; + history_since = null; + } + if (!mucs_joining.has_key(account)) { mucs_joining[account] = new HashSet<Jid>(Jid.hash_bare_func, Jid.equals_bare_func); } @@ -78,7 +87,7 @@ public class MucManager : StreamInteractionModule, Object { } mucs_todo[account].add(jid.with_resource(nick_)); - Muc.JoinResult? res = yield stream.get_module(Xep.Muc.Module.IDENTITY).enter(stream, jid.bare_jid, nick_, password, history_since, null); + Muc.JoinResult? res = yield stream.get_module(Xep.Muc.Module.IDENTITY).enter(stream, jid.bare_jid, nick_, password, history_since, receive_history, null); mucs_joining[account].remove(jid); @@ -91,6 +100,18 @@ public class MucManager : StreamInteractionModule, Object { Conversation joined_conversation = stream_interactor.get_module(ConversationManager.IDENTITY).create_conversation(jid, account, Conversation.Type.GROUPCHAT); joined_conversation.nickname = nick; stream_interactor.get_module(ConversationManager.IDENTITY).start_conversation(joined_conversation); + + if (can_do_mam) { + if (conversation == null) { + // We never joined the conversation before, just fetch the latest MAM page + yield stream_interactor.get_module(MessageProcessor.IDENTITY).history_sync + .fetch_latest_page(account, jid.bare_jid, null, new DateTime.from_unix_utc(0)); + } else { + // Fetch everything up to the last time the user actively joined + stream_interactor.get_module(MessageProcessor.IDENTITY).history_sync + .fetch_everything.begin(account, jid.bare_jid, conversation.active_last_changed); + } + } } else if (res.muc_error != null) { // Join failed enter_errors[jid] = res.muc_error; |
