From f40a34bdc1995e656b09cc1252a8dcce685e373f Mon Sep 17 00:00:00 2001 From: fiaxh Date: Sat, 11 Mar 2017 23:04:58 +0100 Subject: Use delegates + object storage instead of listener objects --- libdino/src/service/avatar_manager.vala | 7 ---- libdino/src/service/muc_manager.vala | 59 ++++++++++++--------------------- 2 files changed, 22 insertions(+), 44 deletions(-) (limited to 'libdino/src/service') diff --git a/libdino/src/service/avatar_manager.vala b/libdino/src/service/avatar_manager.vala index d0b25d3b..69e5580e 100644 --- a/libdino/src/service/avatar_manager.vala +++ b/libdino/src/service/avatar_manager.vala @@ -73,13 +73,6 @@ public class AvatarManager : StreamInteractionModule, Object { } } - private class PublishResponseListenerImpl : Object { - public void on_success(Core.XmppStream stream) { - - } - public void on_error(Core.XmppStream stream) { } - } - public static AvatarManager? get_instance(StreamInteractor stream_interaction) { return (AvatarManager) stream_interaction.get_module(id); } diff --git a/libdino/src/service/muc_manager.vala b/libdino/src/service/muc_manager.vala index c3aaa727..589f26d7 100644 --- a/libdino/src/service/muc_manager.vala +++ b/libdino/src/service/muc_manager.vala @@ -28,7 +28,7 @@ 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, new MucEnterListenerImpl(this, jid, nick, 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)); } public void part(Account account, Jid jid) { @@ -73,10 +73,10 @@ public class MucManager : StreamInteractionModule, Object { return is_groupchat(jid.bare_jid, account) && jid.is_full(); } - public void get_bookmarks(Account account, Xep.Bookmarks.ConferencesRetrieveResponseListener listener) { + public void get_bookmarks(Account account, Xep.Bookmarks.Module.OnResult listener, Object? store) { Core.XmppStream? stream = stream_interactor.get_stream(account); if (stream != null) { - stream.get_module(Xep.Bookmarks.Module.IDENTITY).get_conferences(stream, listener); + stream.get_module(Xep.Bookmarks.Module.IDENTITY).get_conferences(stream, listener, store); } } @@ -158,7 +158,7 @@ public class MucManager : StreamInteractionModule, Object { 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, new BookmarksRetrieveResponseListener(this, account)); + if (stream != null) stream.get_module(Xep.Bookmarks.Module.IDENTITY).get_conferences(stream, join_autojoin_conferences, Tuple.create(this, account)); } private void on_pre_message_received(Entities.Message message, Xmpp.Message.Stanza message_stanza, Conversation conversation) { @@ -184,41 +184,26 @@ public class MucManager : StreamInteractionModule, Object { } } - private class BookmarksRetrieveResponseListener : Xep.Bookmarks.ConferencesRetrieveResponseListener, Object { - MucManager outer = null; - Account account = null; - - public BookmarksRetrieveResponseListener(MucManager outer, Account account) { - this.outer = outer; - this.account = account; - } - - public void on_result(Core.XmppStream stream, ArrayList conferences) { - 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); - } + 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); } } } - - private class MucEnterListenerImpl : Xep.Muc.MucEnterListener, Object { // TODO - private MucManager outer; - private Jid jid; - private string nick; - private Account account; - public MucEnterListenerImpl(MucManager outer, Jid jid, string nick, Account account) { - this.outer = outer; - this.jid = jid; - this.nick = nick; - this.account = account; - } - public void on_success() { - outer.groupchat_joined(account, jid, nick); - } - public void on_error(Xep.Muc.MucEnterError error) { } - } } } \ No newline at end of file -- cgit v1.2.3-70-g09d2