summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Serializer/PayloadSerializers')
-rw-r--r--Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp2
-rw-r--r--Swiften/Serializer/PayloadSerializers/MIXUserPreferenceSerializer.cpp33
-rw-r--r--Swiften/Serializer/PayloadSerializers/MIXUserPreferenceSerializer.h25
-rw-r--r--Swiften/Serializer/PayloadSerializers/UnitTest/MIXUserPreferenceSerializerTest.cpp68
4 files changed, 128 insertions, 0 deletions
diff --git a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp
index 4c3cf66..9832bd5 100644
--- a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp
+++ b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp
@@ -49,6 +49,7 @@
#include <Swiften/Serializer/PayloadSerializers/MIXDestroySerializer.h>
#include <Swiften/Serializer/PayloadSerializers/MIXParticipantSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/MIXCreateSerializer.h>
+#include <Swiften/Serializer/PayloadSerializers/MIXUserPreferenceSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/MUCAdminPayloadSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/MUCDestroyPayloadSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/MUCInvitationPayloadSerializer.h>
@@ -160,6 +161,7 @@ FullPayloadSerializerCollection::FullPayloadSerializerCollection() {
serializers_.push_back(new ForwardedSerializer(this));
serializers_.push_back(new MIXParticipantSerializer());
serializers_.push_back(new MIXCreateSerializer());
+ serializers_.push_back(new MIXUserPreferenceSerializer());
serializers_.push_back(new MIXJoinSerializer());
serializers_.push_back(new MIXDestroySerializer());
serializers_.push_back(new MAMResultSerializer(this));
diff --git a/Swiften/Serializer/PayloadSerializers/MIXUserPreferenceSerializer.cpp b/Swiften/Serializer/PayloadSerializers/MIXUserPreferenceSerializer.cpp
new file mode 100644
index 0000000..2d057ad
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/MIXUserPreferenceSerializer.cpp
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2017 Tarun Gupta
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include <Swiften/Serializer/PayloadSerializers/MIXUserPreferenceSerializer.h>
+
+#include <memory>
+
+#include <Swiften/Serializer/PayloadSerializers/FormSerializer.h>
+#include <Swiften/Serializer/XML/XMLElement.h>
+#include <Swiften/Serializer/XML/XMLRawTextNode.h>
+
+namespace Swift {
+
+MIXUserPreferenceSerializer::MIXUserPreferenceSerializer() {
+}
+
+MIXUserPreferenceSerializer::~MIXUserPreferenceSerializer() {
+}
+
+std::string MIXUserPreferenceSerializer::serializePayload(std::shared_ptr<MIXUserPreference> payload) const {
+ if (!payload) {
+ return "";
+ }
+ XMLElement element("user-preference", "urn:xmpp:mix:1");
+ if(payload->getData()) {
+ element.addNode(std::make_shared<XMLRawTextNode>(FormSerializer().serialize(payload->getData())));
+ }
+ return element.serialize();
+}
+}
diff --git a/Swiften/Serializer/PayloadSerializers/MIXUserPreferenceSerializer.h b/Swiften/Serializer/PayloadSerializers/MIXUserPreferenceSerializer.h
new file mode 100644
index 0000000..301083a
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/MIXUserPreferenceSerializer.h
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2017 Tarun Gupta
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+#include <memory>
+
+#include <Swiften/Base/API.h>
+#include <Swiften/Base/Override.h>
+#include <Swiften/Elements/MIXUserPreference.h>
+#include <Swiften/Serializer/GenericPayloadSerializer.h>
+
+namespace Swift {
+
+ class SWIFTEN_API MIXUserPreferenceSerializer : public GenericPayloadSerializer<MIXUserPreference> {
+ public:
+ MIXUserPreferenceSerializer();
+ virtual ~MIXUserPreferenceSerializer();
+
+ virtual std::string serializePayload(std::shared_ptr<MIXUserPreference>) const SWIFTEN_OVERRIDE;
+ };
+}
diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/MIXUserPreferenceSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/MIXUserPreferenceSerializerTest.cpp
new file mode 100644
index 0000000..7cbfbfc
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/UnitTest/MIXUserPreferenceSerializerTest.cpp
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2017 Tarun Gupta
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include <gtest/gtest.h>
+
+#include <Swiften/Serializer/PayloadSerializers/MIXUserPreferenceSerializer.h>
+#include <Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h>
+
+using namespace Swift;
+
+TEST(MIXUserPreferenceSerializerTest, XEP0369_Example31) {
+ MIXUserPreferenceSerializer testling;
+
+ auto userpreference = std::shared_ptr<MIXUserPreference>(new MIXUserPreference());
+ std::string expectedResult = "<user-preference xmlns=\"urn:xmpp:mix:1\"/>";
+ ASSERT_EQ(expectedResult, testling.serialize(userpreference));
+}
+
+TEST(MIXUserPreferenceSerializerTest, XEP0369_Example32) {
+ MIXUserPreferenceSerializer testling;
+
+ auto userpreference = std::shared_ptr<MIXUserPreference>(new MIXUserPreference());
+ std::shared_ptr<Form> parameters(std::make_shared<Form>());
+ parameters->setType(Form::Type::ResultType);
+
+ std::shared_ptr<FormField> fieldType = std::make_shared<FormField>(FormField::HiddenType);
+ fieldType->setName("FORM_TYPE");
+ fieldType->addValue("urn:xmpp:mix:1");
+ parameters->addField(fieldType);
+
+ std::shared_ptr<FormField> fieldJIDVisibility = std::make_shared<FormField>();
+ fieldJIDVisibility->setName("JID Visibility");
+ fieldJIDVisibility->addValue("never");
+ parameters->addField(fieldJIDVisibility);
+
+ std::shared_ptr<FormField> fieldprivateMessages = std::make_shared<FormField>();
+ fieldprivateMessages->setName("Private Messages");
+ fieldprivateMessages->addValue("allow");
+ parameters->addField(fieldprivateMessages);
+
+ std::shared_ptr<FormField> vCard = std::make_shared<FormField>();
+ vCard->setName("vCard");
+ vCard->addValue("block");
+ parameters->addField(vCard);
+
+ userpreference->setData(parameters);
+
+ std::string expectedResult = "<user-preference xmlns=\"urn:xmpp:mix:1\">"
+ "<x type=\"result\" xmlns=\"jabber:x:data\">"
+ "<field type=\"hidden\" var=\"FORM_TYPE\">"
+ "<value>urn:xmpp:mix:1</value>"
+ "</field>"
+ "<field var=\"JID Visibility\">"
+ "<value>never</value>"
+ "</field>"
+ "<field var=\"Private Messages\">"
+ "<value>allow</value>"
+ "</field>"
+ "<field var=\"vCard\">"
+ "<value>block</value>"
+ "</field>"
+ "</x>"
+ "</user-preference>";
+ ASSERT_EQ(expectedResult, testling.serialize(userpreference));
+}