Skip to content

Commit

Permalink
XEP 0283: Moved - Add support in QXmppPresence
Browse files Browse the repository at this point in the history
This allow to track if the request is being issued as part of a moved
user.
  • Loading branch information
pasnox authored and lnjX committed Oct 8, 2024
1 parent 5a90a37 commit 1aeaa06
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/base/QXmppPresence.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// SPDX-FileCopyrightText: 2009 Manjeet Dahiya <[email protected]>
// SPDX-FileCopyrightText: 2022 Melvin Keskin <[email protected]>
// SPDX-FileCopyrightText: 2024 Filipe Azevedo <[email protected]>
//
// SPDX-License-Identifier: LGPL-2.1-or-later

Expand Down Expand Up @@ -76,6 +77,9 @@ class QXmppPresencePrivate : public QSharedData
// XEP-0405: Mediated Information eXchange (MIX): Participant Server Requirements
QString mixUserJid;
QString mixUserNick;

// XEP-0283: Moved
QString oldJid;
};

QXmppPresencePrivate::QXmppPresencePrivate()
Expand Down Expand Up @@ -348,6 +352,26 @@ void QXmppPresence::setMucSupported(bool supported)
d->mucSupported = supported;
}

///
/// Returns the \xep{0283, Moved} user's old jid.
///
/// \since QXmpp 1.9
///
QString QXmppPresence::oldJid() const
{
return d->oldJid;
}

///
/// Sets the \xep{0283, Moved} user's old jid.
///
/// \since QXmpp 1.9
///
void QXmppPresence::setOldJid(const QString &oldJid)
{
d->oldJid = oldJid;
}

///
/// Returns when the last user interaction with the client took place. See
/// \xep{0319}: Last User Interaction in Presence for details.
Expand Down Expand Up @@ -483,6 +507,9 @@ void QXmppPresence::parseExtension(const QDomElement &element, QXmppElementList
content.parse(contentElement);
d->mujiContents.append(content);
}
// XEP-0283: Moved
} else if (element.tagName() == u"moved" && element.namespaceURI() == ns_moved) {
d->oldJid = element.firstChildElement(u"old-jid"_s).text();
// XEP-0319: Last User Interaction in Presence
} else if (element.tagName() == u"idle" && element.namespaceURI() == ns_idle) {
if (element.hasAttribute(u"since"_s)) {
Expand Down Expand Up @@ -584,6 +611,14 @@ void QXmppPresence::toXml(QXmlStreamWriter *xmlWriter) const
xmlWriter->writeEndElement();
}

// XEP-0283: Moved
if (!d->oldJid.isEmpty()) {
xmlWriter->writeStartElement(QSL65("moved"));
xmlWriter->writeDefaultNamespace(ns_moved.toString());
writeXmlTextElement(xmlWriter, u"old-jid", d->oldJid);
xmlWriter->writeEndElement();
}

// XEP-0319: Last User Interaction in Presence
if (!d->lastUserInteraction.isNull() && d->lastUserInteraction.isValid()) {
xmlWriter->writeStartElement(QSL65("idle"));
Expand Down
5 changes: 5 additions & 0 deletions src/base/QXmppPresence.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// SPDX-FileCopyrightText: 2009 Manjeet Dahiya <[email protected]>
// SPDX-FileCopyrightText: 2022 Melvin Keskin <[email protected]>
// SPDX-FileCopyrightText: 2024 Filipe Azevedo <[email protected]>
//
// SPDX-License-Identifier: LGPL-2.1-or-later

Expand Down Expand Up @@ -115,6 +116,10 @@ class QXMPP_EXPORT QXmppPresence : public QXmppStanza
QVector<QXmppJingleIq::Content> mujiContents() const;
void setMujiContents(const QVector<QXmppJingleIq::Content> &mujiContents);

// XEP-0283: Moved
QString oldJid() const;
void setOldJid(const QString &oldJid);

// XEP-0319: Last User Interaction in Presence
QDateTime lastUserInteraction() const;
void setLastUserInteraction(const QDateTime &);
Expand Down

0 comments on commit 1aeaa06

Please sign in to comment.