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

Start implementing XEP-0449: Stickers #490

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
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 @@ -622,6 +622,14 @@ SPDX-License-Identifier: CC0-1.0
<xmpp:since>1.5</xmpp:since>
</xmpp:SupportedXep>
</implements>
<implements>
<xmpp:SupportedXep>
<xmpp:xep rdf:resource='https://xmpp.org/extensions/xep-0449.html'/>
<xmpp:status>complete</xmpp:status>
<xmpp:version>0.1</xmpp:version>
<xmpp:since>1.5</xmpp:since>
</xmpp:SupportedXep>
</implements>
<release>
<Version>
<revision>1.4.0</revision>
Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ set(INSTALL_HEADER_FILES
base/QXmppSocks.h
base/QXmppStanza.h
base/QXmppStartTlsPacket.h
base/QXmppStickerPackItem.h
base/QXmppStream.h
base/QXmppStreamFeatures.h
base/QXmppStun.h
Expand Down Expand Up @@ -212,6 +213,7 @@ set(SOURCE_FILES
base/QXmppRpcIq.cpp
base/QXmppSasl.cpp
base/QXmppSessionIq.cpp
base/QXmppStickerPackItem.cpp
base/QXmppSocks.cpp
base/QXmppStanza.cpp
base/QXmppStartTlsPacket.cpp
Expand Down
2 changes: 2 additions & 0 deletions src/base/QXmppConstants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,5 +204,7 @@ const char *ns_file_metadata = "urn:xmpp:file:metadata:0";
const char *ns_sfs = "urn:xmpp:sfs:0";
// XEP-0448: Encryption for stateless file sharing
const char *ns_esfs = "urn:xmpp:esfs:0";
// XEP-0449: Stickers
const char *ns_stickers = "urn:xmpp:stickers:0";
// XEP-0450: Automatic Trust Management (ATM)
const char *ns_atm = "urn:xmpp:atm:1";
2 changes: 2 additions & 0 deletions src/base/QXmppConstants_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ extern const char *ns_file_metadata;
extern const char *ns_sfs;
// XEP-0448: Encryption for stateless file sharing
extern const char *ns_esfs;
// XEP-0449: Stickers
extern const char *ns_stickers;
// XEP-0450: Automatic Trust Management (ATM)
extern const char *ns_atm;

Expand Down
41 changes: 41 additions & 0 deletions src/base/QXmppMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ class QXmppMessagePrivate : public QSharedData

// XEP-0448: Encryption for stateless file sharing
QVector<QXmppFileShare> sharedFiles;

// XEP-0449: Stickers
std::optional<QString> stickerPackId;
};

QXmppMessagePrivate::QXmppMessagePrivate()
Expand Down Expand Up @@ -1258,6 +1261,30 @@ void QXmppMessage::setSharedFiles(const QVector<QXmppFileShare> &sharedFiles)
d->sharedFiles = sharedFiles;
}

///
/// \brief Returns the sticker pack id for the sticker contained in this message
///
/// This is used for \xep{0449, Stickers}.
///
/// \since QXmpp 1.5
///
const std::optional<QString> &QXmppMessage::stickerPackId() const
{
return d->stickerPackId;
}

///
/// \brief Sets the sticker pack id for the sticker contained in this message
///
/// This is used for \xep{0449, Stickers}.
///
/// \since QXmpp 1.5
///
void QXmppMessage::setStickerPackId(const std::optional<QString> &stickerPackId)
{
d->stickerPackId = stickerPackId;
}

/// \cond
void QXmppMessage::parse(const QDomElement &element)
{
Expand Down Expand Up @@ -1552,6 +1579,12 @@ bool QXmppMessage::parseExtension(const QDomElement &element, QXmpp::SceMode sce
}
return true;
}

// XEP-0449: Stickers
if (checkElement(element, QStringLiteral("sticker"), ns_stickers)) {
d->stickerPackId = element.attribute("pack");
return true;
}
}
return false;
}
Expand Down Expand Up @@ -1804,5 +1837,13 @@ void QXmppMessage::serializeExtensions(QXmlStreamWriter *writer, QXmpp::SceMode
for (const auto &fileShare : d->sharedFiles) {
fileShare.toXml(writer);
}

// XEP-0449: Sticker
if (d->stickerPackId) {
writer->writeStartElement("sticker");
writer->writeDefaultNamespace(ns_stickers);
writer->writeAttribute("pack", *d->stickerPackId);
writer->writeEndElement();
}
}
}
4 changes: 4 additions & 0 deletions src/base/QXmppMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ class QXMPP_EXPORT QXmppMessage : public QXmppStanza
const QVector<QXmppFileShare> &sharedFiles() const;
void setSharedFiles(const QVector<QXmppFileShare> &sharedFiles);

// XEP-0449: Stickers
const std::optional<QString> &stickerPackId() const;
void setStickerPackId(const std::optional<QString> &stickerPackId);

/// \cond
#ifdef BUILD_OMEMO
// XEP-0384: OMEMO Encryption
Expand Down
4 changes: 2 additions & 2 deletions src/base/QXmppPubSubItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ QXmppPubSubItem::QXmppPubSubItem(const QString &id, const QString &publisher)
/// Default copy-constructor
QXmppPubSubItem::QXmppPubSubItem(const QXmppPubSubItem &iq) = default;
/// Default move-constructor
QXmppPubSubItem::QXmppPubSubItem(QXmppPubSubItem &&) = default;
QXmppPubSubItem::QXmppPubSubItem(QXmppPubSubItem &&) noexcept = default;
QXmppPubSubItem::~QXmppPubSubItem() = default;
/// Default assignment operator
QXmppPubSubItem &QXmppPubSubItem::operator=(const QXmppPubSubItem &iq) = default;
/// Default move-assignment operator
QXmppPubSubItem &QXmppPubSubItem::operator=(QXmppPubSubItem &&iq) = default;
QXmppPubSubItem &QXmppPubSubItem::operator=(QXmppPubSubItem &&iq) noexcept = default;

///
/// Returns the ID of the PubSub item.
Expand Down
4 changes: 2 additions & 2 deletions src/base/QXmppPubSubItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ class QXMPP_EXPORT QXmppPubSubItem
public:
QXmppPubSubItem(const QString &id = {}, const QString &publisher = {});
QXmppPubSubItem(const QXmppPubSubItem &);
QXmppPubSubItem(QXmppPubSubItem &&);
QXmppPubSubItem(QXmppPubSubItem &&) noexcept;
virtual ~QXmppPubSubItem();

QXmppPubSubItem &operator=(const QXmppPubSubItem &);
QXmppPubSubItem &operator=(QXmppPubSubItem &&);
QXmppPubSubItem &operator=(QXmppPubSubItem &&) noexcept;

QString id() const;
void setId(const QString &id);
Expand Down
Loading