aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfiaxh <git@lightrise.org>2021-03-31 21:33:35 +0200
committerfiaxh <git@lightrise.org>2021-04-01 11:52:10 +0200
commitb63a20f9189026a77ccc1769a4ab366d48f63233 (patch)
treecf72835dde5b93346bdbafbda471f8327ef29271
parentc5ab4fed87d2dedb5ccbf671c8b2742a11251a0f (diff)
downloaddino-b63a20f9189026a77ccc1769a4ab366d48f63233.tar.gz
dino-b63a20f9189026a77ccc1769a4ab366d48f63233.zip
Store limited history of contact resources
-rw-r--r--libdino/src/service/entity_info.vala23
1 files changed, 15 insertions, 8 deletions
diff --git a/libdino/src/service/entity_info.vala b/libdino/src/service/entity_info.vala
index 705c728e..b80d4b59 100644
--- a/libdino/src/service/entity_info.vala
+++ b/libdino/src/service/entity_info.vala
@@ -40,6 +40,9 @@ public class EntityInfo : StreamInteractionModule, Object {
entity_caps_hashes[account.bare_jid.domain_jid] = hash;
});
stream_interactor.module_manager.initialize_account_modules.connect(initialize_modules);
+
+ remove_old_entities();
+ Timeout.add_seconds(60 * 60, () => { remove_old_entities(); return true; });
}
public async Gee.Set<Identity>? get_identities(Account account, Jid jid) {
@@ -94,26 +97,30 @@ public class EntityInfo : StreamInteractionModule, Object {
}
private void on_received_available_presence(Account account, Presence.Stanza presence) {
- bool is_gc = stream_interactor.get_module(MucManager.IDENTITY).is_groupchat(presence.from.bare_jid, account);
+ bool is_gc = stream_interactor.get_module(MucManager.IDENTITY).might_be_groupchat(presence.from.bare_jid, account);
if (is_gc) return;
string? caps_hash = EntityCapabilities.get_caps_hash(presence);
if (caps_hash == null) return;
- /* TODO check might_be_groupchat before storing
db.entity.upsert()
- .value(db.entity.account_id, account.id, true)
- .value(db.entity.jid_id, db.get_jid_id(presence.from), true)
- .value(db.entity.resource, presence.from.resourcepart, true)
- .value(db.entity.last_seen, (long)(new DateTime.now_local()).to_unix())
- .value(db.entity.caps_hash, caps_hash)
- .perform();*/
+ .value(db.entity.account_id, account.id, true)
+ .value(db.entity.jid_id, db.get_jid_id(presence.from), true)
+ .value(db.entity.resource, presence.from.resourcepart, true)
+ .value(db.entity.last_seen, (long)(new DateTime.now_local()).to_unix())
+ .value(db.entity.caps_hash, caps_hash)
+ .perform();
if (caps_hash != null) {
entity_caps_hashes[presence.from] = caps_hash;
}
}
+ private void remove_old_entities() {
+ long timestamp = (long)(new DateTime.now_local().add_days(-14)).to_unix();
+ db.entity.delete().with(db.entity.last_seen, "<", timestamp).perform();
+ }
+
private void store_features(string entity, Gee.List<string> features) {
if (entity_features.has_key(entity)) return;