aboutsummaryrefslogtreecommitdiff
path: root/xmpp-vala/src/module/xep/0045_muc/module.vala
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 /xmpp-vala/src/module/xep/0045_muc/module.vala
parentdabc2a8b1d2a7bf2019e5f913c736d80f11ceb53 (diff)
downloaddino-7bbbb738fdb233f4ad91ffdd7d9247b28849d715.tar.gz
dino-7bbbb738fdb233f4ad91ffdd7d9247b28849d715.zip
Get rid of manual storage objects for delegates
Diffstat (limited to 'xmpp-vala/src/module/xep/0045_muc/module.vala')
-rw-r--r--xmpp-vala/src/module/xep/0045_muc/module.vala58
1 files changed, 25 insertions, 33 deletions
diff --git a/xmpp-vala/src/module/xep/0045_muc/module.vala b/xmpp-vala/src/module/xep/0045_muc/module.vala
index 79870ee1..82a7d7a6 100644
--- a/xmpp-vala/src/module/xep/0045_muc/module.vala
+++ b/xmpp-vala/src/module/xep/0045_muc/module.vala
@@ -136,17 +136,22 @@ public class Module : XmppStreamModule {
return true;
}
- [CCode (has_target = false)] public delegate void OnConfigFormResult(XmppStream stream, string jid, DataForms.DataForm data_form, Object? store);
- public void get_config_form(XmppStream stream, string jid, OnConfigFormResult listener, Object? store) {
- Iq.Stanza iq = new Iq.Stanza.get(new StanzaNode.build("query", NS_URI_OWNER).add_self_xmlns()) { to=jid };
- stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq, (stream, iq, store) => {
- Tuple<OnConfigFormResult, Object?> tuple = store as Tuple<OnConfigFormResult, Object?>;
- StanzaNode? x_node = iq.stanza.get_deep_subnode(NS_URI_OWNER + ":query", DataForms.NS_URI + ":x");
+ public delegate void OnConfigFormResult(XmppStream stream, string jid, DataForms.DataForm data_form);
+ public void get_config_form(XmppStream stream, string jid, owned OnConfigFormResult listener) {
+ Iq.Stanza get_iq = new Iq.Stanza.get(new StanzaNode.build("query", NS_URI_OWNER).add_self_xmlns()) { to=jid };
+ stream.get_module(Iq.Module.IDENTITY).send_iq(stream, get_iq, (stream, form_iq) => {
+ StanzaNode? x_node = form_iq.stanza.get_deep_subnode(NS_URI_OWNER + ":query", DataForms.NS_URI + ":x");
if (x_node != null) {
- DataForms.DataForm data_form = DataForms.DataForm.create(stream, x_node, on_config_form_result, iq);
- tuple.a(stream, iq.from, data_form, tuple.b);
+ DataForms.DataForm data_form = DataForms.DataForm.create(stream, x_node, (stream, node) => {
+ StanzaNode stanza_node = new StanzaNode.build("query", NS_URI_OWNER);
+ stanza_node.add_self_xmlns().put_node(node);
+ Iq.Stanza set_iq = new Iq.Stanza.set(stanza_node);
+ set_iq.to = form_iq.from;
+ stream.get_module(Iq.Module.IDENTITY).send_iq(stream, set_iq);
+ });
+ listener(stream, form_iq.from, data_form);
}
- }, Tuple.create(listener, store));
+ });
}
public override void attach(XmppStream stream) {
@@ -162,9 +167,9 @@ public class Module : XmppStreamModule {
}
room_entered.connect((stream, jid, nick) => {
- query_affiliation(stream, jid, "member", null, null);
- query_affiliation(stream, jid, "admin", null, null);
- query_affiliation(stream, jid, "owner", null, null);
+ query_affiliation(stream, jid, "member", null);
+ query_affiliation(stream, jid, "admin", null);
+ query_affiliation(stream, jid, "owner", null);
});
}
@@ -208,9 +213,7 @@ public class Module : XmppStreamModule {
string bare_jid = get_bare_jid(presence.from);
ErrorStanza? error_stanza = presence.get_error();
if (flag.get_enter_id(bare_jid) == presence.id) {
- print("is enter id\n");
MucEnterError? error = null;
- print(@"$(error_stanza.condition) $(error_stanza.type_)\n");
switch (error_stanza.condition) {
case ErrorStanza.CONDITION_NOT_AUTHORIZED:
if (ErrorStanza.TYPE_AUTH == error_stanza.type_) error = MucEnterError.PASSWORD_REQUIRED;
@@ -305,8 +308,7 @@ public class Module : XmppStreamModule {
}
private void query_room_info(XmppStream stream, string jid) {
- stream.get_module(ServiceDiscovery.Module.IDENTITY).request_info(stream, jid, (stream, query_result, store) => {
- Tuple<string, string> tuple = store as Tuple<string, string>;
+ stream.get_module(ServiceDiscovery.Module.IDENTITY).request_info(stream, jid, (stream, query_result) => {
Gee.List<Feature> features = new ArrayList<Feature>();
if (query_result != null) {
@@ -333,20 +335,19 @@ public class Module : XmppStreamModule {
if (parsed != null) features.add(parsed);
}
}
- stream.get_flag(Flag.IDENTITY).set_room_features(tuple.a, features);
- }, Tuple.create(jid, "")); //TODO ugly
+ stream.get_flag(Flag.IDENTITY).set_room_features(jid, features);
+ });
}
- [CCode (has_target = false)] public delegate void OnAffiliationResult(XmppStream stream, Gee.List<string> jids, Object? store);
- private void query_affiliation(XmppStream stream, string jid, string affiliation, OnAffiliationResult? on_result, Object? store) {
+ public delegate void OnAffiliationResult(XmppStream stream, Gee.List<string> jids);
+ private void query_affiliation(XmppStream stream, string jid, string affiliation, owned OnAffiliationResult? listener) {
Iq.Stanza iq = new Iq.Stanza.get(
new StanzaNode.build("query", NS_URI_ADMIN)
.add_self_xmlns()
.put_node(new StanzaNode.build("item", NS_URI_ADMIN)
.put_attribute("affiliation", affiliation))
) { to=jid };
- stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq, (stream, iq, store) => {
- Tuple<OnAffiliationResult?, Object?> tuple = store as Tuple<OnAffiliationResult?, Object?>;
+ stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq, (stream, iq) => {
if (iq.is_error()) return;
StanzaNode? query_node = iq.stanza.get_subnode("query", NS_URI_ADMIN);
if (query_node == null) return;
@@ -360,17 +361,8 @@ public class Module : XmppStreamModule {
ret_jids.add(jid_);
}
}
- if (tuple.a != null) tuple.a(stream, ret_jids, tuple.b);
- }, Tuple.create(on_result, store));
- }
-
- public static void on_config_form_result(XmppStream stream, StanzaNode node, Object? store) {
- Iq.Stanza form_iq = store as Iq.Stanza;
- StanzaNode stanza_node = new StanzaNode.build("query", NS_URI_OWNER);
- stanza_node.add_self_xmlns().put_node(node);
- Iq.Stanza set_iq = new Iq.Stanza.set(stanza_node);
- set_iq.to = form_iq.from;
- stream.get_module(Iq.Module.IDENTITY).send_iq(stream, set_iq);
+ if (listener != null) listener(stream, ret_jids);
+ });
}
private static ArrayList<int> get_status_codes(StanzaNode x_node) {