aboutsummaryrefslogtreecommitdiff
path: root/libdino
diff options
context:
space:
mode:
authorfiaxh <git@lightrise.org>2024-05-26 17:28:28 +0200
committerfiaxh <git@lightrise.org>2024-05-26 17:28:28 +0200
commitf1be90c02f26c942e67978fd6d10ff2feeec8f9e (patch)
tree2c3ad321b92350ecb69d2ee33e187bc410ab2c9d /libdino
parentfe45ab575c687febc1f342b0882a7597bd6ae9dc (diff)
downloaddino-f1be90c02f26c942e67978fd6d10ff2feeec8f9e.tar.gz
dino-f1be90c02f26c942e67978fd6d10ff2feeec8f9e.zip
Add logic for OMEMO by default setting
Diffstat (limited to 'libdino')
-rw-r--r--libdino/src/entity/conversation.vala2
-rw-r--r--libdino/src/entity/settings.vala18
-rw-r--r--libdino/src/service/conversation_manager.vala8
-rw-r--r--libdino/src/service/database.vala32
4 files changed, 57 insertions, 3 deletions
diff --git a/libdino/src/entity/conversation.vala b/libdino/src/entity/conversation.vala
index 353daeae..4115ae83 100644
--- a/libdino/src/entity/conversation.vala
+++ b/libdino/src/entity/conversation.vala
@@ -33,7 +33,7 @@ public class Conversation : Object {
}
}
}
- public Encryption encryption { get; set; default = Encryption.NONE; }
+ public Encryption encryption { get; set; default = Encryption.UNKNOWN; }
public Message? read_up_to { get; set; }
public int read_up_to_item { get; set; default=-1; }
diff --git a/libdino/src/entity/settings.vala b/libdino/src/entity/settings.vala
index 0b09e9b9..be275efc 100644
--- a/libdino/src/entity/settings.vala
+++ b/libdino/src/entity/settings.vala
@@ -79,6 +79,24 @@ public class Settings : Object {
check_spelling_ = value;
}
}
+
+ public Encryption get_default_encryption(Account account) {
+ string? setting = db.account_settings.get_value(account.id, "default-encryption");
+ if (setting != null) {
+ return (Encryption) int.parse(setting);
+ }
+ return Encryption.NONE;
+ }
+
+ public void set_default_encryption(Account account, Encryption encryption) {
+ db.account_settings.upsert()
+ .value(db.account_settings.key, "default-encryption", true)
+ .value(db.account_settings.account_id, account.id, true)
+ .value(db.account_settings.value, ((int)encryption).to_string())
+ .perform();
+
+
+ }
}
}
diff --git a/libdino/src/service/conversation_manager.vala b/libdino/src/service/conversation_manager.vala
index f966ccc7..a757e8af 100644
--- a/libdino/src/service/conversation_manager.vala
+++ b/libdino/src/service/conversation_manager.vala
@@ -48,6 +48,14 @@ public class ConversationManager : StreamInteractionModule, Object {
// Create a new converation
Conversation conversation = new Conversation(jid, account, type);
+ // Set encryption for conversation
+ if (type == Conversation.Type.CHAT ||
+ (type == Conversation.Type.GROUPCHAT && stream_interactor.get_module(MucManager.IDENTITY).is_private_room(account, jid))) {
+ conversation.encryption = Application.get_default().settings.get_default_encryption(account);
+ } else {
+ conversation.encryption = Encryption.NONE;
+ }
+
add_conversation(conversation);
conversation.persist(db);
return conversation;
diff --git a/libdino/src/service/database.vala b/libdino/src/service/database.vala
index dc1d68f3..eba8b7ca 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 = 26;
+ private const int VERSION = 27;
public class AccountTable : Table {
public Column<int> id = new Column.Integer("id") { primary_key = true, auto_increment = true };
@@ -354,6 +354,29 @@ public class Database : Qlite.Database {
}
}
+ public class AccountSettingsTable : Table {
+ public Column<int> id = new Column.Integer("id") { primary_key = true, auto_increment = true };
+ public Column<int> account_id = new Column.Integer("account_id") { not_null = true };
+ public Column<string> key = new Column.Text("key") { not_null = true };
+ public Column<string> value = new Column.Text("value");
+
+ internal AccountSettingsTable(Database db) {
+ base(db, "account_settings");
+ init({id, account_id, key, value});
+ unique({account_id, key}, "REPLACE");
+ }
+
+ public string? get_value(int account_id, string key) {
+ var row_opt = select({value})
+ .with(this.account_id, "=", account_id)
+ .with(this.key, "=", key)
+ .single()
+ .row();
+ if (row_opt.is_present()) return row_opt[value];
+ return null;
+ }
+ }
+
public class ConversationSettingsTable : Table {
public Column<int> id = new Column.Integer("id") { primary_key = true, auto_increment = true };
public Column<int> conversation_id = new Column.Integer("conversation_id") {not_null=true};
@@ -388,6 +411,7 @@ public class Database : Qlite.Database {
public MamCatchupTable mam_catchup { get; private set; }
public ReactionTable reaction { get; private set; }
public SettingsTable settings { get; private set; }
+ public AccountSettingsTable account_settings { get; private set; }
public ConversationSettingsTable conversation_settings { get; private set; }
public Map<int, Jid> jid_table_cache = new HashMap<int, Jid>();
@@ -417,8 +441,9 @@ public class Database : Qlite.Database {
mam_catchup = new MamCatchupTable(this);
reaction = new ReactionTable(this);
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, conversation_settings });
+ 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 });
try {
exec("PRAGMA journal_mode = WAL");
@@ -576,6 +601,9 @@ public class Database : Qlite.Database {
foreach(Row row in account.select()) {
try {
Account account = new Account.from_row(this, row);
+ if (account_table_cache.has_key(account.id)) {
+ account = account_table_cache[account.id];
+ }
ret.add(account);
account_table_cache[account.id] = account;
} catch (InvalidJidError e) {