From a37b5ac823cc5daefac6ab33a16d6f44c747ba9c Mon Sep 17 00:00:00 2001 From: fiaxh Date: Tue, 11 Apr 2017 18:06:01 +0200 Subject: MUC improvements --- libdino/src/service/conversation_manager.vala | 2 +- libdino/src/service/muc_manager.vala | 59 +++++++++++++-------------- libdino/src/service/presence_manager.vala | 4 +- 3 files changed, 31 insertions(+), 34 deletions(-) (limited to 'libdino/src/service') diff --git a/libdino/src/service/conversation_manager.vala b/libdino/src/service/conversation_manager.vala index db9cff91..abc9e502 100644 --- a/libdino/src/service/conversation_manager.vala +++ b/libdino/src/service/conversation_manager.vala @@ -26,7 +26,7 @@ public class ConversationManager : StreamInteractionModule, Object { this.stream_interactor = stream_interactor; stream_interactor.add_module(this); stream_interactor.account_added.connect(on_account_added); - stream_interactor.get_module(MucManager.IDENTITY).groupchat_joined.connect(on_groupchat_joined); + 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_sent.connect(on_message_sent); } diff --git a/libdino/src/service/muc_manager.vala b/libdino/src/service/muc_manager.vala index f63a557c..b9d6dce2 100644 --- a/libdino/src/service/muc_manager.vala +++ b/libdino/src/service/muc_manager.vala @@ -8,8 +8,9 @@ public class MucManager : StreamInteractionModule, Object { public static ModuleIdentity IDENTITY = new ModuleIdentity("muc_manager"); public string id { get { return IDENTITY.id; } } - public signal void groupchat_joined(Account account, Jid jid, string nick); - public signal void groupchat_subject_set(Account account, Jid jid, string subject); + public signal void joined(Account account, Jid jid, string nick); + public signal void left(Account account, Jid jid); + public signal void subject_set(Account account, Jid jid, string? subject); public signal void bookmarks_updated(Account account, ArrayList conferences); private StreamInteractor stream_interactor; @@ -29,7 +30,8 @@ public class MucManager : StreamInteractionModule, Object { public void join(Account account, Jid jid, string nick, string? password = null) { Core.XmppStream stream = stream_interactor.get_stream(account); - if (stream != null) stream.get_module(Xep.Muc.Module.IDENTITY).enter(stream, jid.bare_jid.to_string(), nick, password, on_groupchat_joined, () => {}, Quadruple.create(this, jid, nick, account)); + if (stream == null) return; + stream.get_module(Xep.Muc.Module.IDENTITY).enter(stream, jid.bare_jid.to_string(), nick, password); } public void part(Account account, Jid jid) { @@ -140,22 +142,39 @@ public class MucManager : StreamInteractionModule, Object { return null; } + public bool is_joined(Jid jid, Account account) { + return get_nick(jid, account) != null; + } + private void on_account_added(Account account) { + stream_interactor.module_manager.get_module(account, Xep.Muc.Module.IDENTITY).room_entered.connect( (stream, jid, nick) => { + joined(account, new Jid(jid), nick); + }); + stream_interactor.module_manager.get_module(account, Xep.Muc.Module.IDENTITY).self_removed_from_room.connect( (stream, jid, code) => { + left(account, new Jid(jid)); + }); stream_interactor.module_manager.get_module(account, Xep.Muc.Module.IDENTITY).subject_set.connect( (stream, subject, jid) => { - on_subject_set(account, new Jid(jid), subject); + subject_set(account, new Jid(jid), subject); }); stream_interactor.module_manager.get_module(account, Xep.Bookmarks.Module.IDENTITY).conferences_updated.connect( (stream, conferences) => { bookmarks_updated(account, conferences); }); } - private void on_subject_set(Account account, Jid sender_jid, string subject) { - groupchat_subject_set(account, sender_jid, subject); - } - private void on_stream_negotiated(Account account) { Core.XmppStream stream = stream_interactor.get_stream(account); - if (stream != null) stream.get_module(Xep.Bookmarks.Module.IDENTITY).get_conferences(stream, join_autojoin_conferences, Tuple.create(this, account)); + if (stream != null) stream.get_module(Xep.Bookmarks.Module.IDENTITY).get_conferences(stream, (stream, conferences, o) => { + Tuple tuple = o as Tuple; + MucManager outer_ = tuple.a; + Account account_ = tuple.b; + foreach (Xep.Bookmarks.Conference bookmark in conferences) { + Jid jid = new Jid(bookmark.jid); + outer_.conference_bookmarks[jid] = bookmark; + if (bookmark.autojoin) { + outer_.join(account_, jid, bookmark.nick); + } + } + }, Tuple.create(this, account)); } private void on_pre_message_received(Entities.Message message, Xmpp.Message.Stanza message_stanza, Conversation conversation) { @@ -178,28 +197,6 @@ public class MucManager : StreamInteractionModule, Object { } } } - - private static void on_groupchat_joined(Core.XmppStream stream, Object? store) { - Quadruple quadruple = store as Quadruple; - MucManager outer = quadruple.a; - Jid jid = quadruple.b; - string nick = quadruple.c; - Account account = quadruple.d; - outer.groupchat_joined(account, jid, nick); - } - - private static void join_autojoin_conferences(Core.XmppStream stream, ArrayList conferences, Object? o) { - Tuple tuple = o as Tuple; - MucManager outer = tuple.a; - Account account = tuple.b; - foreach (Xep.Bookmarks.Conference bookmark in conferences) { - Jid jid = new Jid(bookmark.jid); - outer.conference_bookmarks[jid] = bookmark; - if (bookmark.autojoin) { - outer.join(account, jid, bookmark.nick); - } - } - } } } \ No newline at end of file diff --git a/libdino/src/service/presence_manager.vala b/libdino/src/service/presence_manager.vala index 5dfb2cf6..ad2db89f 100644 --- a/libdino/src/service/presence_manager.vala +++ b/libdino/src/service/presence_manager.vala @@ -83,8 +83,8 @@ public class PresenceManager : StreamInteractionModule, Object { stream_interactor.module_manager.get_module(account, Presence.Module.IDENTITY).received_available_show.connect((stream, jid, show) => on_received_available_show(account, new Jid(jid), show) ); - stream_interactor.module_manager.get_module(account, Presence.Module.IDENTITY).received_unavailable.connect((stream, jid) => - on_received_unavailable(account, new Jid(jid)) + stream_interactor.module_manager.get_module(account, Presence.Module.IDENTITY).received_unavailable.connect((stream, presence) => + on_received_unavailable(account, new Jid(presence.from)) ); stream_interactor.module_manager.get_module(account, Presence.Module.IDENTITY).received_subscription_request.connect((stream, jid) => received_subscription_request(new Jid(jid), account) -- cgit v1.2.3-70-g09d2