summaryrefslogtreecommitdiffstats
blob: 4406e71d7a1ad78b78fd3367d2c276f4236f7be7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
 * Copyright (c) 2014-2016 Isode Limited.
 * All rights reserved.
 * See the COPYING file for more information.
 */

#include <Swiften/Serializer/PayloadSerializers/MAMResultSerializer.h>

#include <boost/lexical_cast.hpp>
#include <boost/smart_ptr/make_shared.hpp>

#include <Swiften/Serializer/PayloadSerializerCollection.h>
#include <Swiften/Serializer/PayloadSerializers/ForwardedSerializer.h>
#include <Swiften/Serializer/XML/XMLElement.h>
#include <Swiften/Serializer/XML/XMLRawTextNode.h>

using namespace Swift;

MAMResultSerializer::MAMResultSerializer(PayloadSerializerCollection* serializers) : serializers_(serializers) {
}

MAMResultSerializer::~MAMResultSerializer() {
}

std::string MAMResultSerializer::serializePayload(boost::shared_ptr<MAMResult> payload) const {
	if (!payload) {
		return "";
	}

	XMLElement element("result", "urn:xmpp:mam:0");

	element.setAttribute("id", payload->getID());

	if (payload->getQueryID()) {
		element.setAttribute("queryid", *payload->getQueryID());
	}

	element.addNode(boost::make_shared<XMLRawTextNode>(ForwardedSerializer(serializers_).serialize(payload->getPayload())));

	return element.serialize();
}