2017-01-04 15:12:31 +01:00
|
|
|
#include "emotes.h"
|
2017-01-13 18:59:11 +01:00
|
|
|
#include "resources.h"
|
2017-01-04 15:12:31 +01:00
|
|
|
|
2017-01-26 10:18:02 +01:00
|
|
|
#include <QDebug>
|
|
|
|
|
2017-01-18 21:30:23 +01:00
|
|
|
namespace chatterino {
|
|
|
|
|
2017-01-18 04:33:30 +01:00
|
|
|
QString Emotes::twitchEmoteTemplate(
|
2017-01-17 00:42:32 +01:00
|
|
|
"https://static-cdn.jtvnw.net/emoticons/v1/{id}/{scale}.0");
|
2017-01-04 15:12:31 +01:00
|
|
|
|
2017-01-18 04:33:30 +01:00
|
|
|
ConcurrentMap<QString, TwitchEmoteValue *> Emotes::twitchEmotes;
|
2017-01-18 21:30:23 +01:00
|
|
|
ConcurrentMap<QString, messages::LazyLoadedImage *> Emotes::bttvEmotes;
|
|
|
|
ConcurrentMap<QString, messages::LazyLoadedImage *> Emotes::ffzEmotes;
|
|
|
|
ConcurrentMap<QString, messages::LazyLoadedImage *> Emotes::chatterinoEmotes;
|
|
|
|
ConcurrentMap<QString, messages::LazyLoadedImage *>
|
|
|
|
Emotes::bttvChannelEmoteFromCaches;
|
|
|
|
ConcurrentMap<QString, messages::LazyLoadedImage *>
|
|
|
|
Emotes::ffzChannelEmoteFromCaches;
|
|
|
|
ConcurrentMap<long, messages::LazyLoadedImage *> Emotes::twitchEmoteFromCache;
|
|
|
|
ConcurrentMap<QString, messages::LazyLoadedImage *> Emotes::miscImageFromCache;
|
2017-01-05 20:49:33 +01:00
|
|
|
|
2017-01-18 04:33:30 +01:00
|
|
|
int Emotes::generation = 0;
|
2017-01-15 16:38:30 +01:00
|
|
|
|
2017-01-05 16:07:20 +01:00
|
|
|
Emotes::Emotes()
|
|
|
|
{
|
|
|
|
}
|
2017-01-04 15:12:31 +01:00
|
|
|
|
2017-01-18 21:30:23 +01:00
|
|
|
messages::LazyLoadedImage *
|
2017-01-11 18:52:09 +01:00
|
|
|
Emotes::getTwitchEmoteById(const QString &name, long id)
|
2017-01-06 23:28:48 +01:00
|
|
|
{
|
2017-01-26 10:18:02 +01:00
|
|
|
qDebug() << "loading twitch emote: " << id;
|
|
|
|
|
|
|
|
return Emotes::twitchEmoteFromCache.getOrAdd(id, [&name, &id] {
|
|
|
|
qDebug() << "loading twitch emote: " << id;
|
2017-01-13 18:59:11 +01:00
|
|
|
qreal scale;
|
|
|
|
QString url = getTwitchEmoteLink(id, scale);
|
2017-01-18 21:30:23 +01:00
|
|
|
return new messages::LazyLoadedImage(url, scale, name,
|
|
|
|
name + "\nTwitch Emote");
|
2017-01-13 18:59:11 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
QString
|
|
|
|
Emotes::getTwitchEmoteLink(long id, qreal &scale)
|
|
|
|
{
|
|
|
|
scale = .5;
|
|
|
|
|
2017-01-26 10:18:02 +01:00
|
|
|
QString value = Emotes::twitchEmoteTemplate;
|
|
|
|
|
|
|
|
value.detach();
|
|
|
|
|
|
|
|
return value.replace("{id}", QString::number(id)).replace("{scale}", "2");
|
2017-01-06 23:28:48 +01:00
|
|
|
}
|
|
|
|
|
2017-01-18 21:30:23 +01:00
|
|
|
messages::LazyLoadedImage *
|
2017-01-11 18:52:09 +01:00
|
|
|
Emotes::getCheerImage(long long amount, bool animated)
|
2017-01-05 16:07:20 +01:00
|
|
|
{
|
2017-01-15 17:21:28 +01:00
|
|
|
// TODO: fix this xD
|
2017-01-05 20:49:33 +01:00
|
|
|
return getCheerBadge(amount);
|
|
|
|
}
|
2017-01-04 15:12:31 +01:00
|
|
|
|
2017-01-18 21:30:23 +01:00
|
|
|
messages::LazyLoadedImage *
|
2017-01-11 18:52:09 +01:00
|
|
|
Emotes::getCheerBadge(long long amount)
|
2017-01-05 20:49:33 +01:00
|
|
|
{
|
2017-01-11 18:52:09 +01:00
|
|
|
if (amount >= 100000) {
|
2017-01-18 04:33:30 +01:00
|
|
|
return Resources::getCheerBadge100000();
|
2017-01-11 18:52:09 +01:00
|
|
|
} else if (amount >= 10000) {
|
2017-01-18 04:33:30 +01:00
|
|
|
return Resources::getCheerBadge10000();
|
2017-01-11 18:52:09 +01:00
|
|
|
} else if (amount >= 5000) {
|
2017-01-18 04:33:30 +01:00
|
|
|
return Resources::getCheerBadge5000();
|
2017-01-11 18:52:09 +01:00
|
|
|
} else if (amount >= 1000) {
|
2017-01-18 04:33:30 +01:00
|
|
|
return Resources::getCheerBadge1000();
|
2017-01-11 18:52:09 +01:00
|
|
|
} else if (amount >= 100) {
|
2017-01-18 04:33:30 +01:00
|
|
|
return Resources::getCheerBadge100();
|
2017-01-11 18:52:09 +01:00
|
|
|
} else {
|
2017-01-18 04:33:30 +01:00
|
|
|
return Resources::getCheerBadge1();
|
2017-01-05 20:49:33 +01:00
|
|
|
}
|
2017-01-04 15:12:31 +01:00
|
|
|
}
|
2017-01-18 21:30:23 +01:00
|
|
|
}
|