Only send new room config if something was changed

fixes #675
This commit is contained in:
fiaxh 2019-12-16 01:34:28 +01:00
parent 21c01dcdcb
commit 890b91ce4d
9 changed files with 46 additions and 47 deletions

View file

@ -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) {

View file

@ -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);
}
}

View file

@ -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);

View file

@ -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:

View file

@ -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) {

View file

@ -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");
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(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);
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) {

View file

@ -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) {

View file

@ -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");
}

View file

@ -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) {