diff options
author | fiaxh <git@lightrise.org> | 2020-07-03 21:14:39 +0200 |
---|---|---|
committer | fiaxh <git@lightrise.org> | 2020-07-16 23:31:19 +0200 |
commit | e159fd2492c28c1ef4ab64828ca0e8c2de877b41 (patch) | |
tree | aca3c42854b08b5683a1c85e7c7a74fd0a4bdf0d /xmpp-vala/src/module/xep/0030_service_discovery | |
parent | 74f7fa897f9aec298eeadcfc7a7b971f06498858 (diff) | |
download | dino-e159fd2492c28c1ef4ab64828ca0e8c2de877b41.tar.gz dino-e159fd2492c28c1ef4ab64828ca0e8c2de877b41.zip |
Only query entity caps when we need them
Diffstat (limited to 'xmpp-vala/src/module/xep/0030_service_discovery')
-rw-r--r-- | xmpp-vala/src/module/xep/0030_service_discovery/flag.vala | 29 | ||||
-rw-r--r-- | xmpp-vala/src/module/xep/0030_service_discovery/module.vala | 28 |
2 files changed, 9 insertions, 48 deletions
diff --git a/xmpp-vala/src/module/xep/0030_service_discovery/flag.vala b/xmpp-vala/src/module/xep/0030_service_discovery/flag.vala index 7716ceff..ab311727 100644 --- a/xmpp-vala/src/module/xep/0030_service_discovery/flag.vala +++ b/xmpp-vala/src/module/xep/0030_service_discovery/flag.vala @@ -5,8 +5,6 @@ namespace Xmpp.Xep.ServiceDiscovery { public class Flag : XmppStreamFlag { public static FlagIdentity<Flag> IDENTITY = new FlagIdentity<Flag>(NS_URI, "service_discovery"); - public HashMap<Jid, Gee.List<string>?> entity_features = new HashMap<Jid, Gee.List<string>?>(Jid.hash_func, Jid.equals_func); - private HashMap<Jid, Gee.Set<Identity>?> entity_identities = new HashMap<Jid, Gee.Set<Identity>?>(Jid.hash_func, Jid.equals_func); private HashMap<Jid, Gee.List<Item>?> entity_items = new HashMap<Jid, Gee.List<Item>?>(Jid.hash_func, Jid.equals_func); private Gee.Set<string> own_features_ = new HashSet<string>(); @@ -23,33 +21,6 @@ public class Flag : XmppStreamFlag { owned get { return own_identities_.read_only_view; } } - public Gee.Set<Identity>? get_entity_identities(Jid jid) { - return entity_identities.has_key(jid) ? entity_identities[jid].read_only_view : null; // TODO isn’t this default for hashmap - } - - public bool? has_entity_identity(Jid jid, string category, string type) { - if (!entity_identities.has_key(jid)) return null; - if (entity_identities[jid] == null) return false; - foreach (Identity identity in entity_identities[jid]) { - if (identity.category == category && identity.type_ == type) return true; - } - return false; - } - - public bool? has_entity_feature(Jid jid, string feature) { - if (!entity_features.has_key(jid)) return null; - if (entity_features[jid] == null) return false; - return entity_features[jid].contains(feature); - } - - public void set_entity_identities(Jid jid, Gee.Set<Identity>? identities) { - entity_identities[jid] = identities; - } - - public void set_entity_features(Jid jid, Gee.List<string>? features) { - entity_features[jid] = features; - } - public void set_entity_items(Jid jid, Gee.List<Item>? features) { entity_items[jid] = features; } diff --git a/xmpp-vala/src/module/xep/0030_service_discovery/module.vala b/xmpp-vala/src/module/xep/0030_service_discovery/module.vala index f21146f1..c61d3ab0 100644 --- a/xmpp-vala/src/module/xep/0030_service_discovery/module.vala +++ b/xmpp-vala/src/module/xep/0030_service_discovery/module.vala @@ -12,9 +12,10 @@ public class Module : XmppStreamModule, Iq.Handler { private HashMap<Jid, Future<InfoResult?>> active_info_requests = new HashMap<Jid, Future<InfoResult?>>(Jid.hash_func, Jid.equals_func); public Identity own_identity; + public CapsCache cache; public Module.with_identity(string category, string type, string? name = null) { - own_identity = new Identity(category, type, name); + this.own_identity = new Identity(category, type, name); } public void add_feature(XmppStream stream, string feature) { @@ -42,27 +43,11 @@ public class Module : XmppStreamModule, Iq.Handler { } public async bool has_entity_feature(XmppStream stream, Jid jid, string feature) { - Flag flag = stream.get_flag(Flag.IDENTITY); - - if (flag.has_entity_feature(jid, feature) == null) { - InfoResult? info_result = yield request_info(stream, jid); - stream.get_flag(Flag.IDENTITY).set_entity_features(jid, info_result != null ? info_result.features : null); - stream.get_flag(Flag.IDENTITY).set_entity_identities(jid, info_result != null ? info_result.identities : null); - } - - return flag.has_entity_feature(jid, feature) ?? false; + return yield this.cache.has_entity_feature(jid, feature); } public async Gee.Set<Identity>? get_entity_identities(XmppStream stream, Jid jid) { - Flag flag = stream.get_flag(Flag.IDENTITY); - - if (flag.get_entity_identities(jid) == null) { - InfoResult? info_result = yield request_info(stream, jid); - stream.get_flag(Flag.IDENTITY).set_entity_features(info_result.iq.from, info_result != null ? info_result.features : null); - stream.get_flag(Flag.IDENTITY).set_entity_identities(info_result.iq.from, info_result != null ? info_result.identities : null); - } - - return flag.get_entity_identities(jid); + return yield this.cache.get_entity_identities(jid); } public async InfoResult? request_info(XmppStream stream, Jid jid) { @@ -137,4 +122,9 @@ public class Module : XmppStreamModule, Iq.Handler { } } +public interface CapsCache : Object { + public abstract async bool has_entity_feature(Jid jid, string feature); + public abstract async Gee.Set<Identity> get_entity_identities(Jid jid); +} + } |