From 12cd56612dd6edd056e2cd8aae59ea3ae8f05d1e Mon Sep 17 00:00:00 2001 From: fiaxh Date: Sun, 29 Mar 2020 20:23:47 +0200 Subject: Store entity identity info, use it in conversation list tooltips --- libdino/src/service/database.vala | 55 +++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 20 deletions(-) (limited to 'libdino/src/service/database.vala') diff --git a/libdino/src/service/database.vala b/libdino/src/service/database.vala index 34bbea7a..ebf05637 100644 --- a/libdino/src/service/database.vala +++ b/libdino/src/service/database.vala @@ -7,7 +7,7 @@ using Dino.Entities; namespace Dino { public class Database : Qlite.Database { - private const int VERSION = 12; + private const int VERSION = 13; public class AccountTable : Table { public Column id = new Column.Integer("id") { primary_key = true, auto_increment = true }; @@ -35,6 +35,21 @@ public class Database : Qlite.Database { } } + public class EntityTable : Table { + public Column id = new Column.Integer("id") { primary_key = true, auto_increment = true }; + public Column account_id = new Column.Integer("account_id"); + public Column jid_id = new Column.Integer("jid_id"); + public Column resource = new Column.Text("resource"); + public Column caps_hash = new Column.Text("caps_hash"); + public Column last_seen = new Column.Long("last_seen"); + + internal EntityTable(Database db) { + base(db, "entity"); + init({id, account_id, jid_id, resource, caps_hash, last_seen}); + unique({account_id, jid_id, resource}, "IGNORE"); + } + } + public class ContentItemTable : Table { public Column id = new Column.Integer("id") { primary_key = true, auto_increment = true }; public Column conversation_id = new Column.Integer("conversation_id") { not_null = true }; @@ -162,6 +177,20 @@ public class Database : Qlite.Database { } } + public class EntityIdentityTable : Table { + public Column entity = new Column.Text("entity"); + public Column category = new Column.Text("category"); + public Column type = new Column.Text("type"); + public Column name = new Column.Text("name"); + + internal EntityIdentityTable(Database db) { + base(db, "entity_identity"); + init({entity, category, name, type}); + unique({entity, category, type}, "IGNORE"); + index("entity_identity_idx", {entity}); + } + } + public class EntityFeatureTable : Table { public Column entity = new Column.Text("entity"); public Column feature = new Column.Text("feature"); @@ -215,12 +244,14 @@ public class Database : Qlite.Database { public AccountTable account { get; private set; } public JidTable jid { get; private set; } + public EntityTable entity { get; private set; } public ContentItemTable content_item { get; private set; } public MessageTable message { get; private set; } public RealJidTable real_jid { get; private set; } public FileTransferTable file_transfer { get; private set; } public ConversationTable conversation { get; private set; } public AvatarTable avatar { get; private set; } + public EntityIdentityTable entity_identity { get; private set; } public EntityFeatureTable entity_feature { get; private set; } public RosterTable roster { get; private set; } public MamCatchupTable mam_catchup { get; private set; } @@ -234,17 +265,19 @@ public class Database : Qlite.Database { base(fileName, VERSION); account = new AccountTable(this); jid = new JidTable(this); + entity = new EntityTable(this); content_item = new ContentItemTable(this); message = new MessageTable(this); real_jid = new RealJidTable(this); file_transfer = new FileTransferTable(this); conversation = new ConversationTable(this); avatar = new AvatarTable(this); + entity_identity = new EntityIdentityTable(this); entity_feature = new EntityFeatureTable(this); roster = new RosterTable(this); mam_catchup = new MamCatchupTable(this); settings = new SettingsTable(this); - init({ account, jid, content_item, message, real_jid, file_transfer, conversation, avatar, entity_feature, roster, mam_catchup, settings }); + init({ account, jid, entity, content_item, message, real_jid, file_transfer, conversation, avatar, entity_identity, entity_feature, roster, mam_catchup, settings }); try { exec("PRAGMA synchronous=0"); } catch (Error e) { } @@ -433,24 +466,6 @@ public class Database : Qlite.Database { return ret; } - public void add_entity_features(string entity, Gee.List features) { - foreach (string feature in features) { - entity_feature.insert() - .value(entity_feature.entity, entity) - .value(entity_feature.feature, feature) - .perform(); - } - } - - public Gee.List get_entity_features(string entity) { - ArrayList ret = new ArrayList(); - foreach (Row row in entity_feature.select({entity_feature.feature}).with(entity_feature.entity, "=", entity)) { - ret.add(row[entity_feature.feature]); - } - return ret; - } - - public int get_jid_id(Jid jid_obj) { var bare_jid = jid_obj.bare_jid; if (jid_table_reverse.has_key(bare_jid)) { -- cgit v1.2.3-54-g00ecf