diff options
author | fiaxh <git@mx.ax.lt> | 2017-06-13 18:14:59 +0200 |
---|---|---|
committer | fiaxh <git@mx.ax.lt> | 2017-06-13 20:12:40 +0200 |
commit | 7bbbb738fdb233f4ad91ffdd7d9247b28849d715 (patch) | |
tree | 649ac26e3feef6bae614442a7f3d6ee1057336e0 /libdino/src/service/muc_manager.vala | |
parent | dabc2a8b1d2a7bf2019e5f913c736d80f11ceb53 (diff) | |
download | dino-7bbbb738fdb233f4ad91ffdd7d9247b28849d715.tar.gz dino-7bbbb738fdb233f4ad91ffdd7d9247b28849d715.zip |
Get rid of manual storage objects for delegates
Diffstat (limited to 'libdino/src/service/muc_manager.vala')
-rw-r--r-- | libdino/src/service/muc_manager.vala | 44 |
1 files changed, 18 insertions, 26 deletions
diff --git a/libdino/src/service/muc_manager.vala b/libdino/src/service/muc_manager.vala index 2c916c99..c6f37116 100644 --- a/libdino/src/service/muc_manager.vala +++ b/libdino/src/service/muc_manager.vala @@ -48,14 +48,13 @@ public class MucManager : StreamInteractionModule, Object { if (conversation != null) stream_interactor.get_module(ConversationManager.IDENTITY).close_conversation(conversation); } - [CCode (has_target = false)] public delegate void OnResult(Jid jid, Xep.DataForms.DataForm data_form, Object? store); - public void get_config_form(Account account, Jid jid, OnResult on_result, Object? store) { + public delegate void OnResult(Jid jid, Xep.DataForms.DataForm data_form); + public void get_config_form(Account account, Jid jid, owned OnResult listener) { Core.XmppStream? stream = stream_interactor.get_stream(account); if (stream == null) return; - stream.get_module(Xep.Muc.Module.IDENTITY).get_config_form(stream, jid.to_string(), (stream, jid, data_form, store) => { - Tuple<OnResult, Object?> tuple = store as Tuple<OnResult, Object?>; - tuple.a(new Jid(jid), data_form, tuple.b); - }, Tuple.create(on_result, store)); + stream.get_module(Xep.Muc.Module.IDENTITY).get_config_form(stream, jid.to_string(), (stream, jid, data_form) => { + listener(new Jid(jid), data_form); + }); } public void change_subject(Account account, Jid jid, string subject) { @@ -109,11 +108,9 @@ public class MucManager : StreamInteractionModule, Object { return is_groupchat(jid.bare_jid, account) && jid.is_full(); } - public void get_bookmarks(Account account, Xep.Bookmarks.Module.OnResult listener, Object? store) { + public void get_bookmarks(Account account, owned Xep.Bookmarks.Module.OnResult listener) { Core.XmppStream? stream = stream_interactor.get_stream(account); - if (stream != null) { - stream.get_module(Xep.Bookmarks.Module.IDENTITY).get_conferences(stream, listener, store); - } + if (stream != null) stream.get_module(Xep.Bookmarks.Module.IDENTITY).get_conferences(stream, (owned)listener); } public void add_bookmark(Account account, Xep.Bookmarks.Conference conference) { @@ -223,17 +220,14 @@ public class MucManager : StreamInteractionModule, Object { } private void on_stream_negotiated(Account account, Core.XmppStream stream) { - stream.get_module(Xep.Bookmarks.Module.IDENTITY).get_conferences(stream, (stream, conferences, o) => { - Tuple<MucManager, Account> tuple = o as Tuple<MucManager, Account>; - MucManager outer_ = tuple.a; - Account account_ = tuple.b; + stream.get_module(Xep.Bookmarks.Module.IDENTITY).get_conferences(stream, (stream, conferences) => { foreach (Xep.Bookmarks.Conference bookmark in conferences) { Jid jid = new Jid(bookmark.jid); if (bookmark.autojoin) { - outer_.join(account_, jid, bookmark.nick, bookmark.password); + join(account, jid, bookmark.nick, bookmark.password); } } - }, Tuple.create(this, account)); + }); } private void on_pre_message_received(Entities.Message message, Xmpp.Message.Stanza message_stanza, Conversation conversation) { @@ -292,11 +286,10 @@ public class MucManager : StreamInteractionModule, Object { } private void set_autojoin(Core.XmppStream stream, Jid jid, string? nick, string? password) { - stream.get_module(Xep.Bookmarks.Module.IDENTITY).get_conferences(stream, (stream, conferences, storage) => { - Triple<Jid, string?, string?> triple = storage as Triple<Jid, string?, string?>; - Xep.Bookmarks.Conference changed = new Xep.Bookmarks.Conference(triple.a.to_string()) { nick=triple.b, password=triple.c, autojoin=true }; + stream.get_module(Xep.Bookmarks.Module.IDENTITY).get_conferences(stream, (stream, conferences) => { + Xep.Bookmarks.Conference changed = new Xep.Bookmarks.Conference(jid.to_string()) { nick=nick, password=password, autojoin=true }; foreach (Xep.Bookmarks.Conference conference in conferences) { - if (conference.jid == triple.a.bare_jid.to_string() && conference.nick == triple.b && conference.password == triple.c) { + if (conference.jid == jid.bare_jid.to_string() && conference.nick == nick && conference.password == password) { if (!conference.autojoin) { stream.get_module(Xep.Bookmarks.Module.IDENTITY).replace_conference(stream, conference, changed); } @@ -304,22 +297,21 @@ public class MucManager : StreamInteractionModule, Object { } } stream.get_module(Xep.Bookmarks.Module.IDENTITY).add_conference(stream, changed); - }, Triple.create(jid, nick, password)); + }); } private void unset_autojoin(Core.XmppStream stream, Jid jid) { - stream.get_module(Xep.Bookmarks.Module.IDENTITY).get_conferences(stream, (stream, conferences, storage) => { - Jid jid_ = storage as Jid; + stream.get_module(Xep.Bookmarks.Module.IDENTITY).get_conferences(stream, (stream, conferences) => { foreach (Xep.Bookmarks.Conference conference in conferences) { - if (conference.jid == jid_.bare_jid.to_string()) { + if (conference.jid == jid.bare_jid.to_string()) { if (conference.autojoin) { Xep.Bookmarks.Conference change = new Xep.Bookmarks.Conference(conference.jid) { nick=conference.nick, password=conference.password, autojoin=false }; stream.get_module(Xep.Bookmarks.Module.IDENTITY).replace_conference(stream, conference, change); } } } - }, jid); + }); } } -}
\ No newline at end of file +} |