From 687048d22a16b74e2598812bfe89eee2ff2667f6 Mon Sep 17 00:00:00 2001 From: Evangelos Paterakis Date: Sat, 11 Nov 2023 10:08:26 +0200 Subject: [PATCH] feat: treat the handle as private info --- src/Services/Accounts/AccountStore.vala | 10 ++++++---- src/Services/Accounts/InstanceAccount.vala | 1 + src/Services/Accounts/SecretAccountStore.vala | 9 ++++++--- src/Services/Settings.vala | 1 - 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/Services/Accounts/AccountStore.vala b/src/Services/Accounts/AccountStore.vala index a4ed59f73..2f41e9882 100644 --- a/src/Services/Accounts/AccountStore.vala +++ b/src/Services/Accounts/AccountStore.vala @@ -8,7 +8,7 @@ public abstract class Tuba.AccountStore : GLib.Object { public bool ensure_active_account () { var has_active = false; - var account = find_by_handle (settings.active_account); + var account = find_by_uuid (settings.active_account); if (account == null && !saved.is_empty) { account = saved[0]; @@ -60,9 +60,10 @@ public abstract class Tuba.AccountStore : GLib.Object { ensure_active_account (); } - public InstanceAccount? find_by_handle (string handle) { + public InstanceAccount? find_by_uuid (string uuid) { + if (!GLib.Uuid.string_is_valid (uuid)) return null; var iter = saved.filter (acc => { - return acc.handle == handle; + return acc.uuid == uuid; }); iter.next (); @@ -86,7 +87,7 @@ public abstract class Tuba.AccountStore : GLib.Object { try { account.verify_credentials.end (res); account.error = null; - settings.active_account = account.handle; + settings.active_account = account.uuid; if (account.source != null && account.source.language != null && account.source.language != "") settings.default_language = account.source.language; } @@ -114,6 +115,7 @@ public abstract class Tuba.AccountStore : GLib.Object { if (account == null) throw new Oopsie.INTERNAL (@"Account $handle has unknown backend: $backend"); + if (account.uuid == null || !GLib.Uuid.string_is_valid (account.uuid)) account.uuid = GLib.Uuid.string_random (); return account; } diff --git a/src/Services/Accounts/InstanceAccount.vala b/src/Services/Accounts/InstanceAccount.vala index b01b41989..fe12919eb 100644 --- a/src/Services/Accounts/InstanceAccount.vala +++ b/src/Services/Accounts/InstanceAccount.vala @@ -15,6 +15,7 @@ public class Tuba.InstanceAccount : API.Account, Streamable { public const string KIND_REMOTE_REBLOG = "__remote-reblog"; public const string KIND_EDITED = "update"; + public string uuid { get; construct set; } public string? backend { set; get; } public API.Instance? instance_info { get; set; } public Gee.ArrayList? instance_emojis { get; set; } diff --git a/src/Services/Accounts/SecretAccountStore.vala b/src/Services/Accounts/SecretAccountStore.vala index caeedaa0d..09c89fce8 100644 --- a/src/Services/Accounts/SecretAccountStore.vala +++ b/src/Services/Accounts/SecretAccountStore.vala @@ -1,6 +1,6 @@ public class Tuba.SecretAccountStore : AccountStore { - const string VERSION = "1"; + const string VERSION = "2"; Secret.Schema schema; GLib.HashTable schema_attributes; @@ -107,7 +107,7 @@ public class Tuba.SecretAccountStore : AccountStore { var attrs = new GLib.HashTable (str_hash, str_equal); attrs["version"] = VERSION; - attrs["login"] = account.handle; + attrs["login"] = account.uuid; Secret.password_clearv.begin ( schema, @@ -128,7 +128,7 @@ public class Tuba.SecretAccountStore : AccountStore { void account_to_secret (InstanceAccount account) { var attrs = new GLib.HashTable (str_hash, str_equal); - attrs["login"] = account.handle; + attrs["login"] = account.uuid; attrs["version"] = VERSION; var generator = new Json.Generator (); @@ -176,6 +176,9 @@ public class Tuba.SecretAccountStore : AccountStore { builder.set_member_name ("backend"); builder.add_string_value (account.backend); + builder.set_member_name ("uuid"); + builder.add_string_value (account.uuid); + // If display name has emojis it's // better to save and load them // so users don't see their shortcode diff --git a/src/Services/Settings.vala b/src/Services/Settings.vala index 8f210442f..be7417b0d 100644 --- a/src/Services/Settings.vala +++ b/src/Services/Settings.vala @@ -1,5 +1,4 @@ public class Tuba.Settings : GLib.Settings { - public string active_account { get; set; } public string default_language { get; set; default = "en"; } public ColorScheme color_scheme { get; set; }