Skip to content

Commit 0318b53

Browse files
committed
XEP-0444 message reactions support
1 parent bfb37f5 commit 0318b53

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/xmpp/xmpp-im/types.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,8 @@ class Message::Private : public QSharedData {
749749
QString encryptionProtocol; // XEP-0380
750750
Message::StanzaId stanzaId; // XEP-0359
751751
QList<Reference> references; // XEP-0385 and XEP-0372
752+
753+
std::optional<QStringList> reactions; // XEP-0444
752754
};
753755

754756
#define MessageD() (d ? d : (d = new Private))
@@ -1096,6 +1098,10 @@ void Message::addReference(const Reference &r) { MessageD()->references.append(r
10961098

10971099
void Message::setReferences(const QList<Reference> &r) { MessageD()->references = r; }
10981100

1101+
void Message::setReactions(const QStringList &reactions) { MessageD()->reactions = reactions; }
1102+
1103+
std::optional<QStringList> Message::reactions() const { return d ? d->reactions : QStringList {}; }
1104+
10991105
QString Message::invite() const { return d ? d->invite : QString(); }
11001106

11011107
void Message::setInvite(const QString &s) { MessageD()->invite = s; }
@@ -1433,6 +1439,16 @@ Stanza Message::toStanza(Stream *stream) const
14331439
s.appendChild(r.toXml(&s.doc()));
14341440
}
14351441

1442+
// XEP-0444
1443+
auto reactionsNS = QStringLiteral("urn:xmpp:reactions:0");
1444+
if (d->reactions) {
1445+
auto e = s.createElement(reactionsNS, QStringLiteral("reactions"));
1446+
for (const QString &reaction : *d->reactions) {
1447+
e.appendChild(s.createTextElement(reactionsNS, QStringLiteral("reaction"), reaction));
1448+
}
1449+
s.appendChild(e);
1450+
}
1451+
14361452
return s;
14371453
}
14381454

@@ -1785,6 +1801,20 @@ bool Message::fromStanza(const Stanza &s, bool useTimeZoneOffset, int timeZoneOf
17851801
}
17861802
}
17871803

1804+
// XEP-0444 message reactions
1805+
auto reactionStanza
1806+
= childElementsByTagNameNS(root, "urn:xmpp:reactions:0", QStringLiteral("reactions")).item(0).toElement();
1807+
if (!reactionStanza.isNull()) {
1808+
auto reactionTag = QStringLiteral("reaction");
1809+
QStringList reactions;
1810+
auto reaction = reactionStanza.firstChildElement(reactionTag);
1811+
while (!reaction.isNull()) {
1812+
reactions.append(reaction.text().trimmed());
1813+
reaction = reaction.nextSiblingElement(reactionTag);
1814+
}
1815+
d->reactions = reactions;
1816+
}
1817+
17881818
return true;
17891819
}
17901820

src/xmpp/xmpp-im/xmpp_message.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030

3131
#include <QExplicitlySharedDataPointer>
3232

33+
#include <optional>
34+
3335
class QDateTime;
3436
class QString;
3537

@@ -220,6 +222,10 @@ class Message {
220222
void addReference(const Reference &r);
221223
void setReferences(const QList<Reference> &r);
222224

225+
// XEP-0444 message reaction
226+
void setReactions(const QStringList &reactions);
227+
std::optional<QStringList> reactions() const;
228+
223229
// Obsolete invitation
224230
QString invite() const;
225231
void setInvite(const QString &s);

0 commit comments

Comments
 (0)