mirror-chatterino2/src/singletons/emotemanager.hpp

173 lines
4.2 KiB
C++
Raw Normal View History

#pragma once
2017-04-12 17:46:44 +02:00
#define GIF_FRAME_LENGTH 33
2017-06-11 09:31:45 +02:00
#include "concurrentmap.hpp"
#include "emojis.hpp"
2017-06-11 09:31:45 +02:00
#include "messages/lazyloadedimage.hpp"
#include "signalvector.hpp"
2017-06-11 09:31:45 +02:00
#include "twitch/emotevalue.hpp"
#include "twitch/twitchuser.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 <boost/signals2.hpp>
2017-04-14 17:52:22 +02:00
namespace chatterino {
2017-12-31 00:50:07 +01:00
class SettingsManager;
class WindowManager;
struct EmoteData {
EmoteData()
{
}
EmoteData(messages::LazyLoadedImage *_image)
: image(_image)
{
}
messages::LazyLoadedImage *image = nullptr;
};
typedef ConcurrentMap<QString, EmoteData> EmoteMap;
2017-04-12 17:46:44 +02:00
class EmoteManager
{
2017-12-31 00:50:07 +01:00
explicit EmoteManager(SettingsManager &manager, WindowManager &windowManager);
2017-12-17 02:18:13 +01:00
public:
2017-12-31 00:50:07 +01:00
static EmoteManager &getInstance();
void loadGlobalEmotes();
void reloadBTTVChannelEmotes(const QString &channelName,
std::weak_ptr<EmoteMap> channelEmoteMap);
void reloadFFZChannelEmotes(const QString &channelName,
std::weak_ptr<EmoteMap> channelEmoteMap);
2017-04-12 17:46:44 +02:00
ConcurrentMap<QString, twitch::EmoteValue *> &getTwitchEmotes();
EmoteMap &getFFZEmotes();
EmoteMap &getChatterinoEmotes();
EmoteMap &getBTTVChannelEmoteFromCaches();
2017-12-19 03:41:31 +01:00
EmoteMap &getEmojis();
ConcurrentMap<int, EmoteData> &getFFZChannelEmoteFromCaches();
ConcurrentMap<long, EmoteData> &getTwitchEmoteFromCache();
2017-04-12 17:46:44 +02:00
EmoteData getCheerImage(long long int amount, bool animated);
2017-04-12 17:46:44 +02:00
EmoteData getTwitchEmoteById(long int id, const QString &emoteName);
2017-04-12 17:46:44 +02:00
int getGeneration()
{
return _generation;
}
void incGeneration()
{
_generation++;
}
boost::signals2::signal<void()> &getGifUpdateSignal();
2017-04-12 17:46:44 +02:00
// Bit badge/emotes?
ConcurrentMap<QString, messages::LazyLoadedImage *> miscImageCache;
2017-04-12 17:46:44 +02:00
private:
2017-12-31 00:50:07 +01:00
SettingsManager &settingsManager;
WindowManager &windowManager;
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;
2017-07-02 17:37:17 +02:00
// url Emoji-one image
EmoteMap emojis;
void loadEmojis();
public:
void parseEmojis(std::vector<std::tuple<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
/// Twitch emotes
void refreshTwitchEmotes(const std::shared_ptr<twitch::TwitchUser> &user);
struct TwitchAccountEmoteData {
struct TwitchEmote {
std::string id;
std::string code;
};
// emote set
std::map<std::string, std::vector<TwitchEmote>> emoteSets;
std::vector<std::string> emoteCodes;
2017-07-23 09:53:50 +02:00
bool filled = false;
};
std::map<std::string, TwitchAccountEmoteData> twitchAccountEmotes;
private:
2017-07-23 09:53:50 +02:00
// emote code
2017-04-12 17:46:44 +02:00
ConcurrentMap<QString, twitch::EmoteValue *> _twitchEmotes;
2017-07-23 09:53:50 +02:00
// emote id
ConcurrentMap<long, EmoteData> _twitchEmoteFromCache;
2017-07-02 17:37:17 +02:00
/// BTTV emotes
EmoteMap bttvChannelEmotes;
public:
ConcurrentMap<QString, EmoteMap> bttvChannels;
2017-07-23 09:53:50 +02:00
EmoteMap bttvGlobalEmotes;
SignalVector<std::string> bttvGlobalEmoteCodes;
// roomID
std::map<std::string, SignalVector<std::string>> bttvChannelEmoteCodes;
EmoteMap _bttvChannelEmoteFromCaches;
2017-07-23 09:53:50 +02:00
private:
void loadBTTVEmotes();
2017-07-02 17:37:17 +02:00
/// FFZ emotes
EmoteMap ffzChannelEmotes;
public:
ConcurrentMap<QString, EmoteMap> ffzChannels;
2017-07-23 09:53:50 +02:00
EmoteMap ffzGlobalEmotes;
SignalVector<std::string> ffzGlobalEmoteCodes;
std::map<std::string, SignalVector<std::string>> ffzChannelEmoteCodes;
private:
ConcurrentMap<int, EmoteData> _ffzChannelEmoteFromCaches;
void loadFFZEmotes();
2017-07-02 17:37:17 +02:00
/// Chatterino emotes
EmoteMap _chatterinoEmotes;
2017-04-12 17:46:44 +02:00
boost::signals2::signal<void()> gifUpdateTimerSignal;
QTimer gifUpdateTimer;
bool gifUpdateTimerInitiated = false;
2017-04-12 17:46:44 +02:00
2017-12-17 13:46:54 +01:00
int _generation = 0;
2017-04-12 17:46:44 +02:00
// methods
static QString getTwitchEmoteLink(long id, qreal &scale);
};
2017-05-27 16:16:39 +02:00
2017-04-14 17:52:22 +02:00
} // namespace chatterino