QXmpp Version: 1.10.0
QXmppMessage.h
1// SPDX-FileCopyrightText: 2009 Manjeet Dahiya <manjeetdahiya@gmail.com>
2// SPDX-FileCopyrightText: 2010 Jeremy Lainé <jeremy.laine@m4x.org>
3// SPDX-FileCopyrightText: 2018 Linus Jahn <lnj@kaidan.im>
4// SPDX-FileCopyrightText: 2020 Melvin Keskin <melvo@olomono.de>
5// SPDX-FileCopyrightText: 2023 Tibor Csötönyi <work@taibsu.de>
6//
7// SPDX-License-Identifier: LGPL-2.1-or-later
8
9#ifndef QXMPPMESSAGE_H
10#define QXMPPMESSAGE_H
11
12#include "QXmppFallback.h"
13#include "QXmppFileShare.h"
14#include "QXmppStanza.h"
15
16#include <optional>
17
18// Required for source compatibility
19#include <QDateTime>
20
21class QXmppMessagePrivate;
23class QXmppFallback;
26class QXmppMixInvitation;
27#ifdef BUILD_OMEMO
28class QXmppOmemoElement;
29#endif
33
34namespace QXmpp {
35
41struct Reply {
44 QString to;
46 QString id;
47};
48
49} // namespace QXmpp
50
53 QString id;
55 QString by;
56};
57
63class QXMPP_EXPORT QXmppMessage : public QXmppStanza
64{
65public:
66#if QXMPP_DEPRECATED_SINCE(1, 5)
68 using EncryptionMethod = QXmpp::EncryptionMethod;
69
70 static const EncryptionMethod NoEncryption = EncryptionMethod::NoEncryption;
71 static const EncryptionMethod UnknownEncryption = EncryptionMethod::UnknownEncryption;
72 static const EncryptionMethod OTR = EncryptionMethod::Otr;
73 static const EncryptionMethod LegacyOpenPGP = EncryptionMethod::LegacyOpenPgp;
74 static const EncryptionMethod OX = EncryptionMethod::Ox;
75 static const EncryptionMethod OMEMO = EncryptionMethod::Omemo0;
77#endif
78
80 enum Type {
81 Error = 0,
82 Normal,
83 Chat,
84 GroupChat,
85 Headline
86 };
87
94 enum State {
95 None = 0,
100 Paused
101 };
102
108 enum Marker {
109 NoMarker = 0,
110 Received,
111 Displayed,
112 Acknowledged
113 };
114
120 enum Hint {
121 NoPermanentStore = 1 << 0,
122 NoStore = 1 << 1,
123 NoCopy = 1 << 2,
124 Store = 1 << 3
125 };
126
127 QXmppMessage(const QString &from = QString(), const QString &to = QString(),
128 const QString &body = QString(), const QString &thread = QString());
129
132 ~QXmppMessage() override;
133
136
137 bool isXmppStanza() const override;
138
139 QString body() const;
140 void setBody(const QString &);
141
142 QString e2eeFallbackBody() const;
143 void setE2eeFallbackBody(const QString &fallbackBody);
144
145 QString subject() const;
146 void setSubject(const QString &);
147
148 QString thread() const;
149 void setThread(const QString &);
150
151 QString parentThread() const;
152 void setParentThread(const QString &);
153
154 QXmppMessage::Type type() const;
155 void setType(QXmppMessage::Type);
156
157 // XEP-0066: Out of Band Data
158 QString outOfBandUrl() const;
159 void setOutOfBandUrl(const QString &);
160
161 QVector<QXmppOutOfBandUrl> outOfBandUrls() const;
162 void setOutOfBandUrls(const QVector<QXmppOutOfBandUrl> &urls);
163
164 // XEP-0071: XHTML-IM
165 QString xhtml() const;
166 void setXhtml(const QString &xhtml);
167
168 // XEP-0085: Chat State Notifications
169 QXmppMessage::State state() const;
170 void setState(QXmppMessage::State);
171
172 // XEP-0091: Legacy Delayed Delivery | XEP-0203: Delayed Delivery
173 QDateTime stamp() const;
174 void setStamp(const QDateTime &stamp);
175
176 // XEP-0184: Message Delivery Receipts
177 bool isReceiptRequested() const;
178 void setReceiptRequested(bool requested);
179
180 QString receiptId() const;
181 void setReceiptId(const QString &id);
182
183 // XEP-0224: Attention
184 bool isAttentionRequested() const;
185 void setAttentionRequested(bool requested);
186
187 // XEP-0231: Bits of Binary
188 QXmppBitsOfBinaryDataList bitsOfBinaryData() const;
189 QXmppBitsOfBinaryDataList &bitsOfBinaryData();
190 void setBitsOfBinaryData(const QXmppBitsOfBinaryDataList &bitsOfBinaryData);
191
192 // XEP-0245: The /me Command
193 static bool isSlashMeCommand(const QString &body);
194 bool isSlashMeCommand() const;
195 static QString slashMeCommandText(const QString &body);
196 QString slashMeCommandText() const;
197
198 // XEP-0249: Direct MUC Invitations
199 QString mucInvitationJid() const;
200 void setMucInvitationJid(const QString &jid);
201
202 QString mucInvitationPassword() const;
203 void setMucInvitationPassword(const QString &password);
204
205 QString mucInvitationReason() const;
206 void setMucInvitationReason(const QString &reason);
207
208 // XEP-0280: Message Carbons
209 bool isPrivate() const;
210 void setPrivate(const bool);
211 bool isCarbonForwarded() const;
212 void setCarbonForwarded(bool);
213
214 // XEP-0308: Last Message Correction
215 QString replaceId() const;
216 void setReplaceId(const QString &);
217
218 // XEP-0333: Chat State Markers
219 bool isMarkable() const;
220 void setMarkable(const bool);
221
222 QString markedId() const;
223 void setMarkerId(const QString &);
224
225 QString markedThread() const;
226 void setMarkedThread(const QString &);
227
228 Marker marker() const;
229 void setMarker(const Marker);
230
231 // XEP-0334: Message Processing Hints
232 bool hasHint(const Hint hint) const;
233 void addHint(const Hint hint);
234 void removeHint(const Hint hint);
235 void removeAllHints();
236
237 // XEP-0353: Jingle Message Initiation
238 std::optional<QXmppJingleMessageInitiationElement> jingleMessageInitiationElement() const;
239 void setJingleMessageInitiationElement(const std::optional<QXmppJingleMessageInitiationElement> &jingleMessageInitiationElement);
240
241 // XEP-0359: Unique and Stable Stanza IDs
242#if QXMPP_DEPRECATED_SINCE(1, 8)
243 [[deprecated("Use stanzaIds() instead.")]]
244 QString stanzaId() const;
245 [[deprecated("Use setStanzaIds() instead.")]]
246 void setStanzaId(const QString &id);
247
248 [[deprecated("Use stanzaIds() instead.")]]
249 QString stanzaIdBy() const;
250 [[deprecated("Use setStanzaIds() instead.")]]
251 void setStanzaIdBy(const QString &id);
252#endif
253
254 QVector<QXmppStanzaId> stanzaIds() const;
255 void setStanzaIds(const QVector<QXmppStanzaId> &);
256
257 QString originId() const;
258 void setOriginId(const QString &id);
259
260 // XEP-0367: Message Attaching
261 QString attachId() const;
262 void setAttachId(const QString &);
263
264 // XEP-0369: Mediated Information eXchange (MIX)
265 QString mixParticipantId() const;
266
267 QString mixUserJid() const;
268 void setMixUserJid(const QString &);
269
270 QString mixUserNick() const;
271 void setMixUserNick(const QString &);
272
273 // XEP-0380: Explicit Message Encryption
274 QXmpp::EncryptionMethod encryptionMethod() const;
275 void setEncryptionMethod(QXmpp::EncryptionMethod);
276 QString encryptionMethodNs() const;
277 void setEncryptionMethodNs(const QString &);
278
279 QString encryptionName() const;
280 void setEncryptionName(const QString &);
281
282 // XEP-0382: Spoiler messages
283 bool isSpoiler() const;
284 void setIsSpoiler(bool);
285
286 QString spoilerHint() const;
287 void setSpoilerHint(const QString &);
288
289 // XEP-0407: Mediated Information eXchange (MIX): Miscellaneous Capabilities
290 std::optional<QXmppMixInvitation> mixInvitation() const;
291 void setMixInvitation(const std::optional<QXmppMixInvitation> &mixInvitation);
292
293 // XEP-0428: Fallback Indication
294#if QXMPP_DEPRECATED_SINCE(1, 7)
295 [[deprecated("Use fallbackMarkers()")]] bool isFallback() const;
296 [[deprecated("Use setFallbackMarkers()")]] void setIsFallback(bool isFallback);
297#endif
298 const QVector<QXmppFallback> &fallbackMarkers() const;
299 void setFallbackMarkers(const QVector<QXmppFallback> &);
300 QString readFallbackRemovedText(QXmppFallback::Element element, const QVector<QString> &supportedNamespaces) const;
301 QString readFallbackText(QXmppFallback::Element element, QStringView forNamespace) const;
302
303 // XEP-0434: Trust Messages (TM)
304 std::optional<QXmppTrustMessageElement> trustMessageElement() const;
305 void setTrustMessageElement(const std::optional<QXmppTrustMessageElement> &trustMessageElement);
306
307 // XEP-0444: Message Reactions
308 std::optional<QXmppMessageReaction> reaction() const;
309 void setReaction(const std::optional<QXmppMessageReaction> &reaction);
310
311 // XEP-0447: Stateless file sharing
312 const QVector<QXmppFileShare> &sharedFiles() const;
313 void setSharedFiles(const QVector<QXmppFileShare> &sharedFiles);
314 QVector<QXmppFileSourcesAttachment> fileSourcesAttachments() const;
315 void setFileSourcesAttachments(const QVector<QXmppFileSourcesAttachment> &);
316
317 // XEP-0461: Message Replies
318 std::optional<QXmpp::Reply> reply() const;
319 void setReply(const std::optional<QXmpp::Reply> &);
320 QString readReplyQuoteFromBody() const;
321
322 // XEP-0482: Call Invites
323 std::optional<QXmppCallInviteElement> callInviteElement() const;
324 void setCallInviteElement(std::optional<QXmppCallInviteElement> callInviteElement);
325
327#ifdef BUILD_OMEMO
328 // XEP-0384: OMEMO Encryption
329 std::optional<QXmppOmemoElement> omemoElement() const;
330 void setOmemoElement(const std::optional<QXmppOmemoElement> &omemoElement);
331#endif
332
333 void parse(const QDomElement &element) override final;
334 virtual void parse(const QDomElement &element, QXmpp::SceMode);
335 void toXml(QXmlStreamWriter *writer) const override final;
336 virtual void toXml(QXmlStreamWriter *writer, QXmpp::SceMode) const;
338
339 void parseExtensions(const QDomElement &element, QXmpp::SceMode sceMode);
340 virtual bool parseExtension(const QDomElement &element, QXmpp::SceMode);
341 virtual void serializeExtensions(QXmlStreamWriter *writer, QXmpp::SceMode, const QString &baseNamespace = {}) const;
342
343private:
344 QSharedDataPointer<QXmppMessagePrivate> d;
345};
346
347Q_DECLARE_METATYPE(QXmppMessage)
348
349#endif // QXMPPMESSAGE_H
Definition: QXmppBitsOfBinaryDataList.h:16
The QXmppCallInviteElement class represents a Call Invite element as specified by XEP-0482: Call Invi...
Definition: QXmppJingleData.h:649
Definition: QXmppFallback.h:20
Element
Definition: QXmppFallback.h:22
The QXmppJingleMessageInitiationElement class represents a Jingle Message Initiation element as speci...
Definition: QXmppJingleData.h:602
The QXmppMessageReaction class represents a reaction to a message in the form of emojis as specified ...
Definition: QXmppMessageReaction.h:17
The QXmppMessage class represents an XMPP message.
Definition: QXmppMessage.h:64
QXmppMessage & operator=(QXmppMessage &&)
Move-assignment operator.
QXmppMessage & operator=(const QXmppMessage &other)
Assignment operator.
Type
This enum describes a message type.
Definition: QXmppMessage.h:80
QXmppMessage(QXmppMessage &&)
Move-constructor.
Marker
Definition: QXmppMessage.h:108
Hint
Definition: QXmppMessage.h:120
State
Definition: QXmppMessage.h:94
@ Active
User is actively participating in the chat session.
Definition: QXmppMessage.h:96
@ Inactive
User has not been actively participating in the chat session.
Definition: QXmppMessage.h:97
@ Composing
User is composing a message.
Definition: QXmppMessage.h:99
@ Gone
User has effectively ended their participation in the chat session.
Definition: QXmppMessage.h:98
QXmppMessage(const QXmppMessage &other)
Constructs a copy of other.
virtual void parse(const QDomElement &)=0
virtual bool isXmppStanza() const
Definition: QXmppNonza.h:19
virtual void toXml(QXmlStreamWriter *writer) const =0
Definition: QXmppOutOfBandUrl.h:19
The Error class represents a stanza error.
Definition: QXmppStanza.h:94
The QXmppStanza class is the base class for all XMPP stanzas.
Definition: QXmppStanza.h:88
The QXmppTrustMessageElement class represents a trust message element as defined by XEP-0434: Trust M...
Definition: QXmppTrustMessageElement.h:18
Definition: Algorithms.h:12
SceMode
Definition: QXmppGlobal.h:136
EncryptionMethod
Definition: QXmppGlobal.h:89
Stanza ID element as defined in XEP-0359: Unique and Stable Stanza IDs.
Definition: QXmppMessage.h:51
QString by
JID of the generating entity.
Definition: QXmppMessage.h:55
QString id
Identifier of the stanza element.
Definition: QXmppMessage.h:53
Definition: QXmppMessage.h:41
QString to
Definition: QXmppMessage.h:44
QString id
ID of the referenced message.
Definition: QXmppMessage.h:46