aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libdino/src/entity/account.vala32
-rw-r--r--main/src/windows/preferences_window/add_account_dialog.vala4
2 files changed, 16 insertions, 20 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) {
diff --git a/main/src/windows/preferences_window/add_account_dialog.vala b/main/src/windows/preferences_window/add_account_dialog.vala
index 00acb6aa..bfa98103 100644
--- a/main/src/windows/preferences_window/add_account_dialog.vala
+++ b/main/src/windows/preferences_window/add_account_dialog.vala
@@ -211,7 +211,7 @@ public class AddAccountDialog : Adw.Window {
if (password_group.visible) {
// JID + Psw fields were visible: Try to log in
string password = password_entry.text;
- Account account = new Account(login_jid, null, password, null);
+ Account account = new Account(login_jid, password);
ConnectionManager.ConnectionError.Source? error = yield stream_interactor.get_module(Register.IDENTITY).add_check_account(account);
sign_in_continue_spinner.visible = false;
@@ -351,7 +351,7 @@ public class AddAccountDialog : Adw.Window {
}
}
try {
- Account account = new Account(new Jid.components(username, server_jid.domainpart, null), null, password, null);
+ Account account = new Account(new Jid.components(username, server_jid.domainpart, null), password);
add_activate_account(account);
show_success(account);
} catch (InvalidJidError e) {