diff options
Diffstat (limited to 'Swiften/Serializer/PayloadSerializers/MIXJoinSerializer.cpp')
-rw-r--r-- | Swiften/Serializer/PayloadSerializers/MIXJoinSerializer.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/Swiften/Serializer/PayloadSerializers/MIXJoinSerializer.cpp b/Swiften/Serializer/PayloadSerializers/MIXJoinSerializer.cpp new file mode 100644 index 0000000..cae15c2 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/MIXJoinSerializer.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2017 Tarun Gupta + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <Swiften/Serializer/PayloadSerializers/MIXJoinSerializer.h> + +#include <memory> + +#include <Swiften/Serializer/PayloadSerializers/MIXSubscribeSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/FormSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> + +using namespace Swift; + +MIXJoinSerializer::MIXJoinSerializer() { +} + +MIXJoinSerializer::~MIXJoinSerializer() { +} + +std::string MIXJoinSerializer::serializePayload(std::shared_ptr<MIXJoin> payload) const { + if (!payload) { + return ""; + } + XMLElement element("join", "urn:xmpp:mix:1"); + if (payload->getChannel()) { + element.setAttribute("channel", *payload->getChannel()); + } + if (payload->getJID()) { + element.setAttribute("jid", *payload->getJID()); + } + for (const auto& item : payload->getSubscriptions()) { + element.addNode(std::make_shared<XMLRawTextNode>(MIXSubscribeSerializer().serialize(item))); + } + if (payload->getForm()) { + element.addNode(std::make_shared<XMLRawTextNode>(FormSerializer().serialize(payload->getForm()))); + } + return element.serialize(); +} |