Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce QXmppMovedManager - XEP-0283: Moved #621

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions doc/doap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,14 @@ SPDX-License-Identifier: CC0-1.0
<xmpp:since>1.0</xmpp:since>
</xmpp:SupportedXep>
</implements>
<implements>
<xmpp:SupportedXep>
<xmpp:xep rdf:resource='https://xmpp.org/extensions/xep-0283.html'/>
<xmpp:status>complete</xmpp:status>
<xmpp:version>0.2.0</xmpp:version>
<xmpp:since>1.8</xmpp:since>
</xmpp:SupportedXep>
</implements>
<implements>
<xmpp:SupportedXep>
<xmpp:xep rdf:resource='https://xmpp.org/extensions/xep-0293.html'/>
Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ set(INSTALL_HEADER_FILES
client/QXmppMessageHandler.h
client/QXmppMessageReceiptManager.h
client/QXmppMixManager.h
client/QXmppMovedManager.h
client/QXmppMucManager.h
client/QXmppOutgoingClient.h
client/QXmppRegistrationManager.h
Expand Down Expand Up @@ -267,6 +268,7 @@ set(SOURCE_FILES
client/QXmppMamManager.cpp
client/QXmppMessageReceiptManager.cpp
client/QXmppMixManager.cpp
client/QXmppMovedManager.cpp
client/QXmppMucManager.cpp
client/QXmppOutgoingClient.cpp
client/QXmppRosterManager.cpp
Expand Down
2 changes: 2 additions & 0 deletions src/base/QXmppConstants_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ inline constexpr QStringView ns_thumbs = u"urn:xmpp:thumbs:1";
inline constexpr QStringView ns_muji = u"urn:xmpp:jingle:muji:0";
// XEP-0280: Message Carbons
inline constexpr QStringView ns_carbons = u"urn:xmpp:carbons:2";
// XEP-0283: Moved
inline constexpr QStringView ns_moved = u"urn:xmpp:moved:1";
// XEP-0293: Jingle RTP Feedback Negotiation
inline constexpr QStringView ns_jingle_rtp_feedback_negotiation = u"urn:xmpp:jingle:apps:rtp:rtcp-fb:0";
// XEP-0294: Jingle RTP Header Extensions Negotiation
Expand Down
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
30 changes: 30 additions & 0 deletions src/client/QXmppMovedItem_p.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// SPDX-FileCopyrightText: 2024 Filipe Azevedo <[email protected]>
//
// SPDX-License-Identifier: LGPL-2.1-or-later

#ifndef QXMPPMOVEDITEM_P_H
#define QXMPPMOVEDITEM_P_H

#include <QXmppPubSubBaseItem.h>

class QXmppMovedItem : public QXmppPubSubBaseItem
{
public:
QXmppMovedItem(const QString &newJid = {});

QString newJid() const { return m_newJid; }
void setNewJid(const QString &newJid) { m_newJid = newJid; }

static bool isItem(const QDomElement &itemElement);

protected:
/// \cond
void parsePayload(const QDomElement &payloadElement) override;
void serializePayload(QXmlStreamWriter *writer) const override;
/// \endcond

private:
QString m_newJid;
};

#endif // QXMPPMOVEDITEM_P_H
Loading
Loading