File indexing completed on 2024-12-01 10:39:28

0001 /*
0002    SPDX-FileCopyrightText: 2018-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "customemoji.h"
0010 #include "libruqolacore_export.h"
0011 #include <QObject>
0012 #include <QRegularExpression>
0013 #include <TextEmoticonsCore/EmoticonCategory>
0014 #include <TextEmoticonsCore/UnicodeEmoticon>
0015 class RocketChatAccount;
0016 class LIBRUQOLACORE_EXPORT EmojiManager : public QObject
0017 {
0018     Q_OBJECT
0019 public:
0020     explicit EmojiManager(RocketChatAccount *account, QObject *parent = nullptr);
0021     ~EmojiManager() override;
0022 
0023     void loadCustomEmoji(const QJsonObject &obj);
0024 
0025     [[nodiscard]] int count() const;
0026 
0027     [[nodiscard]] QString replaceEmojiIdentifier(const QString &emojiIdentifier, bool isReaction = false);
0028     void replaceEmojis(QString *str);
0029     [[nodiscard]] QString serverUrl() const;
0030     void setServerUrl(const QString &serverUrl);
0031 
0032     [[nodiscard]] QList<TextEmoticonsCore::UnicodeEmoticon> unicodeEmojiList() const;
0033     [[nodiscard]] QList<TextEmoticonsCore::EmoticonCategory> categories() const;
0034     // Only for test now
0035     [[nodiscard]] QList<TextEmoticonsCore::UnicodeEmoticon> emojisForCategory(const QString &category) const;
0036 
0037     [[nodiscard]] bool isAnimatedImage(const QString &emojiIdentifier) const;
0038 
0039     [[nodiscard]] TextEmoticonsCore::UnicodeEmoticon unicodeEmoticonForEmoji(const QString &emojiIdentifier) const;
0040 
0041     [[nodiscard]] QString customEmojiFileName(const QString &emojiIdentifier) const;
0042     [[nodiscard]] QString normalizedReactionEmoji(const QString &emojiIdentifier) const;
0043 
0044     [[nodiscard]] const QVector<CustomEmoji> &customEmojiList() const;
0045 
0046     void addUpdateEmojiCustomList(const QJsonArray &arrayEmojiCustomArray);
0047     void deleteEmojiCustom(const QJsonArray &obj);
0048     [[nodiscard]] QString customEmojiFileNameFromIdentifier(const QString &emojiIdentifier) const;
0049 
0050 Q_SIGNALS:
0051     void customEmojiChanged(bool fetchListCustom);
0052 
0053 private:
0054     LIBRUQOLACORE_NO_EXPORT void clearCustomEmojiCachedHtml();
0055     // Use identifier in a QMap ???
0056     QVector<CustomEmoji> mCustomEmojiList;
0057     QString mServerUrl;
0058     QRegularExpression mReplacePattern;
0059     RocketChatAccount *const mRocketChatAccount;
0060     bool mReplacePatternDirty = true;
0061 };