aboutsummaryrefslogtreecommitdiff
path: root/libdino
diff options
context:
space:
mode:
authorfiaxh <git@mx.ax.lt>2017-03-11 23:04:58 +0100
committerfiaxh <git@mx.ax.lt>2017-03-11 23:09:57 +0100
commitf40a34bdc1995e656b09cc1252a8dcce685e373f (patch)
treed56684122d0a2f0e13ee9d94e6e8675bae1b4c52 /libdino
parent0ea4ac7e20674e3e6a8d1b3d4b53702dace72907 (diff)
downloaddino-f40a34bdc1995e656b09cc1252a8dcce685e373f.tar.gz
dino-f40a34bdc1995e656b09cc1252a8dcce685e373f.zip
Use delegates + object storage instead of listener objects
Diffstat (limited to 'libdino')
-rw-r--r--libdino/src/service/avatar_manager.vala7
-rw-r--r--libdino/src/service/muc_manager.vala59
-rw-r--r--libdino/src/ui/add_conversation/conference/conference_list.vala20
3 files changed, 29 insertions, 57 deletions
diff --git a/libdino/src/service/avatar_manager.vala b/libdino/src/service/avatar_manager.vala
index d0b25d3b..69e5580e 100644
--- a/libdino/src/service/avatar_manager.vala
+++ b/libdino/src/service/avatar_manager.vala
@@ -73,13 +73,6 @@ public class AvatarManager : StreamInteractionModule, Object {
}
}
- private class PublishResponseListenerImpl : Object {
- public void on_success(Core.XmppStream stream) {
-
- }
- public void on_error(Core.XmppStream stream) { }
- }
-
public static AvatarManager? get_instance(StreamInteractor stream_interaction) {
return (AvatarManager) stream_interaction.get_module(id);
}
diff --git a/libdino/src/service/muc_manager.vala b/libdino/src/service/muc_manager.vala
index c3aaa727..589f26d7 100644
--- a/libdino/src/service/muc_manager.vala
+++ b/libdino/src/service/muc_manager.vala
@@ -28,7 +28,7 @@ public class MucManager : StreamInteractionModule, Object {
public void join(Account account, Jid jid, string nick, string? password = null) {
Core.XmppStream stream = stream_interactor.get_stream(account);
- if (stream != null) stream.get_module(Xep.Muc.Module.IDENTITY).enter(stream, jid.bare_jid.to_string(), nick, password, new MucEnterListenerImpl(this, jid, nick, account));
+ if (stream != null) stream.get_module(Xep.Muc.Module.IDENTITY).enter(stream, jid.bare_jid.to_string(), nick, password, on_groupchat_joined, () => {}, Quadruple.create(this, jid, nick, account));
}
public void part(Account account, Jid jid) {
@@ -73,10 +73,10 @@ public class MucManager : StreamInteractionModule, Object {
return is_groupchat(jid.bare_jid, account) && jid.is_full();
}
- public void get_bookmarks(Account account, Xep.Bookmarks.ConferencesRetrieveResponseListener listener) {
+ public void get_bookmarks(Account account, Xep.Bookmarks.Module.OnResult listener, Object? store) {
Core.XmppStream? stream = stream_interactor.get_stream(account);
if (stream != null) {
- stream.get_module(Xep.Bookmarks.Module.IDENTITY).get_conferences(stream, listener);
+ stream.get_module(Xep.Bookmarks.Module.IDENTITY).get_conferences(stream, listener, store);
}
}
@@ -158,7 +158,7 @@ public class MucManager : StreamInteractionModule, Object {
private void on_stream_negotiated(Account account) {
Core.XmppStream stream = stream_interactor.get_stream(account);
- if (stream != null) stream.get_module(Xep.Bookmarks.Module.IDENTITY).get_conferences(stream, new BookmarksRetrieveResponseListener(this, account));
+ if (stream != null) stream.get_module(Xep.Bookmarks.Module.IDENTITY).get_conferences(stream, join_autojoin_conferences, Tuple.create(this, account));
}
private void on_pre_message_received(Entities.Message message, Xmpp.Message.Stanza message_stanza, Conversation conversation) {
@@ -184,41 +184,26 @@ public class MucManager : StreamInteractionModule, Object {
}
}
- private class BookmarksRetrieveResponseListener : Xep.Bookmarks.ConferencesRetrieveResponseListener, Object {
- MucManager outer = null;
- Account account = null;
-
- public BookmarksRetrieveResponseListener(MucManager outer, Account account) {
- this.outer = outer;
- this.account = account;
- }
-
- public void on_result(Core.XmppStream stream, ArrayList<Xep.Bookmarks.Conference> conferences) {
- foreach (Xep.Bookmarks.Conference bookmark in conferences) {
- Jid jid = new Jid(bookmark.jid);
- outer.conference_bookmarks[jid] = bookmark;
- if (bookmark.autojoin) {
- outer.join(account, jid, bookmark.nick);
- }
+ private static void on_groupchat_joined(Core.XmppStream stream, Object? store) {
+ Quadruple<MucManager, Jid, string, Account> quadruple = store as Quadruple<MucManager, Jid, string, Account>;
+ MucManager outer = quadruple.a;
+ Jid jid = quadruple.b;
+ string nick = quadruple.c;
+ Account account = quadruple.d;
+ outer.groupchat_joined(account, jid, nick);
+ }
+
+ private static void join_autojoin_conferences(Core.XmppStream stream, ArrayList<Xep.Bookmarks.Conference> conferences, Object? o) {
+ Tuple<MucManager, Account> tuple = o as Tuple<MucManager, Account>;
+ MucManager outer = tuple.a;
+ Account account = tuple.b;
+ foreach (Xep.Bookmarks.Conference bookmark in conferences) {
+ Jid jid = new Jid(bookmark.jid);
+ outer.conference_bookmarks[jid] = bookmark;
+ if (bookmark.autojoin) {
+ outer.join(account, jid, bookmark.nick);
}
}
}
-
- private class MucEnterListenerImpl : Xep.Muc.MucEnterListener, Object { // TODO
- private MucManager outer;
- private Jid jid;
- private string nick;
- private Account account;
- public MucEnterListenerImpl(MucManager outer, Jid jid, string nick, Account account) {
- this.outer = outer;
- this.jid = jid;
- this.nick = nick;
- this.account = account;
- }
- public void on_success() {
- outer.groupchat_joined(account, jid, nick);
- }
- public void on_error(Xep.Muc.MucEnterError error) { }
- }
}
} \ No newline at end of file
diff --git a/libdino/src/ui/add_conversation/conference/conference_list.vala b/libdino/src/ui/add_conversation/conference/conference_list.vala
index 17f08ff3..7743ced5 100644
--- a/libdino/src/ui/add_conversation/conference/conference_list.vala
+++ b/libdino/src/ui/add_conversation/conference/conference_list.vala
@@ -29,7 +29,7 @@ protected class ConferenceList : FilterableList {
});
foreach (Account account in stream_interactor.get_accounts()) {
- MucManager.get_instance(stream_interactor).get_bookmarks(account, new BookmarksListener(this, stream_interactor, account));
+ MucManager.get_instance(stream_interactor).get_bookmarks(account, on_conference_bookmarks_received, Tuple.create(this, account));
}
}
@@ -42,18 +42,12 @@ protected class ConferenceList : FilterableList {
}
}
- private class BookmarksListener : Xep.Bookmarks.ConferencesRetrieveResponseListener, Object {
- ConferenceList outer;
- Account account;
- public BookmarksListener(ConferenceList outer, StreamInteractor stream_interactor, Account account) {
- this.outer = outer;
- this.account = account;
- }
-
- public void on_result(Core.XmppStream stream, ArrayList<Xep.Bookmarks.Conference> conferences) {
- outer.lists[account] = conferences;
- Idle.add(() => { outer.refresh_conferences(); return false; });
- }
+ private static void on_conference_bookmarks_received(Core.XmppStream stream, ArrayList<Xep.Bookmarks.Conference> conferences, Object? o) {
+ Tuple<ConferenceList, Account> tuple = o as Tuple<ConferenceList, Account>;
+ ConferenceList list = tuple.a;
+ Account account = tuple.b;
+ list.lists[account] = conferences;
+ Idle.add(() => { list.refresh_conferences(); return false; });
}
private void header(ListBoxRow row, ListBoxRow? before_row) {