File indexing completed on 2024-10-06 04:34:01
0001 /* 0002 SPDX-FileCopyrightText: 2017-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "block.h" 0010 #include "libruqolacore_export.h" 0011 #include "messageattachment.h" 0012 #include "messagepinned.h" 0013 #include "messagestarred.h" 0014 #include "messagetranslation.h" 0015 #include "messageurl.h" 0016 #include "moderation/moderationmessage.h" 0017 #include "reactions.h" 0018 #include "utils.h" 0019 #include <QString> 0020 #include <QVector> 0021 class EmojiManager; 0022 class LIBRUQOLACORE_EXPORT Message 0023 { 0024 Q_GADGET 0025 public: 0026 explicit Message(EmojiManager *emojiManager = nullptr); 0027 Message(const Message &other) = default; 0028 virtual ~Message(); 0029 0030 enum MessageType { 0031 System, 0032 Information, 0033 NormalText, 0034 VideoConference, 0035 }; 0036 0037 Q_ENUM(MessageType) 0038 0039 [[nodiscard]] QString roomId() const; 0040 void setRoomId(const QString &roomId); 0041 0042 [[nodiscard]] bool groupable() const; 0043 void setGroupable(bool groupable); 0044 0045 [[nodiscard]] bool parseUrls() const; 0046 void setParseUrls(bool parseUrls); 0047 0048 [[nodiscard]] QString avatar() const; 0049 void setAvatar(const QString &avatar); 0050 0051 /** 0052 * @brief Constructs Message object from QJsonObject 0053 * 0054 * @param source The Json containing message attributes 0055 * @return Message object, The message constructed from Json 0056 */ 0057 [[nodiscard]] static Message deserialize(const QJsonObject &source, EmojiManager *emojiManager = nullptr); 0058 0059 /** 0060 * @brief Constructs QBytearray from Message object 0061 * 0062 * @param message The Message object 0063 * @return QByteArray, The Json containing message attributes 0064 */ 0065 [[nodiscard]] static QByteArray serialize(const Message &message, bool toBinary = true); 0066 0067 void parseMessage(const QJsonObject &o, bool restApi = false); 0068 0069 [[nodiscard]] bool operator==(const Message &other) const; 0070 0071 Message &operator=(const Message &other) = default; 0072 0073 // To be used in sorted insert: timestamp 0074 bool operator<(const Message &other) const; 0075 0076 [[nodiscard]] QString messageId() const; 0077 void setMessageId(const QString &messageId); 0078 0079 [[nodiscard]] QString text() const; 0080 void setText(const QString &text); 0081 0082 [[nodiscard]] qint64 timeStamp() const; 0083 void setTimeStamp(qint64 timeStamp); 0084 0085 [[nodiscard]] QString username() const; 0086 void setUsername(const QString &username); 0087 0088 [[nodiscard]] QString userId() const; 0089 void setUserId(const QString &userId); 0090 0091 [[nodiscard]] qint64 updatedAt() const; 0092 void setUpdatedAt(qint64 updatedAt); 0093 0094 [[nodiscard]] qint64 editedAt() const; 0095 void setEditedAt(qint64 editedAt); 0096 0097 [[nodiscard]] QString editedByUsername() const; 0098 void setEditedByUsername(const QString &editedByUsername); 0099 0100 [[nodiscard]] bool wasEdited() const; 0101 0102 [[nodiscard]] QString editedByUserId() const; 0103 void setEditedByUserId(const QString &editedByUserId); 0104 0105 [[nodiscard]] QString alias() const; 0106 void setAlias(const QString &alias); 0107 0108 [[nodiscard]] QString systemMessageType() const; 0109 void setSystemMessageType(const QString &systemMessageType); 0110 0111 [[nodiscard]] MessageType messageType() const; 0112 void setMessageType(Message::MessageType messageType); 0113 0114 [[nodiscard]] QVector<MessageAttachment> attachments() const; 0115 void setAttachments(const QVector<MessageAttachment> &attachments); 0116 0117 [[nodiscard]] QVector<MessageUrl> urls() const; 0118 void setUrls(const QVector<MessageUrl> &urls); 0119 0120 [[nodiscard]] QMap<QString, QString> mentions() const; 0121 void setMentions(const QMap<QString, QString> &mentions); 0122 0123 [[nodiscard]] bool isStarred() const; 0124 void setIsStarred(bool starred); 0125 0126 [[nodiscard]] Reactions reactions() const; 0127 void setReactions(const Reactions &reactions); 0128 0129 [[nodiscard]] QString systemMessageText() const; 0130 0131 [[nodiscard]] QString role() const; 0132 void setRole(const QString &role); 0133 0134 [[nodiscard]] bool unread() const; 0135 void setUnread(bool unread); 0136 0137 [[nodiscard]] MessagePinned messagePinned() const; 0138 void setMessagePinned(const MessagePinned &messagePinned); 0139 0140 [[nodiscard]] MessageStarred messageStarred() const; 0141 void setMessageStarred(MessageStarred messageStarred); 0142 0143 [[nodiscard]] int threadCount() const; 0144 void setThreadCount(int threadCount); 0145 0146 [[nodiscard]] qint64 threadLastMessage() const; 0147 void setThreadLastMessage(qint64 threadLastMessage); 0148 0149 [[nodiscard]] qint64 discussionLastMessage() const; 0150 void setDiscussionLastMessage(qint64 discussionLastMessage); 0151 0152 [[nodiscard]] int discussionCount() const; 0153 void setDiscussionCount(int discussionCount); 0154 0155 [[nodiscard]] QString discussionRoomId() const; 0156 void setDiscussionRoomId(const QString &discussionRoomId); 0157 0158 [[nodiscard]] QString threadMessageId() const; 0159 void setThreadMessageId(const QString &threadMessageId); 0160 0161 [[nodiscard]] QString displayTime() const; 0162 0163 [[nodiscard]] MessageTranslation messageTranslation() const; 0164 void setMessageTranslation(const MessageTranslation &messageTranslation); 0165 0166 [[nodiscard]] bool showTranslatedMessage() const; 0167 void setShowTranslatedMessage(bool showTranslatedMessage); 0168 0169 [[nodiscard]] QString name() const; 0170 void setName(const QString &name); 0171 0172 [[nodiscard]] QStringList replies() const; 0173 void setReplies(const QStringList &replies); 0174 0175 [[nodiscard]] QString emoji() const; 0176 void setEmoji(const QString &emoji); 0177 0178 [[nodiscard]] Utils::AvatarInfo avatarInfo() const; 0179 [[nodiscard]] bool pendingMessage() const; 0180 void setPendingMessage(bool pendingMessage); 0181 0182 [[nodiscard]] bool isPinned() const; 0183 [[nodiscard]] bool isAutoTranslated() const; 0184 [[nodiscard]] bool showIgnoredMessage() const; 0185 void setShowIgnoredMessage(bool showIgnoredMessage); 0186 0187 [[nodiscard]] bool isEditingMode() const; 0188 void setIsEditingMode(bool isEditingMode); 0189 0190 [[nodiscard]] QString editedDisplayTime() const; 0191 0192 const QMap<QString, QString> &channels() const; 0193 void setChannels(const QMap<QString, QString> &newChannels); 0194 0195 [[nodiscard]] bool hoverHighlight() const; 0196 void setHoverHighlight(bool newShowReactionIcon); 0197 0198 [[nodiscard]] const QString &localTranslation() const; 0199 void setLocalTranslation(const QString &newLocalTranslation); 0200 0201 [[nodiscard]] QString originalMessageOrAttachmentDescription() const; 0202 0203 [[nodiscard]] QVector<Block> blocks() const; 0204 void setBlocks(const QVector<Block> &newBlocks); 0205 0206 [[nodiscard]] QString dateTime() const; 0207 0208 [[nodiscard]] QColor goToMessageBackgroundColor() const; 0209 void setGoToMessageBackgroundColor(const QColor &newGoToMessageBackgroundColor); 0210 0211 void setVideoConferenceInfo(const VideoConferenceInfo &info); 0212 0213 [[nodiscard]] ModerationMessage moderationMessage() const; 0214 void setModerationMessage(const ModerationMessage &newModerationMessage); 0215 0216 private: 0217 [[nodiscard]] LIBRUQOLACORE_NO_EXPORT static QString generateUniqueId(const QString &messageId, int index); 0218 LIBRUQOLACORE_NO_EXPORT void parseMentions(const QJsonArray &mentions); 0219 LIBRUQOLACORE_NO_EXPORT void parseAttachment(const QJsonArray &attachments); 0220 LIBRUQOLACORE_NO_EXPORT void parseUrls(const QJsonArray &urls); 0221 LIBRUQOLACORE_NO_EXPORT void parseReactions(const QJsonObject &mentions); 0222 LIBRUQOLACORE_NO_EXPORT void parseChannels(const QJsonArray &channels); 0223 LIBRUQOLACORE_NO_EXPORT void parseBlocks(const QJsonArray &blocks); 0224 0225 // Moderation Message Info 0226 // Optimization !!! 0227 ModerationMessage mModerationMessage; 0228 0229 // BackgroundColor 0230 QColor mGoToMessageBackgroundColor; 0231 0232 // Local translation 0233 QString mLocalTranslation; 0234 0235 // Message Pinned 0236 MessagePinned mMessagePinned; 0237 0238 // Message Starred 0239 MessageStarred mMessageStarred; 0240 0241 // Message Translation 0242 MessageTranslation mMessageTranslation; 0243 0244 // Message Object Fields 0245 QVector<MessageAttachment> mAttachments; 0246 0247 // Message urls object 0248 QVector<MessageUrl> mUrls; 0249 0250 // Block 0251 QVector<Block> mBlocks; 0252 0253 // Reactions 0254 Reactions mReactions; 0255 0256 // Mentions username/identifier 0257 QMap<QString, QString> mMentions; 0258 0259 // Channels Name/identifier 0260 QMap<QString, QString> mChannels; 0261 0262 // Users which replies to thread 0263 QStringList mReplies; 0264 0265 // role used when we add/remove role. It will displaying in messagesystem 0266 QString mRole; 0267 0268 // _id 0269 QString mMessageId; 0270 0271 // msg 0272 QString mText; 0273 0274 // u 0275 QString mUsername; 0276 QString mName; 0277 QString mUserId; 0278 0279 // editedBy 0280 QString mEditedByUsername; 0281 QString mEditedByUserId; 0282 0283 // alias 0284 QString mAlias; 0285 0286 QString mSystemMessageType; 0287 0288 // rid 0289 QString mRoomId; 0290 0291 // avatar 0292 QString mAvatar; 0293 0294 // emoji 0295 QString mEmoji; 0296 0297 // drid discussion room id 0298 QString mDiscussionRoomId; 0299 0300 // tmid 0301 QString mThreadMessageId; 0302 0303 // ts 0304 QString mDisplayTime; 0305 qint64 mTimeStamp = -1; 0306 // _updatedAt 0307 qint64 mUpdatedAt = -1; 0308 0309 // editedAt 0310 QString mEditedDisplayTime; 0311 qint64 mEditedAt = -1; 0312 0313 // Thread last message 0314 qint64 mThreadLastMessage = -1; 0315 // Thread count 0316 int mThreadCount = 0; 0317 0318 // Thread last message 0319 qint64 mDiscussionLastMessage = -1; 0320 // Thread count 0321 int mDiscussionCount = 0; 0322 0323 MessageType mMessageType = MessageType::NormalText; 0324 // groupable 0325 bool mGroupable = true; 0326 0327 // parseUrls 0328 bool mParseUrls = false; 0329 0330 // Unread Message 0331 bool mUnread = false; 0332 0333 bool mShowTranslatedMessage = true; 0334 0335 bool mPendingMessage = false; 0336 0337 bool mShowIgnoredMessage = false; 0338 0339 bool mIsEditingMode = false; 0340 0341 bool mHoverHighlight = false; 0342 0343 EmojiManager *mEmojiManager = nullptr; 0344 }; 0345 LIBRUQOLACORE_EXPORT QDebug operator<<(QDebug d, const Message &t);