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 #include "customemoji.h" 0005 0006 QList<CustomEmoji> CustomEmoji::parseCustomEmojis(const QJsonArray &json) 0007 { 0008 QList<CustomEmoji> emojis; 0009 for (auto emojiObj : json) { 0010 if (!emojiObj.isObject()) { 0011 continue; 0012 } 0013 0014 CustomEmoji customEmoji{}; 0015 customEmoji.shortcode = emojiObj[QStringLiteral("shortcode")].toString(); 0016 customEmoji.url = emojiObj[QStringLiteral("static_url")].toString(); 0017 0018 emojis.push_back(customEmoji); 0019 } 0020 0021 return emojis; 0022 } 0023 0024 QString CustomEmoji::replaceCustomEmojis(const QList<CustomEmoji> &emojis, const QString &source) 0025 { 0026 QString processed = source; 0027 for (const auto &emoji : emojis) { 0028 processed = processed.replace(QLatin1Char(':') + emoji.shortcode + QLatin1Char(':'), 0029 QStringLiteral("<img height=\"16\" align=\"middle\" width=\"16\" src=\"") + emoji.url + QStringLiteral("\">")); 0030 } 0031 0032 return processed; 0033 } 0034 0035 #include "moc_customemoji.cpp"