Skip to content

Commit 372e7a3

Browse files
committed
Added missed id to reactions
1 parent 0318b53 commit 372e7a3

File tree

3 files changed

+24
-18
lines changed

3 files changed

+24
-18
lines changed

src/xmpp/xmpp-im/types.cpp

+14-13
Original file line numberDiff line numberDiff line change
@@ -749,8 +749,7 @@ 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
752+
Message::Reactions reactions; // XEP-0444
754753
};
755754

756755
#define MessageD() (d ? d : (d = new Private))
@@ -1098,9 +1097,9 @@ void Message::addReference(const Reference &r) { MessageD()->references.append(r
10981097

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

1101-
void Message::setReactions(const QStringList &reactions) { MessageD()->reactions = reactions; }
1100+
void Message::setReactions(const XMPP::Message::Reactions &reactions) { MessageD()->reactions = reactions; }
11021101

1103-
std::optional<QStringList> Message::reactions() const { return d ? d->reactions : QStringList {}; }
1102+
XMPP::Message::Reactions Message::reactions() const { return d ? d->reactions : Reactions {}; }
11041103

11051104
QString Message::invite() const { return d ? d->invite : QString(); }
11061105

@@ -1441,9 +1440,10 @@ Stanza Message::toStanza(Stream *stream) const
14411440

14421441
// XEP-0444
14431442
auto reactionsNS = QStringLiteral("urn:xmpp:reactions:0");
1444-
if (d->reactions) {
1443+
if (!d->reactions.targetId.isEmpty()) {
14451444
auto e = s.createElement(reactionsNS, QStringLiteral("reactions"));
1446-
for (const QString &reaction : *d->reactions) {
1445+
e.setAttribute(QLatin1String("id"), d->reactions.targetId);
1446+
for (const QString &reaction : d->reactions.reactions) {
14471447
e.appendChild(s.createTextElement(reactionsNS, QStringLiteral("reaction"), reaction));
14481448
}
14491449
s.appendChild(e);
@@ -1805,14 +1805,15 @@ bool Message::fromStanza(const Stanza &s, bool useTimeZoneOffset, int timeZoneOf
18051805
auto reactionStanza
18061806
= childElementsByTagNameNS(root, "urn:xmpp:reactions:0", QStringLiteral("reactions")).item(0).toElement();
18071807
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);
1808+
d->reactions.targetId = reactionStanza.attribute(QLatin1String("id"));
1809+
if (!d->reactions.targetId.isEmpty()) {
1810+
auto reactionTag = QStringLiteral("reaction");
1811+
auto reaction = reactionStanza.firstChildElement(reactionTag);
1812+
while (!reaction.isNull()) {
1813+
d->reactions.reactions.append(reaction.text().trimmed());
1814+
reaction = reaction.nextSiblingElement(reactionTag);
1815+
}
18141816
}
1815-
d->reactions = reactions;
18161817
}
18171818

18181819
return true;

src/xmpp/xmpp-im/xmpp_message.h

+7-2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ class Message {
6868
QString id;
6969
};
7070

71+
struct Reactions {
72+
QString targetId;
73+
QStringList reactions;
74+
};
75+
7176
Message();
7277
Message(const Jid &to);
7378
Message(const Message &from);
@@ -223,8 +228,8 @@ class Message {
223228
void setReferences(const QList<Reference> &r);
224229

225230
// XEP-0444 message reaction
226-
void setReactions(const QStringList &reactions);
227-
std::optional<QStringList> reactions() const;
231+
void setReactions(const Reactions &reactions);
232+
Reactions reactions() const;
228233

229234
// Obsolete invitation
230235
QString invite() const;

src/xmpp/xmpp-im/xmpp_vcard4.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ template <> struct Item<Historical> : public ItemBase<Historical> {
145145
operator QString() const
146146
{
147147
return std::visit(
148-
[this](auto const &v) {
148+
[](auto const &v) {
149149
using Tv = std::decay_t<decltype(v)>;
150150
if constexpr (std::is_same_v<Tv, QString>) {
151151
return v;
@@ -158,7 +158,7 @@ template <> struct Item<Historical> : public ItemBase<Historical> {
158158
operator QDate() const
159159
{
160160
return std::visit(
161-
[this](auto const &v) {
161+
[](auto const &v) {
162162
using Tv = std::decay_t<decltype(v)>;
163163
if constexpr (std::is_same_v<Tv, QDate>) {
164164
return v;
@@ -177,7 +177,7 @@ template <> struct Item<UriOrText> : public ItemBase<UriOrText> {
177177
operator QString() const
178178
{
179179
return std::visit(
180-
[this](auto const &v) {
180+
[](auto const &v) {
181181
using Tv = std::decay_t<decltype(v)>;
182182
if constexpr (std::is_same_v<Tv, QString>) {
183183
return v;

0 commit comments

Comments
 (0)