OMEMO: Don't set publish options, configure only bundle node instead
This commit is contained in:
parent
388cc56674
commit
247a368150
|
@ -75,7 +75,7 @@ public class StreamModule : XmppStreamModule {
|
||||||
if (!am_on_devicelist) {
|
if (!am_on_devicelist) {
|
||||||
debug("Not on device list, adding id");
|
debug("Not on device list, adding id");
|
||||||
node.put_node(new StanzaNode.build("device", NS_URI).put_attribute("id", store.local_registration_id.to_string()));
|
node.put_node(new StanzaNode.build("device", NS_URI).put_attribute("id", store.local_registration_id.to_string()));
|
||||||
stream.get_module(Pubsub.Module.IDENTITY).publish.begin(stream, jid, NODE_DEVICELIST, id, node, Xmpp.Xep.Pubsub.ACCESS_MODEL_OPEN);
|
stream.get_module(Pubsub.Module.IDENTITY).publish.begin(stream, jid, NODE_DEVICELIST, id, node);
|
||||||
}
|
}
|
||||||
publish_bundles_if_needed(stream, jid);
|
publish_bundles_if_needed(stream, jid);
|
||||||
}
|
}
|
||||||
|
@ -254,7 +254,7 @@ public class StreamModule : XmppStreamModule {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (changed) {
|
if (changed) {
|
||||||
publish_bundles(stream, (!)signed_pre_key_record, identity_key_pair, pre_key_records, (int32) store.local_registration_id);
|
publish_bundles.begin(stream, (!)signed_pre_key_record, identity_key_pair, pre_key_records, (int32) store.local_registration_id);
|
||||||
}
|
}
|
||||||
} catch (Error e) {
|
} catch (Error e) {
|
||||||
warning(@"Unexpected error while publishing bundle: $(e.message)\n");
|
warning(@"Unexpected error while publishing bundle: $(e.message)\n");
|
||||||
|
@ -262,7 +262,7 @@ public class StreamModule : XmppStreamModule {
|
||||||
stream.get_module(IDENTITY).active_bundle_requests.remove(jid.bare_jid.to_string() + @":$(store.local_registration_id)");
|
stream.get_module(IDENTITY).active_bundle_requests.remove(jid.bare_jid.to_string() + @":$(store.local_registration_id)");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void publish_bundles(XmppStream stream, SignedPreKeyRecord signed_pre_key_record, IdentityKeyPair identity_key_pair, Set<PreKeyRecord> pre_key_records, int32 device_id) throws Error {
|
public async void publish_bundles(XmppStream stream, SignedPreKeyRecord signed_pre_key_record, IdentityKeyPair identity_key_pair, Set<PreKeyRecord> pre_key_records, int32 device_id) throws Error {
|
||||||
ECKeyPair tmp;
|
ECKeyPair tmp;
|
||||||
StanzaNode bundle = new StanzaNode.build("bundle", NS_URI)
|
StanzaNode bundle = new StanzaNode.build("bundle", NS_URI)
|
||||||
.add_self_xmlns()
|
.add_self_xmlns()
|
||||||
|
@ -281,7 +281,22 @@ public class StreamModule : XmppStreamModule {
|
||||||
}
|
}
|
||||||
bundle.put_node(prekeys);
|
bundle.put_node(prekeys);
|
||||||
|
|
||||||
stream.get_module(Pubsub.Module.IDENTITY).publish.begin(stream, null, @"$NODE_BUNDLES:$device_id", "1", bundle, Xmpp.Xep.Pubsub.ACCESS_MODEL_OPEN);
|
yield stream.get_module(Pubsub.Module.IDENTITY).publish(stream, null, @"$NODE_BUNDLES:$device_id", "1", bundle);
|
||||||
|
yield try_make_bundle_public(stream, device_id);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void try_make_bundle_public(XmppStream stream, int32 device_id) {
|
||||||
|
DataForms.DataForm? data_form = yield stream.get_module(Pubsub.Module.IDENTITY).request_node_config(stream, null, @"$NODE_BUNDLES:$device_id");
|
||||||
|
if (data_form == null) return;
|
||||||
|
|
||||||
|
foreach (DataForms.DataForm.Field field in data_form.fields) {
|
||||||
|
if (field.var == "pubsub#access_model" && field.get_value_string() != Pubsub.ACCESS_MODEL_OPEN) {
|
||||||
|
field.set_value_string(Pubsub.ACCESS_MODEL_OPEN);
|
||||||
|
yield stream.get_module(Pubsub.Module.IDENTITY).submit_node_config(stream, data_form, @"$NODE_BUNDLES:$device_id");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string get_ns() {
|
public override string get_ns() {
|
||||||
|
|
|
@ -9,6 +9,16 @@ namespace Xmpp.Iq {
|
||||||
private HashMap<string, ResponseListener> responseListeners = new HashMap<string, ResponseListener>();
|
private HashMap<string, ResponseListener> responseListeners = new HashMap<string, ResponseListener>();
|
||||||
private HashMap<string, ArrayList<Handler>> namespaceRegistrants = new HashMap<string, ArrayList<Handler>>();
|
private HashMap<string, ArrayList<Handler>> namespaceRegistrants = new HashMap<string, ArrayList<Handler>>();
|
||||||
|
|
||||||
|
public async Iq.Stanza send_iq_async(XmppStream stream, Iq.Stanza iq) {
|
||||||
|
Iq.Stanza? return_stanza = null;
|
||||||
|
send_iq(stream, iq, (_, result_iq) => {
|
||||||
|
return_stanza = result_iq;
|
||||||
|
Idle.add(send_iq_async.callback);
|
||||||
|
});
|
||||||
|
yield;
|
||||||
|
return return_stanza;
|
||||||
|
}
|
||||||
|
|
||||||
public delegate void OnResult(XmppStream stream, Iq.Stanza iq);
|
public delegate void OnResult(XmppStream stream, Iq.Stanza iq);
|
||||||
public void send_iq(XmppStream stream, Iq.Stanza iq, owned OnResult? listener = null) {
|
public void send_iq(XmppStream stream, Iq.Stanza iq, owned OnResult? listener = null) {
|
||||||
stream.write(iq.stanza);
|
stream.write(iq.stanza);
|
||||||
|
|
|
@ -83,7 +83,7 @@ public class DataForm {
|
||||||
return values.size > 0 ? values[0] : "";
|
return values.size > 0 ? values[0] : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void set_value_string(string val) {
|
public void set_value_string(string val) {
|
||||||
StanzaNode? value_node = node.get_subnode("value", NS_URI);
|
StanzaNode? value_node = node.get_subnode("value", NS_URI);
|
||||||
if (value_node == null) {
|
if (value_node == null) {
|
||||||
value_node = new StanzaNode.build("value", NS_URI);
|
value_node = new StanzaNode.build("value", NS_URI);
|
||||||
|
|
|
@ -60,7 +60,7 @@ namespace Xmpp.Xep.Pubsub {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async bool publish(XmppStream stream, Jid? jid, string node_id, string? item_id, StanzaNode content, string? access_model=null, int? max_items = null) {
|
public async bool publish(XmppStream stream, Jid? jid, string node_id, string? item_id, StanzaNode content, string? access_model=null) {
|
||||||
StanzaNode pubsub_node = new StanzaNode.build("pubsub", NS_URI).add_self_xmlns();
|
StanzaNode pubsub_node = new StanzaNode.build("pubsub", NS_URI).add_self_xmlns();
|
||||||
StanzaNode publish_node = new StanzaNode.build("publish", NS_URI).put_attribute("node", node_id);
|
StanzaNode publish_node = new StanzaNode.build("publish", NS_URI).put_attribute("node", node_id);
|
||||||
pubsub_node.put_node(publish_node);
|
pubsub_node.put_node(publish_node);
|
||||||
|
@ -69,7 +69,7 @@ namespace Xmpp.Xep.Pubsub {
|
||||||
items_node.put_node(content);
|
items_node.put_node(content);
|
||||||
publish_node.put_node(items_node);
|
publish_node.put_node(items_node);
|
||||||
|
|
||||||
if (access_model != null || max_items != null) {
|
if (access_model != null) {
|
||||||
StanzaNode publish_options_node = new StanzaNode.build("publish-options", NS_URI);
|
StanzaNode publish_options_node = new StanzaNode.build("publish-options", NS_URI);
|
||||||
pubsub_node.put_node(publish_options_node);
|
pubsub_node.put_node(publish_options_node);
|
||||||
|
|
||||||
|
@ -82,11 +82,6 @@ namespace Xmpp.Xep.Pubsub {
|
||||||
field.set_value_string(access_model);
|
field.set_value_string(access_model);
|
||||||
data_form.add_field(field);
|
data_form.add_field(field);
|
||||||
}
|
}
|
||||||
if (max_items != null) {
|
|
||||||
DataForms.DataForm.Field field = new DataForms.DataForm.Field() { var="pubsub#max_items" };
|
|
||||||
field.set_value_string(max_items.to_string());
|
|
||||||
data_form.add_field(field);
|
|
||||||
}
|
|
||||||
publish_options_node.put_node(data_form.get_submit_node());
|
publish_options_node.put_node(data_form.get_submit_node());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,6 +121,31 @@ namespace Xmpp.Xep.Pubsub {
|
||||||
stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq, null);
|
stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async DataForms.DataForm? request_node_config(XmppStream stream, Jid? jid, string node_id) {
|
||||||
|
StanzaNode pubsub_node = new StanzaNode.build("pubsub", NS_URI_OWNER).add_self_xmlns();
|
||||||
|
StanzaNode publish_node = new StanzaNode.build("configure", NS_URI_OWNER).put_attribute("node", node_id);
|
||||||
|
pubsub_node.put_node(publish_node);
|
||||||
|
|
||||||
|
Iq.Stanza iq = new Iq.Stanza.get(pubsub_node);
|
||||||
|
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, () => {});
|
||||||
|
}
|
||||||
|
|
||||||
|
public async void submit_node_config(XmppStream stream, DataForms.DataForm data_form, string node_id) {
|
||||||
|
StanzaNode submit_node = data_form.get_submit_node();
|
||||||
|
|
||||||
|
StanzaNode pubsub_node = new StanzaNode.build("pubsub", Pubsub.NS_URI_OWNER).add_self_xmlns();
|
||||||
|
StanzaNode publish_node = new StanzaNode.build("configure", Pubsub.NS_URI_OWNER).put_attribute("node", node_id);
|
||||||
|
pubsub_node.put_node(publish_node);
|
||||||
|
publish_node.put_node(submit_node);
|
||||||
|
|
||||||
|
|
||||||
|
Iq.Stanza iq = new Iq.Stanza.set(pubsub_node);
|
||||||
|
yield stream.get_module(Iq.Module.IDENTITY).send_iq_async(stream, iq);
|
||||||
|
}
|
||||||
|
|
||||||
public override void attach(XmppStream stream) {
|
public override void attach(XmppStream stream) {
|
||||||
stream.get_module(MessageModule.IDENTITY).received_message.connect(on_received_message);
|
stream.get_module(MessageModule.IDENTITY).received_message.connect(on_received_message);
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ public class Module : BookmarksProvider, XmppStreamModule {
|
||||||
if (conference.nick != null) {
|
if (conference.nick != null) {
|
||||||
conference_node.put_node((new StanzaNode.build("nick", NS_URI)).put_node(new StanzaNode.text(conference.nick)));
|
conference_node.put_node((new StanzaNode.build("nick", NS_URI)).put_node(new StanzaNode.text(conference.nick)));
|
||||||
}
|
}
|
||||||
yield stream.get_module(Pubsub.Module.IDENTITY).publish(stream, stream.get_flag(Bind.Flag.IDENTITY).my_jid.bare_jid, NS_URI, conference.jid.to_string(), conference_node, Xmpp.Xep.Pubsub.ACCESS_MODEL_WHITELIST, 128);
|
yield stream.get_module(Pubsub.Module.IDENTITY).publish(stream, stream.get_flag(Bind.Flag.IDENTITY).my_jid.bare_jid, NS_URI, conference.jid.to_string(), conference_node, Xmpp.Xep.Pubsub.ACCESS_MODEL_WHITELIST);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async void replace_conference(XmppStream stream, Conference orig_conference, Conference modified_conference) {
|
public async void replace_conference(XmppStream stream, Conference orig_conference, Conference modified_conference) {
|
||||||
|
|
Loading…
Reference in a new issue