From 5b4d301d18d08687b6593532212618e5c01f99ed Mon Sep 17 00:00:00 2001 From: Marvin W Date: Sun, 6 Apr 2025 18:11:38 +0200 Subject: MUC: Close chat when it was closed elsewhere while disconnected --- libdino/src/service/muc_manager.vala | 38 ++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'libdino/src') diff --git a/libdino/src/service/muc_manager.vala b/libdino/src/service/muc_manager.vala index 111ace22..ea02fdb5 100644 --- a/libdino/src/service/muc_manager.vala +++ b/libdino/src/service/muc_manager.vala @@ -21,7 +21,7 @@ public class MucManager : StreamInteractionModule, Object { public signal void conference_removed(Account account, Jid jid); private StreamInteractor stream_interactor; - private HashMap> mucs_todo = new HashMap>(Account.hash_func, Account.equals_func); + private HashMap> mucs_joined = new HashMap>(Account.hash_func, Account.equals_func); private HashMap> mucs_joining = new HashMap>(Account.hash_func, Account.equals_func); private HashMap> mucs_sync_cancellables = new HashMap>(Account.hash_func, Account.equals_func); private HashMap enter_errors = new HashMap(Jid.hash_func, Jid.equals_func); @@ -122,25 +122,26 @@ public class MucManager : StreamInteractionModule, Object { enter_errors[jid] = res.muc_error; } - if (!mucs_todo.has_key(account)) { - mucs_todo[account] = new HashSet(Jid.hash_bare_func, Jid.equals_bare_func); + if (!mucs_joined.has_key(account)) { + mucs_joined[account] = new HashSet(Jid.hash_bare_func, Jid.equals_bare_func); } - mucs_todo[account].add(jid.with_resource(res.nick ?? nick_)); + mucs_joined[account].add(jid.with_resource(res.nick ?? nick_)); return res; } public void part(Account account, Jid jid) { - if (!mucs_todo.has_key(account) || !mucs_todo[account].contains(jid)) return; - - mucs_todo[account].remove(jid); + if (mucs_joined.has_key(account) && mucs_joined[account].contains(jid)) { + mucs_joined[account].remove(jid); + } XmppStream? stream = stream_interactor.get_stream(account); - if (stream == null) return; - unset_autojoin(account, stream, jid); - stream.get_module(Xep.Muc.Module.IDENTITY).exit(stream, jid.bare_jid); + if (stream != null) { + unset_autojoin(account, stream, jid); + stream.get_module(Xep.Muc.Module.IDENTITY).exit(stream, jid.bare_jid); + } - Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation(jid, account); + Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation(jid, account, Conversation.Type.GROUPCHAT); if (conversation != null) stream_interactor.get_module(ConversationManager.IDENTITY).close_conversation(conversation); cancel_sync(account, jid); @@ -182,9 +183,9 @@ public class MucManager : StreamInteractionModule, Object { conversation.nickname = new_nick; - if (mucs_todo.has_key(conversation.account)) { - mucs_todo[conversation.account].remove(conversation.counterpart); - mucs_todo[conversation.account].add(conversation.counterpart.with_resource(new_nick)); + if (mucs_joined.has_key(conversation.account)) { + mucs_joined[conversation.account].remove(conversation.counterpart); + mucs_joined[conversation.account].add(conversation.counterpart.with_resource(new_nick)); } // Update nick in bookmark @@ -630,8 +631,7 @@ public class MucManager : StreamInteractionModule, Object { } else if (conversation.active && !conference.autojoin) { part(account, conference.jid); } - } - if (conference.autojoin) { + } else if (conference.autojoin) { join.begin(account, conference.jid, conference.nick, conference.password); } conference_added(account, conference); @@ -655,9 +655,9 @@ public class MucManager : StreamInteractionModule, Object { XmppStream? stream = stream_interactor.get_stream(account); if (stream == null) return; - if (!mucs_todo.has_key(account)) return; + if (!mucs_joined.has_key(account)) return; - foreach (Jid jid in mucs_todo[account]) { + foreach (Jid jid in mucs_joined[account]) { bool joined = false; @@ -666,7 +666,7 @@ public class MucManager : StreamInteractionModule, Object { }); Timeout.add_seconds(10, () => { - if (joined || !mucs_todo.has_key(account) || stream_interactor.get_stream(account) != stream) return false; + if (joined || !mucs_joined.has_key(account) || stream_interactor.get_stream(account) != stream) return false; join.begin(account, jid.bare_jid, jid.resourcepart, null, true); return false; -- cgit v1.3