Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added publish options for device and boundle nodes #1117

Merged
merged 1 commit into from
Feb 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions Extensions/OMEMO/XMPPIQ+OMEMO.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ + (XMPPIQ*) omemo_iqFetchDeviceIdsForJID:(XMPPJID*)jid
</list>
</item>
</publish>
<publish-options>
<x xmlns="jabber:x:data" type="submit">
<field var="FORM_TYPE" type="hidden">
<value>http://jabber.org/protocol/pubsub#publish-options</value>
</field>
<field var="pubsub#persist_items">
<value>1</value>
</field>
<field var="pubsub#access_model">
<value>open</value>
</field>
</x>
</publish-options>
</pubsub>
</iq>
*/
Expand All @@ -71,6 +84,33 @@ + (XMPPIQ*) omemo_iqPublishDeviceIds:(NSArray<NSNumber*>*)deviceIds elementId:(n
NSXMLElement *pubsub = [NSXMLElement elementWithName:@"pubsub" xmlns:XMLNS_PUBSUB];
[pubsub addChild:publish];

NSXMLElement *x = [NSXMLElement elementWithName:@"x" xmlns:@"jabber:x:data"];
[x addAttributeWithName:@"type" stringValue:@"submit"];

NSXMLElement *formTypeField = [NSXMLElement elementWithName:@"field"];
[formTypeField addAttributeWithName:@"var" stringValue:@"FORM_TYPE"];
[formTypeField addAttributeWithName:@"type" stringValue:@"hidden"];
[formTypeField addChild:[NSXMLElement elementWithName:@"value" stringValue:XMLNS_PUBSUB_PUBLISH_OPTIONS]];

[x addChild:formTypeField];

NSXMLElement *persistanceField = [NSXMLElement elementWithName:@"field"];
[persistanceField addAttributeWithName:@"var" stringValue:@"pubsub#persist_items"];
[persistanceField addChild:[NSXMLElement elementWithName:@"value" objectValue:@"1"]];

[x addChild:persistanceField];

NSXMLElement *accessModelField = [NSXMLElement elementWithName:@"field"];
[accessModelField addAttributeWithName:@"var" stringValue:@"pubsub#access_model"];
[accessModelField addChild:[NSXMLElement elementWithName:@"value" objectValue:@"open"]];

[x addChild:accessModelField];

NSXMLElement *publishOptions = [NSXMLElement elementWithName:@"publish-options"];
[publishOptions addChild:x];

[pubsub addChild:publishOptions];

XMPPIQ *iq = [XMPPIQ iqWithType:@"set" elementID:elementId];
[iq addChild:pubsub];

Expand Down Expand Up @@ -108,6 +148,19 @@ + (XMPPIQ*) omemo_iqPublishDeviceIds:(NSArray<NSNumber*>*)deviceIds elementId:(n
</bundle>
</item>
</publish>
<publish-options>
<x xmlns="jabber:x:data" type="submit">
<field var="FORM_TYPE" type="hidden">
<value>http://jabber.org/protocol/pubsub#publish-options</value>
</field>
<field var="pubsub#persist_items">
<value>1</value>
</field>
<field var="pubsub#access_model">
<value>open</value>
</field>
</x>
</publish-options>
</pubsub>
</iq>

Expand Down Expand Up @@ -156,6 +209,33 @@ + (XMPPIQ*) omemo_iqPublishBundle:(OMEMOBundle*)bundle
NSXMLElement *pubsub = [NSXMLElement elementWithName:@"pubsub" xmlns:XMLNS_PUBSUB];
[pubsub addChild:publish];

NSXMLElement *x = [NSXMLElement elementWithName:@"x" xmlns:@"jabber:x:data"];
[x addAttributeWithName:@"type" stringValue:@"submit"];

NSXMLElement *formTypeField = [NSXMLElement elementWithName:@"field"];
[formTypeField addAttributeWithName:@"var" stringValue:@"FORM_TYPE"];
[formTypeField addAttributeWithName:@"type" stringValue:@"hidden"];
[formTypeField addChild:[NSXMLElement elementWithName:@"value" stringValue:XMLNS_PUBSUB_PUBLISH_OPTIONS]];

[x addChild:formTypeField];

NSXMLElement *persistanceField = [NSXMLElement elementWithName:@"field"];
[persistanceField addAttributeWithName:@"var" stringValue:@"pubsub#persist_items"];
[persistanceField addChild:[NSXMLElement elementWithName:@"value" objectValue:@"1"]];

[x addChild:persistanceField];

NSXMLElement *accessModelField = [NSXMLElement elementWithName:@"field"];
[accessModelField addAttributeWithName:@"var" stringValue:@"pubsub#access_model"];
[accessModelField addChild:[NSXMLElement elementWithName:@"value" objectValue:@"open"]];

[x addChild:accessModelField];

NSXMLElement *publishOptions = [NSXMLElement elementWithName:@"publish-options"];
[publishOptions addChild:x];

[pubsub addChild:publishOptions];

XMPPIQ *iq = [XMPPIQ iqWithType:@"set" elementID:elementId];
[iq addChild:pubsub];
return iq;
Expand Down
39 changes: 39 additions & 0 deletions Xcode/Testing-Shared/OMEMOElementTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ - (void)testDeviceIdSerialization {
</list> \
</item> \
</publish> \
<publish-options> \
<x xmlns='jabber:x:data' type='submit'> \
<field var='FORM_TYPE' type='hidden'> \
<value>http://jabber.org/protocol/pubsub#publish-options</value> \
</field> \
<field var='pubsub#persist_items'> \
<value>1</value> \
</field> \
<field var='pubsub#access_model'> \
<value>open</value> \
</field> \
</x> \
</publish-options> \
</pubsub> \
</iq> \
", [OMEMOModule xmlnsOMEMODeviceList:self.ns], [OMEMOModule xmlnsOMEMO:self.ns]];
Expand Down Expand Up @@ -84,6 +97,19 @@ - (void) testPublishDeviceBundle {
</bundle> \
</item> \
</publish> \
<publish-options> \
<x xmlns='jabber:x:data' type='submit'> \
<field var='FORM_TYPE' type='hidden'> \
<value>http://jabber.org/protocol/pubsub#publish-options</value> \
</field> \
<field var='pubsub#persist_items'> \
<value>1</value> \
</field> \
<field var='pubsub#access_model'> \
<value>open</value> \
</field> \
</x> \
</publish-options> \
</pubsub> \
</iq> \
", [OMEMOModule xmlnsOMEMOBundles:self.ns], [OMEMOModule xmlnsOMEMO:self.ns]];
Expand Down Expand Up @@ -251,6 +277,19 @@ - (void) testBundleParsing {
</bundle> \
</item> \
</publish> \
<publish-options> \
<x xmlns='jabber:x:data' type='submit'> \
<field var='FORM_TYPE' type='hidden'> \
<value>http://jabber.org/protocol/pubsub#publish-options</value> \
</field> \
<field var='pubsub#persist_items'> \
<value>1</value> \
</field> \
<field var='pubsub#access_model'> \
<value>open</value> \
</field> \
</x> \
</publish-options> \
</pubsub> \
</iq> \
",[OMEMOModule xmlnsOMEMOBundles:self.ns], [OMEMOModule xmlnsOMEMO:self.ns]];
Expand Down