aboutsummaryrefslogtreecommitdiff
path: root/libdino/src
diff options
context:
space:
mode:
authorfiaxh <git@mx.ax.lt>2017-06-13 18:14:59 +0200
committerfiaxh <git@mx.ax.lt>2017-06-13 20:12:40 +0200
commit7bbbb738fdb233f4ad91ffdd7d9247b28849d715 (patch)
tree649ac26e3feef6bae614442a7f3d6ee1057336e0 /libdino/src
parentdabc2a8b1d2a7bf2019e5f913c736d80f11ceb53 (diff)
downloaddino-7bbbb738fdb233f4ad91ffdd7d9247b28849d715.tar.gz
dino-7bbbb738fdb233f4ad91ffdd7d9247b28849d715.zip
Get rid of manual storage objects for delegates
Diffstat (limited to 'libdino/src')
-rw-r--r--libdino/src/service/connection_manager.vala27
-rw-r--r--libdino/src/service/message_processor.vala18
-rw-r--r--libdino/src/service/muc_manager.vala44
3 files changed, 34 insertions, 55 deletions
diff --git a/libdino/src/service/connection_manager.vala b/libdino/src/service/connection_manager.vala
index 03c97bdb..509964b3 100644
--- a/libdino/src/service/connection_manager.vala
+++ b/libdino/src/service/connection_manager.vala
@@ -178,7 +178,7 @@ public class ConnectionManager {
return;
}
if (network_manager != null && network_manager.State != NetworkManager.CONNECTED_GLOBAL) {
- wait_sec = 60;
+ wait_sec = 30;
}
print(@"recovering in $wait_sec\n");
Timeout.add_seconds(wait_sec, () => {
@@ -194,13 +194,17 @@ public class ConnectionManager {
}
private void check_reconnect(Account account) {
- PingResponseListenerImpl ping_response_listener = new PingResponseListenerImpl(this, account);
+ bool acked = false;
+
Core.XmppStream stream = connections[account].stream;
- stream.get_module(Xep.Ping.Module.IDENTITY).send_ping(stream, account.domainpart, ping_response_listener);
+ stream.get_module(Xep.Ping.Module.IDENTITY).send_ping(stream, account.domainpart, (stream) => {
+ acked = true;
+ change_connection_state(account, ConnectionState.CONNECTED);
+ });
Timeout.add_seconds(5, () => {
if (connections[account].stream != stream) return false;
- if (ping_response_listener.acked) return false;
+ if (acked) return false;
change_connection_state(account, ConnectionState.DISCONNECTED);
try {
@@ -210,21 +214,6 @@ public class ConnectionManager {
});
}
- private class PingResponseListenerImpl : Xep.Ping.ResponseListener, Object {
- public bool acked = false;
- ConnectionManager outer;
- Account account;
- public PingResponseListenerImpl(ConnectionManager outer, Account account) {
- this.outer = outer;
- this.account = account;
- }
- public void on_result(Core.XmppStream stream) {
- print("ping ok\n");
- acked = true;
- outer.change_connection_state(account, ConnectionState.CONNECTED);
- }
- }
-
private void on_nm_state_changed(uint32 state) {
print("nm " + state.to_string() + "\n");
if (state == NetworkManager.CONNECTED_GLOBAL) {
diff --git a/libdino/src/service/message_processor.vala b/libdino/src/service/message_processor.vala
index ccaec915..390199d5 100644
--- a/libdino/src/service/message_processor.vala
+++ b/libdino/src/service/message_processor.vala
@@ -118,23 +118,21 @@ public class MessageProcessor : StreamInteractionModule, Object {
}
} else {
Core.XmppStream stream = stream_interactor.get_stream(account);
- if (stream != null) stream.get_module(Xep.ServiceDiscovery.Module.IDENTITY).get_entity_categories(stream, message.counterpart.bare_jid.to_string(), (stream, identities, store) => {
- Triple<MessageProcessor, Entities.Message, Xmpp.Message.Stanza> triple = store as Triple<MessageProcessor, Entities.Message, Xmpp.Message.Stanza>;
- Entities.Message m = triple.b;
+ if (stream != null) stream.get_module(Xep.ServiceDiscovery.Module.IDENTITY).get_entity_categories(stream, message.counterpart.bare_jid.to_string(), (stream, identities) => {
if (identities == null) {
- m.type_ = Entities.Message.Type.CHAT;
- triple.a.process_message(m, triple.c);
+ message.type_ = Entities.Message.Type.CHAT;
+ process_message(message, message_stanza);
return;
}
foreach (Xep.ServiceDiscovery.Identity identity in identities) {
if (identity.category == Xep.ServiceDiscovery.Identity.CATEGORY_CONFERENCE) {
- m.type_ = Entities.Message.Type.GROUPCHAT_PM;
+ message.type_ = Entities.Message.Type.GROUPCHAT_PM;
} else {
- m.type_ = Entities.Message.Type.CHAT;
+ message.type_ = Entities.Message.Type.CHAT;
}
- triple.a.process_message(m, triple.c);
+ process_message(message, message_stanza);
}
- }, Triple.create(this, message, message_stanza));
+ });
}
}
}
@@ -185,4 +183,4 @@ public class MessageProcessor : StreamInteractionModule, Object {
}
}
-} \ No newline at end of file
+}
diff --git a/libdino/src/service/muc_manager.vala b/libdino/src/service/muc_manager.vala
index 2c916c99..c6f37116 100644
--- a/libdino/src/service/muc_manager.vala
+++ b/libdino/src/service/muc_manager.vala
@@ -48,14 +48,13 @@ public class MucManager : StreamInteractionModule, Object {
if (conversation != null) stream_interactor.get_module(ConversationManager.IDENTITY).close_conversation(conversation);
}
- [CCode (has_target = false)] public delegate void OnResult(Jid jid, Xep.DataForms.DataForm data_form, Object? store);
- public void get_config_form(Account account, Jid jid, OnResult on_result, Object? store) {
+ public delegate void OnResult(Jid jid, Xep.DataForms.DataForm data_form);
+ public void get_config_form(Account account, Jid jid, owned OnResult listener) {
Core.XmppStream? stream = stream_interactor.get_stream(account);
if (stream == null) return;
- stream.get_module(Xep.Muc.Module.IDENTITY).get_config_form(stream, jid.to_string(), (stream, jid, data_form, store) => {
- Tuple<OnResult, Object?> tuple = store as Tuple<OnResult, Object?>;
- tuple.a(new Jid(jid), data_form, tuple.b);
- }, Tuple.create(on_result, store));
+ stream.get_module(Xep.Muc.Module.IDENTITY).get_config_form(stream, jid.to_string(), (stream, jid, data_form) => {
+ listener(new Jid(jid), data_form);
+ });
}
public void change_subject(Account account, Jid jid, string subject) {
@@ -109,11 +108,9 @@ public class MucManager : StreamInteractionModule, Object {
return is_groupchat(jid.bare_jid, account) && jid.is_full();
}
- public void get_bookmarks(Account account, Xep.Bookmarks.Module.OnResult listener, Object? store) {
+ public void get_bookmarks(Account account, owned Xep.Bookmarks.Module.OnResult listener) {
Core.XmppStream? stream = stream_interactor.get_stream(account);
- if (stream != null) {
- stream.get_module(Xep.Bookmarks.Module.IDENTITY).get_conferences(stream, listener, store);
- }
+ if (stream != null) stream.get_module(Xep.Bookmarks.Module.IDENTITY).get_conferences(stream, (owned)listener);
}
public void add_bookmark(Account account, Xep.Bookmarks.Conference conference) {
@@ -223,17 +220,14 @@ public class MucManager : StreamInteractionModule, Object {
}
private void on_stream_negotiated(Account account, Core.XmppStream stream) {
- stream.get_module(Xep.Bookmarks.Module.IDENTITY).get_conferences(stream, (stream, conferences, o) => {
- Tuple<MucManager, Account> tuple = o as Tuple<MucManager, Account>;
- MucManager outer_ = tuple.a;
- Account account_ = tuple.b;
+ stream.get_module(Xep.Bookmarks.Module.IDENTITY).get_conferences(stream, (stream, conferences) => {
foreach (Xep.Bookmarks.Conference bookmark in conferences) {
Jid jid = new Jid(bookmark.jid);
if (bookmark.autojoin) {
- outer_.join(account_, jid, bookmark.nick, bookmark.password);
+ join(account, jid, bookmark.nick, bookmark.password);
}
}
- }, Tuple.create(this, account));
+ });
}
private void on_pre_message_received(Entities.Message message, Xmpp.Message.Stanza message_stanza, Conversation conversation) {
@@ -292,11 +286,10 @@ public class MucManager : StreamInteractionModule, Object {
}
private void set_autojoin(Core.XmppStream stream, Jid jid, string? nick, string? password) {
- stream.get_module(Xep.Bookmarks.Module.IDENTITY).get_conferences(stream, (stream, conferences, storage) => {
- Triple<Jid, string?, string?> triple = storage as Triple<Jid, string?, string?>;
- Xep.Bookmarks.Conference changed = new Xep.Bookmarks.Conference(triple.a.to_string()) { nick=triple.b, password=triple.c, autojoin=true };
+ stream.get_module(Xep.Bookmarks.Module.IDENTITY).get_conferences(stream, (stream, conferences) => {
+ Xep.Bookmarks.Conference changed = new Xep.Bookmarks.Conference(jid.to_string()) { nick=nick, password=password, autojoin=true };
foreach (Xep.Bookmarks.Conference conference in conferences) {
- if (conference.jid == triple.a.bare_jid.to_string() && conference.nick == triple.b && conference.password == triple.c) {
+ if (conference.jid == jid.bare_jid.to_string() && conference.nick == nick && conference.password == password) {
if (!conference.autojoin) {
stream.get_module(Xep.Bookmarks.Module.IDENTITY).replace_conference(stream, conference, changed);
}
@@ -304,22 +297,21 @@ public class MucManager : StreamInteractionModule, Object {
}
}
stream.get_module(Xep.Bookmarks.Module.IDENTITY).add_conference(stream, changed);
- }, Triple.create(jid, nick, password));
+ });
}
private void unset_autojoin(Core.XmppStream stream, Jid jid) {
- stream.get_module(Xep.Bookmarks.Module.IDENTITY).get_conferences(stream, (stream, conferences, storage) => {
- Jid jid_ = storage as Jid;
+ stream.get_module(Xep.Bookmarks.Module.IDENTITY).get_conferences(stream, (stream, conferences) => {
foreach (Xep.Bookmarks.Conference conference in conferences) {
- if (conference.jid == jid_.bare_jid.to_string()) {
+ if (conference.jid == jid.bare_jid.to_string()) {
if (conference.autojoin) {
Xep.Bookmarks.Conference change = new Xep.Bookmarks.Conference(conference.jid) { nick=conference.nick, password=conference.password, autojoin=false };
stream.get_module(Xep.Bookmarks.Module.IDENTITY).replace_conference(stream, conference, change);
}
}
}
- }, jid);
+ });
}
}
-} \ No newline at end of file
+}