From 881b9eec9dcd8fd8c81b0b9d7bfd2ae714d7722e Mon Sep 17 00:00:00 2001 From: fiaxh Date: Thu, 19 Nov 2020 18:33:03 +0100 Subject: Improve entity identity getter --- libdino/src/service/entity_info.vala | 55 ++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 24 deletions(-) (limited to 'libdino') diff --git a/libdino/src/service/entity_info.vala b/libdino/src/service/entity_info.vala index c0c55a40..705c728e 100644 --- a/libdino/src/service/entity_info.vala +++ b/libdino/src/service/entity_info.vala @@ -42,32 +42,35 @@ public class EntityInfo : StreamInteractionModule, Object { stream_interactor.module_manager.initialize_account_modules.connect(initialize_modules); } - public async Identity? get_identity(Account account, Jid jid) { - Gee.Set? identities = null; - + public async Gee.Set? get_identities(Account account, Jid jid) { if (jid_identity.has_key(jid)) { - identities = jid_identity[jid]; + return jid_identity[jid]; } - if (identities == null) { - string? hash = entity_caps_hashes[jid]; - if (hash != null) { - identities = get_identities(hash); - } + string? hash = entity_caps_hashes[jid]; + if (hash != null) { + Gee.Set? identities = get_stored_identities(hash); + if (identities != null) return identities; + } - if (identities == null) { - ServiceDiscovery.InfoResult? info_result = yield get_info_result(account, jid, hash); - identities = info_result.identities; - } + ServiceDiscovery.InfoResult? info_result = yield get_info_result(account, jid, hash); + if (info_result != null) { + return info_result.identities; } - if (identities != null) { - foreach (var identity in identities) { - if (identity.category == Identity.CATEGORY_CLIENT) { - return identity; - } + return null; + } + + public async Identity? get_identity(Account account, Jid jid) { + Gee.Set? identities = yield get_identities(account, jid); + if (identities == null) return null; + + foreach (var identity in identities) { + if (identity.category == Identity.CATEGORY_CLIENT) { + return identity; } } + return null; } @@ -78,7 +81,7 @@ public class EntityInfo : StreamInteractionModule, Object { string? hash = entity_caps_hashes[jid]; if (hash != null) { - Gee.List? features = get_features(hash); + Gee.List? features = get_stored_features(hash); if (features != null) { return features.contains(feature); } @@ -132,9 +135,10 @@ public class EntityInfo : StreamInteractionModule, Object { .value(db.entity_identity.entity_name, identity.name) .perform(); } + entity_identity[entity] = identities; } - private Gee.List? get_features(string entity) { + private Gee.List? get_stored_features(string entity) { Gee.List? features = entity_features[entity]; if (features != null) { return features; @@ -152,7 +156,7 @@ public class EntityInfo : StreamInteractionModule, Object { return features; } - private Gee.Set get_identities(string entity) { + private Gee.Set? get_stored_identities(string entity) { Gee.Set? identities = entity_identity[entity]; if (identities != null) { return identities; @@ -164,6 +168,11 @@ public class EntityInfo : StreamInteractionModule, Object { var identity = new Identity(row[db.entity_identity.category], row[db.entity_identity.type], row[db.entity_identity.entity_name]); identities.add(identity); } + + if (entity_identity.size == 0) { + return null; + } + entity_identity[entity] = identities; return identities; } @@ -209,9 +218,7 @@ public class CapsCacheImpl : CapsCache, Object { } public async Gee.Set get_entity_identities(Jid jid) { - var ret = new HashSet(Identity.hash_func, Identity.equals_func); - ret.add(yield entity_info.get_identity(account, jid)); - return ret; + return yield entity_info.get_identities(account, jid); } } } -- cgit v1.2.3-54-g00ecf