diff --git a/CMakeLists.txt b/CMakeLists.txt index 30b8326e3..17fd5f526 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,6 +60,7 @@ else() set(QTLOCATION_MODULE_QML_VERSION "5.15") endif() +set(QUOTIENT_FORCE_NAMESPACED_INCLUDES TRUE) ecm_setup_version(${PROJECT_VERSION} VARIABLE_PREFIX NEOCHAT diff --git a/autotests/neochatroomtest.cpp b/autotests/neochatroomtest.cpp index df368df3f..0585481de 100644 --- a/autotests/neochatroomtest.cpp +++ b/autotests/neochatroomtest.cpp @@ -7,9 +7,9 @@ #include "neochatroom.h" -#include -#include -#include +#include +#include +#include using namespace Quotient; diff --git a/autotests/texthandlertest.cpp b/autotests/texthandlertest.cpp index be4de1e07..7336532d6 100644 --- a/autotests/texthandlertest.cpp +++ b/autotests/texthandlertest.cpp @@ -6,9 +6,9 @@ #include "texthandler.h" +#include +#include #include -#include -#include using namespace Quotient; diff --git a/src/actionshandler.cpp b/src/actionshandler.cpp index 4f7990267..466049ca0 100644 --- a/src/actionshandler.cpp +++ b/src/actionshandler.cpp @@ -3,8 +3,8 @@ #include "actionshandler.h" -#include -#include +#include +#include #include diff --git a/src/actionshandler.h b/src/actionshandler.h index f39ab0a07..20288dd2d 100644 --- a/src/actionshandler.h +++ b/src/actionshandler.h @@ -5,7 +5,7 @@ #include -#include +#include #include "neochatroom.h" diff --git a/src/controller.cpp b/src/controller.cpp index f00266cba..cc3f0a80f 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -31,16 +31,15 @@ #include -#include "accountregistry.h" - -#include -#include -#include -#include -#include -#include - -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include "neochatconfig.h" #include "neochatroom.h" diff --git a/src/controller.h b/src/controller.h index 8357635de..f6cb0f328 100644 --- a/src/controller.h +++ b/src/controller.h @@ -9,8 +9,8 @@ #include -#include -#include +#include +#include class NeoChatRoom; class NeoChatUser; diff --git a/src/events/imagepackevent.h b/src/events/imagepackevent.h index 2df1722b8..9cf458a44 100644 --- a/src/events/imagepackevent.h +++ b/src/events/imagepackevent.h @@ -4,8 +4,8 @@ #pragma once #include -#include -#include +#include +#include namespace Quotient { diff --git a/src/events/joinrulesevent.h b/src/events/joinrulesevent.h index bad154a1e..5dd96d32c 100644 --- a/src/events/joinrulesevent.h +++ b/src/events/joinrulesevent.h @@ -3,7 +3,7 @@ #pragma once -#include +#include namespace Quotient { diff --git a/src/events/pollevent.h b/src/events/pollevent.h index 377bf2015..b68824cec 100644 --- a/src/events/pollevent.h +++ b/src/events/pollevent.h @@ -3,8 +3,7 @@ #pragma once -#include -#include +#include namespace Quotient { diff --git a/src/joinrulesevent.h b/src/joinrulesevent.h new file mode 100644 index 000000000..3943f736d --- /dev/null +++ b/src/joinrulesevent.h @@ -0,0 +1,36 @@ +// SPDX-FileCopyrightText: 2021 Carl Schwan +// SPDX-License-Identifier: LGPL-2.1-or-later + +#pragma once + +#include + +namespace Quotient +{ +#ifdef QUOTIENT_07 +class JoinRulesEvent : public StateEvent +#else +class JoinRulesEvent : public StateEventBase +#endif +{ +public: +#ifdef QUOTIENT_07 + QUO_EVENT(JoinRulesEvent, "m.room.join_rules") +#else + DEFINE_EVENT_TYPEID("m.room.join_rules", JoinRulesEvent) +#endif + + explicit JoinRulesEvent(const QJsonObject &obj) +#ifdef QUOTIENT_07 + : StateEvent(obj) +#else + : StateEventBase(typeId(), obj) +#endif + { + } + + QString joinRule() const; + QJsonArray allow() const; +}; +REGISTER_EVENT_TYPE(JoinRulesEvent) +} diff --git a/src/linkpreviewer.cpp b/src/linkpreviewer.cpp index 521aadd3b..103c06b99 100644 --- a/src/linkpreviewer.cpp +++ b/src/linkpreviewer.cpp @@ -3,8 +3,10 @@ #include "linkpreviewer.h" -#include -#include +#include "controller.h" + +#include +#include #include "neochatroom.h" diff --git a/src/login.cpp b/src/login.cpp index 65693667d..32a2ad423 100644 --- a/src/login.cpp +++ b/src/login.cpp @@ -3,10 +3,9 @@ #include "login.h" -#include - -#include -#include +#include +#include +#include #include "controller.h" diff --git a/src/main.cpp b/src/main.cpp index 29449764d..5b33c759e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -28,10 +28,11 @@ #include "neochat-version.h" -#include -#include -#include -#include +#include +#include +#include +#include +#include #include "actionshandler.h" #include "blurhashimageprovider.h" @@ -81,7 +82,7 @@ #include "spacehierarchycache.h" #include "urlhelper.h" #include "windowcontroller.h" -#include + #ifdef HAVE_COLORSCHEME #include "colorschemer.h" #endif diff --git a/src/matriximageprovider.cpp b/src/matriximageprovider.cpp index ad62cf427..f978cf82a 100644 --- a/src/matriximageprovider.cpp +++ b/src/matriximageprovider.cpp @@ -13,7 +13,7 @@ #include #include "controller.h" -#include +#include using namespace Quotient; diff --git a/src/matriximageprovider.h b/src/matriximageprovider.h index a1ec6fe62..6833d41f1 100644 --- a/src/matriximageprovider.h +++ b/src/matriximageprovider.h @@ -6,7 +6,7 @@ #include -#include +#include #include diff --git a/src/models/accountemoticonmodel.cpp b/src/models/accountemoticonmodel.cpp index 0b6e3444f..30e6411b3 100644 --- a/src/models/accountemoticonmodel.cpp +++ b/src/models/accountemoticonmodel.cpp @@ -3,7 +3,7 @@ #include "accountemoticonmodel.h" -#include +#include #include using namespace Quotient; diff --git a/src/models/accountemoticonmodel.h b/src/models/accountemoticonmodel.h index 4b9a56082..ea21f6f2d 100644 --- a/src/models/accountemoticonmodel.h +++ b/src/models/accountemoticonmodel.h @@ -4,12 +4,14 @@ #pragma once #include "events/imagepackevent.h" + #include #include #include #include #include -#include + +#include class ImagePacksModel; diff --git a/src/models/actionsmodel.cpp b/src/models/actionsmodel.cpp index ca7c903ea..b21dbaf3c 100644 --- a/src/models/actionsmodel.cpp +++ b/src/models/actionsmodel.cpp @@ -6,8 +6,8 @@ #include "controller.h" #include "neochatroom.h" #include "roommanager.h" -#include -#include +#include +#include #include diff --git a/src/models/actionsmodel.h b/src/models/actionsmodel.h index 962d3f4c3..7805df336 100644 --- a/src/models/actionsmodel.h +++ b/src/models/actionsmodel.h @@ -5,7 +5,7 @@ #include #include -#include +#include class NeoChatRoom; diff --git a/src/models/customemojimodel.cpp b/src/models/customemojimodel.cpp index b653136f2..9a1959d1b 100644 --- a/src/models/customemojimodel.cpp +++ b/src/models/customemojimodel.cpp @@ -9,10 +9,9 @@ #include "controller.h" #include "emojimodel.h" -#include -#include -#include -#include +#include +#include +#include using namespace Quotient; diff --git a/src/models/devicesmodel.cpp b/src/models/devicesmodel.cpp index 9beae7067..de34443b0 100644 --- a/src/models/devicesmodel.cpp +++ b/src/models/devicesmodel.cpp @@ -3,12 +3,13 @@ #include "devicesmodel.h" -#include - #include "controller.h" + #include -#include -#include + +#include +#include +#include using namespace Quotient; diff --git a/src/models/devicesmodel.h b/src/models/devicesmodel.h index 106d73158..ec2b19456 100644 --- a/src/models/devicesmodel.h +++ b/src/models/devicesmodel.h @@ -4,9 +4,9 @@ #pragma once #include - #include -#include + +#include namespace Quotient { diff --git a/src/models/keywordnotificationrulemodel.cpp b/src/models/keywordnotificationrulemodel.cpp new file mode 100644 index 000000000..13fb876b4 --- /dev/null +++ b/src/models/keywordnotificationrulemodel.cpp @@ -0,0 +1,110 @@ +// SPDX-FileCopyrightText: 2022 James Graham +// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL + +#include "keywordnotificationrulemodel.h" +#include "controller.h" +#include "notificationsmanager.h" + +#include +#include +#include +#include +#include +#include + +KeywordNotificationRuleModel::KeywordNotificationRuleModel(QObject *parent) + : QAbstractListModel(parent) +{ + if (Controller::instance().activeConnection()) { + controllerConnectionChanged(); + } + connect(&Controller::instance(), &Controller::activeConnectionChanged, this, &KeywordNotificationRuleModel::controllerConnectionChanged); +} + +void KeywordNotificationRuleModel::controllerConnectionChanged() +{ + connect(Controller::instance().activeConnection(), &Quotient::Connection::accountDataChanged, this, &KeywordNotificationRuleModel::updateNotificationRules); + updateNotificationRules("m.push_rules"); +} + +void KeywordNotificationRuleModel::updateNotificationRules(const QString &type) +{ + if (type != "m.push_rules") { + return; + } + + const QJsonObject ruleDataJson = Controller::instance().activeConnection()->accountDataJson("m.push_rules"); + const Quotient::PushRuleset ruleData = Quotient::fromJson(ruleDataJson["global"].toObject()); + const QVector contentRules = ruleData.content; + + beginResetModel(); + m_notificationRules.clear(); + for (const auto &i : contentRules) { + if (!m_notificationRules.contains(i.ruleId) && i.ruleId[0] != '.') { + m_notificationRules.append(i.ruleId); + } + } + endResetModel(); +} + +QVariant KeywordNotificationRuleModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) { + return {}; + } + + if (index.row() >= m_notificationRules.count()) { + qDebug() << "KeywordNotificationRuleModel, something's wrong: index.row() >= m_notificationRules.count()"; + return {}; + } + + if (role == NameRole) { + return m_notificationRules.at(index.row()); + } + + return {}; +} + +int KeywordNotificationRuleModel::rowCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent) + + return m_notificationRules.count(); +} + +void KeywordNotificationRuleModel::addKeyword(const QString &keyword) +{ + if (m_notificationRules.count() == 0) { + NotificationsManager::instance().initializeKeywordNotificationAction(); + } + + const QVector actions = NotificationsManager::instance().getKeywordNotificationActions(); + + auto job = Controller::instance() + .activeConnection() + ->callApi("global", "content", keyword, actions, "", "", QVector(), keyword); + connect(job, &Quotient::BaseJob::success, this, [this, keyword]() { + beginInsertRows(QModelIndex(), m_notificationRules.count(), m_notificationRules.count()); + m_notificationRules.append(keyword); + endInsertRows(); + }); +} + +void KeywordNotificationRuleModel::removeKeywordAtIndex(int index) +{ + auto job = Controller::instance().activeConnection()->callApi("global", "content", m_notificationRules[index]); + connect(job, &Quotient::BaseJob::success, this, [this, index]() { + beginRemoveRows(QModelIndex(), index, index); + m_notificationRules.removeAt(index); + endRemoveRows(); + + if (m_notificationRules.count() == 0) { + NotificationsManager::instance().deactivateKeywordNotificationAction(); + } + }); +} + +QHash KeywordNotificationRuleModel::roleNames() const +{ + return {{NameRole, QByteArrayLiteral("name")}}; +} diff --git a/src/models/keywordnotificationrulemodel.h b/src/models/keywordnotificationrulemodel.h new file mode 100644 index 000000000..54a1a3360 --- /dev/null +++ b/src/models/keywordnotificationrulemodel.h @@ -0,0 +1,66 @@ +// SPDX-FileCopyrightText: 2022 James Graham +// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL + +#pragma once + +#include + +#include + +/** + * @class KeywordNotificationRuleModel + * + * This class defines the model for managing notification push rule keywords. + */ +class KeywordNotificationRuleModel : public QAbstractListModel +{ + Q_OBJECT + +public: + /** + * @brief Defines the model roles. + */ + enum EventRoles { + NameRole = Qt::DisplayRole, /**< The push rule keyword. */ + }; + + KeywordNotificationRuleModel(QObject *parent = nullptr); + + /** + * @brief Get the given role value at the given index. + * + * @sa QAbstractItemModel::data + */ + [[nodiscard]] QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; + + /** + * @brief Number of rows in the model. + * + * @sa QAbstractItemModel::rowCount + */ + [[nodiscard]] int rowCount(const QModelIndex &parent = QModelIndex()) const override; + + /** + * @brief Returns a mapping from Role enum values to role names. + * + * @sa EventRoles, QAbstractItemModel::roleNames() + */ + [[nodiscard]] QHash roleNames() const override; + + /** + * @brief Add a new keyword to the model. + */ + Q_INVOKABLE void addKeyword(const QString &keyword); + + /** + * @brief Remove a keyword from the model. + */ + Q_INVOKABLE void removeKeywordAtIndex(int index); + +private Q_SLOTS: + void controllerConnectionChanged(); + void updateNotificationRules(const QString &type); + +private: + QList m_notificationRules; +}; diff --git a/src/models/livelocationsmodel.cpp b/src/models/livelocationsmodel.cpp index 0a02e4533..1dcf5f309 100644 --- a/src/models/livelocationsmodel.cpp +++ b/src/models/livelocationsmodel.cpp @@ -4,7 +4,7 @@ #include "livelocationsmodel.h" -#include +#include #include diff --git a/src/models/locationsmodel.h b/src/models/locationsmodel.h index 44f96bae1..1faa7fe3f 100644 --- a/src/models/locationsmodel.h +++ b/src/models/locationsmodel.h @@ -9,7 +9,7 @@ #include "neochatroom.h" -#include +#include class LocationsModel : public QAbstractListModel { diff --git a/src/models/mediamessagefiltermodel.cpp b/src/models/mediamessagefiltermodel.cpp index 8d175a1fa..df9496657 100644 --- a/src/models/mediamessagefiltermodel.cpp +++ b/src/models/mediamessagefiltermodel.cpp @@ -3,7 +3,7 @@ #include "mediamessagefiltermodel.h" #include "models/messageeventmodel.h" -#include +#include MediaMessageFilterModel::MediaMessageFilterModel(QObject *parent) : QSortFilterProxyModel(parent) diff --git a/src/models/messageeventmodel.cpp b/src/models/messageeventmodel.cpp index 0bf705418..93a6ef586 100644 --- a/src/models/messageeventmodel.cpp +++ b/src/models/messageeventmodel.cpp @@ -5,17 +5,18 @@ #include "messageeventmodel_logging.h" #include "neochatconfig.h" -#include -#include -#include -#include -#include -#include -#include -#include + +#include +#include +#include +#include +#include +#include +#include +#include #include "events/pollevent.h" -#include "events/stickerevent.h" +#include #include #include diff --git a/src/models/publicroomlistmodel.cpp b/src/models/publicroomlistmodel.cpp index a8f3f1de4..23953adfa 100644 --- a/src/models/publicroomlistmodel.cpp +++ b/src/models/publicroomlistmodel.cpp @@ -3,7 +3,7 @@ #include "publicroomlistmodel.h" -#include +#include using namespace Quotient; diff --git a/src/models/publicroomlistmodel.h b/src/models/publicroomlistmodel.h index cecf3cabe..eff97c61d 100644 --- a/src/models/publicroomlistmodel.h +++ b/src/models/publicroomlistmodel.h @@ -6,7 +6,7 @@ #include #include -#include +#include namespace Quotient { diff --git a/src/models/pushrulemodel.cpp b/src/models/pushrulemodel.cpp index da5df9f6f..e5afe6988 100644 --- a/src/models/pushrulemodel.cpp +++ b/src/models/pushrulemodel.cpp @@ -5,12 +5,11 @@ #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include "controller.h" #include "neochatconfig.h" diff --git a/src/models/pushrulemodel.h b/src/models/pushrulemodel.h index 4a7b25e32..1e303baf2 100644 --- a/src/models/pushrulemodel.h +++ b/src/models/pushrulemodel.h @@ -5,7 +5,7 @@ #include -#include +#include #include "notificationsmanager.h" diff --git a/src/models/roomlistmodel.cpp b/src/models/roomlistmodel.cpp index 2cb4562e0..471b46fa6 100644 --- a/src/models/roomlistmodel.cpp +++ b/src/models/roomlistmodel.cpp @@ -8,7 +8,8 @@ #include "neochatroom.h" #include "roommanager.h" #include "spacehierarchycache.h" -#include "user.h" + +#include #include #if QT_VERSION < QT_VERSION_CHECK(6, 6, 0) diff --git a/src/models/roomlistmodel.h b/src/models/roomlistmodel.h index eb0d73c2f..eabc73e8d 100644 --- a/src/models/roomlistmodel.h +++ b/src/models/roomlistmodel.h @@ -3,7 +3,7 @@ #pragma once -#include +#include #include diff --git a/src/models/searchmodel.cpp b/src/models/searchmodel.cpp index 468e188b0..3fd07d541 100644 --- a/src/models/searchmodel.cpp +++ b/src/models/searchmodel.cpp @@ -2,12 +2,16 @@ // SPDX-License-Identifier: LGPL-2.0-or-later #include "searchmodel.h" -#include "events/stickerevent.h" + #include "messageeventmodel.h" #include "neochatroom.h" #include "neochatuser.h" +#include + #include -#include + +#include +#include using namespace Quotient; diff --git a/src/models/searchmodel.h b/src/models/searchmodel.h index 74247c0f4..624ad348e 100644 --- a/src/models/searchmodel.h +++ b/src/models/searchmodel.h @@ -6,7 +6,7 @@ #include #include -#include +#include namespace Quotient { diff --git a/src/models/serverlistmodel.cpp b/src/models/serverlistmodel.cpp index 6db86f947..c02441ad5 100644 --- a/src/models/serverlistmodel.cpp +++ b/src/models/serverlistmodel.cpp @@ -5,7 +5,7 @@ #include "controller.h" -#include +#include #include diff --git a/src/models/serverlistmodel.h b/src/models/serverlistmodel.h index f094df69d..0bb796d10 100644 --- a/src/models/serverlistmodel.h +++ b/src/models/serverlistmodel.h @@ -3,7 +3,7 @@ #pragma once -#include +#include #include #include diff --git a/src/models/userdirectorylistmodel.cpp b/src/models/userdirectorylistmodel.cpp index 675c75bf2..9b1a06818 100644 --- a/src/models/userdirectorylistmodel.cpp +++ b/src/models/userdirectorylistmodel.cpp @@ -3,8 +3,8 @@ #include "userdirectorylistmodel.h" -#include -#include +#include +#include using namespace Quotient; diff --git a/src/models/userdirectorylistmodel.h b/src/models/userdirectorylistmodel.h index b0ef2cd8f..37006a9f3 100644 --- a/src/models/userdirectorylistmodel.h +++ b/src/models/userdirectorylistmodel.h @@ -6,7 +6,7 @@ #include #include -#include +#include namespace Quotient { diff --git a/src/models/userlistmodel.cpp b/src/models/userlistmodel.cpp index aeec2bada..3e80db90f 100644 --- a/src/models/userlistmodel.cpp +++ b/src/models/userlistmodel.cpp @@ -3,8 +3,8 @@ #include "userlistmodel.h" -#include -#include +#include +#include #include "neochatroom.h" diff --git a/src/models/userlistmodel.h b/src/models/userlistmodel.h index e55e258a5..ffb72c4bd 100644 --- a/src/models/userlistmodel.h +++ b/src/models/userlistmodel.h @@ -3,6 +3,8 @@ #pragma once +#include + #include #include #include diff --git a/src/neochatroom.cpp b/src/neochatroom.cpp index 0afec308a..2d7f66517 100644 --- a/src/neochatroom.cpp +++ b/src/neochatroom.cpp @@ -12,35 +12,33 @@ #include #include -#include +#include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include "controller.h" #include "events/joinrulesevent.h" #include "events/pollevent.h" -#include "events/stickerevent.h" #include "filetransferpseudojob.h" #include "neochatconfig.h" #include "notificationsmanager.h" diff --git a/src/neochatroom.h b/src/neochatroom.h index 08370acb2..392151065 100644 --- a/src/neochatroom.h +++ b/src/neochatroom.h @@ -3,8 +3,7 @@ #pragma once -#include -#include +#include #include #include diff --git a/src/neochatuser.cpp b/src/neochatuser.cpp index dd2b3409d..1acb3aa76 100644 --- a/src/neochatuser.cpp +++ b/src/neochatuser.cpp @@ -7,7 +7,7 @@ #include #include -#include +#include using namespace Quotient; diff --git a/src/neochatuser.h b/src/neochatuser.h index 7606bfdb6..797b33909 100644 --- a/src/neochatuser.h +++ b/src/neochatuser.h @@ -5,7 +5,7 @@ #include -#include +#include /** * @class NeoChatUser diff --git a/src/notificationsmanager.cpp b/src/notificationsmanager.cpp index bf8a14339..26e470504 100644 --- a/src/notificationsmanager.cpp +++ b/src/notificationsmanager.cpp @@ -11,11 +11,11 @@ #include #include -#include - -#include -#include -#include +#include +#include +#include +#include +#include #include "controller.h" #include "neochatconfig.h" diff --git a/src/notificationsmanager.h b/src/notificationsmanager.h index 769afabe4..2ba087669 100644 --- a/src/notificationsmanager.h +++ b/src/notificationsmanager.h @@ -9,8 +9,8 @@ #include #include #include -#include -#include +#include +#include namespace Quotient { diff --git a/src/pollhandler.cpp b/src/pollhandler.cpp index 006e36605..eee59e146 100644 --- a/src/pollhandler.cpp +++ b/src/pollhandler.cpp @@ -2,12 +2,15 @@ // SPDX-License-Identifier: LGPL-2.0-or-later #include "pollhandler.h" + #include "events/pollevent.h" #include "neochatroom.h" + +#include +#include +#include + #include -#include -#include -#include using namespace Quotient; diff --git a/src/roommanager.cpp b/src/roommanager.cpp index 588fb10d1..1ca2d2dc8 100644 --- a/src/roommanager.cpp +++ b/src/roommanager.cpp @@ -3,6 +3,7 @@ // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL #include "roommanager.h" + #include "controller.h" #include "neochatconfig.h" #include "neochatroom.h" @@ -10,10 +11,11 @@ #include #include #include -#include -#include -#include -#include + +#include +#include +#include +#include #ifndef Q_OS_ANDROID #include diff --git a/src/roommanager.h b/src/roommanager.h index 0fc45a9a3..9fd9615c3 100644 --- a/src/roommanager.h +++ b/src/roommanager.h @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include "chatdocumenthandler.h" diff --git a/src/spacehierarchycache.cpp b/src/spacehierarchycache.cpp index a9a3914f3..aac45b127 100644 --- a/src/spacehierarchycache.cpp +++ b/src/spacehierarchycache.cpp @@ -3,8 +3,8 @@ #include "spacehierarchycache.h" -#include -#include +#include +#include #include "controller.h" #include "neochatroom.h" diff --git a/src/stickerevent.h b/src/stickerevent.h new file mode 100644 index 000000000..42d9b65be --- /dev/null +++ b/src/stickerevent.h @@ -0,0 +1,43 @@ +// SPDX-FileCopyrightText: 2020 Carl Schwan +// SPDX-License-Identifier: LGPL-2.1-or-later + +#pragma once + +#include +#include + +namespace Quotient +{ +/// Sticker messages are specialised image messages that are displayed without +/// controls (e.g. no "download" link, or light-box view on click, as would be +/// displayed for for m.image events). +class StickerEvent : public RoomEvent +{ +public: +#ifdef QUOTIENT_07 + QUO_EVENT(StickerEvent, "m.sticker") +#else + DEFINE_EVENT_TYPEID("m.sticker", StickerEvent) +#endif + + explicit StickerEvent(const QJsonObject &obj); + + /// \brief A textual representation or associated description of the + /// sticker image. + /// + /// This could be the alt text of the original image, or a message to + /// accompany and further describe the sticker. + QString body() const; + + /// \brief Metadata about the image referred to in url including a + /// thumbnail representation. + const EventContent::ImageContent &image() const; + + /// \brief The URL to the sticker image. This must be a valid mxc:// URI. + QUrl url() const; + +private: + EventContent::ImageContent m_imageContent; +}; +REGISTER_EVENT_TYPE(StickerEvent) +} diff --git a/src/texthandler.cpp b/src/texthandler.cpp index b0f67fd53..a7bec3399 100644 --- a/src/texthandler.cpp +++ b/src/texthandler.cpp @@ -5,10 +5,11 @@ #include #include - #include -#include -#include + +#include +#include +#include #include