mirror-chatterino2/src/singletons/emotemanager.hpp

96 lines
2.4 KiB
C++
Raw Normal View History

#pragma once
2017-04-12 17:46:44 +02:00
#define GIF_FRAME_LENGTH 33
#include "emojis.hpp"
#include "messages/image.hpp"
2018-06-05 17:39:49 +02:00
#include "providers/bttv/bttvemotes.hpp"
#include "providers/twitch/twitchemotes.hpp"
#include "signalvector.hpp"
2017-12-31 22:58:35 +01:00
#include "util/concurrentmap.hpp"
#include "util/emotemap.hpp"
2017-04-12 17:46:44 +02:00
#include <QMap>
#include <QMutex>
#include <QRegularExpression>
#include <QString>
2017-04-12 17:46:44 +02:00
#include <QTimer>
#include <pajlada/signals/signal.hpp>
2017-04-12 17:46:44 +02:00
2017-04-14 17:52:22 +02:00
namespace chatterino {
2017-12-31 22:58:35 +01:00
namespace singletons {
2017-04-12 17:46:44 +02:00
class EmoteManager
{
public:
2018-04-01 16:43:30 +02:00
EmoteManager();
~EmoteManager() = delete;
providers::twitch::TwitchEmotes twitch;
2018-06-05 17:39:49 +02:00
providers::bttv::BTTVEmotes bttv;
void initialize();
void reloadFFZChannelEmotes(const QString &channelName,
2017-12-31 22:58:35 +01:00
std::weak_ptr<util::EmoteMap> channelEmoteMap);
2017-04-12 17:46:44 +02:00
2017-12-31 22:58:35 +01:00
util::EmoteMap &getFFZEmotes();
util::EmoteMap &getChatterinoEmotes();
util::EmojiMap &getEmojis();
2017-12-31 22:58:35 +01:00
util::ConcurrentMap<int, util::EmoteData> &getFFZChannelEmoteFromCaches();
2017-04-12 17:46:44 +02:00
2017-12-31 22:58:35 +01:00
util::EmoteData getCheerImage(long long int amount, bool animated);
2017-04-12 17:46:44 +02:00
pajlada::Signals::NoArgSignal &getGifUpdateSignal();
2017-04-12 17:46:44 +02:00
// Bit badge/emotes?
util::ConcurrentMap<QString, messages::Image *> miscImageCache;
2017-04-12 17:46:44 +02:00
private:
2017-07-02 17:37:17 +02:00
/// Emojis
QRegularExpression findShortCodesRegex;
2017-07-02 17:37:17 +02:00
// shortCodeToEmoji maps strings like "sunglasses" to its emoji
QMap<QString, EmojiData> emojiShortCodeToEmoji;
2017-07-02 17:37:17 +02:00
// Maps the first character of the emoji unicode string to a vector of possible emojis
QMap<QChar, QVector<EmojiData>> emojiFirstByte;
util::EmojiMap emojis;
void loadEmojis();
public:
2017-12-31 22:58:35 +01:00
void parseEmojis(std::vector<std::tuple<util::EmoteData, QString>> &parsedWords,
const QString &text);
2017-04-12 17:46:44 +02:00
QString replaceShortCodes(const QString &text);
std::vector<std::string> emojiShortCodes;
2017-07-02 17:37:17 +02:00
/// FFZ emotes
2017-12-31 22:58:35 +01:00
util::EmoteMap ffzChannelEmotes;
public:
2017-12-31 22:58:35 +01:00
util::ConcurrentMap<QString, util::EmoteMap> ffzChannels;
util::EmoteMap ffzGlobalEmotes;
SignalVector<std::string> ffzGlobalEmoteCodes;
std::map<std::string, SignalVector<std::string>> ffzChannelEmoteCodes;
private:
2017-12-31 22:58:35 +01:00
util::ConcurrentMap<int, util::EmoteData> _ffzChannelEmoteFromCaches;
void loadFFZEmotes();
2017-07-02 17:37:17 +02:00
/// Chatterino emotes
2017-12-31 22:58:35 +01:00
util::EmoteMap _chatterinoEmotes;
2017-04-12 17:46:44 +02:00
pajlada::Signals::NoArgSignal gifUpdateTimerSignal;
QTimer gifUpdateTimer;
bool gifUpdateTimerInitiated = false;
2017-04-12 17:46:44 +02:00
};
2017-05-27 16:16:39 +02:00
} // namespace singletons
2017-04-14 17:52:22 +02:00
} // namespace chatterino