diff options
| author | Linus Jahn <lnj@kaidan.im> | 2020-04-06 14:30:48 +0200 |
|---|---|---|
| committer | LNJ <lnj@kaidan.im> | 2020-04-06 15:57:01 +0200 |
| commit | e336f2a2eba0f5c7f02054532442e9119d4c82e7 (patch) | |
| tree | 03e0f9298bc4bd171a812030b960f8e02d509600 /src/base | |
| parent | ca6b557101ad860acf08b994851f216567f03e6d (diff) | |
| download | qxmpp-e336f2a2eba0f5c7f02054532442e9119d4c82e7.tar.gz | |
Clean up QXmppMessage
Diffstat (limited to 'src/base')
| -rw-r--r-- | src/base/QXmppMessage.cpp | 702 | ||||
| -rw-r--r-- | src/base/QXmppMessage.h | 95 |
2 files changed, 467 insertions, 330 deletions
diff --git a/src/base/QXmppMessage.cpp b/src/base/QXmppMessage.cpp index 743e1dc6..a66a6743 100644 --- a/src/base/QXmppMessage.cpp +++ b/src/base/QXmppMessage.cpp @@ -98,47 +98,52 @@ class QXmppMessagePrivate : public QSharedData public: QXmppMessagePrivate(); - QXmppMessage::Type type; - QDateTime stamp; - StampType stampType; - QXmppMessage::State state; - - bool attentionRequested; QString body; QString subject; QString thread; QString parentThread; + QXmppMessage::Type type; + + // XEP-0066: Out of Band Data + QString outOfBandUrl; // XEP-0071: XHTML-IM QString xhtml; - // Request message receipt as per XEP-0184. + // XEP-0085: Chat State Notifications + QXmppMessage::State state; + + // XEP-0091: Legacy Delayed Delivery | XEP-0203: Delayed Delivery + QDateTime stamp; + StampType stampType; + + // XEP-0184: Message Delivery Receipts QString receiptId; bool receiptRequested; + // XEP-0224: Attention + bool attentionRequested; + + // XEP-0231: Bits of Binary + QXmppBitsOfBinaryDataList bitsOfBinaryData; + // XEP-0249: Direct MUC Invitations QString mucInvitationJid; QString mucInvitationPassword; QString mucInvitationReason; - // XEP-0333: Chat Markers - bool markable; - QXmppMessage::Marker marker; - QString markedId; - QString markedThread; - - // XEP-0231: Bits of Binary - QXmppBitsOfBinaryDataList bitsOfBinaryData; - // XEP-0280: Message Carbons bool privatemsg; - // XEP-0066: Out of Band Data - QString outOfBandUrl; - // XEP-0308: Last Message Correction QString replaceId; + // XEP-0333: Chat Markers + bool markable; + QXmppMessage::Marker marker; + QString markedId; + QString markedThread; + // XEP-0334: Message Processing Hints quint8 hints; @@ -168,13 +173,13 @@ public: QXmppMessagePrivate::QXmppMessagePrivate() : type(QXmppMessage::Normal), - stampType(DelayedDelivery), state(QXmppMessage::None), - attentionRequested(false), + stampType(DelayedDelivery), receiptRequested(false), + attentionRequested(false), + privatemsg(false), markable(false), marker(QXmppMessage::NoMarker), - privatemsg(false), hints(0), isSpoiler(false), isFallback(false) @@ -230,108 +235,6 @@ void QXmppMessage::setBody(const QString &body) d->body = body; } -/// Returns true if the user's attention is requested, as defined -/// by \xep{0224}: Attention. - -bool QXmppMessage::isAttentionRequested() const -{ - return d->attentionRequested; -} - -/// Sets whether the user's attention is requested, as defined -/// by \xep{0224}: Attention. -/// -/// \a param requested - -void QXmppMessage::setAttentionRequested(bool requested) -{ - d->attentionRequested = requested; -} - -/// Returns true if a delivery receipt is requested, as defined -/// by \xep{0184}: Message Delivery Receipts. - -bool QXmppMessage::isReceiptRequested() const -{ - return d->receiptRequested; -} - -/// Sets whether a delivery receipt is requested, as defined -/// by \xep{0184}: Message Delivery Receipts. -/// -/// \a param requested - -void QXmppMessage::setReceiptRequested(bool requested) -{ - d->receiptRequested = requested; - if (requested && id().isEmpty()) - generateAndSetNextId(); -} - -/// If this message is a delivery receipt, returns the ID of the -/// original message. - -QString QXmppMessage::receiptId() const -{ - return d->receiptId; -} - -/// Make this message a delivery receipt for the message with -/// the given \a id. - -void QXmppMessage::setReceiptId(const QString &id) -{ - d->receiptId = id; -} - -/// Returns the JID for a multi-user chat direct invitation as defined -/// by \xep{0249}: Direct MUC Invitations. - -QString QXmppMessage::mucInvitationJid() const -{ - return d->mucInvitationJid; -} - -/// Sets the JID for a multi-user chat direct invitation as defined -/// by \xep{0249}: Direct MUC Invitations. - -void QXmppMessage::setMucInvitationJid(const QString &jid) -{ - d->mucInvitationJid = jid; -} - -/// Returns the password for a multi-user chat direct invitation as defined -/// by \xep{0249}: Direct MUC Invitations. - -QString QXmppMessage::mucInvitationPassword() const -{ - return d->mucInvitationPassword; -} - -/// Sets the \a password for a multi-user chat direct invitation as defined -/// by \xep{0249}: Direct MUC Invitations. - -void QXmppMessage::setMucInvitationPassword(const QString &password) -{ - d->mucInvitationPassword = password; -} - -/// Returns the reason for a multi-user chat direct invitation as defined -/// by \xep{0249}: Direct MUC Invitations. - -QString QXmppMessage::mucInvitationReason() const -{ - return d->mucInvitationReason; -} - -/// Sets the \a reason for a multi-user chat direct invitation as defined -/// by \xep{0249}: Direct MUC Invitations. - -void QXmppMessage::setMucInvitationReason(const QString &reason) -{ - d->mucInvitationReason = reason; -} - /// Returns the message's type. QXmppMessage::Type QXmppMessage::type() const @@ -348,39 +251,6 @@ void QXmppMessage::setType(QXmppMessage::Type type) d->type = type; } -/// Returns the message's timestamp (if any). - -QDateTime QXmppMessage::stamp() const -{ - return d->stamp; -} - -/// Sets the message's timestamp. -/// -/// \param stamp - -void QXmppMessage::setStamp(const QDateTime &stamp) -{ - d->stamp = stamp; -} - -/// Returns the message's chat state. -/// - -QXmppMessage::State QXmppMessage::state() const -{ - return d->state; -} - -/// Sets the message's chat state. -/// -/// \param state - -void QXmppMessage::setState(QXmppMessage::State state) -{ - d->state = state; -} - /// Returns the message's subject. QString QXmppMessage::subject() const @@ -437,112 +307,191 @@ void QXmppMessage::setParentThread(const QString &parent) d->parentThread = parent; } -/// Returns the message's XHTML body as defined by -/// \xep{0071}: XHTML-IM. +/// +/// Returns a possibly attached URL from \xep{0066}: Out of Band Data +/// +/// \since QXmpp 1.0 +/// +QString QXmppMessage::outOfBandUrl() const +{ + return d->outOfBandUrl; +} + +/// +/// Sets the attached URL for \xep{0066}: Out of Band Data +/// +/// \since QXmpp 1.0 +/// +void QXmppMessage::setOutOfBandUrl(const QString &url) +{ + d->outOfBandUrl = url; +} +/// +/// Returns the message's XHTML body as defined by \xep{0071}: XHTML-IM. +/// +/// \since QXmpp 0.6.2 +/// QString QXmppMessage::xhtml() const { return d->xhtml; } -/// Sets the message's XHTML body as defined by -/// \xep{0071}: XHTML-IM. - +/// +/// Sets the message's XHTML body as defined by \xep{0071}: XHTML-IM. +/// +/// \since QXmpp 0.6.2 +/// void QXmppMessage::setXhtml(const QString &xhtml) { d->xhtml = xhtml; } -/// Returns true if a message is markable, as defined -/// \xep{0333}: Chat Markers. - -bool QXmppMessage::isMarkable() const +/// +/// Returns the the chat state notification according to \xep{0085}: Chat State +/// Notifications. +/// +/// \since QXmpp 0.2 +/// +QXmppMessage::State QXmppMessage::state() const { - return d->markable; + return d->state; } -/// Sets if the message is markable, as defined -/// \xep{0333}: Chat Markers. - -void QXmppMessage::setMarkable(const bool markable) +/// +/// Sets the the chat state notification according to \xep{0085}: Chat State +/// Notifications. +/// +/// \since QXmpp 0.2 +/// +void QXmppMessage::setState(QXmppMessage::State state) { - d->markable = markable; + d->state = state; } -/// Returns the message's marker id, as defined -/// \xep{0333}: Chat Markers. - -QString QXmppMessage::markedId() const +/// +/// Returns the optional timestamp of the message specified using \xep{0093}: +/// Legacy Delayed Delivery or using \xep{0203}: Delayed Delivery (preferred). +/// +/// \since QXmpp 0.2 +/// +QDateTime QXmppMessage::stamp() const { - return d->markedId; + return d->stamp; } -/// Sets the message's marker id, as defined -/// \xep{0333}: Chat Markers. - -void QXmppMessage::setMarkerId(const QString &markerId) +/// +/// Sets the message's timestamp without modifying the type of the stamp +/// (\xep{0093}: Legacy Delayed Delivery or \xep{0203}: Delayed Delivery). +/// +/// By default messages are constructed with the new delayed delivery XEP, but +/// parsed messages keep their type. +/// +/// \since QXmpp 0.2 +/// +void QXmppMessage::setStamp(const QDateTime &stamp) { - d->markedId = markerId; + d->stamp = stamp; } -/// Returns the message's marker thread, as defined -/// \xep{0333}: Chat Markers. - -QString QXmppMessage::markedThread() const +/// +/// Returns true if a delivery receipt is requested, as defined by \xep{0184}: +/// Message Delivery Receipts. +/// +/// \since QXmpp 0.4 +/// +bool QXmppMessage::isReceiptRequested() const { - return d->markedThread; + return d->receiptRequested; } -/// Sets the message's marked thread, as defined -/// \xep{0333}: Chat Markers. - -void QXmppMessage::setMarkedThread(const QString &markedThread) +/// +/// Sets whether a delivery receipt is requested, as defined by \xep{0184}: +/// Message Delivery Receipts. +/// +/// \since QXmpp 0.4 +/// +void QXmppMessage::setReceiptRequested(bool requested) { - d->markedThread = markedThread; + d->receiptRequested = requested; + if (requested && id().isEmpty()) + generateAndSetNextId(); } -/// Returns the message's marker, as defined -/// \xep{0333}: Chat Markers. +/// +/// If this message is a delivery receipt, returns the ID of the original +/// message. +/// +/// \since QXmpp 0.4 +/// +QString QXmppMessage::receiptId() const +{ + return d->receiptId; +} -QXmppMessage::Marker QXmppMessage::marker() const +/// +/// Make this message a delivery receipt for the message with the given \a id. +/// +/// \since QXmpp 0.4 +/// +void QXmppMessage::setReceiptId(const QString &id) { - return d->marker; + d->receiptId = id; } -/// Sets the message's marker, as defined -/// \xep{0333}: Chat Markers +/// +/// Returns true if the user's attention is requested, as defined by \xep{0224}: +/// Attention. +/// +/// \since QXmpp 0.4 +/// +bool QXmppMessage::isAttentionRequested() const +{ + return d->attentionRequested; +} -void QXmppMessage::setMarker(const Marker marker) +/// +/// Sets whether the user's attention is requested, as defined by \xep{0224}: +/// Attention. +/// +/// \param requested Whether to request attention (true) or not (false) +/// +/// \since QXmpp 0.4 +/// +void QXmppMessage::setAttentionRequested(bool requested) { - d->marker = marker; + d->attentionRequested = requested; } +/// /// Returns a list of data packages attached using \xep{0231}: Bits of Binary. /// /// This could be used to resolve \c cid: URIs found in the X-HTML body. /// /// \since QXmpp 1.2 - +/// QXmppBitsOfBinaryDataList QXmppMessage::bitsOfBinaryData() const { return d->bitsOfBinaryData; } +/// /// Returns a list of data attached using \xep{0231}: Bits of Binary. /// /// This could be used to resolve \c cid: URIs found in the X-HTML body. /// /// \since QXmpp 1.2 - +/// QXmppBitsOfBinaryDataList &QXmppMessage::bitsOfBinaryData() { return d->bitsOfBinaryData; } +/// /// Sets a list of \xep{0231}: Bits of Binary attachments to be included. /// /// \since QXmpp 1.2 - +/// void QXmppMessage::setBitsOfBinaryData(const QXmppBitsOfBinaryDataList &bitsOfBinaryData) { d->bitsOfBinaryData = bitsOfBinaryData; @@ -608,90 +557,239 @@ QString QXmppMessage::slashMeCommandText() const return slashMeCommandText(d->body); } -/// Returns if the message is marked with a <private> tag, -/// in which case it will not be forwarded to other resources -/// according to \xep{0280}: Message Carbons. +/// +/// Returns the JID for a multi-user chat direct invitation as defined by +/// \xep{0249}: Direct MUC Invitations. +/// +/// \since QXmpp 0.7.4 +/// +QString QXmppMessage::mucInvitationJid() const +{ + return d->mucInvitationJid; +} -bool QXmppMessage::isPrivate() const +/// +/// Sets the JID for a multi-user chat direct invitation as defined by +/// \xep{0249}: Direct MUC Invitations. +/// +/// \since QXmpp 0.7.4 +/// +void QXmppMessage::setMucInvitationJid(const QString &jid) { - return d->privatemsg; + d->mucInvitationJid = jid; } -/// If true is passed, the message is marked with a <private> tag, -/// in which case it will not be forwarded to other resources -/// according to \xep{0280}: Message Carbons. +/// +/// Returns the password for a multi-user chat direct invitation as defined by +/// \xep{0249}: Direct MUC Invitations. +/// +/// \since QXmpp 0.7.4 +/// +QString QXmppMessage::mucInvitationPassword() const +{ + return d->mucInvitationPassword; +} -void QXmppMessage::setPrivate(const bool priv) +/// +/// Sets the \a password for a multi-user chat direct invitation as defined by +/// \xep{0249}: Direct MUC Invitations. +/// +/// \since QXmpp 0.7.4 +/// +void QXmppMessage::setMucInvitationPassword(const QString &password) { - d->privatemsg = priv; + d->mucInvitationPassword = password; } -/// Returns a possibly attached URL from \xep{0066}: Out of Band Data +/// +/// Returns the reason for a multi-user chat direct invitation as defined by +/// \xep{0249}: Direct MUC Invitations. +/// +/// \since QXmpp 0.7.4 +/// +QString QXmppMessage::mucInvitationReason() const +{ + return d->mucInvitationReason; +} -QString QXmppMessage::outOfBandUrl() const +/// +/// Sets the \a reason for a multi-user chat direct invitation as defined by +/// \xep{0249}: Direct MUC Invitations. +/// +/// \since QXmpp 0.7.4 +/// +void QXmppMessage::setMucInvitationReason(const QString &reason) { - return d->outOfBandUrl; + d->mucInvitationReason = reason; } -/// Sets the attached URL for \xep{0066}: Out of Band Data +/// +/// Returns if the message is marked with a <private/> tag, in which case +/// it will not be forwarded to other resources according to \xep{0280}: Message +/// Carbons. +/// +/// \since QXmpp 1.0 +/// +bool QXmppMessage::isPrivate() const +{ + return d->privatemsg; +} -void QXmppMessage::setOutOfBandUrl(const QString &url) +/// +/// If true is passed, the message is marked with a <private/> tag, in +/// which case it will not be forwarded to other resources according to +/// \xep{0280}: Message Carbons. +/// +/// \since QXmpp 1.0 +/// +void QXmppMessage::setPrivate(const bool priv) { - d->outOfBandUrl = url; + d->privatemsg = priv; } +/// /// Returns the message id to replace with this message as used in \xep{0308}: /// Last Message Correction. If the returned string is empty, this message is /// not replacing another. - +/// +/// \since QXmpp 1.0 +/// QString QXmppMessage::replaceId() const { return d->replaceId; } +/// /// Sets the message id to replace with this message as in \xep{0308}: Last /// Message Correction. - +/// +/// \since QXmpp 1.0 +/// void QXmppMessage::setReplaceId(const QString &replaceId) { d->replaceId = replaceId; } +/// +/// Returns true if a message is markable, as defined by \xep{0333}: Chat +/// Markers. +/// +/// \since QXmpp 0.8.1 +/// +bool QXmppMessage::isMarkable() const +{ + return d->markable; +} + +/// +/// Sets if the message is markable, as defined by \xep{0333}: Chat Markers. +/// +/// \since QXmpp 0.8.1 +/// +void QXmppMessage::setMarkable(const bool markable) +{ + d->markable = markable; +} + +/// +/// Returns the message's marker id, as defined by \xep{0333}: Chat Markers. +/// +/// \since QXmpp 0.8.1 +/// +QString QXmppMessage::markedId() const +{ + return d->markedId; +} + +/// +/// Sets the message's marker id, as defined by \xep{0333}: Chat Markers. +/// +/// \since QXmpp 0.8.1 +/// +void QXmppMessage::setMarkerId(const QString &markerId) +{ + d->markedId = markerId; +} + +/// +/// Returns the message's marker thread, as defined by \xep{0333}: Chat Markers. +/// +/// \since QXmpp 0.8.1 +/// +QString QXmppMessage::markedThread() const +{ + return d->markedThread; +} + +/// +/// Sets the message's marked thread, as defined by \xep{0333}: Chat Markers. +/// +/// \since QXmpp 0.8.1 +/// +void QXmppMessage::setMarkedThread(const QString &markedThread) +{ + d->markedThread = markedThread; +} + +/// +/// Returns the message's marker, as defined by \xep{0333}: Chat Markers. +/// +/// \since QXmpp 0.8.1 +/// +QXmppMessage::Marker QXmppMessage::marker() const +{ + return d->marker; +} + +/// +/// Sets the message's marker, as defined by \xep{0333}: Chat Markers +/// +/// \since QXmpp 0.8.1 +/// +void QXmppMessage::setMarker(const Marker marker) +{ + d->marker = marker; +} + +/// /// Returns true if the message contains the hint passed, as defined in /// \xep{0334}: Message Processing Hints /// /// \since QXmpp 1.1 - +/// bool QXmppMessage::hasHint(const Hint hint) const { return d->hints & hint; } +/// /// Adds a hint to the message, as defined in \xep{0334}: Message Processing /// Hints /// /// \since QXmpp 1.1 - +/// void QXmppMessage::addHint(const Hint hint) { d->hints |= hint; } -/// Removes a hint from the message, as defined in \xep{0334}: Message Processing -/// Hints +/// +/// Removes a hint from the message, as defined in \xep{0334}: Message +/// Processing Hints /// /// \since QXmpp 1.1 - +/// void QXmppMessage::removeHint(const Hint hint) { d->hints &= ~hint; } +/// /// Removes all hints from the message, as defined in \xep{0334}: Message /// Processing Hints /// /// \since QXmpp 1.1 - +/// void QXmppMessage::removeAllHints() { d->hints = 0; @@ -763,65 +861,72 @@ void QXmppMessage::setOriginId(const QString &id) d->originId = id; } +/// /// Returns the message id this message is linked/attached to. See \xep{0367}: /// Message Attaching for details. /// /// \since QXmpp 1.1 - +/// QString QXmppMessage::attachId() const { return d->attachId; } -/// Sets the id of the attached message as in \xep{0367}: Message Attaching. This -/// can be used for a "reply to" or "reaction" function. +/// +/// Sets the id of the attached message as in \xep{0367}: Message Attaching. +/// This can be used for a "reply to" or "reaction" function. /// /// The used message id depends on the message context, see the Business rules /// section of the XEP for details about when to use which id. /// /// \since QXmpp 1.1 - +/// void QXmppMessage::setAttachId(const QString &attachId) { d->attachId = attachId; } +/// /// Returns the actual JID of a MIX channel participant. /// /// \since QXmpp 1.1 - +/// QString QXmppMessage::mixUserJid() const { return d->mixUserJid; } +/// /// Sets the actual JID of a MIX channel participant. /// /// \since QXmpp 1.1 - +/// void QXmppMessage::setMixUserJid(const QString &mixUserJid) { d->mixUserJid = mixUserJid; } +/// /// Returns the MIX participant's nickname. /// /// \since QXmpp 1.1 - +/// QString QXmppMessage::mixUserNick() const { return d->mixUserNick; } +/// /// Sets the MIX participant's nickname. /// /// \since QXmpp 1.1 - +/// void QXmppMessage::setMixUserNick(const QString &mixUserNick) { d->mixUserNick = mixUserNick; } +/// /// Returns the encryption method this message is advertised to be encrypted /// with. /// @@ -834,7 +939,7 @@ void QXmppMessage::setMixUserNick(const QString &mixUserNick) /// also a name with \c encryptionName(). /// /// \since QXmpp 1.1 - +/// QXmppMessage::EncryptionMethod QXmppMessage::encryptionMethod() const { if (d->encryptionMethod.isEmpty()) @@ -846,42 +951,46 @@ QXmppMessage::EncryptionMethod QXmppMessage::encryptionMethod() const return static_cast<QXmppMessage::EncryptionMethod>(index); } +/// /// Advertises that this message is encrypted with the given encryption method. /// See \xep{0380}: Explicit Message Encryption for details. /// /// \since QXmpp 1.1 - +/// void QXmppMessage::setEncryptionMethod(QXmppMessage::EncryptionMethod method) { d->encryptionMethod = ENCRYPTION_NAMESPACES.at(int(method)); } +/// /// Returns the namespace of the advertised encryption method via. \xep{0380}: /// Explicit Message Encryption. /// /// \since QXmpp 1.1 - +/// QString QXmppMessage::encryptionMethodNs() const { return d->encryptionMethod; } +/// /// Sets the namespace of the encryption method this message advertises to be /// encrypted with. See \xep{0380}: Explicit Message Encryption for details. /// /// \since QXmpp 1.1 - +/// void QXmppMessage::setEncryptionMethodNs(const QString &encryptionMethod) { d->encryptionMethod = encryptionMethod; } +/// /// Returns the associated name of the encryption method this message /// advertises to be encrypted with. See \xep{0380}: Explicit Message Encryption /// for details. /// /// \since QXmpp 1.1 - +/// QString QXmppMessage::encryptionName() const { if (!d->encryptionName.isEmpty()) @@ -889,6 +998,7 @@ QString QXmppMessage::encryptionName() const return ENCRYPTION_NAMES.at(int(encryptionMethod())); } +/// /// Sets the name of the encryption method for \xep{0380}: Explicit Message /// Encryption. /// @@ -896,24 +1006,26 @@ QString QXmppMessage::encryptionName() const /// not one of the methods listed in the XEP. /// /// \since QXmpp 1.1 - +/// void QXmppMessage::setEncryptionName(const QString &encryptionName) { d->encryptionName = encryptionName; } +/// /// Returns true, if this is a spoiler message according to \xep{0382}: Spoiler /// messages. The spoiler hint however can still be empty. /// /// A spoiler message's content should not be visible to the user by default. /// /// \since QXmpp 1.1 - +/// bool QXmppMessage::isSpoiler() const { return d->isSpoiler; } +/// /// Sets whether this is a spoiler message as specified in \xep{0382}: Spoiler /// messages. /// @@ -922,23 +1034,25 @@ bool QXmppMessage::isSpoiler() const /// the content as usual. /// /// \since QXmpp 1.1 - +/// void QXmppMessage::setIsSpoiler(bool isSpoiler) { d->isSpoiler = isSpoiler; } +/// /// Returns the spoiler hint as specified in \xep{0382}: Spoiler messages. /// /// The hint may be empty, even if isSpoiler is true. /// /// \since QXmpp 1.1 - +/// QString QXmppMessage::spoilerHint() const { return d->spoilerHint; } +/// /// Sets a spoiler hint for \xep{0382}: Spoiler messages. If the spoiler hint /// is not empty, isSpoiler will be set to true. /// @@ -948,7 +1062,7 @@ QString QXmppMessage::spoilerHint() const /// supporting spoiler messages. /// /// \since QXmpp 1.1 - +/// void QXmppMessage::setSpoilerHint(const QString &spoilerHint) { d->spoilerHint = spoilerHint; @@ -1038,10 +1152,11 @@ void QXmppMessage::toXml(QXmlStreamWriter *xmlWriter) const } error().toXml(xmlWriter); - // chat states - if (d->state > None && d->state <= Paused) { - xmlWriter->writeStartElement(CHAT_STATES.at(d->state)); - xmlWriter->writeDefaultNamespace(ns_chat_states); + // XEP-0066: Out of Band Data + if (!d->outOfBandUrl.isEmpty()) { + xmlWriter->writeStartElement(QStringLiteral("x")); + xmlWriter->writeDefaultNamespace(ns_oob); + xmlWriter->writeTextElement(QStringLiteral("url"), d->outOfBandUrl); xmlWriter->writeEndElement(); } @@ -1057,7 +1172,14 @@ void QXmppMessage::toXml(QXmlStreamWriter *xmlWriter) const xmlWriter->writeEndElement(); } - // time stamp + // XEP-0085: Chat State Notifications + if (d->state > None && d->state <= Paused) { + xmlWriter->writeStartElement(CHAT_STATES.at(d->state)); + xmlWriter->writeDefaultNamespace(ns_chat_states); + xmlWriter->writeEndElement(); + } + + // XEP-0091: Legacy Delayed Delivery | XEP-0203: Delayed Delivery if (d->stamp.isValid()) { QDateTime utcStamp = d->stamp.toUTC(); if (d->stampType == DelayedDelivery) { @@ -1107,22 +1229,6 @@ void QXmppMessage::toXml(QXmlStreamWriter *xmlWriter) const xmlWriter->writeEndElement(); } - // XEP-0333: Chat Markers - if (d->markable) { - xmlWriter->writeStartElement(QStringLiteral("markable")); - xmlWriter->writeDefaultNamespace(ns_chat_markers); - xmlWriter->writeEndElement(); - } - if (d->marker != NoMarker) { - xmlWriter->writeStartElement(MARKER_TYPES.at(d->marker)); - xmlWriter->writeDefaultNamespace(ns_chat_markers); - xmlWriter->writeAttribute(QStringLiteral("id"), d->markedId); - if (!d->markedThread.isNull() && !d->markedThread.isEmpty()) { - xmlWriter->writeAttribute(QStringLiteral("thread"), d->markedThread); - } - xmlWriter->writeEndElement(); - } - // XEP-0231: Bits of Binary for (const auto &data : qAsConst(d->bitsOfBinaryData)) data.toXmlElementFromChild(xmlWriter); @@ -1134,14 +1240,6 @@ void QXmppMessage::toXml(QXmlStreamWriter *xmlWriter) const xmlWriter->writeEndElement(); } - // XEP-0066: Out of Band Data - if (!d->outOfBandUrl.isEmpty()) { - xmlWriter->writeStartElement(QStringLiteral("x")); - xmlWriter->writeDefaultNamespace(ns_oob); - xmlWriter->writeTextElement(QStringLiteral("url"), d->outOfBandUrl); - xmlWriter->writeEndElement(); - } - // XEP-0308: Last Message Correction if (!d->replaceId.isEmpty()) { xmlWriter->writeStartElement(QStringLiteral("replace")); @@ -1150,6 +1248,22 @@ void QXmppMessage::toXml(QXmlStreamWriter *xmlWriter) const xmlWriter->writeEndElement(); } + // XEP-0333: Chat Markers + if (d->markable) { + xmlWriter->writeStartElement(QStringLiteral("markable")); + xmlWriter->writeDefaultNamespace(ns_chat_markers); + xmlWriter->writeEndElement(); + } + if (d->marker != NoMarker) { + xmlWriter->writeStartElement(MARKER_TYPES.at(d->marker)); + xmlWriter->writeDefaultNamespace(ns_chat_markers); + xmlWriter->writeAttribute(QStringLiteral("id"), d->markedId); + if (!d->markedThread.isNull() && !d->markedThread.isEmpty()) { + xmlWriter->writeAttribute(QStringLiteral("thread"), d->markedThread); + } + xmlWriter->writeEndElement(); + } + // XEP-0334: Message Processing Hints for (quint8 i = 0; i < HINT_TYPES.size(); i++) { if (hasHint(Hint(1 << i))) { @@ -1224,17 +1338,19 @@ void QXmppMessage::toXml(QXmlStreamWriter *xmlWriter) const } /// \endcond +/// /// Parses message extensions /// /// \param element child element of the message to be parsed -/// \param unknownExtensions extensions not known are added to this list as QXmppElement - +/// \param unknownExtensions extensions not known are added to this list as +/// QXmppElement +/// void QXmppMessage::parseExtension(const QDomElement &element, QXmppElementList &unknownExtensions) { if (element.tagName() == QStringLiteral("x")) { parseXElement(element, unknownExtensions); - // XEP-0071: XHTML-IM } else if (checkElement(element, QStringLiteral("html"), ns_xhtml_im)) { + // XEP-0071: XHTML-IM QDomElement bodyElement = element.firstChildElement(QStringLiteral("body")); if (!bodyElement.isNull() && bodyElement.namespaceURI() == ns_xhtml) { QTextStream stream(&d->xhtml, QIODevice::WriteOnly); @@ -1247,13 +1363,13 @@ void QXmppMessage::parseExtension(const QDomElement &element, QXmppElementList & d->xhtml.replace(QStringLiteral("</body>"), QString()); d->xhtml = d->xhtml.trimmed(); } - // XEP-0085: Chat State Notifications } else if (element.namespaceURI() == ns_chat_states) { + // XEP-0085: Chat State Notifications int i = CHAT_STATES.indexOf(element.tagName()); if (i > 0) d->state = static_cast<QXmppMessage::State>(i); - // XEP-0184: Message Delivery Receipts } else if (checkElement(element, QStringLiteral("received"), ns_message_receipts)) { + // XEP-0184: Message Delivery Receipts d->receiptId = element.attribute(QStringLiteral("id")); // compatibility with old-style XEP @@ -1261,27 +1377,27 @@ void QXmppMessage::parseExtension(const QDomElement &element, QXmppElementList & d->receiptId = id(); } else if (checkElement(element, QStringLiteral("request"), ns_message_receipts)) { d->receiptRequested = true; - // XEP-0203: Delayed Delivery } else if (checkElement(element, QStringLiteral("delay"), ns_delayed_delivery)) { + // XEP-0203: Delayed Delivery d->stamp = QXmppUtils::datetimeFromString( element.attribute(QStringLiteral("stamp"))); d->stampType = DelayedDelivery; - // \xep{0224}: Attention } else if (checkElement(element, QStringLiteral("attention"), ns_attention)) { + // XEP-0224: Attention d->attentionRequested = true; - // XEP-0231: Bits of Binary } else if (QXmppBitsOfBinaryData::isBitsOfBinaryData(element)) { + // XEP-0231: Bits of Binary QXmppBitsOfBinaryData data; data.parseElementFromChild(element); d->bitsOfBinaryData << data; - // XEP-0280: Message Carbons } else if (checkElement(element, QStringLiteral("private"), ns_carbons)) { + // XEP-0280: Message Carbons d->privatemsg = true; - // XEP-0308: Last Message Correction } else if (checkElement(element, QStringLiteral("replace"), ns_message_correct)) { + // XEP-0308: Last Message Correction d->replaceId = element.attribute(QStringLiteral("id")); - // XEP-0333: Chat Markers } else if (element.namespaceURI() == ns_chat_markers) { + // XEP-0333: Chat Markers if (element.tagName() == QStringLiteral("markable")) { d->markable = true; } else { @@ -1292,9 +1408,9 @@ void QXmppMessage::parseExtension(const QDomElement &element, QXmppElementList & d->markedThread = element.attribute(QStringLiteral("thread")); } } - // XEP-0334: Message Processing Hints } else if (element.namespaceURI() == ns_message_processing_hints && HINT_TYPES.contains(element.tagName())) { + // XEP-0334: Message Processing Hints addHint(Hint(1 << HINT_TYPES.indexOf(element.tagName()))); } else if (checkElement(element, QStringLiteral("stanza-id"), ns_sid)) { // XEP-0359: Unique and Stable Stanza IDs @@ -1305,16 +1421,16 @@ void QXmppMessage::parseExtension(const QDomElement &element, QXmppElementList & } else if (checkElement(element, QStringLiteral("attach-to"), ns_message_attaching)) { // XEP-0367: Message Attaching d->attachId = element.attribute(QStringLiteral("id")); - // XEP-0369: Mediated Information eXchange (MIX) } else if (checkElement(element, QStringLiteral("mix"), ns_mix)) { + // XEP-0369: Mediated Information eXchange (MIX) d->mixUserJid = element.firstChildElement(QStringLiteral("jid")).text(); d->mixUserNick = element.firstChildElement(QStringLiteral("nick")).text(); - // XEP-0380: Explicit Message Encryption } else if (checkElement(element, QStringLiteral("encryption"), ns_eme)) { + // XEP-0380: Explicit Message Encryption d->encryptionMethod = element.attribute(QStringLiteral("namespace")); d->encryptionName = element.attribute(QStringLiteral("name")); - // XEP-0382: Spoiler messages } else if (checkElement(element, QStringLiteral("spoiler"), ns_spoiler)) { + // XEP-0382: Spoiler messages d->isSpoiler = true; d->spoilerHint = element.text(); } else if (checkElement(element, QStringLiteral("fallback"), ns_fallback_indication)) { @@ -1326,11 +1442,13 @@ void QXmppMessage::parseExtension(const QDomElement &element, QXmppElementList & } } -/// Parses <x/> child elements of the message +/// +/// Parses <x/> child elements of the message /// /// \param element child element of the message to be parsed -/// \param unknownExtensions extensions not known are added to this list as QXmppElement - +/// \param unknownExtensions extensions not known are added to this list as +/// QXmppElement +/// void QXmppMessage::parseXElement(const QDomElement &element, QXmppElementList &unknownExtensions) { if (element.namespaceURI() == ns_legacy_delayed_delivery) { diff --git a/src/base/QXmppMessage.h b/src/base/QXmppMessage.h index 3f311519..02c633bd 100644 --- a/src/base/QXmppMessage.h +++ b/src/base/QXmppMessage.h @@ -34,10 +34,11 @@ class QXmppMessagePrivate; class QXmppBitsOfBinaryDataList; +/// /// \brief The QXmppMessage class represents an XMPP message. /// /// \ingroup Stanzas - +/// class QXMPP_EXPORT QXmppMessage : public QXmppStanza { public: @@ -50,8 +51,12 @@ public: Headline }; + /// /// This enum describes a chat state as defined by \xep{0085}: Chat State /// Notifications. + /// + /// \since QXmpp 0.2 + /// enum State { None = 0, ///< The message does not contain any chat state information. Active, ///< User is actively participating in the chat session. @@ -61,7 +66,11 @@ public: Paused ///< User had been composing but now has stopped. }; + /// /// This enum describes a chat marker as defined by \xep{0333}: Chat Markers. + /// + /// \since QXmpp 0.8.1 + /// enum Marker { NoMarker = 0, Received, @@ -69,9 +78,11 @@ public: Acknowledged }; + /// /// \xep{0334}: Message Processing Hints /// /// \since QXmpp 1.1 + /// enum Hint { NoPermanentStore = 1 << 0, ///< Do not allow permanent storage NoStore = 1 << 1, ///< Do not store at all @@ -79,11 +90,13 @@ public: Store = 1 << 3 ///< Do store the message }; + /// /// This enum describes different end-to-end encryption methods. These can /// be used to mark a message explicitly as encrypted with a specific /// algothim. See \xep{0380}: Explicit Message Encryption for details. /// /// \since QXmpp 1.1 + /// enum EncryptionMethod { NoEncryption, ///< No encryption UnknownEncryption, ///< Unknown encryption @@ -106,30 +119,6 @@ public: QString body() const; void setBody(const QString &); - bool isAttentionRequested() const; - void setAttentionRequested(bool requested); - - bool isReceiptRequested() const; - void setReceiptRequested(bool requested); - - QString mucInvitationJid() const; - void setMucInvitationJid(const QString &jid); - - QString mucInvitationPassword() const; - void setMucInvitationPassword(const QString &password); - - QString mucInvitationReason() const; - void setMucInvitationReason(const QString &reason); - - QString receiptId() const; - void setReceiptId(const QString &id); - - QDateTime stamp() const; - void setStamp(const QDateTime &stamp); - - QXmppMessage::State state() const; - void setState(QXmppMessage::State); - QString subject() const; void setSubject(const QString &); @@ -142,21 +131,32 @@ public: QXmppMessage::Type type() const; void setType(QXmppMessage::Type); + // XEP-0066: Out of Band Data + QString outOfBandUrl() const; + void setOutOfBandUrl(const QString &); + + // XEP-0071: XHTML-IM QString xhtml() const; void setXhtml(const QString &xhtml); - // XEP-0333: Chat State Markers - bool isMarkable() const; - void setMarkable(const bool); + // XEP-0085: Chat State Notifications + QXmppMessage::State state() const; + void setState(QXmppMessage::State); - QString markedId() const; - void setMarkerId(const QString &); + // XEP-0091: Legacy Delayed Delivery | XEP-0203: Delayed Delivery + QDateTime stamp() const; + void setStamp(const QDateTime &stamp); - QString markedThread() const; - void setMarkedThread(const QString &); + // XEP-0184: Message Delivery Receipts + bool isReceiptRequested() const; + void setReceiptRequested(bool requested); - Marker marker() const; - void setMarker(const Marker); + QString receiptId() const; + void setReceiptId(const QString &id); + + // XEP-0224: Attention + bool isAttentionRequested() const; + void setAttentionRequested(bool requested); // XEP-0231: Bits of Binary QXmppBitsOfBinaryDataList bitsOfBinaryData() const; @@ -169,18 +169,37 @@ public: static QString slashMeCommandText(const QString &body); QString slashMeCommandText() const; + // XEP-0249: Direct MUC Invitations + QString mucInvitationJid() const; + void setMucInvitationJid(const QString &jid); + + QString mucInvitationPassword() const; + void setMucInvitationPassword(const QString &password); + + QString mucInvitationReason() const; + void setMucInvitationReason(const QString &reason); + // XEP-0280: Message Carbons bool isPrivate() const; void setPrivate(const bool); - // XEP-0066: Out of Band Data - QString outOfBandUrl() const; - void setOutOfBandUrl(const QString &); - // XEP-0308: Last Message Correction QString replaceId() const; void setReplaceId(const QString &); + // XEP-0333: Chat State Markers + bool isMarkable() const; + void setMarkable(const bool); + + QString markedId() const; + void setMarkerId(const QString &); + + QString markedThread() const; + void setMarkedThread(const QString &); + + Marker marker() const; + void setMarker(const Marker); + // XEP-0334: Message Processing Hints bool hasHint(const Hint hint) const; void addHint(const Hint hint); |
