From f8f305efe551838c780dce4224c06bed695d8a62 Mon Sep 17 00:00:00 2001 From: fiaxh Date: Fri, 24 Apr 2020 14:19:42 +0200 Subject: xmpp-vala: Use more async --- xmpp-vala/src/module/xep/0045_muc/module.vala | 52 ++++++++++++++------------- 1 file changed, 27 insertions(+), 25 deletions(-) (limited to 'xmpp-vala/src/module/xep/0045_muc') diff --git a/xmpp-vala/src/module/xep/0045_muc/module.vala b/xmpp-vala/src/module/xep/0045_muc/module.vala index 3434c138..f8845427 100644 --- a/xmpp-vala/src/module/xep/0045_muc/module.vala +++ b/xmpp-vala/src/module/xep/0045_muc/module.vala @@ -333,9 +333,9 @@ public class Module : XmppStreamModule { Jid bare_jid = presence.from.bare_jid; if (flag.get_enter_id(bare_jid) != null) { - query_affiliation(stream, bare_jid, "member", null); - query_affiliation(stream, bare_jid, "admin", null); - query_affiliation(stream, bare_jid, "owner", null); + query_affiliation.begin(stream, bare_jid, "member"); + query_affiliation.begin(stream, bare_jid, "admin"); + query_affiliation.begin(stream, bare_jid, "owner"); flag.finish_muc_enter(bare_jid, presence.from.resourcepart); flag.enter_futures[bare_jid].set_value(new JoinResult() {nick=presence.from.resourcepart}); @@ -437,36 +437,38 @@ public class Module : XmppStreamModule { room_info_updated(stream, jid); } - public delegate void OnAffiliationResult(XmppStream stream, Gee.List jids); - private void query_affiliation(XmppStream stream, Jid jid, string affiliation, owned OnAffiliationResult? listener) { + private async Gee.List? query_affiliation(XmppStream stream, Jid jid, string affiliation) { Iq.Stanza iq = new Iq.Stanza.get( new StanzaNode.build("query", NS_URI_ADMIN) .add_self_xmlns() .put_node(new StanzaNode.build("item", NS_URI_ADMIN) .put_attribute("affiliation", affiliation)) ) { to=jid }; - stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq, (stream, iq) => { - if (iq.is_error()) return; - StanzaNode? query_node = iq.stanza.get_subnode("query", NS_URI_ADMIN); - if (query_node == null) return; - Gee.List item_nodes = query_node.get_subnodes("item", NS_URI_ADMIN); - Gee.List ret_jids = new ArrayList(Jid.equals_func); - foreach (StanzaNode item in item_nodes) { - string jid__ = item.get_attribute("jid"); - string? affiliation_ = item.get_attribute("affiliation"); - if (jid__ != null && affiliation_ != null) { - try { - Jid jid_ = new Jid(jid__); - stream.get_flag(Flag.IDENTITY).set_offline_member(iq.from, jid_, parse_affiliation(affiliation_)); - ret_jids.add(jid_); - received_occupant_jid(stream, iq.from, jid_); - } catch (InvalidJidError e) { - warning("Received invalid occupant jid: %s", e.message); - } + + + Iq.Stanza iq_result = yield stream.get_module(Iq.Module.IDENTITY).send_iq_async(stream, iq); + if (iq_result.is_error()) return null; + + StanzaNode? query_node = iq_result.stanza.get_subnode("query", NS_URI_ADMIN); + if (query_node == null) return null; + + Gee.List item_nodes = query_node.get_subnodes("item", NS_URI_ADMIN); + Gee.List ret_jids = new ArrayList(Jid.equals_func); + foreach (StanzaNode item in item_nodes) { + string jid__ = item.get_attribute("jid"); + string? affiliation_ = item.get_attribute("affiliation"); + if (jid__ != null && affiliation_ != null) { + try { + Jid jid_ = new Jid(jid__); + stream.get_flag(Flag.IDENTITY).set_offline_member(iq_result.from, jid_, parse_affiliation(affiliation_)); + ret_jids.add(jid_); + received_occupant_jid(stream, iq_result.from, jid_); + } catch (InvalidJidError e) { + warning("Received invalid occupant jid: %s", e.message); } } - if (listener != null) listener(stream, ret_jids); - }); + } + return ret_jids; } private static ArrayList get_status_codes(StanzaNode x_node) { -- cgit v1.2.3-70-g09d2