summaryrefslogtreecommitdiffstats
blob: 6f4027787ff5a1bc2d0f351beae61faf75397ef3 (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
42
43
44
45
46
47
48
49
50
/*
 * Copyright (c) 2014-2016 Isode Limited.
 * All rights reserved.
 * See the COPYING file for more information.
 */

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

#include <memory>

#include <boost/lexical_cast.hpp>

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

using namespace Swift;

MAMFinSerializer::MAMFinSerializer() {
}

MAMFinSerializer::~MAMFinSerializer() {
}

std::string MAMFinSerializer::serializePayload(std::shared_ptr<MAMFin> payload) const {
    if (!payload) {
        return "";
    }

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

    if (payload->isComplete()) {
        element.setAttribute("complete", "true");
    }

    if (!payload->isStable()) {
        element.setAttribute("stable", "false");
    }

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

    if (payload->getResultSet()) {
        element.addNode(std::make_shared<XMLRawTextNode>(ResultSetSerializer().serialize(payload->getResultSet())));
    }

    return element.serialize();
}