From 4c060bfaf88777dcc75192f658ad2089ac33bc50 Mon Sep 17 00:00:00 2001 From: mimi89999 Date: Mon, 4 Feb 2019 18:51:12 +0100 Subject: [PATCH] Added publish options for device and boundle nodes --- Extensions/OMEMO/XMPPIQ+OMEMO.m | 80 ++++++++++++++++++++++++ Xcode/Testing-Shared/OMEMOElementTests.m | 39 ++++++++++++ 2 files changed, 119 insertions(+) diff --git a/Extensions/OMEMO/XMPPIQ+OMEMO.m b/Extensions/OMEMO/XMPPIQ+OMEMO.m index bc241f62a5..2288bc3eb0 100644 --- a/Extensions/OMEMO/XMPPIQ+OMEMO.m +++ b/Extensions/OMEMO/XMPPIQ+OMEMO.m @@ -50,6 +50,19 @@ + (XMPPIQ*) omemo_iqFetchDeviceIdsForJID:(XMPPJID*)jid + + + + http://jabber.org/protocol/pubsub#publish-options + + + 1 + + + open + + + */ @@ -71,6 +84,33 @@ + (XMPPIQ*) omemo_iqPublishDeviceIds:(NSArray*)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]; @@ -108,6 +148,19 @@ + (XMPPIQ*) omemo_iqPublishDeviceIds:(NSArray*)deviceIds elementId:(n + + + + http://jabber.org/protocol/pubsub#publish-options + + + 1 + + + open + + + @@ -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; diff --git a/Xcode/Testing-Shared/OMEMOElementTests.m b/Xcode/Testing-Shared/OMEMOElementTests.m index 8b200e490e..ec0d8c7efc 100644 --- a/Xcode/Testing-Shared/OMEMOElementTests.m +++ b/Xcode/Testing-Shared/OMEMOElementTests.m @@ -54,6 +54,19 @@ - (void)testDeviceIdSerialization { \ \ \ + \ + \ + \ + http://jabber.org/protocol/pubsub#publish-options \ + \ + \ + 1 \ + \ + \ + open \ + \ + \ + \ \ \ ", [OMEMOModule xmlnsOMEMODeviceList:self.ns], [OMEMOModule xmlnsOMEMO:self.ns]]; @@ -84,6 +97,19 @@ - (void) testPublishDeviceBundle { \ \ \ + \ + \ + \ + http://jabber.org/protocol/pubsub#publish-options \ + \ + \ + 1 \ + \ + \ + open \ + \ + \ + \ \ \ ", [OMEMOModule xmlnsOMEMOBundles:self.ns], [OMEMOModule xmlnsOMEMO:self.ns]]; @@ -251,6 +277,19 @@ - (void) testBundleParsing { \ \ \ + \ + \ + \ + http://jabber.org/protocol/pubsub#publish-options \ + \ + \ + 1 \ + \ + \ + open \ + \ + \ + \ \ \ ",[OMEMOModule xmlnsOMEMOBundles:self.ns], [OMEMOModule xmlnsOMEMO:self.ns]];