File indexing completed on 2024-09-15 04:28:25
0001 // SPDX-FileCopyrightText: 2020 Carl Schwan <carlschwan@kde.org> 0002 // SPDX-License-Identifier: GPL-3.0-or-later 0003 0004 #pragma once 0005 0006 #include <QObject> 0007 #include <QQmlEngine> 0008 0009 #include <Quotient/events/roommessageevent.h> 0010 0011 #include "chatbarcache.h" 0012 #include "neochatroom.h" 0013 0014 class NeoChatRoom; 0015 0016 /** 0017 * @class ActionsHandler 0018 * 0019 * This class handles chat messages ready for posting to a room. 0020 * 0021 * Everything that needs to be done to prepare the message for posting in a room 0022 * including: 0023 * - File handling 0024 * - User mentions 0025 * - Quick edits 0026 * - Chat actions 0027 * - Custom emojis 0028 * 0029 * @note A chat action is a message starting with /, resulting in something other 0030 * than a normal message being sent (e.g. /me, /join). 0031 * 0032 * @sa ActionsModel, NeoChatRoom 0033 */ 0034 class ActionsHandler : public QObject 0035 { 0036 Q_OBJECT 0037 QML_ELEMENT 0038 0039 /** 0040 * @brief The room that messages will be sent to. 0041 */ 0042 Q_PROPERTY(NeoChatRoom *room READ room WRITE setRoom NOTIFY roomChanged) 0043 0044 public: 0045 explicit ActionsHandler(QObject *parent = nullptr); 0046 0047 [[nodiscard]] NeoChatRoom *room() const; 0048 void setRoom(NeoChatRoom *room); 0049 0050 Q_SIGNALS: 0051 void roomChanged(); 0052 void showEffect(const QString &effect); 0053 0054 public Q_SLOTS: 0055 /** 0056 * @brief Pre-process text and send message event. 0057 */ 0058 void handleMessageEvent(ChatBarCache *chatBarCache); 0059 0060 private: 0061 NeoChatRoom *m_room = nullptr; 0062 void checkEffects(const QString &text); 0063 0064 QString handleMentions(QString handledText, QList<Mention> *mentions); 0065 void handleMessage(const QString &text, QString handledText, ChatBarCache *chatBarCache); 0066 };