diff options
author | fiaxh <git@lightrise.org> | 2020-03-29 20:23:47 +0200 |
---|---|---|
committer | fiaxh <git@lightrise.org> | 2020-03-29 20:24:39 +0200 |
commit | 12cd56612dd6edd056e2cd8aae59ea3ae8f05d1e (patch) | |
tree | 1da6667e85128aad0c2992b3c2b490f42defce6f /xmpp-vala/src/module | |
parent | 853dfa2d6f0d1300b096f0c6a12ca179208f5287 (diff) | |
download | dino-12cd56612dd6edd056e2cd8aae59ea3ae8f05d1e.tar.gz dino-12cd56612dd6edd056e2cd8aae59ea3ae8f05d1e.zip |
Store entity identity info, use it in conversation list tooltips
Diffstat (limited to 'xmpp-vala/src/module')
-rw-r--r-- | xmpp-vala/src/module/xep/0030_service_discovery/identity.vala | 6 | ||||
-rw-r--r-- | xmpp-vala/src/module/xep/0115_entitiy_capabilities.vala | 40 |
2 files changed, 32 insertions, 14 deletions
diff --git a/xmpp-vala/src/module/xep/0030_service_discovery/identity.vala b/xmpp-vala/src/module/xep/0030_service_discovery/identity.vala index e29eb111..43aecfb2 100644 --- a/xmpp-vala/src/module/xep/0030_service_discovery/identity.vala +++ b/xmpp-vala/src/module/xep/0030_service_discovery/identity.vala @@ -4,6 +4,10 @@ public class Identity { public const string CATEGORY_CLIENT = "client"; public const string CATEGORY_CONFERENCE = "conference"; + public const string TYPE_PC = "pc"; + public const string TYPE_PHONE = "phone"; + public const string TYPE_TABLET = "tablet"; + public string category { get; set; } public string type_ { get; set; } public string? name { get; set; } @@ -15,4 +19,4 @@ public class Identity { } } -}
\ No newline at end of file +} diff --git a/xmpp-vala/src/module/xep/0115_entitiy_capabilities.vala b/xmpp-vala/src/module/xep/0115_entitiy_capabilities.vala index 18c5a660..22946d4b 100644 --- a/xmpp-vala/src/module/xep/0115_entitiy_capabilities.vala +++ b/xmpp-vala/src/module/xep/0115_entitiy_capabilities.vala @@ -3,12 +3,24 @@ using Gee; namespace Xmpp.Xep.EntityCapabilities { private const string NS_URI = "http://jabber.org/protocol/caps"; + private Regex? sha1_base64_regex = null; + + public string? get_caps_hash(Presence.Stanza presence) { + if (sha1_base64_regex == null) { + sha1_base64_regex = /^[A-Za-z0-9+\/]{27}=$/; + } + StanzaNode? c_node = presence.stanza.get_subnode("c", NS_URI); + if (c_node == null) return null; + string? ver_attribute = c_node.get_attribute("ver", NS_URI); + if (ver_attribute == null || !sha1_base64_regex.match(ver_attribute)) return null; + return ver_attribute; + } + public class Module : XmppStreamModule { public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "0115_entity_capabilities"); private string own_ver_hash; private Storage storage; - private Regex sha1_base64_regex = /^[A-Za-z0-9+\/]{27}=$/; public Module(Storage storage) { this.storage = storage; @@ -45,18 +57,17 @@ namespace Xmpp.Xep.EntityCapabilities { } private void on_received_presence(XmppStream stream, Presence.Stanza presence) { - StanzaNode? c_node = presence.stanza.get_subnode("c", NS_URI); - if (c_node != null) { - string? ver_attribute = c_node.get_attribute("ver", NS_URI); - if (ver_attribute == null || !sha1_base64_regex.match(ver_attribute)) return; - Gee.List<string> capabilities = storage.get_features(ver_attribute); - if (capabilities.size == 0) { - stream.get_module(ServiceDiscovery.Module.IDENTITY).request_info(stream, presence.from, (stream, query_result) => { - store_entity_result(stream, ver_attribute, query_result); - }); - } else { - stream.get_flag(ServiceDiscovery.Flag.IDENTITY).set_entity_features(presence.from, capabilities); - } + string? caps_hash = get_caps_hash(presence); + if (caps_hash == null) return; + + Gee.List<string> capabilities = storage.get_features(caps_hash); + ServiceDiscovery.Identity identity = storage.get_identities(caps_hash); + if (identity == null) { + stream.get_module(ServiceDiscovery.Module.IDENTITY).request_info(stream, presence.from, (stream, query_result) => { + store_entity_result(stream, caps_hash, query_result); + }); + } else { + stream.get_flag(ServiceDiscovery.Flag.IDENTITY).set_entity_features(presence.from, capabilities); } } @@ -69,6 +80,7 @@ namespace Xmpp.Xep.EntityCapabilities { } if (compute_hash(query_result.identities, query_result.features, data_forms) == entity) { + storage.store_identities(entity, query_result.identities); storage.store_features(entity, query_result.features); stream.get_flag(ServiceDiscovery.Flag.IDENTITY).set_entity_features(query_result.iq.from, query_result.features); } @@ -142,7 +154,9 @@ namespace Xmpp.Xep.EntityCapabilities { } public interface Storage : Object { + public abstract void store_identities(string entity, Gee.List<ServiceDiscovery.Identity> identities); public abstract void store_features(string entity, Gee.List<string> capabilities); + public abstract ServiceDiscovery.Identity? get_identities(string entity); public abstract Gee.List<string> get_features(string entity); } } |