diff options
author | fiaxh <git@lightrise.org> | 2019-12-16 01:34:28 +0100 |
---|---|---|
committer | fiaxh <git@lightrise.org> | 2019-12-16 01:41:04 +0100 |
commit | 890b91ce4d968f838b46686295883500eba55c78 (patch) | |
tree | 62983c8fb2fe49e0cbab66cef944121e1f074ef3 | |
parent | 21c01dcdcb3ba7f7d5c6fcd18c5fd2117f050e5e (diff) | |
download | dino-890b91ce4d968f838b46686295883500eba55c78.tar.gz dino-890b91ce4d968f838b46686295883500eba55c78.zip |
Only send new room config if something was changed
fixes #675
-rw-r--r-- | libdino/src/service/muc_manager.vala | 13 | ||||
-rw-r--r-- | main/src/ui/contact_details/muc_config_form_provider.vala | 17 | ||||
-rw-r--r-- | main/src/ui/manage_accounts/add_account_dialog.vala | 2 | ||||
-rw-r--r-- | main/src/ui/util/data_forms.vala | 2 | ||||
-rw-r--r-- | xmpp-vala/src/module/xep/0004_data_forms.vala | 22 | ||||
-rw-r--r-- | xmpp-vala/src/module/xep/0045_muc/module.vala | 31 | ||||
-rw-r--r-- | xmpp-vala/src/module/xep/0060_pubsub.vala | 2 | ||||
-rw-r--r-- | xmpp-vala/src/module/xep/0077_in_band_registration.vala | 2 | ||||
-rw-r--r-- | xmpp-vala/src/module/xep/0115_entitiy_capabilities.vala | 2 |
9 files changed, 46 insertions, 47 deletions
diff --git a/libdino/src/service/muc_manager.vala b/libdino/src/service/muc_manager.vala index fa76ddd5..01185731 100644 --- a/libdino/src/service/muc_manager.vala +++ b/libdino/src/service/muc_manager.vala @@ -62,13 +62,16 @@ public class MucManager : StreamInteractionModule, Object { if (conversation != null) stream_interactor.get_module(ConversationManager.IDENTITY).close_conversation(conversation); } - public delegate void OnResult(Jid jid, Xep.DataForms.DataForm data_form); - public void get_config_form(Account account, Jid jid, owned OnResult listener) { + public async DataForms.DataForm? get_config_form(Account account, Jid jid) { + XmppStream? stream = stream_interactor.get_stream(account); + if (stream == null) return null; + return yield stream.get_module(Xep.Muc.Module.IDENTITY).get_config_form(stream, jid); + } + + public void set_config_form(Account account, Jid jid, DataForms.DataForm data_form) { XmppStream? stream = stream_interactor.get_stream(account); if (stream == null) return; - stream.get_module(Xep.Muc.Module.IDENTITY).get_config_form(stream, jid, (stream, jid, data_form) => { - listener(jid, data_form); - }); + stream.get_module(Xep.Muc.Module.IDENTITY).set_config_form(stream, jid, data_form); } public void change_subject(Account account, Jid jid, string subject) { diff --git a/main/src/ui/contact_details/muc_config_form_provider.vala b/main/src/ui/contact_details/muc_config_form_provider.vala index a088bd97..2b1bb6d9 100644 --- a/main/src/ui/contact_details/muc_config_form_provider.vala +++ b/main/src/ui/contact_details/muc_config_form_provider.vala @@ -19,12 +19,23 @@ public class MucConfigFormProvider : Plugins.ContactDetailsProvider, Object { if (conversation.type_ == Conversation.Type.GROUPCHAT) { Xmpp.XmppStream? stream = stream_interactor.get_stream(conversation.account); if (stream == null) return; - stream_interactor.get_module(MucManager.IDENTITY).get_config_form(conversation.account, conversation.counterpart, (jid, data_form) => { - contact_details.save.connect(() => { data_form.submit(); }); + + stream_interactor.get_module(MucManager.IDENTITY).get_config_form.begin(conversation.account, conversation.counterpart, (_, res) => { + DataForms.DataForm? data_form = stream_interactor.get_module(MucManager.IDENTITY).get_config_form.end(res); + if (data_form == null) return; + for (int i = 0; i < data_form.fields.size; i++) { DataForms.DataForm.Field field = data_form.fields[i]; add_field(field, contact_details); } + + string config_backup = data_form.stanza_node.to_string(); + contact_details.save.connect(() => { + // Only send the config form if something was changed + if (config_backup != data_form.stanza_node.to_string()) { + stream_interactor.get_module(MucManager.IDENTITY).set_config_form(conversation.account, conversation.counterpart, data_form); + } + }); }); } } @@ -74,7 +85,7 @@ public class MucConfigFormProvider : Plugins.ContactDetailsProvider, Object { } } - Widget? widget = Util.get_data_form_fild_widget(field); + Widget? widget = Util.get_data_form_field_widget(field); if (widget != null) contact_details.add(_("Room Configuration"), label, desc, widget); } } diff --git a/main/src/ui/manage_accounts/add_account_dialog.vala b/main/src/ui/manage_accounts/add_account_dialog.vala index 0ad8b72d..5dd6621b 100644 --- a/main/src/ui/manage_accounts/add_account_dialog.vala +++ b/main/src/ui/manage_accounts/add_account_dialog.vala @@ -302,7 +302,7 @@ public class AddAccountDialog : Gtk.Dialog { register_form_continue.grab_focus(); } else if (form.fields.size > 0) { foreach (Xep.DataForms.DataForm.Field field in form.fields) { - Widget? field_widget = Util.get_data_form_fild_widget(field); + Widget? field_widget = Util.get_data_form_field_widget(field); if (field.label != null && field.label != "" && field_widget != null) { form_box.add(new Label(field.label) { xalign=0, margin_top=7, visible=true }); form_box.add(field_widget); diff --git a/main/src/ui/util/data_forms.vala b/main/src/ui/util/data_forms.vala index 11308462..c3449a86 100644 --- a/main/src/ui/util/data_forms.vala +++ b/main/src/ui/util/data_forms.vala @@ -6,7 +6,7 @@ using Xmpp.Xep; namespace Dino.Ui.Util { -public static Widget? get_data_form_fild_widget(DataForms.DataForm.Field field) { +public static Widget? get_data_form_field_widget(DataForms.DataForm.Field field) { if (field.type_ == null) return null; switch (field.type_) { case DataForms.DataForm.Type.BOOLEAN: 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<Field> fields = new ArrayList<Field>(); 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<StanzaNode> 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<DataForms.DataForm> data_forms = new ArrayList<DataForms.DataForm>(); 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) { |