File indexing completed on 2024-04-28 16:10:14

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 
0008 #include <Quotient/events/roommessageevent.h>
0009 
0010 #include "neochatroom.h"
0011 
0012 class CustomEmojiModel;
0013 class NeoChatRoom;
0014 
0015 /**
0016  * @class ActionsHandler
0017  *
0018  * This class handles chat messages ready for posting to a room.
0019  *
0020  * Everything that needs to be done to prepare the message for posting in a room
0021  * including:
0022  *  - File handling
0023  *  - User mentions
0024  *  - Quick edits
0025  *  - Chat actions
0026  *  - Custom emojis
0027  *
0028  * @note A chat action is a message starting with /, resulting in something other
0029  *       than a normal message being sent (e.g. /me, /join).
0030  *
0031  * @sa ActionsModel, NeoChatRoom
0032  */
0033 class ActionsHandler : public QObject
0034 {
0035     Q_OBJECT
0036 
0037     /**
0038      * @brief The room that messages will be sent to.
0039      */
0040     Q_PROPERTY(NeoChatRoom *room READ room WRITE setRoom NOTIFY roomChanged)
0041 
0042 public:
0043     explicit ActionsHandler(QObject *parent = nullptr);
0044 
0045     [[nodiscard]] NeoChatRoom *room() const;
0046     void setRoom(NeoChatRoom *room);
0047 
0048 Q_SIGNALS:
0049     void roomChanged();
0050     void showEffect(const QString &effect);
0051 
0052 public Q_SLOTS:
0053 
0054     /**
0055      * @brief Pre-process text and send message.
0056      */
0057     void handleNewMessage();
0058 
0059     /**
0060      * @brief Pre-process text and send edit.
0061      */
0062     void handleEdit();
0063 
0064 private:
0065     NeoChatRoom *m_room = nullptr;
0066     void checkEffects(const QString &text);
0067 
0068     QString handleMentions(QString handledText, const bool &isEdit = false);
0069     void handleMessage(const QString &text, QString handledText, const bool &isEdit = false);
0070 };