2017-06-07 10:09:24 +02:00
|
|
|
#pragma once
|
2017-04-12 17:46:44 +02:00
|
|
|
|
|
|
|
#define GIF_FRAME_LENGTH 33
|
|
|
|
|
2017-06-26 16:41:20 +02:00
|
|
|
#include "emojis.hpp"
|
2018-01-11 20:16:25 +01:00
|
|
|
#include "messages/image.hpp"
|
2018-02-05 15:11:50 +01:00
|
|
|
#include "providers/twitch/emotevalue.hpp"
|
|
|
|
#include "providers/twitch/twitchaccount.hpp"
|
2017-07-23 14:16:13 +02:00
|
|
|
#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>
|
2017-07-31 22:15:02 +02:00
|
|
|
#include <QRegularExpression>
|
2017-06-26 16:41:20 +02:00
|
|
|
#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 22:58:35 +01:00
|
|
|
namespace singletons {
|
2017-06-13 21:13:58 +02:00
|
|
|
|
2017-12-31 22:58:35 +01:00
|
|
|
class SettingManager;
|
2017-12-31 00:50:07 +01:00
|
|
|
class WindowManager;
|
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
class EmoteManager
|
|
|
|
{
|
2017-12-31 22:58:35 +01:00
|
|
|
explicit EmoteManager(singletons::SettingManager &manager,
|
|
|
|
singletons::WindowManager &windowManager);
|
2017-06-13 21:13:58 +02:00
|
|
|
|
2017-12-17 02:18:13 +01:00
|
|
|
public:
|
2017-12-31 00:50:07 +01:00
|
|
|
static EmoteManager &getInstance();
|
2017-10-11 10:34:04 +02:00
|
|
|
|
2017-06-13 21:13:58 +02:00
|
|
|
void loadGlobalEmotes();
|
|
|
|
|
2017-09-16 00:05:06 +02:00
|
|
|
void reloadBTTVChannelEmotes(const QString &channelName,
|
2017-12-31 22:58:35 +01:00
|
|
|
std::weak_ptr<util::EmoteMap> channelEmoteMap);
|
2017-09-16 00:05:06 +02:00
|
|
|
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
|
|
|
|
2018-02-05 15:11:50 +01:00
|
|
|
util::ConcurrentMap<QString, providers::twitch::EmoteValue *> &getTwitchEmotes();
|
2017-12-31 22:58:35 +01:00
|
|
|
util::EmoteMap &getFFZEmotes();
|
|
|
|
util::EmoteMap &getChatterinoEmotes();
|
|
|
|
util::EmoteMap &getBTTVChannelEmoteFromCaches();
|
|
|
|
util::EmoteMap &getEmojis();
|
|
|
|
util::ConcurrentMap<int, util::EmoteData> &getFFZChannelEmoteFromCaches();
|
|
|
|
util::ConcurrentMap<long, util::EmoteData> &getTwitchEmoteFromCache();
|
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
|
|
|
|
2017-12-31 22:58:35 +01:00
|
|
|
util::EmoteData getTwitchEmoteById(long int id, const QString &emoteName);
|
2017-04-12 17:46:44 +02:00
|
|
|
|
|
|
|
int getGeneration()
|
|
|
|
{
|
|
|
|
return _generation;
|
|
|
|
}
|
|
|
|
|
|
|
|
void incGeneration()
|
|
|
|
{
|
|
|
|
_generation++;
|
|
|
|
}
|
|
|
|
|
2017-06-13 21:13:58 +02:00
|
|
|
boost::signals2::signal<void()> &getGifUpdateSignal();
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2017-07-09 17:58:59 +02:00
|
|
|
// Bit badge/emotes?
|
2018-01-11 20:16:25 +01:00
|
|
|
util::ConcurrentMap<QString, messages::Image *> miscImageCache;
|
2017-07-09 17:58:59 +02:00
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
private:
|
2017-12-31 22:58:35 +01:00
|
|
|
SettingManager &settingsManager;
|
2017-12-31 00:50:07 +01:00
|
|
|
WindowManager &windowManager;
|
|
|
|
|
2017-07-02 17:37:17 +02:00
|
|
|
/// Emojis
|
2017-07-31 22:15:02 +02:00
|
|
|
QRegularExpression findShortCodesRegex;
|
|
|
|
|
2017-07-02 17:37:17 +02:00
|
|
|
// shortCodeToEmoji maps strings like "sunglasses" to its emoji
|
|
|
|
QMap<QString, EmojiData> emojiShortCodeToEmoji;
|
2017-06-26 16:41:20 +02:00
|
|
|
|
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-06-26 16:41:20 +02:00
|
|
|
|
2017-07-02 17:37:17 +02:00
|
|
|
// url Emoji-one image
|
2017-12-31 22:58:35 +01:00
|
|
|
util::EmoteMap emojis;
|
2017-06-26 16:41:20 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
2017-07-31 22:15:02 +02:00
|
|
|
QString replaceShortCodes(const QString &text);
|
|
|
|
|
2017-08-01 00:10:02 +02:00
|
|
|
std::vector<std::string> emojiShortCodes;
|
|
|
|
|
2017-07-02 17:37:17 +02:00
|
|
|
/// Twitch emotes
|
2018-02-05 15:11:50 +01:00
|
|
|
void refreshTwitchEmotes(const std::shared_ptr<providers::twitch::TwitchAccount> &user);
|
2017-07-23 14:16:13 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
2017-07-23 14:16:13 +02:00
|
|
|
bool filled = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
std::map<std::string, TwitchAccountEmoteData> twitchAccountEmotes;
|
|
|
|
|
|
|
|
private:
|
2017-07-23 09:53:50 +02:00
|
|
|
// emote code
|
2018-02-05 15:11:50 +01:00
|
|
|
util::ConcurrentMap<QString, providers::twitch::EmoteValue *> _twitchEmotes;
|
2017-07-23 09:53:50 +02:00
|
|
|
|
|
|
|
// emote id
|
2017-12-31 22:58:35 +01:00
|
|
|
util::ConcurrentMap<long, util::EmoteData> _twitchEmoteFromCache;
|
2017-06-26 16:41:20 +02:00
|
|
|
|
2017-07-02 17:37:17 +02:00
|
|
|
/// BTTV emotes
|
2017-12-31 22:58:35 +01:00
|
|
|
util::EmoteMap bttvChannelEmotes;
|
2017-07-09 17:58:59 +02:00
|
|
|
|
|
|
|
public:
|
2017-12-31 22:58:35 +01:00
|
|
|
util::ConcurrentMap<QString, util::EmoteMap> bttvChannels;
|
|
|
|
util::EmoteMap bttvGlobalEmotes;
|
2017-07-23 14:16:13 +02:00
|
|
|
SignalVector<std::string> bttvGlobalEmoteCodes;
|
|
|
|
// roomID
|
|
|
|
std::map<std::string, SignalVector<std::string>> bttvChannelEmoteCodes;
|
2017-12-31 22:58:35 +01:00
|
|
|
util::EmoteMap _bttvChannelEmoteFromCaches;
|
2017-06-26 16:41:20 +02:00
|
|
|
|
2017-07-23 09:53:50 +02:00
|
|
|
private:
|
2017-06-26 16:41:20 +02:00
|
|
|
void loadBTTVEmotes();
|
|
|
|
|
2017-07-02 17:37:17 +02:00
|
|
|
/// FFZ emotes
|
2017-12-31 22:58:35 +01:00
|
|
|
util::EmoteMap ffzChannelEmotes;
|
2017-07-09 17:58:59 +02:00
|
|
|
|
|
|
|
public:
|
2017-12-31 22:58:35 +01:00
|
|
|
util::ConcurrentMap<QString, util::EmoteMap> ffzChannels;
|
|
|
|
util::EmoteMap ffzGlobalEmotes;
|
2017-07-23 14:16:13 +02:00
|
|
|
SignalVector<std::string> ffzGlobalEmoteCodes;
|
|
|
|
std::map<std::string, SignalVector<std::string>> ffzChannelEmoteCodes;
|
2017-07-09 17:58:59 +02:00
|
|
|
|
|
|
|
private:
|
2017-12-31 22:58:35 +01:00
|
|
|
util::ConcurrentMap<int, util::EmoteData> _ffzChannelEmoteFromCaches;
|
2017-06-26 16:41:20 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
2017-12-17 13:31:08 +01: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
|
|
|
};
|
2017-05-27 16:16:39 +02:00
|
|
|
|
2018-01-07 02:56:45 +01:00
|
|
|
} // namespace singletons
|
2017-04-14 17:52:22 +02:00
|
|
|
} // namespace chatterino
|