diff options
Diffstat (limited to 'libdino')
-rw-r--r-- | libdino/src/entity/account.vala | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/libdino/src/entity/account.vala b/libdino/src/entity/account.vala index e9b9f34b..e7729fa0 100644 --- a/libdino/src/entity/account.vala +++ b/libdino/src/entity/account.vala @@ -8,7 +8,10 @@ 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;} private set {} } + public string resourcepart { + get { return full_jid.resourcepart; } + private set { full_jid.resourcepart = value; } + } public Jid bare_jid { owned get { return full_jid.bare_jid; } } public Jid full_jid { get; private set; } public string? password { get; set; } @@ -21,20 +24,14 @@ public class Account : Object { private Database? db; - public Account(Jid bare_jid, string? resourcepart, string? password, string? alias) { + public Account(Jid bare_jid, string password) { this.id = -1; - if (resourcepart != null) { - try { - this.full_jid = bare_jid.with_resource(resourcepart); - } catch (InvalidJidError e) { - warning("Tried to create account with invalid resource (%s), defaulting to auto generated", e.message); - } - } - if (this.full_jid == null) { - set_random_resource(); + try { + this.full_jid = bare_jid.with_resource(get_random_resource()); + } catch (InvalidJidError e) { + error("Auto-generated resource was invalid (%s)", e.message); } this.password = password; - this.alias = alias; } public Account.from_row(Database db, Qlite.Row row) throws InvalidJidError { @@ -73,12 +70,11 @@ public class Account : Object { } 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); - } + this.resourcepart = get_random_resource(); + } + + private static string get_random_resource() { + return "dino." + Random.next_int().to_string("%x"); } public bool equals(Account acc) { |