aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libdino/src/entity/account.vala17
-rw-r--r--libdino/src/service/connection_manager.vala10
-rw-r--r--libdino/src/service/module_manager.vala4
3 files changed, 18 insertions, 13 deletions
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);
}
diff --git a/libdino/src/service/connection_manager.vala b/libdino/src/service/connection_manager.vala
index 43580c06..2baf0ea8 100644
--- a/libdino/src/service/connection_manager.vala
+++ b/libdino/src/service/connection_manager.vala
@@ -179,13 +179,12 @@ public class ConnectionManager : Object {
}
}
- private async void connect_stream(Account account, string? resource = null) {
+ private async void connect_stream(Account account) {
if (!connections.has_key(account)) return;
debug("[%s] (Maybe) Establishing a new connection", account.bare_jid.to_string());
connection_errors.unset(account);
- if (resource == null) resource = account.resourcepart;
XmppStreamResult stream_result;
@@ -201,7 +200,7 @@ public class ConnectionManager : Object {
connection_directly_retry[account] = false;
change_connection_state(account, ConnectionState.CONNECTING);
- stream_result = yield Xmpp.establish_stream(account.bare_jid, module_manager.get_modules(account, resource), log_options,
+ stream_result = yield Xmpp.establish_stream(account.bare_jid, module_manager.get_modules(account), log_options,
(peer_cert, errors) => { return on_invalid_certificate(account.domainpart, peer_cert, errors); }
);
connections[account].stream = stream_result.stream;
@@ -226,7 +225,7 @@ public class ConnectionManager : Object {
XmppStream stream = stream_result.stream;
- debug("[%s] New connection with resource %s: %p", account.bare_jid.to_string(), resource, stream);
+ debug("[%s] New connection: %p", account.full_jid.to_string(), stream);
connections[account].established = new DateTime.now_utc();
stream.attached_modules.connect((stream) => {
@@ -263,7 +262,8 @@ public class ConnectionManager : Object {
set_connection_error(account, new ConnectionError(ConnectionError.Source.STREAM_ERROR, flag.error_type));
if (flag.resource_rejected) {
- connect_stream.begin(account, account.resourcepart + "-" + random_uuid());
+ account.set_random_resource();
+ connect_stream.begin(account);
return;
}
}
diff --git a/libdino/src/service/module_manager.vala b/libdino/src/service/module_manager.vala
index eeb5369a..eb9e4fbc 100644
--- a/libdino/src/service/module_manager.vala
+++ b/libdino/src/service/module_manager.vala
@@ -24,7 +24,7 @@ public class ModuleManager {
return null;
}
- public ArrayList<XmppStreamModule> get_modules(Account account, string? resource = null) {
+ public ArrayList<XmppStreamModule> get_modules(Account account) {
ArrayList<XmppStreamModule> modules = new ArrayList<XmppStreamModule>();
lock (module_map) {
@@ -34,7 +34,7 @@ public class ModuleManager {
foreach (XmppStreamModule module in module_map[account]) {
if (module.get_id() == Bind.Module.IDENTITY.id) {
- ((Bind.Module) module).requested_resource = resource ?? account.resourcepart;
+ ((Bind.Module) module).requested_resource = account.resourcepart;
} else if (module.get_id() == Sasl.Module.IDENTITY.id) {
((Sasl.Module) module).password = account.password;
}