File indexing completed on 2024-05-12 05:04:18

0001 // SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
0002 // SPDX-License-Identifier: GPL-3.0-or-later
0003 
0004 #pragma once
0005 
0006 #include <QJsonArray>
0007 
0008 /// Represents a custom emoji on a server, usually represents with colons e.g. :kde:
0009 class CustomEmoji
0010 {
0011     Q_GADGET
0012 
0013     Q_PROPERTY(QString shortName MEMBER shortcode)
0014     Q_PROPERTY(QString unicode MEMBER url)
0015     Q_PROPERTY(bool isCustom MEMBER isCustom)
0016 
0017 public:
0018     /// Parses an array of custom emoji, usually returned as a property with a key of "emojis"
0019     /// \param json The JSON array to parse
0020     static QList<CustomEmoji> parseCustomEmojis(const QJsonArray &json);
0021 
0022     /// Replaces parts of a plaintext string that contain an existing custom emoji
0023     /// \param emojis The list of custom emojis, given from CustomEmoji::parseCustomEmojis()
0024     /// \param source The plaintext source to use
0025     /// \returns HTML to be used as rich text
0026     static QString replaceCustomEmojis(const QList<CustomEmoji> &emojis, const QString &source);
0027 
0028     /// The shortcode name. For example, :kde: would have a shortcode of "kde"
0029     QString shortcode;
0030 
0031     /// The static URL of the emoji
0032     QString url;
0033 
0034     /// Whether the emoji is custom, should always be true
0035     bool isCustom = true;
0036 };
0037 
0038 Q_DECLARE_METATYPE(CustomEmoji)