QXmpp Version: 1.11.3
Loading...
Searching...
No Matches
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;
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 Q_DECLARE_FLAGS(Hints, Hint)
127
128 QXmppMessage(const QString &from = QString(), const QString &to = QString(),
129 const QString &body = QString(), const QString &thread = QString());
130
133 ~QXmppMessage() override;
134
137
138 bool isXmppStanza() const override;
139
140 QString body() const;
141 void setBody(const QString &);
142
143 QString e2eeFallbackBody() const;
144 void setE2eeFallbackBody(const QString &fallbackBody);
145
146 QString subject() const;
147 void setSubject(const QString &);
148
149 QString thread() const;
150 void setThread(const QString &);
151
152 QString parentThread() const;
153 void setParentThread(const QString &);
154
155 QXmppMessage::Type type() const;
156 void setType(QXmppMessage::Type);
157
158 // XEP-0066: Out of Band Data
159 QString outOfBandUrl() const;
160 void setOutOfBandUrl(const QString &);
161
162 QVector<QXmppOutOfBandUrl> outOfBandUrls() const;
163 void setOutOfBandUrls(const QVector<QXmppOutOfBandUrl> &urls);
164
165 // XEP-0071: XHTML-IM
166 QString xhtml() const;
167 void setXhtml(const QString &xhtml);
168
169 // XEP-0085: Chat State Notifications
170 QXmppMessage::State state() const;
171 void setState(QXmppMessage::State);
172
173 // XEP-0091: Legacy Delayed Delivery | XEP-0203: Delayed Delivery
174 QDateTime stamp() const;
175 void setStamp(const QDateTime &stamp);
176
177 // XEP-0184: Message Delivery Receipts
178 bool isReceiptRequested() const;
179 void setReceiptRequested(bool requested);
180
181 QString receiptId() const;
182 void setReceiptId(const QString &id);
183
184 // XEP-0224: Attention
185 bool isAttentionRequested() const;
186 void setAttentionRequested(bool requested);
187
188 // XEP-0231: Bits of Binary
189 QXmppBitsOfBinaryDataList bitsOfBinaryData() const;
190 QXmppBitsOfBinaryDataList &bitsOfBinaryData();
191 void setBitsOfBinaryData(const QXmppBitsOfBinaryDataList &bitsOfBinaryData);
192
193 // XEP-0245: The /me Command
194 static bool isSlashMeCommand(const QString &body);
195 bool isSlashMeCommand() const;
196 static QString slashMeCommandText(const QString &body);
197 QString slashMeCommandText() const;
198
199 // XEP-0249: Direct MUC Invitations
200 QString mucInvitationJid() const;
201 void setMucInvitationJid(const QString &jid);
202
203 QString mucInvitationPassword() const;
204 void setMucInvitationPassword(const QString &password);
205
206 QString mucInvitationReason() const;
207 void setMucInvitationReason(const QString &reason);
208
209 // XEP-0280: Message Carbons
210 bool isPrivate() const;
211 void setPrivate(const bool);
212 bool isCarbonForwarded() const;
213 void setCarbonForwarded(bool);
214
215 // XEP-0308: Last Message Correction
216 QString replaceId() const;
217 void setReplaceId(const QString &);
218
219 // XEP-0333: Chat State Markers
220 bool isMarkable() const;
221 void setMarkable(const bool);
222
223 QString markedId() const;
224 void setMarkerId(const QString &);
225
226 QString markedThread() const;
227 void setMarkedThread(const QString &);
228
229 Marker marker() const;
230 void setMarker(const Marker);
231
232 // XEP-0334: Message Processing Hints
233 bool hasHint(const Hint hint) const;
234 void addHint(const Hint hint);
235 void removeHint(const Hint hint);
236 void removeAllHints();
237
238 // XEP-0353: Jingle Message Initiation
239 std::optional<QXmppJingleMessageInitiationElement> jingleMessageInitiationElement() const;
240 void setJingleMessageInitiationElement(const std::optional<QXmppJingleMessageInitiationElement> &jingleMessageInitiationElement);
241
242 // XEP-0359: Unique and Stable Stanza IDs
243#if QXMPP_DEPRECATED_SINCE(1, 8)
244 [[deprecated("Use stanzaIds() instead.")]]
245 QString stanzaId() const;
246 [[deprecated("Use setStanzaIds() instead.")]]
247 void setStanzaId(const QString &id);
248
249 [[deprecated("Use stanzaIds() instead.")]]
250 QString stanzaIdBy() const;
251 [[deprecated("Use setStanzaIds() instead.")]]
252 void setStanzaIdBy(const QString &id);
253#endif
254
255 QVector<QXmppStanzaId> stanzaIds() const;
256 void setStanzaIds(const QVector<QXmppStanzaId> &);
257
258 QString originId() const;
259 void setOriginId(const QString &id);
260
261 // XEP-0367: Message Attaching
262 QString attachId() const;
263 void setAttachId(const QString &);
264
265 // XEP-0369: Mediated Information eXchange (MIX)
266 QString mixParticipantId() const;
267
268 QString mixUserJid() const;
269 void setMixUserJid(const QString &);
270
271 QString mixUserNick() const;
272 void setMixUserNick(const QString &);
273
274 // XEP-0380: Explicit Message Encryption
275 QXmpp::EncryptionMethod encryptionMethod() const;
276 void setEncryptionMethod(QXmpp::EncryptionMethod);
277 QString encryptionMethodNs() const;
278 void setEncryptionMethodNs(const QString &);
279
280 QString encryptionName() const;
281 void setEncryptionName(const QString &);
282
283 // XEP-0382: Spoiler messages
284 bool isSpoiler() const;
285 void setIsSpoiler(bool);
286
287 QString spoilerHint() const;
288 void setSpoilerHint(const QString &);
289
290 // XEP-0407: Mediated Information eXchange (MIX): Miscellaneous Capabilities
291 std::optional<QXmppMixInvitation> mixInvitation() const;
292 void setMixInvitation(const std::optional<QXmppMixInvitation> &mixInvitation);
293
294 // XEP-0428: Fallback Indication
295#if QXMPP_DEPRECATED_SINCE(1, 7)
296 [[deprecated("Use fallbackMarkers()")]]
297 bool isFallback() const;
298 [[deprecated("Use setFallbackMarkers()")]]
299 void setIsFallback(bool isFallback);
300#endif
301 const QVector<QXmppFallback> &fallbackMarkers() const;
302 void setFallbackMarkers(const QVector<QXmppFallback> &);
303 QString readFallbackRemovedText(QXmppFallback::Element element, const QVector<QString> &supportedNamespaces) const;
304 QString readFallbackText(QXmppFallback::Element element, QStringView forNamespace) const;
305
306 // XEP-0434: Trust Messages (TM)
307 std::optional<QXmppTrustMessageElement> trustMessageElement() const;
308 void setTrustMessageElement(const std::optional<QXmppTrustMessageElement> &trustMessageElement);
309
310 // XEP-0444: Message Reactions
311 std::optional<QXmppMessageReaction> reaction() const;
312 void setReaction(const std::optional<QXmppMessageReaction> &reaction);
313
314 // XEP-0447: Stateless file sharing
315 const QVector<QXmppFileShare> &sharedFiles() const;
316 void setSharedFiles(const QVector<QXmppFileShare> &sharedFiles);
317 QVector<QXmppFileSourcesAttachment> fileSourcesAttachments() const;
318 void setFileSourcesAttachments(const QVector<QXmppFileSourcesAttachment> &);
319
320 // XEP-0461: Message Replies
321 std::optional<QXmpp::Reply> reply() const;
322 void setReply(const std::optional<QXmpp::Reply> &);
323 QString readReplyQuoteFromBody() const;
324
325 // XEP-0482: Call Invites
326 std::optional<QXmppCallInviteElement> callInviteElement() const;
327 void setCallInviteElement(std::optional<QXmppCallInviteElement> callInviteElement);
328
330#ifdef BUILD_OMEMO
331 // XEP-0384: OMEMO Encryption
332 std::optional<QXmppOmemoElement> omemoElement() const;
333 void setOmemoElement(const std::optional<QXmppOmemoElement> &omemoElement);
334#endif
335
336 void parse(const QDomElement &element) override final;
337 virtual void parse(const QDomElement &element, QXmpp::SceMode);
338 void toXml(QXmlStreamWriter *writer) const override final;
339 virtual void toXml(QXmlStreamWriter *writer, QXmpp::SceMode) const;
341
342 void parseExtensions(const QDomElement &element, QXmpp::SceMode sceMode);
343 virtual bool parseExtension(const QDomElement &element, QXmpp::SceMode);
344 virtual void serializeExtensions(QXmlStreamWriter *writer, QXmpp::SceMode, const QString &baseNamespace = {}) const;
345
346private:
347 QSharedDataPointer<QXmppMessagePrivate> d;
348};
349
350Q_DECLARE_OPERATORS_FOR_FLAGS(QXmppMessage::Hints)
351Q_DECLARE_METATYPE(QXmppMessage)
352
353#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:661
Definition QXmppFallback.h:20
Element
Definition QXmppFallback.h:22
The QXmppJingleMessageInitiationElement class represents a Jingle Message Initiation element as speci...
Definition QXmppJingleData.h:616
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:21
The Error class represents a stanza error.
Definition QXmppStanza.h:96
The QXmppStanza class is the base class for all XMPP stanzas.
Definition QXmppStanza.h:90
The QXmppTrustMessageElement class represents a trust message element as defined by XEP-0434: Trust M...
Definition QXmppTrustMessageElement.h:19
QXmppMixInvitation()
The QXmppMixInvitation class is used to invite a user to a XEP-0369: Mediated Information eXchange (M...
Definition QXmppMixInvitation.cpp:40
Definition Algorithms.h:14
SceMode
Definition QXmppGlobal.h:144
EncryptionMethod
Definition QXmppGlobal.h:97
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