From 4d4ba7dde6d3153fa5ea652a8b37d7b78f511484 Mon Sep 17 00:00:00 2001 From: fiaxh Date: Sun, 29 Sep 2024 16:54:50 +0200 Subject: Generate new resource on resource conflict --- libdino/src/entity/account.vala | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'libdino/src/entity') diff --git a/libdino/src/entity/account.vala b/libdino/src/entity/account.vala index 51ceb8d1..e9b9f34b 100644 --- a/libdino/src/entity/account.vala +++ b/libdino/src/entity/account.vala @@ -8,7 +8,7 @@ public class Account : Object { public int id { get; set; } public string localpart { get { return full_jid.localpart; } } public string domainpart { get { return full_jid.domainpart; } } - public string resourcepart { get { return full_jid.resourcepart;} } + public string resourcepart { get { return full_jid.resourcepart;} private set {} } public Jid bare_jid { owned get { return full_jid.bare_jid; } } public Jid full_jid { get; private set; } public string? password { get; set; } @@ -31,11 +31,7 @@ public class Account : Object { } } if (this.full_jid == null) { - try { - this.full_jid = bare_jid.with_resource("dino." + Random.next_int().to_string("%x")); - } catch (InvalidJidError e) { - error("Auto-generated resource was invalid (%s)", e.message); - } + set_random_resource(); } this.password = password; this.alias = alias; @@ -76,6 +72,15 @@ public class Account : Object { db = null; } + public void set_random_resource() { + try { + this.full_jid = bare_jid.with_resource("dino." + Random.next_int().to_string("%x")); + this.resourcepart = ""; // trigger a notify on the property + } catch (InvalidJidError e) { + error("Auto-generated resource was invalid (%s)", e.message); + } + } + public bool equals(Account acc) { return equals_func(this, acc); } -- cgit v1.2.3-70-g09d2