Skip to content

Commit

Permalink
Added XEP-0424: message retraction support
Browse files Browse the repository at this point in the history
  • Loading branch information
Ri0n committed Jul 3, 2024
1 parent c94e7df commit e50f3d3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/xmpp/xmpp-im/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,7 @@ class Message::Private : public QSharedData {
Message::StanzaId stanzaId; // XEP-0359
QList<Reference> references; // XEP-0385 and XEP-0372
Message::Reactions reactions; // XEP-0444
QString retraction; // XEP-0424
};

#define MessageD() (d ? d : (d = new Private))
Expand Down Expand Up @@ -1103,6 +1104,10 @@ void Message::setReactions(const XMPP::Message::Reactions &reactions) { MessageD

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

void Message::setRetraction(const QString &retractedMessageId) { MessageD()->retraction = retractedMessageId; }

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

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

void Message::setInvite(const QString &s) { MessageD()->invite = s; }
Expand Down Expand Up @@ -1452,6 +1457,14 @@ Stanza Message::toStanza(Stream *stream) const
s.appendChild(s.createElement(QStringLiteral("urn:xmpp:hints"), QStringLiteral("store")));
}

// XEP-0424
if (!d->retraction.isEmpty()) {
auto e = s.createElement("urn:xmpp:message-retract:1", QStringLiteral("retract"));
e.setAttribute(QLatin1String("id"), d->retraction);
s.appendChild(e);
s.appendChild(s.createElement(QStringLiteral("urn:xmpp:hints"), QStringLiteral("store")));
}

return s;
}

Expand Down Expand Up @@ -1820,6 +1833,11 @@ bool Message::fromStanza(const Stanza &s, bool useTimeZoneOffset, int timeZoneOf
}
}

// XEP-0424 message retraction
d->retraction = childElementsByTagNameNS(root, "urn:xmpp:message-retract:1", QStringLiteral("retract"))
.item(0)
.toElement()
.attribute(QLatin1String("id"));
return true;
}

Expand Down
3 changes: 3 additions & 0 deletions src/xmpp/xmpp-im/xmpp_message.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ class Message {
void setReactions(const Reactions &reactions);
Reactions reactions() const;

void setRetraction(const QString &retractedMessageId);
QString retraction() const;

// Obsolete invitation
QString invite() const;
void setInvite(const QString &s);
Expand Down

0 comments on commit e50f3d3

Please sign in to comment.