From 890b91ce4d968f838b46686295883500eba55c78 Mon Sep 17 00:00:00 2001 From: fiaxh Date: Mon, 16 Dec 2019 01:34:28 +0100 Subject: Only send new room config if something was changed fixes #675 --- xmpp-vala/src/module/xep/0004_data_forms.vala | 22 +++------------ xmpp-vala/src/module/xep/0045_muc/module.vala | 31 +++++++++++----------- xmpp-vala/src/module/xep/0060_pubsub.vala | 2 +- .../src/module/xep/0077_in_band_registration.vala | 2 +- .../src/module/xep/0115_entitiy_capabilities.vala | 2 +- 5 files changed, 22 insertions(+), 37 deletions(-) (limited to 'xmpp-vala/src/module') diff --git a/xmpp-vala/src/module/xep/0004_data_forms.vala b/xmpp-vala/src/module/xep/0004_data_forms.vala index 52275bc5..e042725b 100644 --- a/xmpp-vala/src/module/xep/0004_data_forms.vala +++ b/xmpp-vala/src/module/xep/0004_data_forms.vala @@ -10,19 +10,6 @@ public class DataForm { public Gee.List fields = new ArrayList(); public string? form_type = null; - public XmppStream stream; - public OnResult on_result; - - public void cancel() { - StanzaNode stanza_node = new StanzaNode.build("x", NS_URI); - stanza_node.add_self_xmlns().set_attribute("type", "cancel"); - on_result(stream, stanza_node); - } - - public void submit() { - on_result(stream, get_submit_node()); - } - public StanzaNode get_submit_node() { stanza_node.set_attribute("type", "submit"); return stanza_node; @@ -197,10 +184,8 @@ public class DataForm { // TODO text-multi - internal DataForm.from_node(StanzaNode node, XmppStream stream, owned OnResult? listener = null) { + internal DataForm.from_node(StanzaNode node) { this.stanza_node = node; - this.stream = stream; - this.on_result = (owned)listener; Gee.List field_nodes = node.get_subnodes("field", NS_URI); foreach (StanzaNode field_node in field_nodes) { @@ -235,9 +220,8 @@ public class DataForm { this.stanza_node = new StanzaNode.build("x", NS_URI).add_self_xmlns(); } - public delegate void OnResult(XmppStream stream, StanzaNode node); - public static DataForm? create_from_node(XmppStream stream, StanzaNode node, owned OnResult listener) { - return new DataForm.from_node(node, stream, (owned)listener); + public static DataForm? create_from_node(StanzaNode node) { + return new DataForm.from_node(node); } public void add_field(Field field) { diff --git a/xmpp-vala/src/module/xep/0045_muc/module.vala b/xmpp-vala/src/module/xep/0045_muc/module.vala index 8ce0e20e..3ff28b2b 100644 --- a/xmpp-vala/src/module/xep/0045_muc/module.vala +++ b/xmpp-vala/src/module/xep/0045_muc/module.vala @@ -177,22 +177,23 @@ public class Module : XmppStreamModule { stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq); } - public delegate void OnConfigFormResult(XmppStream stream, Jid jid, DataForms.DataForm data_form); - public void get_config_form(XmppStream stream, Jid jid, owned OnConfigFormResult listener) { + public async DataForms.DataForm? get_config_form(XmppStream stream, Jid jid) { 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_from_node(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); - } - }); + Iq.Stanza result_iq = yield stream.get_module(Iq.Module.IDENTITY).send_iq_async(stream, get_iq); + + StanzaNode? x_node = result_iq.stanza.get_deep_subnode(NS_URI_OWNER + ":query", DataForms.NS_URI + ":x"); + if (x_node != null) { + DataForms.DataForm data_form = DataForms.DataForm.create_from_node(x_node); + return data_form; + } + return null; + } + + public void set_config_form(XmppStream stream, Jid jid, DataForms.DataForm data_form) { + StanzaNode stanza_node = new StanzaNode.build("query", NS_URI_OWNER); + stanza_node.add_self_xmlns().put_node(data_form.get_submit_node()); + Iq.Stanza set_iq = new Iq.Stanza.set(stanza_node) { to=jid }; + stream.get_module(Iq.Module.IDENTITY).send_iq(stream, set_iq); } public override void attach(XmppStream stream) { diff --git a/xmpp-vala/src/module/xep/0060_pubsub.vala b/xmpp-vala/src/module/xep/0060_pubsub.vala index 21daca82..279d87c3 100644 --- a/xmpp-vala/src/module/xep/0060_pubsub.vala +++ b/xmpp-vala/src/module/xep/0060_pubsub.vala @@ -130,7 +130,7 @@ namespace Xmpp.Xep.Pubsub { Iq.Stanza result_iq = yield stream.get_module(Iq.Module.IDENTITY).send_iq_async(stream, iq); StanzaNode? data_form_node = result_iq.stanza.get_deep_subnode(Pubsub.NS_URI_OWNER + ":pubsub", Pubsub.NS_URI_OWNER + ":configure", "jabber:x:data:x"); if (data_form_node == null) return null; - return DataForms.DataForm.create_from_node(stream, data_form_node, () => {}); + return DataForms.DataForm.create_from_node(data_form_node); } public async void submit_node_config(XmppStream stream, DataForms.DataForm data_form, string node_id) { diff --git a/xmpp-vala/src/module/xep/0077_in_band_registration.vala b/xmpp-vala/src/module/xep/0077_in_band_registration.vala index 297f973c..f7bfeb26 100644 --- a/xmpp-vala/src/module/xep/0077_in_band_registration.vala +++ b/xmpp-vala/src/module/xep/0077_in_band_registration.vala @@ -55,7 +55,7 @@ public class Form : DataForms.DataForm { internal Form.from_node(XmppStream stream, Iq.Stanza iq) { StanzaNode? x_node = iq.stanza.get_deep_subnode(NS_URI + ":query", DataForms.NS_URI + ":x"); - base.from_node(x_node ?? new StanzaNode.build("x", NS_URI).add_self_xmlns(), stream); + base.from_node(x_node ?? new StanzaNode.build("x", NS_URI).add_self_xmlns()); oob = iq.stanza.get_deep_string_content(NS_URI + ":query", "jabber:x:oob:x", "url"); } diff --git a/xmpp-vala/src/module/xep/0115_entitiy_capabilities.vala b/xmpp-vala/src/module/xep/0115_entitiy_capabilities.vala index b61a7f43..18c5a660 100644 --- a/xmpp-vala/src/module/xep/0115_entitiy_capabilities.vala +++ b/xmpp-vala/src/module/xep/0115_entitiy_capabilities.vala @@ -65,7 +65,7 @@ namespace Xmpp.Xep.EntityCapabilities { Gee.List data_forms = new ArrayList(); foreach (StanzaNode node in query_result.iq.stanza.get_deep_subnodes(ServiceDiscovery.NS_URI_INFO + ":query", DataForms.NS_URI + ":x")) { - data_forms.add(DataForms.DataForm.create_from_node(stream, node, (stream, node) => {})); + data_forms.add(DataForms.DataForm.create_from_node(node)); } if (compute_hash(query_result.identities, query_result.features, data_forms) == entity) { -- cgit v1.2.3-70-g09d2