Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: treat the handle as private info #638

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/Services/Accounts/AccountStore.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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 ();

Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions src/Services/Accounts/InstanceAccount.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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; set; }
public string? backend { set; get; }
public API.Instance? instance_info { get; set; }
public Gee.ArrayList<API.Emoji>? instance_emojis { get; set; }
Expand Down
9 changes: 6 additions & 3 deletions src/Services/Accounts/SecretAccountStore.vala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
public class Tuba.SecretAccountStore : AccountStore {

const string VERSION = "1";
const string VERSION = "2";

Secret.Schema schema;
GLib.HashTable<string,Secret.SchemaAttributeType> schema_attributes;
Expand Down Expand Up @@ -107,7 +107,7 @@ public class Tuba.SecretAccountStore : AccountStore {

var attrs = new GLib.HashTable<string,string> (str_hash, str_equal);
attrs["version"] = VERSION;
attrs["login"] = account.handle;
attrs["login"] = account.uuid;

Secret.password_clearv.begin (
schema,
Expand All @@ -128,7 +128,7 @@ public class Tuba.SecretAccountStore : AccountStore {

void account_to_secret (InstanceAccount account) {
var attrs = new GLib.HashTable<string,string> (str_hash, str_equal);
attrs["login"] = account.handle;
attrs["login"] = account.uuid;
attrs["version"] = VERSION;

var generator = new Json.Generator ();
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/Services/Settings.vala
Original file line number Diff line number Diff line change
@@ -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; }
Expand Down