aboutsummaryrefslogtreecommitdiff
path: root/libdino/src/service/entity_capabilities_storage.vala
diff options
context:
space:
mode:
authorfiaxh <git@lightrise.org>2020-03-29 20:23:47 +0200
committerfiaxh <git@lightrise.org>2020-03-29 20:24:39 +0200
commit12cd56612dd6edd056e2cd8aae59ea3ae8f05d1e (patch)
tree1da6667e85128aad0c2992b3c2b490f42defce6f /libdino/src/service/entity_capabilities_storage.vala
parent853dfa2d6f0d1300b096f0c6a12ca179208f5287 (diff)
downloaddino-12cd56612dd6edd056e2cd8aae59ea3ae8f05d1e.tar.gz
dino-12cd56612dd6edd056e2cd8aae59ea3ae8f05d1e.zip
Store entity identity info, use it in conversation list tooltips
Diffstat (limited to 'libdino/src/service/entity_capabilities_storage.vala')
-rw-r--r--libdino/src/service/entity_capabilities_storage.vala52
1 files changed, 49 insertions, 3 deletions
diff --git a/libdino/src/service/entity_capabilities_storage.vala b/libdino/src/service/entity_capabilities_storage.vala
index 94d9d88e..d9f66913 100644
--- a/libdino/src/service/entity_capabilities_storage.vala
+++ b/libdino/src/service/entity_capabilities_storage.vala
@@ -1,23 +1,69 @@
using Gee;
-
+using Qlite;
using Xmpp;
+using Xmpp.Xep.ServiceDiscovery;
namespace Dino {
public class EntityCapabilitiesStorage : Xep.EntityCapabilities.Storage, Object {
private Database db;
+ private HashMap<string, Gee.List<string>> features_cache = new HashMap<string, Gee.List<string>>();
+ private HashMap<string, Identity> identity_cache = new HashMap<string, Identity>();
public EntityCapabilitiesStorage(Database db) {
this.db = db;
}
public void store_features(string entity, Gee.List<string> features) {
- db.add_entity_features(entity, features);
+ foreach (string feature in features) {
+ db.entity_feature.insert()
+ .value(db.entity_feature.entity, entity)
+ .value(db.entity_feature.feature, feature)
+ .perform();
+ }
+ }
+
+ public void store_identities(string entity, Gee.List<Identity> identities) {
+ foreach (Identity identity in identities) {
+ if (identity.category == Identity.CATEGORY_CLIENT) {
+ db.entity_identity.insert()
+ .value(db.entity_identity.entity, entity)
+ .value(db.entity_identity.category, identity.category)
+ .value(db.entity_identity.type, identity.type_)
+ .value(db.entity_identity.name, identity.name)
+ .perform();
+ return;
+ }
+ }
}
public Gee.List<string> get_features(string entity) {
- return db.get_entity_features(entity);
+ Gee.List<string>? features = features_cache[entity];
+ if (features != null) {
+ return features;
+ }
+
+ features = new ArrayList<string>();
+ foreach (Row row in db.entity_feature.select({db.entity_feature.feature}).with(db.entity_feature.entity, "=", entity)) {
+ features.add(row[db.entity_feature.feature]);
+ }
+ features_cache[entity] = features;
+ return features;
+ }
+
+ public Identity? get_identities(string entity) {
+ Identity? identity = identity_cache[entity];
+ if (identity != null) {
+ return identity;
+ }
+
+ RowOption row = db.entity_identity.select().with(db.entity_identity.entity, "=", entity).single().row();
+ if (row.is_present()) {
+ identity = new Identity(row[db.entity_identity.category], row[db.entity_identity.type], row[db.entity_identity.name]);
+ }
+ identity_cache[entity] = identity;
+ return identity;
}
}
}