aboutsummaryrefslogtreecommitdiff
path: root/src/base/QXmppMixInvitation.cpp
blob: c9178a21edfe086ff479ae439e01297913ec47f9 (plain) (blame)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*
 * Copyright (C) 2008-2021 The QXmpp developers
 *
 * Author:
 *  Melvin Keskin
 *
 * Source:
 *  https://github.com/qxmpp-project/qxmpp
 *
 * This file is a part of QXmpp library.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 */

#include "QXmppMixInvitation.h"

#include "QXmppConstants_p.h"
#include "QXmppUtils.h"

#include <QDomElement>
#include <QSharedData>

class QXmppMixInvitationPrivate : public QSharedData
{
public:
    QString inviterJid;
    QString inviteeJid;
    QString channelJid;
    QString token;
};

///
/// Default constructor
///
QXmppMixInvitation::QXmppMixInvitation()
    : d(new QXmppMixInvitationPrivate)
{
}

///
/// Copy constructor
///
QXmppMixInvitation::QXmppMixInvitation(const QXmppMixInvitation &other) = default;

///
/// Default assignment operator.
///
QXmppMixInvitation &QXmppMixInvitation::operator=(const QXmppMixInvitation &other) = default;

///
/// Destructor
///
QXmppMixInvitation::~QXmppMixInvitation() = default;

///
/// Returns the JID of the inviter.
///
/// \return the inviter's JID
///
QString QXmppMixInvitation::inviterJid() const
{
    return d->inviterJid;
}

///
/// Sets the JID of the inviter.
///
/// \param inviterJid inviter's JID
///
void QXmppMixInvitation::setInviterJid(const QString &inviterJid)
{
    d->inviterJid = inviterJid;
}

///
/// Returns the JID of the invitee.
///
/// \return the invitee's JID
///
QString QXmppMixInvitation::inviteeJid() const
{
    return d->inviteeJid;
}

///
/// Sets the JID of the invitee.
///
/// \param inviteeJid invitee's JID
///
void QXmppMixInvitation::setInviteeJid(const QString &inviteeJid)
{
    d->inviteeJid = inviteeJid;
}

///
/// Returns the JID of the channel.
///
/// \return the channel's JID
///
QString QXmppMixInvitation::channelJid() const
{
    return d->channelJid;
}

///
/// Sets the JID of the channel.
///
/// \param channelJid channel JID
///
void QXmppMixInvitation::setChannelJid(const QString &channelJid)
{
    d->channelJid = channelJid;
}

///
/// Returns the token which is generated by the server and used by the invitee
/// for authentication.
///
/// \return the generated token used for authentication
///
QString QXmppMixInvitation::token() const
{
    return d->token;
}

///
/// Sets the token which is generated by the server and used by the invitee for
/// authentication.
///
/// \param token authentication token
///
void QXmppMixInvitation::setToken(const QString &token)
{
    d->token = token;
}

/// \cond
void QXmppMixInvitation::parse(const QDomElement &element)
{
    d->inviterJid = element.firstChildElement(QStringLiteral("inviter")).text();
    d->inviteeJid = element.firstChildElement(QStringLiteral("invitee")).text();
    d->channelJid = element.firstChildElement(QStringLiteral("channel")).text();
    d->token = element.firstChildElement(QStringLiteral("token")).text();
}

void QXmppMixInvitation::toXml(QXmlStreamWriter *writer) const
{
    writer->writeStartElement(QStringLiteral("invitation"));
    writer->writeDefaultNamespace(ns_mix_misc);

    helperToXmlAddTextElement(writer, QStringLiteral("inviter"), d->inviterJid);
    helperToXmlAddTextElement(writer, QStringLiteral("invitee"), d->inviteeJid);
    helperToXmlAddTextElement(writer, QStringLiteral("channel"), d->channelJid);
    helperToXmlAddTextElement(writer, QStringLiteral("token"), d->token);

    writer->writeEndElement();
}
/// \endcond

///
/// Determines whether the given DOM element is a MIX invitation.
///
/// \param element DOM element being checked
///
/// \return true if element is a MIX invitation, otherwise false
///
bool QXmppMixInvitation::isMixInvitation(const QDomElement &element)
{
    return element.tagName() == QStringLiteral("invitation") &&
        element.namespaceURI() == ns_mix_misc;
}