From aaf4542e6208460c305db4be36b15dc832ddc95a Mon Sep 17 00:00:00 2001 From: Patiga Date: Tue, 28 Jun 2022 12:11:17 +0200 Subject: Implement XEP-0447: Stateless file sharing --- libdino/src/service/database.vala | 56 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 4 deletions(-) (limited to 'libdino/src/service/database.vala') diff --git a/libdino/src/service/database.vala b/libdino/src/service/database.vala index eba8b7ca..30d6d55f 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 = 27; + private const int VERSION = 28; public class AccountTable : Table { public Column id = new Column.Integer("id") { primary_key = true, auto_increment = true }; @@ -191,15 +191,57 @@ public class Database : Qlite.Database { public Column file_name = new Column.Text("file_name"); public Column path = new Column.Text("path"); public Column mime_type = new Column.Text("mime_type"); - public Column size = new Column.Integer("size"); + public Column size = new Column.Long("size") { default = "-1", min_version=28 }; public Column state = new Column.Integer("state"); public Column provider = new Column.Integer("provider"); public Column info = new Column.Text("info"); + public Column modification_date = new Column.Long("modification_date") { default = "-1", min_version=28 }; + public Column width = new Column.Integer("width") { default = "-1", min_version=28 }; + public Column height = new Column.Integer("height") { default = "-1", min_version=28 }; + public Column length = new Column.Integer("length") { default = "-1", min_version=28 }; internal FileTransferTable(Database db) { base(db, "file_transfer"); init({id, account_id, counterpart_id, counterpart_resource, our_resource, direction, time, local_time, - encryption, file_name, path, mime_type, size, state, provider, info}); + encryption, file_name, path, mime_type, size, state, provider, info, modification_date, width, height, + length}); + } + } + + public class FileHashesTable : Table { + public Column id = new Column.Integer("id"); + public Column algo = new Column.Text("algo") { not_null = true }; + public Column value = new Column.Text("value") { not_null = true }; + + internal FileHashesTable(Database db) { + base(db, "file_hashes"); + init({id, algo, value}); + unique({id, algo}, "REPLACE"); + } + } + + public class FileThumbnailsTable : Table { + public Column id = new Column.Integer("id"); + public Column uri = new Column.Text("uri") { not_null = true }; + public Column mime_type = new Column.Text("mime_type"); + public Column width = new Column.Integer("width"); + public Column height = new Column.Integer("height"); + + internal FileThumbnailsTable(Database db) { + base(db, "file_thumbnails"); + init({id, uri, mime_type, width, height}); + } + } + + public class SfsSourcesTable : Table { + public Column id = new Column.Integer("id"); + public Column type = new Column.Text("type") { not_null = true }; + public Column data = new Column.Text("data") { not_null = true }; + + internal SfsSourcesTable(Database db) { + base(db, "sfs_sources"); + init({id, type, data}); + unique({id, type, data}, "REPLACE"); } } @@ -401,6 +443,9 @@ public class Database : Qlite.Database { public RealJidTable real_jid { get; private set; } public OccupantIdTable occupantid { get; private set; } public FileTransferTable file_transfer { get; private set; } + public FileHashesTable file_hashes { get; private set; } + public FileThumbnailsTable file_thumbnails { get; private set; } + public SfsSourcesTable sfs_sources { get; private set; } public CallTable call { get; private set; } public CallCounterpartTable call_counterpart { get; private set; } public ConversationTable conversation { get; private set; } @@ -431,6 +476,9 @@ public class Database : Qlite.Database { occupantid = new OccupantIdTable(this); real_jid = new RealJidTable(this); file_transfer = new FileTransferTable(this); + file_hashes = new FileHashesTable(this); + file_thumbnails = new FileThumbnailsTable(this); + sfs_sources = new SfsSourcesTable(this); call = new CallTable(this); call_counterpart = new CallCounterpartTable(this); conversation = new ConversationTable(this); @@ -443,7 +491,7 @@ public class Database : Qlite.Database { settings = new SettingsTable(this); account_settings = new AccountSettingsTable(this); conversation_settings = new ConversationSettingsTable(this); - init({ account, jid, entity, content_item, message, body_meta, message_correction, reply, real_jid, occupantid, file_transfer, call, call_counterpart, conversation, avatar, entity_identity, entity_feature, roster, mam_catchup, reaction, settings, account_settings, conversation_settings }); + init({ account, jid, entity, content_item, message, body_meta, message_correction, reply, real_jid, occupantid, file_transfer, file_hashes, file_thumbnails, sfs_sources, call, call_counterpart, conversation, avatar, entity_identity, entity_feature, roster, mam_catchup, reaction, settings, account_settings, conversation_settings }); try { exec("PRAGMA journal_mode = WAL"); -- cgit v1.2.3-70-g09d2