aboutsummaryrefslogtreecommitdiff
path: root/src/base/QXmppMessage.cpp
diff options
context:
space:
mode:
authorLinus Jahn <lnj@kaidan.im>2020-03-30 01:46:38 +0200
committerLNJ <lnj@kaidan.im>2020-03-31 00:17:06 +0200
commit1cef71d96857825407be192788105a43eb5e1846 (patch)
tree7c83952e9dd830409c626b8c83a54ba842c7fa7f /src/base/QXmppMessage.cpp
parent7f080d08252dfb699d4e3ae072cc3db0d2de129d (diff)
downloadqxmpp-1cef71d96857825407be192788105a43eb5e1846.tar.gz
Implement XEP-0245: The /me Command
This adds parsing for recognizing /me commands in message bodies. It complies with version 1.0 of XEP-0245: The /me Command. https://xmpp.org/extensions/xep-0245.html
Diffstat (limited to 'src/base/QXmppMessage.cpp')
-rw-r--r--src/base/QXmppMessage.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/base/QXmppMessage.cpp b/src/base/QXmppMessage.cpp
index df45d17b..daf3e782 100644
--- a/src/base/QXmppMessage.cpp
+++ b/src/base/QXmppMessage.cpp
@@ -523,6 +523,66 @@ void QXmppMessage::setBitsOfBinaryData(const QXmppBitsOfBinaryDataList &bitsOfBi
d->bitsOfBinaryData = bitsOfBinaryData;
}
+///
+/// Returns whether the given text is a '/me command' as defined in \xep{0245}:
+/// The /me Command.
+///
+/// \since QXmpp 1.3
+///
+bool QXmppMessage::isSlashMeCommand(const QString &body)
+{
+ return body.startsWith(QStringLiteral("/me "));
+}
+
+///
+/// Returns whether the body of the message is a '/me command' as defined in
+/// \xep{0245}: The /me Command.
+///
+/// \note If you want to check a custom string for the /me command, you can use
+/// the static version of this method. This can be helpful when checking user
+/// input before a message was sent.
+///
+/// \since QXmpp 1.3
+///
+bool QXmppMessage::isSlashMeCommand() const
+{
+ return isSlashMeCommand(d->body);
+}
+
+///
+/// Returns the part of the body after the /me command.
+///
+/// This cuts off '/me ' (with the space) from the body, in case the body
+/// starts with that. In case the body does not contain a /me command as
+/// defined in \xep{0245}: The /me Command, a null string is returned.
+///
+/// This is useful when displaying the /me command correctly to the user.
+///
+/// \since QXmpp 1.3
+///
+QString QXmppMessage::slashMeCommandText(const QString &body)
+{
+ if (isSlashMeCommand(body))
+ return body.mid(4);
+ return {};
+}
+
+///
+/// Returns the part of the body after the /me command.
+///
+/// This cuts off '/me ' (with the space) from the body, in case the body
+/// starts with that. In case the body does not contain a /me command as
+/// defined in \xep{0245}: The /me Command, a null string is returned.
+///
+/// This is useful when displaying the /me command correctly to the user.
+///
+/// \since QXmpp 1.3
+///
+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.