diff options
author | fiaxh <git@lightrise.org> | 2020-04-23 13:53:44 +0200 |
---|---|---|
committer | fiaxh <git@lightrise.org> | 2020-04-24 14:18:24 +0200 |
commit | e7bc68ad4d02b8e5f6ba26c0e917abf4d9ab2ccc (patch) | |
tree | f1ef7e1d98723774a31374bfda7ab0804f38c6d4 /xmpp-vala/src/module/xep/0191_blocking_command.vala | |
parent | 9661116d7814059fad7bf6a6ae5c0f684aed5bda (diff) | |
download | dino-e7bc68ad4d02b8e5f6ba26c0e917abf4d9ab2ccc.tar.gz dino-e7bc68ad4d02b8e5f6ba26c0e917abf4d9ab2ccc.zip |
Handle entity hash in server features node, make ServiceDiscovery request_info/items async, add caching has_entity_feature
Diffstat (limited to 'xmpp-vala/src/module/xep/0191_blocking_command.vala')
-rw-r--r-- | xmpp-vala/src/module/xep/0191_blocking_command.vala | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/xmpp-vala/src/module/xep/0191_blocking_command.vala b/xmpp-vala/src/module/xep/0191_blocking_command.vala index 2fc1d3b4..fbedc8b3 100644 --- a/xmpp-vala/src/module/xep/0191_blocking_command.vala +++ b/xmpp-vala/src/module/xep/0191_blocking_command.vala @@ -80,29 +80,24 @@ public class Module : XmppStreamModule, Iq.Handler { public override string get_ns() { return NS_URI; } public override string get_id() { return IDENTITY.id; } - private void on_stream_negotiated(XmppStream stream) { - stream.get_module(Xep.ServiceDiscovery.Module.IDENTITY).request_info(stream, stream.remote_name, (stream, info_result) => { - if (info_result.features.contains(NS_URI)) { - stream.add_flag(new Flag()); - get_blocklist(stream, (stream, jids) => { - stream.get_flag(Flag.IDENTITY).blocklist = jids; - }); - return; - } - }); + private async void on_stream_negotiated(XmppStream stream) { + bool has_feature = yield stream.get_module(ServiceDiscovery.Module.IDENTITY).has_entity_feature(stream, stream.remote_name, NS_URI); + if (has_feature) { + stream.add_flag(new Flag()); + stream.get_flag(Flag.IDENTITY).blocklist = yield get_blocklist(stream); + } } - private delegate void OnBlocklist(XmppStream stream, Gee.List<string> jids); - private void get_blocklist(XmppStream stream, owned OnBlocklist listener) { + private async Gee.List<string> get_blocklist(XmppStream stream) { StanzaNode blocklist_node = new StanzaNode.build("blocklist", NS_URI).add_self_xmlns(); Iq.Stanza iq = new Iq.Stanza.get(blocklist_node); - stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq, (stream, iq) => { - StanzaNode? node = iq.stanza.get_subnode("blocklist", NS_URI); - if (node != null) { - Gee.List<string> jids = get_jids_from_items(node); - listener(stream, jids); - } - }); + + Iq.Stanza result_iq = yield stream.get_module(Iq.Module.IDENTITY).send_iq_async(stream, iq); + StanzaNode? node = result_iq.stanza.get_subnode("blocklist", NS_URI); + if (node != null) { + return get_jids_from_items(node); + } + return new ArrayList<string>(); } private Gee.List<string> get_jids_from_items(StanzaNode node) { |