Skip to content

Commit

Permalink
Added missed id to reactions
Browse files Browse the repository at this point in the history
  • Loading branch information
Ri0n committed Jun 18, 2024
1 parent 0318b53 commit 372e7a3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
27 changes: 14 additions & 13 deletions src/xmpp/xmpp-im/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -749,8 +749,7 @@ class Message::Private : public QSharedData {
QString encryptionProtocol; // XEP-0380
Message::StanzaId stanzaId; // XEP-0359
QList<Reference> references; // XEP-0385 and XEP-0372

std::optional<QStringList> reactions; // XEP-0444
Message::Reactions reactions; // XEP-0444
};

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

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

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

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

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

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

// XEP-0444
auto reactionsNS = QStringLiteral("urn:xmpp:reactions:0");
if (d->reactions) {
if (!d->reactions.targetId.isEmpty()) {
auto e = s.createElement(reactionsNS, QStringLiteral("reactions"));
for (const QString &reaction : *d->reactions) {
e.setAttribute(QLatin1String("id"), d->reactions.targetId);
for (const QString &reaction : d->reactions.reactions) {
e.appendChild(s.createTextElement(reactionsNS, QStringLiteral("reaction"), reaction));
}
s.appendChild(e);
Expand Down Expand Up @@ -1805,14 +1805,15 @@ bool Message::fromStanza(const Stanza &s, bool useTimeZoneOffset, int timeZoneOf
auto reactionStanza
= childElementsByTagNameNS(root, "urn:xmpp:reactions:0", QStringLiteral("reactions")).item(0).toElement();
if (!reactionStanza.isNull()) {
auto reactionTag = QStringLiteral("reaction");
QStringList reactions;
auto reaction = reactionStanza.firstChildElement(reactionTag);
while (!reaction.isNull()) {
reactions.append(reaction.text().trimmed());
reaction = reaction.nextSiblingElement(reactionTag);
d->reactions.targetId = reactionStanza.attribute(QLatin1String("id"));
if (!d->reactions.targetId.isEmpty()) {
auto reactionTag = QStringLiteral("reaction");
auto reaction = reactionStanza.firstChildElement(reactionTag);
while (!reaction.isNull()) {
d->reactions.reactions.append(reaction.text().trimmed());
reaction = reaction.nextSiblingElement(reactionTag);
}
}
d->reactions = reactions;
}

return true;
Expand Down
9 changes: 7 additions & 2 deletions src/xmpp/xmpp-im/xmpp_message.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ class Message {
QString id;
};

struct Reactions {
QString targetId;
QStringList reactions;
};

Message();
Message(const Jid &to);
Message(const Message &from);
Expand Down Expand Up @@ -223,8 +228,8 @@ class Message {
void setReferences(const QList<Reference> &r);

// XEP-0444 message reaction
void setReactions(const QStringList &reactions);
std::optional<QStringList> reactions() const;
void setReactions(const Reactions &reactions);
Reactions reactions() const;

// Obsolete invitation
QString invite() const;
Expand Down
6 changes: 3 additions & 3 deletions src/xmpp/xmpp-im/xmpp_vcard4.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ template <> struct Item<Historical> : public ItemBase<Historical> {
operator QString() const
{
return std::visit(
[this](auto const &v) {
[](auto const &v) {
using Tv = std::decay_t<decltype(v)>;
if constexpr (std::is_same_v<Tv, QString>) {
return v;
Expand All @@ -158,7 +158,7 @@ template <> struct Item<Historical> : public ItemBase<Historical> {
operator QDate() const
{
return std::visit(
[this](auto const &v) {
[](auto const &v) {
using Tv = std::decay_t<decltype(v)>;
if constexpr (std::is_same_v<Tv, QDate>) {
return v;
Expand All @@ -177,7 +177,7 @@ template <> struct Item<UriOrText> : public ItemBase<UriOrText> {
operator QString() const
{
return std::visit(
[this](auto const &v) {
[](auto const &v) {
using Tv = std::decay_t<decltype(v)>;
if constexpr (std::is_same_v<Tv, QString>) {
return v;
Expand Down

0 comments on commit 372e7a3

Please sign in to comment.