From b0b81b88c6948dcfd2b1b82a9fe7357316a3af1f Mon Sep 17 00:00:00 2001 From: fiaxh Date: Sun, 29 Jan 2023 23:06:01 +0100 Subject: Always display reaction+reply buttons, disable if not possible --- libdino/src/service/entity_info.vala | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'libdino/src/service/entity_info.vala') diff --git a/libdino/src/service/entity_info.vala b/libdino/src/service/entity_info.vala index d7d0bc9e..d1217e81 100644 --- a/libdino/src/service/entity_info.vala +++ b/libdino/src/service/entity_info.vala @@ -79,22 +79,34 @@ public class EntityInfo : StreamInteractionModule, Object { } public async bool has_feature(Account account, Jid jid, string feature) { + int has_feature_cached = has_feature_cached_int(account, jid, feature); + if (has_feature_cached != -1) { + return has_feature_cached == 1; + } + + ServiceDiscovery.InfoResult? info_result = yield get_info_result(account, jid, entity_caps_hashes[jid]); + if (info_result == null) return false; + + return info_result.features.contains(feature); + } + + public bool has_feature_cached(Account account, Jid jid, string feature) { + return has_feature_cached_int(account, jid, feature) == 1; + } + + private int has_feature_cached_int(Account account, Jid jid, string feature) { if (jid_features.has_key(jid)) { - return jid_features[jid].contains(feature); + return jid_features[jid].contains(feature) ? 1 : 0; } string? hash = entity_caps_hashes[jid]; if (hash != null) { Gee.List? features = get_stored_features(hash); if (features != null) { - return features.contains(feature); + return features.contains(feature) ? 1 : 0; } } - - ServiceDiscovery.InfoResult? info_result = yield get_info_result(account, jid, hash); - if (info_result == null) return false; - - return info_result.features.contains(feature); + return -1; } private void on_received_available_presence(Account account, Presence.Stanza presence) { -- cgit v1.2.3-54-g00ecf