Merge branch 'master' into apa-notification-on-live
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
#include "providers/bttv/BttvEmotes.hpp"
|
||||
|
||||
#include "common/Common.hpp"
|
||||
#include "common/NetworkRequest.hpp"
|
||||
#include "debug/Log.hpp"
|
||||
#include "messages/Emote.hpp"
|
||||
#include "messages/Image.hpp"
|
||||
#include "messages/ImageSet.hpp"
|
||||
#include "providers/twitch/TwitchChannel.hpp"
|
||||
@@ -10,11 +12,140 @@
|
||||
#include <QThread>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
namespace {
|
||||
Url getEmoteLink(QString urlTemplate, const EmoteId &id,
|
||||
const QString &emoteScale)
|
||||
{
|
||||
urlTemplate.detach();
|
||||
|
||||
Url getEmoteLink(QString urlTemplate, const EmoteId &id,
|
||||
const QString &emoteScale)
|
||||
return {urlTemplate.replace("{{id}}", id.string)
|
||||
.replace("{{image}}", emoteScale)};
|
||||
}
|
||||
std::pair<Outcome, EmoteMap> parseGlobalEmotes(
|
||||
const QJsonObject &jsonRoot, const EmoteMap ¤tEmotes)
|
||||
{
|
||||
auto emotes = EmoteMap();
|
||||
auto jsonEmotes = jsonRoot.value("emotes").toArray();
|
||||
auto urlTemplate =
|
||||
qS("https:") + jsonRoot.value("urlTemplate").toString();
|
||||
|
||||
for (auto jsonEmote : jsonEmotes) {
|
||||
auto id = EmoteId{jsonEmote.toObject().value("id").toString()};
|
||||
auto name =
|
||||
EmoteName{jsonEmote.toObject().value("code").toString()};
|
||||
|
||||
auto emote = Emote(
|
||||
{name,
|
||||
ImageSet{
|
||||
Image::fromUrl(getEmoteLink(urlTemplate, id, "1x"), 1),
|
||||
Image::fromUrl(getEmoteLink(urlTemplate, id, "2x"), 0.5),
|
||||
Image::fromUrl(getEmoteLink(urlTemplate, id, "3x"), 0.25)},
|
||||
Tooltip{name.string + "<br />Global Bttv Emote"},
|
||||
Url{"https://manage.betterttv.net/emotes/" + id.string}});
|
||||
|
||||
emotes[name] =
|
||||
cachedOrMakeEmotePtr(std::move(emote), currentEmotes);
|
||||
}
|
||||
|
||||
return {Success, std::move(emotes)};
|
||||
}
|
||||
EmotePtr cachedOrMake(Emote &&emote, const EmoteId &id)
|
||||
{
|
||||
static std::unordered_map<EmoteId, std::weak_ptr<const Emote>> cache;
|
||||
static std::mutex mutex;
|
||||
|
||||
return cachedOrMakeEmotePtr(std::move(emote), cache, mutex, id);
|
||||
}
|
||||
std::pair<Outcome, EmoteMap> parseChannelEmotes(const QJsonObject &jsonRoot)
|
||||
{
|
||||
auto emotes = EmoteMap();
|
||||
auto jsonEmotes = jsonRoot.value("emotes").toArray();
|
||||
auto urlTemplate = "https:" + jsonRoot.value("urlTemplate").toString();
|
||||
|
||||
for (auto jsonEmote_ : jsonEmotes) {
|
||||
auto jsonEmote = jsonEmote_.toObject();
|
||||
|
||||
auto id = EmoteId{jsonEmote.value("id").toString()};
|
||||
auto name = EmoteName{jsonEmote.value("code").toString()};
|
||||
// emoteObject.value("imageType").toString();
|
||||
|
||||
auto emote = Emote(
|
||||
{name,
|
||||
ImageSet{
|
||||
Image::fromUrl(getEmoteLink(urlTemplate, id, "1x"), 1),
|
||||
Image::fromUrl(getEmoteLink(urlTemplate, id, "2x"), 0.5),
|
||||
Image::fromUrl(getEmoteLink(urlTemplate, id, "3x"), 0.25)},
|
||||
Tooltip{name.string + "<br />Channel Bttv Emote"},
|
||||
Url{"https://manage.betterttv.net/emotes/" + id.string}});
|
||||
|
||||
emotes[name] = cachedOrMake(std::move(emote), id);
|
||||
}
|
||||
|
||||
return {Success, std::move(emotes)};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
//
|
||||
// BttvEmotes
|
||||
//
|
||||
BttvEmotes::BttvEmotes()
|
||||
: global_(std::make_shared<EmoteMap>())
|
||||
{
|
||||
}
|
||||
|
||||
std::shared_ptr<const EmoteMap> BttvEmotes::emotes() const
|
||||
{
|
||||
return this->global_.get();
|
||||
}
|
||||
|
||||
boost::optional<EmotePtr> BttvEmotes::emote(const EmoteName &name) const
|
||||
{
|
||||
auto emotes = this->global_.get();
|
||||
auto it = emotes->find(name);
|
||||
|
||||
if (it == emotes->end()) return boost::none;
|
||||
return it->second;
|
||||
}
|
||||
|
||||
void BttvEmotes::loadEmotes()
|
||||
{
|
||||
auto request = NetworkRequest(QString(globalEmoteApiUrl));
|
||||
|
||||
request.setCaller(QThread::currentThread());
|
||||
request.setTimeout(30000);
|
||||
|
||||
request.onSuccess([this](auto result) -> Outcome {
|
||||
auto emotes = this->global_.get();
|
||||
auto pair = parseGlobalEmotes(result.parseJson(), *emotes);
|
||||
if (pair.first)
|
||||
this->global_.set(
|
||||
std::make_shared<EmoteMap>(std::move(pair.second)));
|
||||
return pair.first;
|
||||
});
|
||||
|
||||
request.execute();
|
||||
}
|
||||
|
||||
void BttvEmotes::loadChannel(const QString &channelName,
|
||||
std::function<void(EmoteMap &&)> callback)
|
||||
{
|
||||
auto request =
|
||||
NetworkRequest(QString(bttvChannelEmoteApiUrl) + channelName);
|
||||
|
||||
request.setCaller(QThread::currentThread());
|
||||
request.setTimeout(3000);
|
||||
|
||||
request.onSuccess([callback = std::move(callback)](auto result) -> Outcome {
|
||||
auto pair = parseChannelEmotes(result.parseJson());
|
||||
if (pair.first) callback(std::move(pair.second));
|
||||
return pair.first;
|
||||
});
|
||||
|
||||
request.execute();
|
||||
}
|
||||
|
||||
static Url getEmoteLink(QString urlTemplate, const EmoteId &id,
|
||||
const QString &emoteScale)
|
||||
{
|
||||
urlTemplate.detach();
|
||||
|
||||
@@ -22,93 +153,4 @@ Url getEmoteLink(QString urlTemplate, const EmoteId &id,
|
||||
.replace("{{image}}", emoteScale)};
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
AccessGuard<const EmoteMap> BttvEmotes::accessGlobalEmotes() const
|
||||
{
|
||||
return this->globalEmotes_.accessConst();
|
||||
}
|
||||
|
||||
boost::optional<EmotePtr> BttvEmotes::getGlobalEmote(const EmoteName &name)
|
||||
{
|
||||
auto emotes = this->globalEmotes_.access();
|
||||
auto it = emotes->find(name);
|
||||
|
||||
if (it == emotes->end()) return boost::none;
|
||||
return it->second;
|
||||
}
|
||||
|
||||
// FOURTF: never returns anything
|
||||
// boost::optional<EmotePtr> BttvEmotes::getEmote(const EmoteId &id)
|
||||
//{
|
||||
// auto cache = this->channelEmoteCache_.access();
|
||||
// auto it = cache->find(id);
|
||||
//
|
||||
// if (it != cache->end()) {
|
||||
// auto shared = it->second.lock();
|
||||
// if (shared) {
|
||||
// return shared;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return boost::none;
|
||||
//}
|
||||
|
||||
void BttvEmotes::loadGlobalEmotes()
|
||||
{
|
||||
auto request = NetworkRequest(QString(globalEmoteApiUrl));
|
||||
|
||||
request.setCaller(QThread::currentThread());
|
||||
request.setTimeout(30000);
|
||||
request.onSuccess([this](auto result) -> Outcome {
|
||||
// if (auto shared = weak.lock()) {
|
||||
auto currentEmotes = this->globalEmotes_.access();
|
||||
|
||||
auto pair = this->parseGlobalEmotes(result.parseJson(), *currentEmotes);
|
||||
|
||||
if (pair.first) {
|
||||
*currentEmotes = std::move(pair.second);
|
||||
}
|
||||
|
||||
return pair.first;
|
||||
// }
|
||||
return Failure;
|
||||
});
|
||||
|
||||
request.execute();
|
||||
}
|
||||
|
||||
std::pair<Outcome, EmoteMap> BttvEmotes::parseGlobalEmotes(
|
||||
const QJsonObject &jsonRoot, const EmoteMap ¤tEmotes)
|
||||
{
|
||||
auto emotes = EmoteMap();
|
||||
auto jsonEmotes = jsonRoot.value("emotes").toArray();
|
||||
auto urlTemplate =
|
||||
QString("https:" + jsonRoot.value("urlTemplate").toString());
|
||||
|
||||
for (const QJsonValue &jsonEmote : jsonEmotes) {
|
||||
auto id = EmoteId{jsonEmote.toObject().value("id").toString()};
|
||||
auto name = EmoteName{jsonEmote.toObject().value("code").toString()};
|
||||
|
||||
auto emote = Emote(
|
||||
{name,
|
||||
ImageSet{
|
||||
Image::fromUrl(getEmoteLink(urlTemplate, id, "1x"), 1),
|
||||
Image::fromUrl(getEmoteLink(urlTemplate, id, "2x"), 0.5),
|
||||
Image::fromUrl(getEmoteLink(urlTemplate, id, "3x"), 0.25)},
|
||||
Tooltip{name.string + "<br />Global Bttv Emote"},
|
||||
Url{"https://manage.betterttv.net/emotes/" + id.string}});
|
||||
|
||||
auto it = currentEmotes.find(name);
|
||||
if (it != currentEmotes.end() && *it->second == emote) {
|
||||
// reuse old shared_ptr if nothing changed
|
||||
emotes[name] = it->second;
|
||||
} else {
|
||||
emotes[name] = std::make_shared<Emote>(std::move(emote));
|
||||
}
|
||||
}
|
||||
|
||||
return {Success, std::move(emotes)};
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -1,33 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "common/UniqueAccess.hpp"
|
||||
#include "messages/Emote.hpp"
|
||||
#include "messages/EmoteCache.hpp"
|
||||
#include "boost/optional.hpp"
|
||||
#include "common/Aliases.hpp"
|
||||
#include "common/Atomic.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class BttvEmotes final : std::enable_shared_from_this<BttvEmotes>
|
||||
struct Emote;
|
||||
using EmotePtr = std::shared_ptr<const Emote>;
|
||||
class EmoteMap;
|
||||
|
||||
class BttvEmotes final
|
||||
{
|
||||
static constexpr const char *globalEmoteApiUrl =
|
||||
"https://api.betterttv.net/2/emotes";
|
||||
static constexpr const char *bttvChannelEmoteApiUrl =
|
||||
"https://api.betterttv.net/2/channels/";
|
||||
|
||||
public:
|
||||
// BttvEmotes();
|
||||
BttvEmotes();
|
||||
|
||||
AccessGuard<const EmoteMap> accessGlobalEmotes() const;
|
||||
boost::optional<EmotePtr> getGlobalEmote(const EmoteName &name);
|
||||
boost::optional<EmotePtr> getEmote(const EmoteId &id);
|
||||
|
||||
void loadGlobalEmotes();
|
||||
std::shared_ptr<const EmoteMap> emotes() const;
|
||||
boost::optional<EmotePtr> emote(const EmoteName &name) const;
|
||||
void loadEmotes();
|
||||
static void loadChannel(const QString &channelName,
|
||||
std::function<void(EmoteMap &&)> callback);
|
||||
|
||||
private:
|
||||
std::pair<Outcome, EmoteMap> parseGlobalEmotes(
|
||||
const QJsonObject &jsonRoot, const EmoteMap ¤tEmotes);
|
||||
|
||||
UniqueAccess<EmoteMap> globalEmotes_;
|
||||
// UniqueAccess<WeakEmoteIdMap> channelEmoteCache_;
|
||||
Atomic<std::shared_ptr<const EmoteMap>> global_;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -11,78 +11,4 @@
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
static Url getEmoteLink(QString urlTemplate, const EmoteId &id,
|
||||
const QString &emoteScale);
|
||||
static std::pair<Outcome, EmoteMap> bttvParseChannelEmotes(
|
||||
const QJsonObject &jsonRoot);
|
||||
|
||||
void loadBttvChannelEmotes(const QString &channelName,
|
||||
std::function<void(EmoteMap &&)> callback)
|
||||
{
|
||||
auto request =
|
||||
NetworkRequest(QString(bttvChannelEmoteApiUrl) + channelName);
|
||||
|
||||
request.setCaller(QThread::currentThread());
|
||||
request.setTimeout(3000);
|
||||
request.onSuccess([callback = std::move(callback)](auto result) -> Outcome {
|
||||
auto pair = bttvParseChannelEmotes(result.parseJson());
|
||||
|
||||
if (pair.first == Success) callback(std::move(pair.second));
|
||||
|
||||
return pair.first;
|
||||
});
|
||||
|
||||
request.execute();
|
||||
}
|
||||
|
||||
static std::pair<Outcome, EmoteMap> bttvParseChannelEmotes(
|
||||
const QJsonObject &jsonRoot)
|
||||
{
|
||||
static UniqueAccess<std::unordered_map<EmoteId, std::weak_ptr<const Emote>>>
|
||||
cache_;
|
||||
|
||||
auto cache = cache_.access();
|
||||
auto emotes = EmoteMap();
|
||||
auto jsonEmotes = jsonRoot.value("emotes").toArray();
|
||||
auto urlTemplate =
|
||||
QString("https:" + jsonRoot.value("urlTemplate").toString());
|
||||
|
||||
for (auto jsonEmote_ : jsonEmotes) {
|
||||
auto jsonEmote = jsonEmote_.toObject();
|
||||
|
||||
auto id = EmoteId{jsonEmote.value("id").toString()};
|
||||
auto name = EmoteName{jsonEmote.value("code").toString()};
|
||||
// emoteObject.value("imageType").toString();
|
||||
|
||||
auto emote = Emote(
|
||||
{name,
|
||||
ImageSet{
|
||||
Image::fromUrl(getEmoteLink(urlTemplate, id, "1x"), 1),
|
||||
Image::fromUrl(getEmoteLink(urlTemplate, id, "2x"), 0.5),
|
||||
Image::fromUrl(getEmoteLink(urlTemplate, id, "3x"), 0.25)},
|
||||
Tooltip{name.string + "<br />Channel Bttv Emote"},
|
||||
Url{"https://manage.betterttv.net/emotes/" + id.string}});
|
||||
|
||||
auto shared = (*cache)[id].lock();
|
||||
if (shared && *shared == emote) {
|
||||
// reuse old shared_ptr if nothing changed
|
||||
emotes[name] = shared;
|
||||
} else {
|
||||
(*cache)[id] = emotes[name] =
|
||||
std::make_shared<Emote>(std::move(emote));
|
||||
}
|
||||
}
|
||||
|
||||
return {Success, std::move(emotes)};
|
||||
}
|
||||
|
||||
static Url getEmoteLink(QString urlTemplate, const EmoteId &id,
|
||||
const QString &emoteScale)
|
||||
{
|
||||
urlTemplate.detach();
|
||||
|
||||
return {urlTemplate.replace("{{id}}", id.string)
|
||||
.replace("{{image}}", emoteScale)};
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -6,11 +6,4 @@ class QString;
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class EmoteMap;
|
||||
constexpr const char *bttvChannelEmoteApiUrl =
|
||||
"https://api.betterttv.net/2/channels/";
|
||||
|
||||
void loadBttvChannelEmotes(const QString &channelName,
|
||||
std::function<void(EmoteMap &&)> callback);
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -14,39 +14,41 @@ ChatterinoBadges::ChatterinoBadges()
|
||||
|
||||
boost::optional<EmotePtr> ChatterinoBadges::getBadge(const UserName &username)
|
||||
{
|
||||
return this->badges.access()->get(username);
|
||||
return boost::none;
|
||||
// return this->badges.access()->get(username);
|
||||
}
|
||||
|
||||
void ChatterinoBadges::loadChatterinoBadges()
|
||||
{
|
||||
static QString url("https://fourtf.com/chatterino/badges.json");
|
||||
// static QString url("https://fourtf.com/chatterino/badges.json");
|
||||
|
||||
NetworkRequest req(url);
|
||||
req.setCaller(QThread::currentThread());
|
||||
// NetworkRequest req(url);
|
||||
// req.setCaller(QThread::currentThread());
|
||||
|
||||
req.onSuccess([this](auto result) {
|
||||
auto jsonRoot = result.parseJson();
|
||||
auto badges = this->badges.access();
|
||||
auto replacement = badges->makeReplacment();
|
||||
// req.onSuccess([this](auto result) {
|
||||
// auto jsonRoot = result.parseJson();
|
||||
// auto badges = this->badges.access();
|
||||
// auto replacement = badges->makeReplacment();
|
||||
|
||||
for (auto jsonBadge_ : jsonRoot.value("badges").toArray()) {
|
||||
auto jsonBadge = jsonBadge_.toObject();
|
||||
// for (auto jsonBadge_ : jsonRoot.value("badges").toArray()) {
|
||||
// auto jsonBadge = jsonBadge_.toObject();
|
||||
|
||||
auto emote = Emote{
|
||||
EmoteName{}, ImageSet{Url{jsonBadge.value("image").toString()}},
|
||||
Tooltip{jsonBadge.value("tooltip").toString()}, Url{}};
|
||||
// auto emote = Emote{
|
||||
// EmoteName{},
|
||||
// ImageSet{Url{jsonBadge.value("image").toString()}},
|
||||
// Tooltip{jsonBadge.value("tooltip").toString()}, Url{}};
|
||||
|
||||
for (auto jsonUser : jsonBadge.value("users").toArray()) {
|
||||
replacement.add(UserName{jsonUser.toString()},
|
||||
std::move(emote));
|
||||
}
|
||||
}
|
||||
// for (auto jsonUser : jsonBadge.value("users").toArray()) {
|
||||
// replacement.add(UserName{jsonUser.toString()},
|
||||
// std::move(emote));
|
||||
// }
|
||||
// }
|
||||
|
||||
replacement.apply();
|
||||
return Success;
|
||||
});
|
||||
// replacement.apply();
|
||||
// return Success;
|
||||
//});
|
||||
|
||||
req.execute();
|
||||
// req.execute();
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <boost/optional.hpp>
|
||||
#include <unordered_map>
|
||||
#include "common/Common.hpp"
|
||||
#include "common/UniqueAccess.hpp"
|
||||
#include "messages/Emote.hpp"
|
||||
#include "messages/EmoteCache.hpp"
|
||||
|
||||
#include "common/Aliases.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
struct Emote;
|
||||
using EmotePtr = std::shared_ptr<const Emote>;
|
||||
|
||||
class ChatterinoBadges
|
||||
{
|
||||
public:
|
||||
@@ -19,7 +19,7 @@ public:
|
||||
private:
|
||||
void loadChatterinoBadges();
|
||||
|
||||
UniqueAccess<EmoteCache<UserName>> badges;
|
||||
// UniqueAccess<EmoteCache<UserName>> badges;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "Application.hpp"
|
||||
#include "debug/Log.hpp"
|
||||
#include "messages/Emote.hpp"
|
||||
#include "singletons/Settings.hpp"
|
||||
|
||||
#include <rapidjson/error/en.h>
|
||||
@@ -12,82 +13,81 @@
|
||||
#include <memory>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
namespace {
|
||||
void parseEmoji(const std::shared_ptr<EmojiData> &emojiData,
|
||||
const rapidjson::Value &unparsedEmoji,
|
||||
QString shortCode = QString())
|
||||
{
|
||||
static uint unicodeBytes[4];
|
||||
|
||||
void parseEmoji(const std::shared_ptr<EmojiData> &emojiData,
|
||||
const rapidjson::Value &unparsedEmoji,
|
||||
QString shortCode = QString())
|
||||
{
|
||||
static uint unicodeBytes[4];
|
||||
struct {
|
||||
bool apple;
|
||||
bool google;
|
||||
bool twitter;
|
||||
bool emojione;
|
||||
bool facebook;
|
||||
bool messenger;
|
||||
} capabilities;
|
||||
|
||||
struct {
|
||||
bool apple;
|
||||
bool google;
|
||||
bool twitter;
|
||||
bool emojione;
|
||||
bool facebook;
|
||||
bool messenger;
|
||||
} capabilities;
|
||||
|
||||
if (!shortCode.isEmpty()) {
|
||||
emojiData->shortCodes.push_back(shortCode);
|
||||
} else {
|
||||
const auto &shortCodes = unparsedEmoji["short_names"];
|
||||
for (const auto &shortCode : shortCodes.GetArray()) {
|
||||
emojiData->shortCodes.emplace_back(shortCode.GetString());
|
||||
if (!shortCode.isEmpty()) {
|
||||
emojiData->shortCodes.push_back(shortCode);
|
||||
} else {
|
||||
const auto &shortCodes = unparsedEmoji["short_names"];
|
||||
for (const auto &shortCode : shortCodes.GetArray()) {
|
||||
emojiData->shortCodes.emplace_back(shortCode.GetString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rj::getSafe(unparsedEmoji, "non_qualified", emojiData->nonQualifiedCode);
|
||||
rj::getSafe(unparsedEmoji, "unified", emojiData->unifiedCode);
|
||||
rj::getSafe(unparsedEmoji, "non_qualified",
|
||||
emojiData->nonQualifiedCode);
|
||||
rj::getSafe(unparsedEmoji, "unified", emojiData->unifiedCode);
|
||||
|
||||
rj::getSafe(unparsedEmoji, "has_img_apple", capabilities.apple);
|
||||
rj::getSafe(unparsedEmoji, "has_img_google", capabilities.google);
|
||||
rj::getSafe(unparsedEmoji, "has_img_twitter", capabilities.twitter);
|
||||
rj::getSafe(unparsedEmoji, "has_img_emojione", capabilities.emojione);
|
||||
rj::getSafe(unparsedEmoji, "has_img_facebook", capabilities.facebook);
|
||||
rj::getSafe(unparsedEmoji, "has_img_messenger", capabilities.messenger);
|
||||
rj::getSafe(unparsedEmoji, "has_img_apple", capabilities.apple);
|
||||
rj::getSafe(unparsedEmoji, "has_img_google", capabilities.google);
|
||||
rj::getSafe(unparsedEmoji, "has_img_twitter", capabilities.twitter);
|
||||
rj::getSafe(unparsedEmoji, "has_img_emojione", capabilities.emojione);
|
||||
rj::getSafe(unparsedEmoji, "has_img_facebook", capabilities.facebook);
|
||||
rj::getSafe(unparsedEmoji, "has_img_messenger", capabilities.messenger);
|
||||
|
||||
if (capabilities.apple) {
|
||||
emojiData->capabilities.insert("Apple");
|
||||
}
|
||||
if (capabilities.google) {
|
||||
emojiData->capabilities.insert("Google");
|
||||
}
|
||||
if (capabilities.twitter) {
|
||||
emojiData->capabilities.insert("Twitter");
|
||||
}
|
||||
if (capabilities.emojione) {
|
||||
emojiData->capabilities.insert("EmojiOne 3");
|
||||
}
|
||||
if (capabilities.facebook) {
|
||||
emojiData->capabilities.insert("Facebook");
|
||||
}
|
||||
if (capabilities.messenger) {
|
||||
emojiData->capabilities.insert("Messenger");
|
||||
}
|
||||
if (capabilities.apple) {
|
||||
emojiData->capabilities.insert("Apple");
|
||||
}
|
||||
if (capabilities.google) {
|
||||
emojiData->capabilities.insert("Google");
|
||||
}
|
||||
if (capabilities.twitter) {
|
||||
emojiData->capabilities.insert("Twitter");
|
||||
}
|
||||
if (capabilities.emojione) {
|
||||
emojiData->capabilities.insert("EmojiOne 3");
|
||||
}
|
||||
if (capabilities.facebook) {
|
||||
emojiData->capabilities.insert("Facebook");
|
||||
}
|
||||
if (capabilities.messenger) {
|
||||
emojiData->capabilities.insert("Messenger");
|
||||
}
|
||||
|
||||
QStringList unicodeCharacters;
|
||||
if (!emojiData->nonQualifiedCode.isEmpty()) {
|
||||
unicodeCharacters = emojiData->nonQualifiedCode.toLower().split('-');
|
||||
} else {
|
||||
unicodeCharacters = emojiData->unifiedCode.toLower().split('-');
|
||||
QStringList unicodeCharacters;
|
||||
if (!emojiData->nonQualifiedCode.isEmpty()) {
|
||||
unicodeCharacters =
|
||||
emojiData->nonQualifiedCode.toLower().split('-');
|
||||
} else {
|
||||
unicodeCharacters = emojiData->unifiedCode.toLower().split('-');
|
||||
}
|
||||
if (unicodeCharacters.length() < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
int numUnicodeBytes = 0;
|
||||
|
||||
for (const QString &unicodeCharacter : unicodeCharacters) {
|
||||
unicodeBytes[numUnicodeBytes++] =
|
||||
QString(unicodeCharacter).toUInt(nullptr, 16);
|
||||
}
|
||||
|
||||
emojiData->value = QString::fromUcs4(unicodeBytes, numUnicodeBytes);
|
||||
}
|
||||
if (unicodeCharacters.length() < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
int numUnicodeBytes = 0;
|
||||
|
||||
for (const QString &unicodeCharacter : unicodeCharacters) {
|
||||
unicodeBytes[numUnicodeBytes++] =
|
||||
QString(unicodeCharacter).toUInt(nullptr, 16);
|
||||
}
|
||||
|
||||
emojiData->value = QString::fromUcs4(unicodeBytes, numUnicodeBytes);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void Emojis::load()
|
||||
@@ -103,12 +103,10 @@ void Emojis::load()
|
||||
|
||||
void Emojis::loadEmojis()
|
||||
{
|
||||
std::map<std::string, QString> toneNames;
|
||||
toneNames["1F3FB"] = "tone1";
|
||||
toneNames["1F3FC"] = "tone2";
|
||||
toneNames["1F3FD"] = "tone3";
|
||||
toneNames["1F3FE"] = "tone4";
|
||||
toneNames["1F3FF"] = "tone5";
|
||||
auto toneNames = std::map<std::string, QString>{
|
||||
{"1F3FB", "tone1"}, {"1F3FC", "tone2"}, {"1F3FD", "tone3"},
|
||||
{"1F3FE", "tone4"}, {"1F3FF", "tone5"},
|
||||
};
|
||||
|
||||
QFile file(":/emoji.json");
|
||||
file.open(QFile::ReadOnly);
|
||||
@@ -118,7 +116,7 @@ void Emojis::loadEmojis()
|
||||
rapidjson::ParseResult result = root.Parse(data.toUtf8(), data.length());
|
||||
|
||||
if (result.Code() != rapidjson::kParseErrorNone) {
|
||||
Log("JSON parse error: {} ({})",
|
||||
log("JSON parse error: {} ({})",
|
||||
rapidjson::GetParseError_En(result.Code()), result.Offset());
|
||||
return;
|
||||
}
|
||||
@@ -146,7 +144,7 @@ void Emojis::loadEmojis()
|
||||
|
||||
auto toneNameIt = toneNames.find(tone);
|
||||
if (toneNameIt == toneNames.end()) {
|
||||
Log("Tone with key {} does not exist in tone names map",
|
||||
log("Tone with key {} does not exist in tone names map",
|
||||
tone);
|
||||
continue;
|
||||
}
|
||||
@@ -218,8 +216,8 @@ void Emojis::loadEmojiSet()
|
||||
{
|
||||
auto app = getApp();
|
||||
|
||||
app->settings->emojiSet.connect([=](const auto &emojiSet, auto) {
|
||||
Log("Using emoji set {}", emojiSet);
|
||||
getSettings()->emojiSet.connect([=](const auto &emojiSet, auto) {
|
||||
log("Using emoji set {}", emojiSet);
|
||||
this->emojis.each([=](const auto &name,
|
||||
std::shared_ptr<EmojiData> &emoji) {
|
||||
QString emojiSetToUse = emojiSet;
|
||||
@@ -233,27 +231,12 @@ void Emojis::loadEmojiSet()
|
||||
// {"Google", "https://cdn.jsdelivr.net/npm/emoji-datasource-google@4.0.4/img/google/64/"},
|
||||
// {"Messenger", "https://cdn.jsdelivr.net/npm/emoji-datasource-messenger@4.0.4/img/messenger/64/"},
|
||||
|
||||
// {"EmojiOne 2", "https://cdnjs.cloudflare.com/ajax/libs/emojione/2.2.6/assets/png/"},
|
||||
// {"EmojiOne 3", "https://braize.pajlada.com/emoji/img/emojione/64/"},
|
||||
// {"Twitter", "https://braize.pajlada.com/emoji/img/twitter/64/"},
|
||||
// {"Facebook", "https://braize.pajlada.com/emoji/img/facebook/64/"},
|
||||
// {"Apple", "https://braize.pajlada.com/emoji/img/apple/64/"},
|
||||
// {"Google", "https://braize.pajlada.com/emoji/img/google/64/"},
|
||||
// {"Messenger", "https://braize.pajlada.com/emoji/img/messenger/64/"},
|
||||
|
||||
{"EmojiOne 3", "https://pajbot.com/static/emoji/img/emojione/64/"},
|
||||
{"Twitter", "https://pajbot.com/static/emoji/img/twitter/64/"},
|
||||
{"Facebook", "https://pajbot.com/static/emoji/img/facebook/64/"},
|
||||
{"Apple", "https://pajbot.com/static/emoji/img/apple/64/"},
|
||||
{"Google", "https://pajbot.com/static/emoji/img/google/64/"},
|
||||
{"Messenger", "https://pajbot.com/static/emoji/img/messenger/64/"},
|
||||
|
||||
// {"EmojiOne 3", "https://cdn.fourtf.com/emoji/emojione/64/"},
|
||||
// {"Twitter", "https://cdn.fourtf.com/emoji/twitter/64/"},
|
||||
// {"Facebook", "https://cdn.fourtf.com/emoji/facebook/64/"},
|
||||
// {"Apple", "https://cdn.fourtf.com/emoji/apple/64/"},
|
||||
// {"Google", "https://cdn.fourtf.com/emoji/google/64/"},
|
||||
// {"Messenger", "https://cdn.fourtf.com/emoji/messenger/64/"},
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/Emotemap.hpp"
|
||||
#include "common/SimpleSignalVector.hpp"
|
||||
#include "messages/Emote.hpp"
|
||||
#include "util/ConcurrentMap.hpp"
|
||||
|
||||
#include <QMap>
|
||||
@@ -14,6 +11,9 @@
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
struct Emote;
|
||||
using EmotePtr = std::shared_ptr<const Emote>;
|
||||
|
||||
struct EmojiData {
|
||||
// actual byte-representation of the emoji (i.e. \154075\156150 which is
|
||||
// :male:)
|
||||
|
||||
+122
-130
@@ -3,172 +3,164 @@
|
||||
#include <QJsonArray>
|
||||
|
||||
#include "common/NetworkRequest.hpp"
|
||||
#include "common/Outcome.hpp"
|
||||
#include "debug/Log.hpp"
|
||||
#include "messages/Emote.hpp"
|
||||
#include "messages/Image.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
namespace {
|
||||
Url getEmoteLink(const QJsonObject &urls, const QString &emoteScale)
|
||||
{
|
||||
auto emote = urls.value(emoteScale);
|
||||
if (emote.isUndefined()) {
|
||||
return {""};
|
||||
Url getEmoteLink(const QJsonObject &urls, const QString &emoteScale)
|
||||
{
|
||||
auto emote = urls.value(emoteScale);
|
||||
if (emote.isUndefined()) {
|
||||
return {""};
|
||||
}
|
||||
|
||||
assert(emote.isString());
|
||||
|
||||
return {"https:" + emote.toString()};
|
||||
}
|
||||
void fillInEmoteData(const QJsonObject &urls, const EmoteName &name,
|
||||
const QString &tooltip, Emote &emoteData)
|
||||
{
|
||||
auto url1x = getEmoteLink(urls, "1");
|
||||
auto url2x = getEmoteLink(urls, "2");
|
||||
auto url3x = getEmoteLink(urls, "4");
|
||||
|
||||
assert(emote.isString());
|
||||
//, code, tooltip
|
||||
emoteData.name = name;
|
||||
emoteData.images =
|
||||
ImageSet{Image::fromUrl(url1x, 1), Image::fromUrl(url2x, 0.5),
|
||||
Image::fromUrl(url3x, 0.25)};
|
||||
emoteData.tooltip = {tooltip};
|
||||
}
|
||||
EmotePtr cachedOrMake(Emote &&emote, const EmoteId &id)
|
||||
{
|
||||
static std::unordered_map<EmoteId, std::weak_ptr<const Emote>> cache;
|
||||
static std::mutex mutex;
|
||||
|
||||
return {"https:" + emote.toString()};
|
||||
}
|
||||
return cachedOrMakeEmotePtr(std::move(emote), cache, mutex, id);
|
||||
}
|
||||
std::pair<Outcome, EmoteMap> parseGlobalEmotes(
|
||||
const QJsonObject &jsonRoot, const EmoteMap ¤tEmotes)
|
||||
{
|
||||
auto jsonSets = jsonRoot.value("sets").toObject();
|
||||
auto emotes = EmoteMap();
|
||||
|
||||
void fillInEmoteData(const QJsonObject &urls, const EmoteName &name,
|
||||
const QString &tooltip, Emote &emoteData)
|
||||
{
|
||||
auto url1x = getEmoteLink(urls, "1");
|
||||
auto url2x = getEmoteLink(urls, "2");
|
||||
auto url3x = getEmoteLink(urls, "4");
|
||||
for (auto jsonSet : jsonSets) {
|
||||
auto jsonEmotes = jsonSet.toObject().value("emoticons").toArray();
|
||||
|
||||
//, code, tooltip
|
||||
emoteData.name = name;
|
||||
emoteData.images =
|
||||
ImageSet{Image::fromUrl(url1x, 1), Image::fromUrl(url2x, 0.5),
|
||||
Image::fromUrl(url3x, 0.25)};
|
||||
emoteData.tooltip = {tooltip};
|
||||
}
|
||||
for (auto jsonEmoteValue : jsonEmotes) {
|
||||
auto jsonEmote = jsonEmoteValue.toObject();
|
||||
|
||||
auto name = EmoteName{jsonEmote.value("name").toString()};
|
||||
auto id = EmoteId{jsonEmote.value("id").toString()};
|
||||
auto urls = jsonEmote.value("urls").toObject();
|
||||
|
||||
auto emote = Emote();
|
||||
fillInEmoteData(urls, name,
|
||||
name.string + "<br/>Global FFZ Emote", emote);
|
||||
emote.homePage =
|
||||
Url{QString("https://www.frankerfacez.com/emoticon/%1-%2")
|
||||
.arg(id.string)
|
||||
.arg(name.string)};
|
||||
|
||||
emotes[name] =
|
||||
cachedOrMakeEmotePtr(std::move(emote), currentEmotes);
|
||||
}
|
||||
}
|
||||
|
||||
return {Success, std::move(emotes)};
|
||||
}
|
||||
std::pair<Outcome, EmoteMap> parseChannelEmotes(const QJsonObject &jsonRoot)
|
||||
{
|
||||
auto jsonSets = jsonRoot.value("sets").toObject();
|
||||
auto emotes = EmoteMap();
|
||||
|
||||
for (auto jsonSet : jsonSets) {
|
||||
auto jsonEmotes = jsonSet.toObject().value("emoticons").toArray();
|
||||
|
||||
for (auto _jsonEmote : jsonEmotes) {
|
||||
auto jsonEmote = _jsonEmote.toObject();
|
||||
|
||||
// margins
|
||||
auto id =
|
||||
EmoteId{QString::number(jsonEmote.value("id").toInt())};
|
||||
auto name = EmoteName{jsonEmote.value("name").toString()};
|
||||
auto urls = jsonEmote.value("urls").toObject();
|
||||
|
||||
Emote emote;
|
||||
fillInEmoteData(urls, name,
|
||||
name.string + "<br/>Channel FFZ Emote", emote);
|
||||
emote.homePage =
|
||||
Url{QString("https://www.frankerfacez.com/emoticon/%1-%2")
|
||||
.arg(id.string)
|
||||
.arg(name.string)};
|
||||
|
||||
emotes[name] = cachedOrMake(std::move(emote), id);
|
||||
}
|
||||
}
|
||||
|
||||
return {Success, std::move(emotes)};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
AccessGuard<const EmoteCache<EmoteName>> FfzEmotes::accessGlobalEmotes() const
|
||||
FfzEmotes::FfzEmotes()
|
||||
: global_(std::make_shared<EmoteMap>())
|
||||
{
|
||||
return this->globalEmotes_.accessConst();
|
||||
}
|
||||
|
||||
boost::optional<EmotePtr> FfzEmotes::getEmote(const EmoteId &id)
|
||||
std::shared_ptr<const EmoteMap> FfzEmotes::emotes() const
|
||||
{
|
||||
auto cache = this->channelEmoteCache_.access();
|
||||
auto it = cache->find(id);
|
||||
|
||||
if (it != cache->end()) {
|
||||
auto shared = it->second.lock();
|
||||
if (shared) {
|
||||
return shared;
|
||||
}
|
||||
}
|
||||
return this->global_.get();
|
||||
}
|
||||
|
||||
boost::optional<EmotePtr> FfzEmotes::emote(const EmoteName &name) const
|
||||
{
|
||||
auto emotes = this->global_.get();
|
||||
auto it = emotes->find(name);
|
||||
if (it != emotes->end()) return it->second;
|
||||
return boost::none;
|
||||
}
|
||||
|
||||
boost::optional<EmotePtr> FfzEmotes::getGlobalEmote(const EmoteName &name)
|
||||
{
|
||||
return this->globalEmotes_.access()->get(name);
|
||||
}
|
||||
|
||||
void FfzEmotes::loadGlobalEmotes()
|
||||
void FfzEmotes::loadEmotes()
|
||||
{
|
||||
QString url("https://api.frankerfacez.com/v1/set/global");
|
||||
|
||||
NetworkRequest request(url);
|
||||
request.setCaller(QThread::currentThread());
|
||||
request.setTimeout(30000);
|
||||
|
||||
request.onSuccess([this](auto result) -> Outcome {
|
||||
return this->parseGlobalEmotes(result.parseJson());
|
||||
auto emotes = this->emotes();
|
||||
auto pair = parseGlobalEmotes(result.parseJson(), *emotes);
|
||||
if (pair.first)
|
||||
this->global_.set(
|
||||
std::make_shared<EmoteMap>(std::move(pair.second)));
|
||||
return pair.first;
|
||||
});
|
||||
|
||||
request.execute();
|
||||
}
|
||||
|
||||
Outcome FfzEmotes::parseGlobalEmotes(const QJsonObject &jsonRoot)
|
||||
void FfzEmotes::loadChannel(const QString &channelName,
|
||||
std::function<void(EmoteMap &&)> callback)
|
||||
{
|
||||
auto jsonSets = jsonRoot.value("sets").toObject();
|
||||
auto emotes = this->globalEmotes_.access();
|
||||
auto replacement = emotes->makeReplacment();
|
||||
log("[FFZEmotes] Reload FFZ Channel Emotes for channel %s\n", channelName);
|
||||
|
||||
for (auto jsonSet : jsonSets) {
|
||||
auto jsonEmotes = jsonSet.toObject().value("emoticons").toArray();
|
||||
NetworkRequest request("https://api.frankerfacez.com/v1/room/" +
|
||||
channelName);
|
||||
request.setCaller(QThread::currentThread());
|
||||
request.setTimeout(3000);
|
||||
|
||||
for (auto jsonEmoteValue : jsonEmotes) {
|
||||
auto jsonEmote = jsonEmoteValue.toObject();
|
||||
request.onSuccess([callback = std::move(callback)](auto result) -> Outcome {
|
||||
auto pair = parseChannelEmotes(result.parseJson());
|
||||
if (pair.first) callback(std::move(pair.second));
|
||||
return pair.first;
|
||||
});
|
||||
|
||||
auto name = EmoteName{jsonEmote.value("name").toString()};
|
||||
auto id = EmoteId{jsonEmote.value("id").toString()};
|
||||
auto urls = jsonEmote.value("urls").toObject();
|
||||
|
||||
auto emote = Emote();
|
||||
fillInEmoteData(urls, name, name.string + "<br/>Global FFZ Emote",
|
||||
emote);
|
||||
emote.homePage =
|
||||
Url{QString("https://www.frankerfacez.com/emoticon/%1-%2")
|
||||
.arg(id.string)
|
||||
.arg(name.string)};
|
||||
|
||||
replacement.add(name, emote);
|
||||
}
|
||||
}
|
||||
|
||||
return Success;
|
||||
}
|
||||
|
||||
void FfzEmotes::loadChannelEmotes(const QString &channelName,
|
||||
std::function<void(EmoteMap &&)> callback)
|
||||
{
|
||||
// printf("[FFZEmotes] Reload FFZ Channel Emotes for channel %s\n",
|
||||
// qPrintable(channelName));
|
||||
|
||||
// QString url("https://api.frankerfacez.com/v1/room/" + channelName);
|
||||
|
||||
// NetworkRequest request(url);
|
||||
// request.setCaller(QThread::currentThread());
|
||||
// request.setTimeout(3000);
|
||||
// request.onSuccess([this, channelName, _map](auto result) -> Outcome {
|
||||
// return this->parseChannelEmotes(result.parseJson());
|
||||
//});
|
||||
|
||||
// request.execute();
|
||||
}
|
||||
|
||||
Outcome parseChannelEmotes(const QJsonObject &jsonRoot)
|
||||
{
|
||||
// auto rootNode = result.parseJson();
|
||||
// auto map = _map.lock();
|
||||
|
||||
// if (_map.expired()) {
|
||||
// return false;
|
||||
//}
|
||||
|
||||
// map->clear();
|
||||
|
||||
// auto setsNode = rootNode.value("sets").toObject();
|
||||
|
||||
// std::vector<QString> codes;
|
||||
// for (const QJsonValue &setNode : setsNode) {
|
||||
// auto emotesNode = setNode.toObject().value("emoticons").toArray();
|
||||
|
||||
// for (const QJsonValue &emoteNode : emotesNode) {
|
||||
// QJsonObject emoteObject = emoteNode.toObject();
|
||||
|
||||
// // margins
|
||||
// int id = emoteObject.value("id").toInt();
|
||||
// QString code = emoteObject.value("name").toString();
|
||||
|
||||
// QJsonObject urls = emoteObject.value("urls").toObject();
|
||||
|
||||
// auto emote = this->channelEmoteCache_.getOrAdd(id, [id, &code,
|
||||
// &urls] {
|
||||
// EmoteData emoteData;
|
||||
// fillInEmoteData(urls, code, code + "<br/>Channel FFZ Emote",
|
||||
// emoteData); emoteData.pageLink =
|
||||
// QString("https://www.frankerfacez.com/emoticon/%1-%2").arg(id).arg(code);
|
||||
|
||||
// return emoteData;
|
||||
// });
|
||||
|
||||
// this->channelEmotes.insert(code, emote);
|
||||
// map->insert(code, emote);
|
||||
// codes.push_back(code);
|
||||
// }
|
||||
|
||||
// this->channelEmoteCodes[channelName] = codes;
|
||||
//}
|
||||
|
||||
return Success;
|
||||
request.execute();
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -1,39 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "common/UniqueAccess.hpp"
|
||||
#include "messages/Emote.hpp"
|
||||
#include "messages/EmoteCache.hpp"
|
||||
#include "boost/optional.hpp"
|
||||
#include "common/Aliases.hpp"
|
||||
#include "common/Atomic.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class FfzEmotes final : std::enable_shared_from_this<FfzEmotes>
|
||||
struct Emote;
|
||||
using EmotePtr = std::shared_ptr<const Emote>;
|
||||
class EmoteMap;
|
||||
|
||||
class FfzEmotes final
|
||||
{
|
||||
static constexpr const char *globalEmoteApiUrl =
|
||||
"https://api.frankerfacez.com/v1/set/global";
|
||||
static constexpr const char *channelEmoteApiUrl =
|
||||
"https://api.betterttv.net/2/channels/";
|
||||
|
||||
public:
|
||||
// FfzEmotes();
|
||||
FfzEmotes();
|
||||
|
||||
static std::shared_ptr<FfzEmotes> create();
|
||||
std::shared_ptr<const EmoteMap> emotes() const;
|
||||
boost::optional<EmotePtr> emote(const EmoteName &name) const;
|
||||
void loadEmotes();
|
||||
static void loadChannel(const QString &channelName,
|
||||
std::function<void(EmoteMap &&)> callback);
|
||||
|
||||
AccessGuard<const EmoteCache<EmoteName>> accessGlobalEmotes() const;
|
||||
boost::optional<EmotePtr> getGlobalEmote(const EmoteName &name);
|
||||
boost::optional<EmotePtr> getEmote(const EmoteId &id);
|
||||
|
||||
void loadGlobalEmotes();
|
||||
void loadChannelEmotes(const QString &channelName,
|
||||
std::function<void(EmoteMap &&)> callback);
|
||||
|
||||
protected:
|
||||
Outcome parseGlobalEmotes(const QJsonObject &jsonRoot);
|
||||
Outcome parseChannelEmotes(const QJsonObject &jsonRoot);
|
||||
|
||||
UniqueAccess<EmoteCache<EmoteName>> globalEmotes_;
|
||||
UniqueAccess<WeakEmoteIdMap> channelEmoteCache_;
|
||||
private:
|
||||
Atomic<std::shared_ptr<const EmoteMap>> global_;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "AbstractIrcServer.hpp"
|
||||
|
||||
#include "common/Channel.hpp"
|
||||
#include "common/Common.hpp"
|
||||
#include "debug/Log.hpp"
|
||||
#include "messages/LimitedQueueSnapshot.hpp"
|
||||
#include "messages/Message.hpp"
|
||||
#include "messages/MessageBuilder.hpp"
|
||||
@@ -131,7 +133,7 @@ std::shared_ptr<Channel> AbstractIrcServer::getOrAddChannel(
|
||||
chan->destroyed.connect([this, clojuresInCppAreShit] {
|
||||
// fourtf: issues when the server itself is destroyed
|
||||
|
||||
Log("[AbstractIrcServer::addChannel] {} was destroyed",
|
||||
log("[AbstractIrcServer::addChannel] {} was destroyed",
|
||||
clojuresInCppAreShit);
|
||||
this->channels.remove(clojuresInCppAreShit);
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/Channel.hpp"
|
||||
#include "providers/irc/IrcConnection2.hpp"
|
||||
|
||||
#include <IrcMessage>
|
||||
@@ -11,6 +10,9 @@
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class Channel;
|
||||
using ChannelPtr = std::shared_ptr<Channel>;
|
||||
|
||||
class AbstractIrcServer
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "providers/twitch/TwitchMessageBuilder.hpp"
|
||||
#include "providers/twitch/TwitchServer.hpp"
|
||||
#include "singletons/Resources.hpp"
|
||||
#include "singletons/Settings.hpp"
|
||||
#include "singletons/WindowManager.hpp"
|
||||
#include "util/IrcHelpers.hpp"
|
||||
|
||||
@@ -145,7 +146,7 @@ void IrcMessageHandler::handleClearChatMessage(Communi::IrcMessage *message)
|
||||
auto chan = app->twitch.server->getChannelOrEmpty(chanName);
|
||||
|
||||
if (chan->isEmpty()) {
|
||||
Log("[IrcMessageHandler:handleClearChatMessage] Twitch channel {} not "
|
||||
log("[IrcMessageHandler:handleClearChatMessage] Twitch channel {} not "
|
||||
"found",
|
||||
chanName);
|
||||
return;
|
||||
@@ -209,7 +210,7 @@ void IrcMessageHandler::handleUserStateMessage(Communi::IrcMessage *message)
|
||||
void IrcMessageHandler::handleWhisperMessage(Communi::IrcMessage *message)
|
||||
{
|
||||
auto app = getApp();
|
||||
Log("Received whisper!");
|
||||
log("Received whisper!");
|
||||
MessageParseArgs args;
|
||||
|
||||
args.isReceivedWhisper = true;
|
||||
@@ -230,7 +231,7 @@ void IrcMessageHandler::handleWhisperMessage(Communi::IrcMessage *message)
|
||||
|
||||
c->addMessage(_message);
|
||||
|
||||
if (app->settings->inlineWhispers) {
|
||||
if (getSettings()->inlineWhispers) {
|
||||
app->twitch.server->forEachChannel([_message](ChannelPtr channel) {
|
||||
channel->addMessage(_message); //
|
||||
});
|
||||
@@ -326,7 +327,7 @@ void IrcMessageHandler::handleNoticeMessage(Communi::IrcNoticeMessage *message)
|
||||
auto channel = app->twitch.server->getChannelOrEmpty(channelName);
|
||||
|
||||
if (channel->isEmpty()) {
|
||||
Log("[IrcManager:handleNoticeMessage] Channel {} not found in channel "
|
||||
log("[IrcManager:handleNoticeMessage] Channel {} not found in channel "
|
||||
"manager ",
|
||||
channelName);
|
||||
return;
|
||||
@@ -366,7 +367,7 @@ void IrcMessageHandler::handleWriteConnectionNoticeMessage(
|
||||
return;
|
||||
}
|
||||
|
||||
Log("Showing notice message from write connection with message id '{}'",
|
||||
log("Showing notice message from write connection with message id '{}'",
|
||||
msgID);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "providers/twitch/PartialTwitchUser.hpp"
|
||||
|
||||
#include "common/Common.hpp"
|
||||
#include "common/NetworkRequest.hpp"
|
||||
#include "debug/Log.hpp"
|
||||
#include "providers/twitch/TwitchCommon.hpp"
|
||||
@@ -42,23 +43,23 @@ void PartialTwitchUser::getId(std::function<void(QString)> successCallback,
|
||||
request.onSuccess([successCallback](auto result) -> Outcome {
|
||||
auto root = result.parseJson();
|
||||
if (!root.value("users").isArray()) {
|
||||
Log("API Error while getting user id, users is not an array");
|
||||
log("API Error while getting user id, users is not an array");
|
||||
return Failure;
|
||||
}
|
||||
|
||||
auto users = root.value("users").toArray();
|
||||
if (users.size() != 1) {
|
||||
Log("API Error while getting user id, users array size is not 1");
|
||||
log("API Error while getting user id, users array size is not 1");
|
||||
return Failure;
|
||||
}
|
||||
if (!users[0].isObject()) {
|
||||
Log("API Error while getting user id, first user is not an object");
|
||||
log("API Error while getting user id, first user is not an object");
|
||||
return Failure;
|
||||
}
|
||||
auto firstUser = users[0].toObject();
|
||||
auto id = firstUser.value("_id");
|
||||
if (!id.isString()) {
|
||||
Log("API Error: while getting user id, first user object `_id` key "
|
||||
log("API Error: while getting user id, first user object `_id` key "
|
||||
"is not a "
|
||||
"string");
|
||||
return Failure;
|
||||
|
||||
@@ -24,157 +24,159 @@ static std::map<QString, std::string> sentMessages;
|
||||
|
||||
namespace detail {
|
||||
|
||||
PubSubClient::PubSubClient(WebsocketClient &websocketClient,
|
||||
WebsocketHandle handle)
|
||||
: websocketClient_(websocketClient)
|
||||
, handle_(handle)
|
||||
{
|
||||
}
|
||||
|
||||
void PubSubClient::start()
|
||||
{
|
||||
assert(!this->started_);
|
||||
|
||||
this->started_ = true;
|
||||
|
||||
this->ping();
|
||||
}
|
||||
|
||||
void PubSubClient::stop()
|
||||
{
|
||||
assert(this->started_);
|
||||
|
||||
this->started_ = false;
|
||||
}
|
||||
|
||||
bool PubSubClient::listen(rapidjson::Document &message)
|
||||
{
|
||||
int numRequestedListens = message["data"]["topics"].Size();
|
||||
|
||||
if (this->numListens_ + numRequestedListens > MAX_PUBSUB_LISTENS) {
|
||||
// This PubSubClient is already at its peak listens
|
||||
return false;
|
||||
PubSubClient::PubSubClient(WebsocketClient &websocketClient,
|
||||
WebsocketHandle handle)
|
||||
: websocketClient_(websocketClient)
|
||||
, handle_(handle)
|
||||
{
|
||||
}
|
||||
|
||||
this->numListens_ += numRequestedListens;
|
||||
void PubSubClient::start()
|
||||
{
|
||||
assert(!this->started_);
|
||||
|
||||
for (const auto &topic : message["data"]["topics"].GetArray()) {
|
||||
this->listeners_.emplace_back(
|
||||
Listener{topic.GetString(), false, false, false});
|
||||
this->started_ = true;
|
||||
|
||||
this->ping();
|
||||
}
|
||||
|
||||
auto uuid = CreateUUID();
|
||||
void PubSubClient::stop()
|
||||
{
|
||||
assert(this->started_);
|
||||
|
||||
rj::set(message, "nonce", uuid);
|
||||
this->started_ = false;
|
||||
}
|
||||
|
||||
std::string payload = rj::stringify(message);
|
||||
sentMessages[uuid] = payload;
|
||||
bool PubSubClient::listen(rapidjson::Document &message)
|
||||
{
|
||||
int numRequestedListens = message["data"]["topics"].Size();
|
||||
|
||||
this->send(payload.c_str());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void PubSubClient::unlistenPrefix(const std::string &prefix)
|
||||
{
|
||||
std::vector<std::string> topics;
|
||||
|
||||
for (auto it = this->listeners_.begin(); it != this->listeners_.end();) {
|
||||
const auto &listener = *it;
|
||||
if (listener.topic.find(prefix) == 0) {
|
||||
topics.push_back(listener.topic);
|
||||
it = this->listeners_.erase(it);
|
||||
} else {
|
||||
++it;
|
||||
if (this->numListens_ + numRequestedListens > MAX_PUBSUB_LISTENS) {
|
||||
// This PubSubClient is already at its peak listens
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (topics.empty()) {
|
||||
return;
|
||||
}
|
||||
this->numListens_ += numRequestedListens;
|
||||
|
||||
auto message = createUnlistenMessage(topics);
|
||||
|
||||
auto uuid = CreateUUID();
|
||||
|
||||
rj::set(message, "nonce", CreateUUID());
|
||||
|
||||
std::string payload = rj::stringify(message);
|
||||
sentMessages[uuid] = payload;
|
||||
|
||||
this->send(payload.c_str());
|
||||
}
|
||||
|
||||
void PubSubClient::handlePong()
|
||||
{
|
||||
assert(this->awaitingPong_);
|
||||
|
||||
Log("Got pong!");
|
||||
|
||||
this->awaitingPong_ = false;
|
||||
}
|
||||
|
||||
bool PubSubClient::isListeningToTopic(const std::string &payload)
|
||||
{
|
||||
for (const auto &listener : this->listeners_) {
|
||||
if (listener.topic == payload) {
|
||||
return true;
|
||||
for (const auto &topic : message["data"]["topics"].GetArray()) {
|
||||
this->listeners_.emplace_back(
|
||||
Listener{topic.GetString(), false, false, false});
|
||||
}
|
||||
|
||||
auto uuid = CreateUUID();
|
||||
|
||||
rj::set(message, "nonce", uuid);
|
||||
|
||||
std::string payload = rj::stringify(message);
|
||||
sentMessages[uuid] = payload;
|
||||
|
||||
this->send(payload.c_str());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
void PubSubClient::unlistenPrefix(const std::string &prefix)
|
||||
{
|
||||
std::vector<std::string> topics;
|
||||
|
||||
void PubSubClient::ping()
|
||||
{
|
||||
assert(this->started_);
|
||||
for (auto it = this->listeners_.begin();
|
||||
it != this->listeners_.end();) {
|
||||
const auto &listener = *it;
|
||||
if (listener.topic.find(prefix) == 0) {
|
||||
topics.push_back(listener.topic);
|
||||
it = this->listeners_.erase(it);
|
||||
} else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
if (!this->send(pingPayload)) {
|
||||
return;
|
||||
if (topics.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto message = createUnlistenMessage(topics);
|
||||
|
||||
auto uuid = CreateUUID();
|
||||
|
||||
rj::set(message, "nonce", CreateUUID());
|
||||
|
||||
std::string payload = rj::stringify(message);
|
||||
sentMessages[uuid] = payload;
|
||||
|
||||
this->send(payload.c_str());
|
||||
}
|
||||
|
||||
this->awaitingPong_ = true;
|
||||
void PubSubClient::handlePong()
|
||||
{
|
||||
assert(this->awaitingPong_);
|
||||
|
||||
auto self = this->shared_from_this();
|
||||
log("Got pong!");
|
||||
|
||||
runAfter(this->websocketClient_.get_io_service(), std::chrono::seconds(15),
|
||||
[self](auto timer) {
|
||||
if (!self->started_) {
|
||||
return;
|
||||
}
|
||||
this->awaitingPong_ = false;
|
||||
}
|
||||
|
||||
if (self->awaitingPong_) {
|
||||
Log("No pong respnose, disconnect!");
|
||||
// TODO(pajlada): Label this connection as "disconnect me"
|
||||
}
|
||||
});
|
||||
|
||||
runAfter(this->websocketClient_.get_io_service(), std::chrono::minutes(5),
|
||||
[self](auto timer) {
|
||||
if (!self->started_) {
|
||||
return;
|
||||
}
|
||||
|
||||
self->ping(); //
|
||||
});
|
||||
}
|
||||
|
||||
bool PubSubClient::send(const char *payload)
|
||||
{
|
||||
WebsocketErrorCode ec;
|
||||
this->websocketClient_.send(this->handle_, payload,
|
||||
websocketpp::frame::opcode::text, ec);
|
||||
|
||||
if (ec) {
|
||||
Log("Error sending message {}: {}", payload, ec.message());
|
||||
// TODO(pajlada): Check which error code happened and maybe gracefully
|
||||
// handle it
|
||||
bool PubSubClient::isListeningToTopic(const std::string &payload)
|
||||
{
|
||||
for (const auto &listener : this->listeners_) {
|
||||
if (listener.topic == payload) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
void PubSubClient::ping()
|
||||
{
|
||||
assert(this->started_);
|
||||
|
||||
if (!this->send(pingPayload)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this->awaitingPong_ = true;
|
||||
|
||||
auto self = this->shared_from_this();
|
||||
|
||||
runAfter(this->websocketClient_.get_io_service(),
|
||||
std::chrono::seconds(15), [self](auto timer) {
|
||||
if (!self->started_) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (self->awaitingPong_) {
|
||||
log("No pong respnose, disconnect!");
|
||||
// TODO(pajlada): Label this connection as "disconnect
|
||||
// me"
|
||||
}
|
||||
});
|
||||
|
||||
runAfter(this->websocketClient_.get_io_service(),
|
||||
std::chrono::minutes(5), [self](auto timer) {
|
||||
if (!self->started_) {
|
||||
return;
|
||||
}
|
||||
|
||||
self->ping(); //
|
||||
});
|
||||
}
|
||||
|
||||
bool PubSubClient::send(const char *payload)
|
||||
{
|
||||
WebsocketErrorCode ec;
|
||||
this->websocketClient_.send(this->handle_, payload,
|
||||
websocketpp::frame::opcode::text, ec);
|
||||
|
||||
if (ec) {
|
||||
log("Error sending message {}: {}", payload, ec.message());
|
||||
// TODO(pajlada): Check which error code happened and maybe
|
||||
// gracefully handle it
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
@@ -207,26 +209,26 @@ PubSub::PubSub()
|
||||
action.state = ModeChangedAction::State::On;
|
||||
|
||||
if (!data.HasMember("args")) {
|
||||
Log("Missing required args member");
|
||||
log("Missing required args member");
|
||||
return;
|
||||
}
|
||||
|
||||
const auto &args = data["args"];
|
||||
|
||||
if (!args.IsArray()) {
|
||||
Log("args member must be an array");
|
||||
log("args member must be an array");
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.Size() == 0) {
|
||||
Log("Missing duration argument in slowmode on");
|
||||
log("Missing duration argument in slowmode on");
|
||||
return;
|
||||
}
|
||||
|
||||
const auto &durationArg = args[0];
|
||||
|
||||
if (!durationArg.IsString()) {
|
||||
Log("Duration arg must be a string");
|
||||
log("Duration arg must be a string");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -314,7 +316,7 @@ PubSub::PubSub()
|
||||
return;
|
||||
}
|
||||
} catch (const std::runtime_error &ex) {
|
||||
Log("Error parsing moderation action: {}", ex.what());
|
||||
log("Error parsing moderation action: {}", ex.what());
|
||||
}
|
||||
|
||||
action.modded = false;
|
||||
@@ -339,7 +341,7 @@ PubSub::PubSub()
|
||||
return;
|
||||
}
|
||||
} catch (const std::runtime_error &ex) {
|
||||
Log("Error parsing moderation action: {}", ex.what());
|
||||
log("Error parsing moderation action: {}", ex.what());
|
||||
}
|
||||
|
||||
action.modded = true;
|
||||
@@ -380,7 +382,7 @@ PubSub::PubSub()
|
||||
|
||||
this->signals_.moderation.userBanned.invoke(action);
|
||||
} catch (const std::runtime_error &ex) {
|
||||
Log("Error parsing moderation action: {}", ex.what());
|
||||
log("Error parsing moderation action: {}", ex.what());
|
||||
}
|
||||
};
|
||||
|
||||
@@ -410,7 +412,7 @@ PubSub::PubSub()
|
||||
|
||||
this->signals_.moderation.userBanned.invoke(action);
|
||||
} catch (const std::runtime_error &ex) {
|
||||
Log("Error parsing moderation action: {}", ex.what());
|
||||
log("Error parsing moderation action: {}", ex.what());
|
||||
}
|
||||
};
|
||||
|
||||
@@ -436,7 +438,7 @@ PubSub::PubSub()
|
||||
|
||||
this->signals_.moderation.userUnbanned.invoke(action);
|
||||
} catch (const std::runtime_error &ex) {
|
||||
Log("Error parsing moderation action: {}", ex.what());
|
||||
log("Error parsing moderation action: {}", ex.what());
|
||||
}
|
||||
};
|
||||
|
||||
@@ -462,7 +464,7 @@ PubSub::PubSub()
|
||||
|
||||
this->signals_.moderation.userUnbanned.invoke(action);
|
||||
} catch (const std::runtime_error &ex) {
|
||||
Log("Error parsing moderation action: {}", ex.what());
|
||||
log("Error parsing moderation action: {}", ex.what());
|
||||
}
|
||||
};
|
||||
|
||||
@@ -493,7 +495,7 @@ void PubSub::addClient()
|
||||
auto con = this->websocketClient.get_connection(TWITCH_PUBSUB_URL, ec);
|
||||
|
||||
if (ec) {
|
||||
Log("Unable to establish connection: {}", ec.message());
|
||||
log("Unable to establish connection: {}", ec.message());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -512,7 +514,7 @@ void PubSub::listenToWhispers(std::shared_ptr<TwitchAccount> account)
|
||||
|
||||
std::string userID = account->getUserId().toStdString();
|
||||
|
||||
Log("Connection open!");
|
||||
log("Connection open!");
|
||||
websocketpp::lib::error_code ec;
|
||||
|
||||
std::vector<std::string> topics({"whispers." + userID});
|
||||
@@ -520,7 +522,7 @@ void PubSub::listenToWhispers(std::shared_ptr<TwitchAccount> account)
|
||||
this->listen(createListenMessage(topics, account));
|
||||
|
||||
if (ec) {
|
||||
Log("Unable to send message to websocket server: {}", ec.message());
|
||||
log("Unable to send message to websocket server: {}", ec.message());
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -544,11 +546,11 @@ void PubSub::listenToChannelModerationActions(
|
||||
std::string topic(fS("chat_moderator_actions.{}.{}", userID, channelID));
|
||||
|
||||
if (this->isListeningToTopic(topic)) {
|
||||
Log("We are already listening to topic {}", topic);
|
||||
log("We are already listening to topic {}", topic);
|
||||
return;
|
||||
}
|
||||
|
||||
Log("Listen to topic {}", topic);
|
||||
log("Listen to topic {}", topic);
|
||||
|
||||
this->listenToTopic(topic, account);
|
||||
}
|
||||
@@ -564,18 +566,18 @@ void PubSub::listenToTopic(const std::string &topic,
|
||||
void PubSub::listen(rapidjson::Document &&msg)
|
||||
{
|
||||
if (this->tryListen(msg)) {
|
||||
Log("Successfully listened!");
|
||||
log("Successfully listened!");
|
||||
return;
|
||||
}
|
||||
|
||||
Log("Added to the back of the queue");
|
||||
log("Added to the back of the queue");
|
||||
this->requests.emplace_back(
|
||||
std::make_unique<rapidjson::Document>(std::move(msg)));
|
||||
}
|
||||
|
||||
bool PubSub::tryListen(rapidjson::Document &msg)
|
||||
{
|
||||
Log("tryListen with {} clients", this->clients.size());
|
||||
log("tryListen with {} clients", this->clients.size());
|
||||
for (const auto &p : this->clients) {
|
||||
const auto &client = p.second;
|
||||
if (client->listen(msg)) {
|
||||
@@ -608,13 +610,13 @@ void PubSub::onMessage(websocketpp::connection_hdl hdl,
|
||||
rapidjson::ParseResult res = msg.Parse(payload.c_str());
|
||||
|
||||
if (!res) {
|
||||
Log("Error parsing message '{}' from PubSub: {}", payload,
|
||||
log("Error parsing message '{}' from PubSub: {}", payload,
|
||||
rapidjson::GetParseError_En(res.Code()));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!msg.IsObject()) {
|
||||
Log("Error parsing message '{}' from PubSub. Root object is not an "
|
||||
log("Error parsing message '{}' from PubSub. Root object is not an "
|
||||
"object",
|
||||
payload);
|
||||
return;
|
||||
@@ -623,7 +625,7 @@ void PubSub::onMessage(websocketpp::connection_hdl hdl,
|
||||
std::string type;
|
||||
|
||||
if (!rj::getSafe(msg, "type", type)) {
|
||||
Log("Missing required string member `type` in message root");
|
||||
log("Missing required string member `type` in message root");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -631,14 +633,14 @@ void PubSub::onMessage(websocketpp::connection_hdl hdl,
|
||||
this->handleListenResponse(msg);
|
||||
} else if (type == "MESSAGE") {
|
||||
if (!msg.HasMember("data")) {
|
||||
Log("Missing required object member `data` in message root");
|
||||
log("Missing required object member `data` in message root");
|
||||
return;
|
||||
}
|
||||
|
||||
const auto &data = msg["data"];
|
||||
|
||||
if (!data.IsObject()) {
|
||||
Log("Member `data` must be an object");
|
||||
log("Member `data` must be an object");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -654,7 +656,7 @@ void PubSub::onMessage(websocketpp::connection_hdl hdl,
|
||||
|
||||
client.second->handlePong();
|
||||
} else {
|
||||
Log("Unknown message type: {}", type);
|
||||
log("Unknown message type: {}", type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -699,7 +701,7 @@ PubSub::WebsocketContextPtr PubSub::onTLSInit(websocketpp::connection_hdl hdl)
|
||||
boost::asio::ssl::context::no_sslv2 |
|
||||
boost::asio::ssl::context::single_dh_use);
|
||||
} catch (const std::exception &e) {
|
||||
Log("Exception caught in OnTLSInit: {}", e.what());
|
||||
log("Exception caught in OnTLSInit: {}", e.what());
|
||||
}
|
||||
|
||||
return ctx;
|
||||
@@ -714,12 +716,12 @@ void PubSub::handleListenResponse(const rapidjson::Document &msg)
|
||||
rj::getSafe(msg, "nonce", nonce);
|
||||
|
||||
if (error.empty()) {
|
||||
Log("Successfully listened to nonce {}", nonce);
|
||||
log("Successfully listened to nonce {}", nonce);
|
||||
// Nothing went wrong
|
||||
return;
|
||||
}
|
||||
|
||||
Log("PubSub error: {} on nonce {}", error, nonce);
|
||||
log("PubSub error: {} on nonce {}", error, nonce);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -729,14 +731,14 @@ void PubSub::handleMessageResponse(const rapidjson::Value &outerData)
|
||||
QString topic;
|
||||
|
||||
if (!rj::getSafe(outerData, "topic", topic)) {
|
||||
Log("Missing required string member `topic` in outerData");
|
||||
log("Missing required string member `topic` in outerData");
|
||||
return;
|
||||
}
|
||||
|
||||
std::string payload;
|
||||
|
||||
if (!rj::getSafe(outerData, "message", payload)) {
|
||||
Log("Expected string message in outerData");
|
||||
log("Expected string message in outerData");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -745,7 +747,7 @@ void PubSub::handleMessageResponse(const rapidjson::Value &outerData)
|
||||
rapidjson::ParseResult res = msg.Parse(payload.c_str());
|
||||
|
||||
if (!res) {
|
||||
Log("Error parsing message '{}' from PubSub: {}", payload,
|
||||
log("Error parsing message '{}' from PubSub: {}", payload,
|
||||
rapidjson::GetParseError_En(res.Code()));
|
||||
return;
|
||||
}
|
||||
@@ -754,7 +756,7 @@ void PubSub::handleMessageResponse(const rapidjson::Value &outerData)
|
||||
std::string whisperType;
|
||||
|
||||
if (!rj::getSafe(msg, "type", whisperType)) {
|
||||
Log("Bad whisper data");
|
||||
log("Bad whisper data");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -765,7 +767,7 @@ void PubSub::handleMessageResponse(const rapidjson::Value &outerData)
|
||||
} else if (whisperType == "thread") {
|
||||
// Handle thread?
|
||||
} else {
|
||||
Log("Invalid whisper type: {}", whisperType);
|
||||
log("Invalid whisper type: {}", whisperType);
|
||||
assert(false);
|
||||
return;
|
||||
}
|
||||
@@ -777,30 +779,30 @@ void PubSub::handleMessageResponse(const rapidjson::Value &outerData)
|
||||
std::string moderationAction;
|
||||
|
||||
if (!rj::getSafe(data, "moderation_action", moderationAction)) {
|
||||
Log("Missing moderation action in data: {}", rj::stringify(data));
|
||||
log("Missing moderation action in data: {}", rj::stringify(data));
|
||||
return;
|
||||
}
|
||||
|
||||
auto handlerIt = this->moderationActionHandlers.find(moderationAction);
|
||||
|
||||
if (handlerIt == this->moderationActionHandlers.end()) {
|
||||
Log("No handler found for moderation action {}", moderationAction);
|
||||
log("No handler found for moderation action {}", moderationAction);
|
||||
return;
|
||||
}
|
||||
|
||||
// Invoke handler function
|
||||
handlerIt->second(data, topicParts[2]);
|
||||
} else {
|
||||
Log("Unknown topic: {}", topic);
|
||||
log("Unknown topic: {}", topic);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void PubSub::runThread()
|
||||
{
|
||||
Log("Start pubsub manager thread");
|
||||
log("Start pubsub manager thread");
|
||||
this->websocketClient.run();
|
||||
Log("Done with pubsub manager thread");
|
||||
log("Done with pubsub manager thread");
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -32,41 +32,42 @@ using WebsocketErrorCode = websocketpp::lib::error_code;
|
||||
|
||||
namespace detail {
|
||||
|
||||
struct Listener {
|
||||
std::string topic;
|
||||
bool authed;
|
||||
bool persistent;
|
||||
bool confirmed = false;
|
||||
};
|
||||
struct Listener {
|
||||
std::string topic;
|
||||
bool authed;
|
||||
bool persistent;
|
||||
bool confirmed = false;
|
||||
};
|
||||
|
||||
class PubSubClient : public std::enable_shared_from_this<PubSubClient>
|
||||
{
|
||||
public:
|
||||
PubSubClient(WebsocketClient &_websocketClient, WebsocketHandle _handle);
|
||||
class PubSubClient : public std::enable_shared_from_this<PubSubClient>
|
||||
{
|
||||
public:
|
||||
PubSubClient(WebsocketClient &_websocketClient,
|
||||
WebsocketHandle _handle);
|
||||
|
||||
void start();
|
||||
void stop();
|
||||
void start();
|
||||
void stop();
|
||||
|
||||
bool listen(rapidjson::Document &message);
|
||||
void unlistenPrefix(const std::string &prefix);
|
||||
bool listen(rapidjson::Document &message);
|
||||
void unlistenPrefix(const std::string &prefix);
|
||||
|
||||
void handlePong();
|
||||
void handlePong();
|
||||
|
||||
bool isListeningToTopic(const std::string &topic);
|
||||
bool isListeningToTopic(const std::string &topic);
|
||||
|
||||
private:
|
||||
void ping();
|
||||
bool send(const char *payload);
|
||||
private:
|
||||
void ping();
|
||||
bool send(const char *payload);
|
||||
|
||||
WebsocketClient &websocketClient_;
|
||||
WebsocketHandle handle_;
|
||||
uint16_t numListens_ = 0;
|
||||
WebsocketClient &websocketClient_;
|
||||
WebsocketHandle handle_;
|
||||
uint16_t numListens_ = 0;
|
||||
|
||||
std::vector<Listener> listeners_;
|
||||
std::vector<Listener> listeners_;
|
||||
|
||||
std::atomic<bool> awaitingPong_{false};
|
||||
std::atomic<bool> started_{false};
|
||||
};
|
||||
std::atomic<bool> awaitingPong_{false};
|
||||
std::atomic<bool> started_{false};
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "providers/twitch/PubsubHelpers.hpp"
|
||||
|
||||
#include "providers/twitch/PubsubActions.hpp"
|
||||
#include "providers/twitch/TwitchAccount.hpp"
|
||||
#include "util/RapidjsonHelpers.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "debug/Log.hpp"
|
||||
#include "providers/twitch/TwitchAccount.hpp"
|
||||
#include "util/RapidjsonHelpers.hpp"
|
||||
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/asio/steady_timer.hpp>
|
||||
|
||||
#include <memory>
|
||||
#include "debug/Log.hpp"
|
||||
#include "util/RapidjsonHelpers.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class TwitchAccount;
|
||||
struct ActionUser;
|
||||
|
||||
const rapidjson::Value &getArgs(const rapidjson::Value &data);
|
||||
@@ -35,7 +33,7 @@ void runAfter(boost::asio::io_service &ioService, Duration duration,
|
||||
|
||||
timer->async_wait([timer, cb](const boost::system::error_code &ec) {
|
||||
if (ec) {
|
||||
Log("Error in runAfter: {}", ec.message());
|
||||
log("Error in runAfter: {}", ec.message());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -52,7 +50,7 @@ void runAfter(std::shared_ptr<boost::asio::steady_timer> timer,
|
||||
|
||||
timer->async_wait([timer, cb](const boost::system::error_code &ec) {
|
||||
if (ec) {
|
||||
Log("Error in runAfter: {}", ec.message());
|
||||
log("Error in runAfter: {}", ec.message());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "Application.hpp"
|
||||
#include "common/NetworkRequest.hpp"
|
||||
#include "common/Outcome.hpp"
|
||||
#include "debug/Log.hpp"
|
||||
#include "providers/twitch/PartialTwitchUser.hpp"
|
||||
#include "providers/twitch/TwitchCommon.hpp"
|
||||
@@ -14,32 +15,32 @@ namespace chatterino {
|
||||
|
||||
namespace {
|
||||
|
||||
EmoteName cleanUpCode(const EmoteName &dirtyEmoteCode)
|
||||
{
|
||||
auto cleanCode = dirtyEmoteCode.string;
|
||||
cleanCode.detach();
|
||||
EmoteName cleanUpCode(const EmoteName &dirtyEmoteCode)
|
||||
{
|
||||
auto cleanCode = dirtyEmoteCode.string;
|
||||
cleanCode.detach();
|
||||
|
||||
static QMap<QString, QString> emoteNameReplacements{
|
||||
{"[oO](_|\\.)[oO]", "O_o"}, {"\\>\\;\\(", ">("},
|
||||
{"\\<\\;3", "<3"}, {"\\:-?(o|O)", ":O"},
|
||||
{"\\:-?(p|P)", ":P"}, {"\\:-?[\\\\/]", ":/"},
|
||||
{"\\:-?[z|Z|\\|]", ":Z"}, {"\\:-?\\(", ":("},
|
||||
{"\\:-?\\)", ":)"}, {"\\:-?D", ":D"},
|
||||
{"\\;-?(p|P)", ";P"}, {"\\;-?\\)", ";)"},
|
||||
{"R-?\\)", "R)"}, {"B-?\\)", "B)"},
|
||||
};
|
||||
static QMap<QString, QString> emoteNameReplacements{
|
||||
{"[oO](_|\\.)[oO]", "O_o"}, {"\\>\\;\\(", ">("},
|
||||
{"\\<\\;3", "<3"}, {"\\:-?(o|O)", ":O"},
|
||||
{"\\:-?(p|P)", ":P"}, {"\\:-?[\\\\/]", ":/"},
|
||||
{"\\:-?[z|Z|\\|]", ":Z"}, {"\\:-?\\(", ":("},
|
||||
{"\\:-?\\)", ":)"}, {"\\:-?D", ":D"},
|
||||
{"\\;-?(p|P)", ";P"}, {"\\;-?\\)", ";)"},
|
||||
{"R-?\\)", "R)"}, {"B-?\\)", "B)"},
|
||||
};
|
||||
|
||||
auto it = emoteNameReplacements.find(dirtyEmoteCode.string);
|
||||
if (it != emoteNameReplacements.end()) {
|
||||
cleanCode = it.value();
|
||||
auto it = emoteNameReplacements.find(dirtyEmoteCode.string);
|
||||
if (it != emoteNameReplacements.end()) {
|
||||
cleanCode = it.value();
|
||||
}
|
||||
|
||||
cleanCode.replace("<", "<");
|
||||
cleanCode.replace(">", ">");
|
||||
|
||||
return {cleanCode};
|
||||
}
|
||||
|
||||
cleanCode.replace("<", "<");
|
||||
cleanCode.replace(">", ">");
|
||||
|
||||
return {cleanCode};
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TwitchAccount::TwitchAccount(const QString &username, const QString &oauthToken,
|
||||
@@ -78,6 +79,16 @@ const QString &TwitchAccount::getUserId() const
|
||||
return this->userId_;
|
||||
}
|
||||
|
||||
QColor TwitchAccount::color()
|
||||
{
|
||||
return this->color_.get();
|
||||
}
|
||||
|
||||
void TwitchAccount::setColor(QColor color)
|
||||
{
|
||||
this->color_.set(color);
|
||||
}
|
||||
|
||||
bool TwitchAccount::setOAuthClient(const QString &newClientID)
|
||||
{
|
||||
if (this->oauthClient_.compare(newClientID) == 0) {
|
||||
@@ -143,7 +154,7 @@ void TwitchAccount::loadIgnores()
|
||||
}
|
||||
TwitchUser ignoredUser;
|
||||
if (!rj::getSafe(userIt->value, ignoredUser)) {
|
||||
Log("Error parsing twitch user JSON {}",
|
||||
log("Error parsing twitch user JSON {}",
|
||||
rj::stringify(userIt->value));
|
||||
continue;
|
||||
}
|
||||
@@ -368,13 +379,13 @@ std::set<TwitchUser> TwitchAccount::getIgnores() const
|
||||
|
||||
void TwitchAccount::loadEmotes()
|
||||
{
|
||||
Log("Loading Twitch emotes for user {}", this->getUserName());
|
||||
log("Loading Twitch emotes for user {}", this->getUserName());
|
||||
|
||||
const auto &clientID = this->getOAuthClient();
|
||||
const auto &oauthToken = this->getOAuthToken();
|
||||
|
||||
if (clientID.isEmpty() || oauthToken.isEmpty()) {
|
||||
Log("Missing Client ID or OAuth token");
|
||||
log("Missing Client ID or OAuth token");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -386,7 +397,7 @@ void TwitchAccount::loadEmotes()
|
||||
req.makeAuthorizedV5(this->getOAuthClient(), this->getOAuthToken());
|
||||
|
||||
req.onError([=](int errorCode) {
|
||||
Log("[TwitchAccount::loadEmotes] Error {}", errorCode);
|
||||
log("[TwitchAccount::loadEmotes] Error {}", errorCode);
|
||||
if (errorCode == 203) {
|
||||
// onFinished(FollowResult_NotFollowing);
|
||||
} else {
|
||||
@@ -406,7 +417,7 @@ void TwitchAccount::loadEmotes()
|
||||
}
|
||||
|
||||
AccessGuard<const TwitchAccount::TwitchAccountEmoteData>
|
||||
TwitchAccount::accessEmotes() const
|
||||
TwitchAccount::accessEmotes() const
|
||||
{
|
||||
return this->emotes_.accessConst();
|
||||
}
|
||||
@@ -420,7 +431,7 @@ void TwitchAccount::parseEmotes(const rapidjson::Document &root)
|
||||
|
||||
auto emoticonSets = root.FindMember("emoticon_sets");
|
||||
if (emoticonSets == root.MemberEnd() || !emoticonSets->value.IsObject()) {
|
||||
Log("No emoticon_sets in load emotes response");
|
||||
log("No emoticon_sets in load emotes response");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -434,19 +445,19 @@ void TwitchAccount::parseEmotes(const rapidjson::Document &root)
|
||||
for (const rapidjson::Value &emoteJSON :
|
||||
emoteSetJSON.value.GetArray()) {
|
||||
if (!emoteJSON.IsObject()) {
|
||||
Log("Emote value was invalid");
|
||||
log("Emote value was invalid");
|
||||
return;
|
||||
}
|
||||
|
||||
uint64_t idNumber;
|
||||
if (!rj::getSafe(emoteJSON, "id", idNumber)) {
|
||||
Log("No ID key found in Emote value");
|
||||
log("No ID key found in Emote value");
|
||||
return;
|
||||
}
|
||||
|
||||
QString _code;
|
||||
if (!rj::getSafe(emoteJSON, "code", _code)) {
|
||||
Log("No code key found in Emote value");
|
||||
log("No code key found in Emote value");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -468,7 +479,7 @@ void TwitchAccount::parseEmotes(const rapidjson::Document &root)
|
||||
void TwitchAccount::loadEmoteSetData(std::shared_ptr<EmoteSet> emoteSet)
|
||||
{
|
||||
if (!emoteSet) {
|
||||
Log("null emote set sent");
|
||||
log("null emote set sent");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -486,7 +497,7 @@ void TwitchAccount::loadEmoteSetData(std::shared_ptr<EmoteSet> emoteSet)
|
||||
req.setUseQuickLoadCache(true);
|
||||
|
||||
req.onError([](int errorCode) -> bool {
|
||||
Log("Error code {} while loading emote set data", errorCode);
|
||||
log("Error code {} while loading emote set data", errorCode);
|
||||
return true;
|
||||
});
|
||||
|
||||
@@ -507,16 +518,15 @@ void TwitchAccount::loadEmoteSetData(std::shared_ptr<EmoteSet> emoteSet)
|
||||
return Failure;
|
||||
}
|
||||
|
||||
Log("Loaded twitch emote set data for {}!", emoteSet->key);
|
||||
log("Loaded twitch emote set data for {}!", emoteSet->key);
|
||||
|
||||
if (type == "sub") {
|
||||
emoteSet->text =
|
||||
QString("Twitch Subscriber Emote (%1)").arg(channelName);
|
||||
} else {
|
||||
emoteSet->text =
|
||||
QString("Twitch Account Emote (%1)").arg(channelName);
|
||||
}
|
||||
auto name = channelName;
|
||||
name.detach();
|
||||
name[0] = name[0].toUpper();
|
||||
|
||||
emoteSet->text = name;
|
||||
|
||||
emoteSet->type = type;
|
||||
emoteSet->channelName = channelName;
|
||||
|
||||
return Success;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/Aliases.hpp"
|
||||
#include "common/Atomic.hpp"
|
||||
#include "common/UniqueAccess.hpp"
|
||||
#include "controllers/accounts/Account.hpp"
|
||||
#include "messages/Emote.hpp"
|
||||
@@ -44,6 +46,7 @@ public:
|
||||
QString key;
|
||||
QString channelName;
|
||||
QString text;
|
||||
QString type;
|
||||
std::vector<TwitchEmote> emotes;
|
||||
};
|
||||
|
||||
@@ -65,9 +68,11 @@ public:
|
||||
const QString &getUserName() const;
|
||||
const QString &getOAuthToken() const;
|
||||
const QString &getOAuthClient() const;
|
||||
|
||||
const QString &getUserId() const;
|
||||
|
||||
QColor color();
|
||||
void setColor(QColor color);
|
||||
|
||||
// Attempts to update the users OAuth Client ID
|
||||
// Returns true if the value has changed, otherwise false
|
||||
bool setOAuthClient(const QString &newClientID);
|
||||
@@ -103,8 +108,6 @@ public:
|
||||
void loadEmotes();
|
||||
AccessGuard<const TwitchAccountEmoteData> accessEmotes() const;
|
||||
|
||||
QColor color;
|
||||
|
||||
private:
|
||||
void parseEmotes(const rapidjson::Document &document);
|
||||
void loadEmoteSetData(std::shared_ptr<EmoteSet> emoteSet);
|
||||
@@ -114,6 +117,7 @@ private:
|
||||
QString userName_;
|
||||
QString userId_;
|
||||
const bool isAnon_;
|
||||
Atomic<QColor> color_;
|
||||
|
||||
mutable std::mutex ignoresMutex_;
|
||||
std::set<TwitchUser> ignores_;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "common/Common.hpp"
|
||||
#include "debug/Log.hpp"
|
||||
#include "providers/twitch/TwitchAccount.hpp"
|
||||
#include "providers/twitch/TwitchCommon.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
@@ -93,20 +94,20 @@ void TwitchAccountManager::reloadUsers()
|
||||
|
||||
switch (this->addUser(userData)) {
|
||||
case AddUserResponse::UserAlreadyExists: {
|
||||
Log("User {} already exists", userData.username);
|
||||
log("User {} already exists", userData.username);
|
||||
// Do nothing
|
||||
} break;
|
||||
case AddUserResponse::UserValuesUpdated: {
|
||||
Log("User {} already exists, and values updated!",
|
||||
log("User {} already exists, and values updated!",
|
||||
userData.username);
|
||||
if (userData.username == this->getCurrent()->getUserName()) {
|
||||
Log("It was the current user, so we need to reconnect "
|
||||
log("It was the current user, so we need to reconnect "
|
||||
"stuff!");
|
||||
this->currentUserChanged.invoke();
|
||||
}
|
||||
} break;
|
||||
case AddUserResponse::UserAdded: {
|
||||
Log("Added user {}", userData.username);
|
||||
log("Added user {}", userData.username);
|
||||
listUpdated = true;
|
||||
} break;
|
||||
}
|
||||
@@ -125,12 +126,12 @@ void TwitchAccountManager::load()
|
||||
QString newUsername(QString::fromStdString(newValue));
|
||||
auto user = this->findUserByUsername(newUsername);
|
||||
if (user) {
|
||||
Log("[AccountManager:currentUsernameChanged] User successfully "
|
||||
log("[AccountManager:currentUsernameChanged] User successfully "
|
||||
"updated to {}",
|
||||
newUsername);
|
||||
this->currentUser_ = user;
|
||||
} else {
|
||||
Log("[AccountManager:currentUsernameChanged] User successfully "
|
||||
log("[AccountManager:currentUsernameChanged] User successfully "
|
||||
"updated to anonymous");
|
||||
this->currentUser_ = this->anonymousUser_;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class TwitchAccount;
|
||||
class AccountController;
|
||||
|
||||
class TwitchAccountManager
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "providers/twitch/TwitchApi.hpp"
|
||||
|
||||
#include "common/Common.hpp"
|
||||
#include "common/NetworkRequest.hpp"
|
||||
#include "debug/Log.hpp"
|
||||
#include "providers/twitch/TwitchCommon.hpp"
|
||||
@@ -20,25 +21,25 @@ void TwitchApi::findUserId(const QString user,
|
||||
request.onSuccess([successCallback](auto result) mutable -> Outcome {
|
||||
auto root = result.parseJson();
|
||||
if (!root.value("users").isArray()) {
|
||||
Log("API Error while getting user id, users is not an array");
|
||||
log("API Error while getting user id, users is not an array");
|
||||
successCallback("");
|
||||
return Failure;
|
||||
}
|
||||
auto users = root.value("users").toArray();
|
||||
if (users.size() != 1) {
|
||||
Log("API Error while getting user id, users array size is not 1");
|
||||
log("API Error while getting user id, users array size is not 1");
|
||||
successCallback("");
|
||||
return Failure;
|
||||
}
|
||||
if (!users[0].isObject()) {
|
||||
Log("API Error while getting user id, first user is not an object");
|
||||
log("API Error while getting user id, first user is not an object");
|
||||
successCallback("");
|
||||
return Failure;
|
||||
}
|
||||
auto firstUser = users[0].toObject();
|
||||
auto id = firstUser.value("_id");
|
||||
if (!id.isString()) {
|
||||
Log("API Error: while getting user id, first user object `_id` key "
|
||||
log("API Error: while getting user id, first user object `_id` key "
|
||||
"is not a "
|
||||
"string");
|
||||
successCallback("");
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
#include <functional>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
|
||||
@@ -4,19 +4,14 @@
|
||||
#include <QJsonObject>
|
||||
#include <QJsonValue>
|
||||
#include <QThread>
|
||||
|
||||
#include "common/NetworkRequest.hpp"
|
||||
#include "common/Outcome.hpp"
|
||||
#include "debug/Log.hpp"
|
||||
#include "messages/Emote.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
TwitchBadges::TwitchBadges()
|
||||
{
|
||||
}
|
||||
|
||||
void TwitchBadges::initialize(Settings &settings, Paths &paths)
|
||||
{
|
||||
this->loadTwitchBadges();
|
||||
}
|
||||
|
||||
void TwitchBadges::loadTwitchBadges()
|
||||
{
|
||||
static QString url(
|
||||
@@ -26,32 +21,34 @@ void TwitchBadges::loadTwitchBadges()
|
||||
req.setCaller(QThread::currentThread());
|
||||
req.onSuccess([this](auto result) -> Outcome {
|
||||
auto root = result.parseJson();
|
||||
QJsonObject sets = root.value("badge_sets").toObject();
|
||||
auto badgeSets = this->badgeSets_.access();
|
||||
|
||||
for (QJsonObject::iterator it = sets.begin(); it != sets.end(); ++it) {
|
||||
QJsonObject versions =
|
||||
it.value().toObject().value("versions").toObject();
|
||||
auto jsonSets = root.value("badge_sets").toObject();
|
||||
for (auto sIt = jsonSets.begin(); sIt != jsonSets.end(); ++sIt) {
|
||||
auto key = sIt.key();
|
||||
auto versions = sIt.value().toObject().value("versions").toObject();
|
||||
|
||||
for (auto vIt = versions.begin(); vIt != versions.end(); ++vIt) {
|
||||
auto versionObj = vIt.value().toObject();
|
||||
|
||||
for (auto versionIt = std::begin(versions);
|
||||
versionIt != std::end(versions); ++versionIt) {
|
||||
auto emote = Emote{
|
||||
{""},
|
||||
ImageSet{
|
||||
Image::fromUrl({root.value("image_url_1x").toString()},
|
||||
1),
|
||||
Image::fromUrl({root.value("image_url_2x").toString()},
|
||||
0.5),
|
||||
Image::fromUrl({root.value("image_url_4x").toString()},
|
||||
0.25),
|
||||
Image::fromUrl(
|
||||
{versionObj.value("image_url_1x").toString()}, 1),
|
||||
Image::fromUrl(
|
||||
{versionObj.value("image_url_2x").toString()}, .5),
|
||||
Image::fromUrl(
|
||||
{versionObj.value("image_url_4x").toString()}, .25),
|
||||
},
|
||||
Tooltip{root.value("description").toString()},
|
||||
Url{root.value("clickURL").toString()}};
|
||||
// "title"
|
||||
// "clickAction"
|
||||
|
||||
QJsonObject versionObj = versionIt.value().toObject();
|
||||
this->badges.emplace(versionIt.key(),
|
||||
std::make_shared<Emote>(emote));
|
||||
log("{} {}", key, vIt.key());
|
||||
|
||||
(*badgeSets)[key][vIt.key()] = std::make_shared<Emote>(emote);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,4 +58,18 @@ void TwitchBadges::loadTwitchBadges()
|
||||
req.execute();
|
||||
}
|
||||
|
||||
boost::optional<EmotePtr> TwitchBadges::badge(const QString &set,
|
||||
const QString &version) const
|
||||
{
|
||||
auto badgeSets = this->badgeSets_.access();
|
||||
auto it = badgeSets->find(set);
|
||||
if (it != badgeSets->end()) {
|
||||
auto it2 = it->second.find(version);
|
||||
if (it2 != it->second.end()) {
|
||||
return it2->second;
|
||||
}
|
||||
}
|
||||
return boost::none;
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -1,26 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
#include <messages/Emote.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "common/UniqueAccess.hpp"
|
||||
#include "util/QStringHash.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
struct Emote;
|
||||
using EmotePtr = std::shared_ptr<const Emote>;
|
||||
|
||||
class Settings;
|
||||
class Paths;
|
||||
|
||||
class TwitchBadges
|
||||
{
|
||||
public:
|
||||
TwitchBadges();
|
||||
|
||||
void initialize(Settings &settings, Paths &paths);
|
||||
|
||||
private:
|
||||
void loadTwitchBadges();
|
||||
|
||||
std::unordered_map<QString, EmotePtr> badges;
|
||||
boost::optional<EmotePtr> badge(const QString &set,
|
||||
const QString &version) const;
|
||||
|
||||
private:
|
||||
UniqueAccess<
|
||||
std::unordered_map<QString, std::unordered_map<QString, EmotePtr>>>
|
||||
badgeSets_; // "bits": { "100": ... "500": ...
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
#include "providers/twitch/TwitchChannel.hpp"
|
||||
|
||||
#include "Application.hpp"
|
||||
#include "common/Common.hpp"
|
||||
#include "common/NetworkRequest.hpp"
|
||||
#include "controllers/accounts/AccountController.hpp"
|
||||
#include "controllers/notifications/NotificationController.hpp"
|
||||
#include "debug/Log.hpp"
|
||||
#include "messages/Message.hpp"
|
||||
#include "providers/bttv/BttvEmotes.hpp"
|
||||
#include "providers/bttv/LoadBttvChannelEmote.hpp"
|
||||
#include "providers/twitch/PubsubClient.hpp"
|
||||
#include "providers/twitch/TwitchCommon.hpp"
|
||||
@@ -25,18 +27,67 @@
|
||||
#include <QTimer>
|
||||
|
||||
namespace chatterino {
|
||||
namespace {
|
||||
auto parseRecentMessages(const QJsonObject &jsonRoot,
|
||||
TwitchChannel &channel)
|
||||
{
|
||||
QJsonArray jsonMessages = jsonRoot.value("messages").toArray();
|
||||
std::vector<MessagePtr> messages;
|
||||
|
||||
TwitchChannel::TwitchChannel(const QString &name)
|
||||
if (jsonMessages.empty()) return messages;
|
||||
|
||||
for (const auto jsonMessage : jsonMessages) {
|
||||
auto content = jsonMessage.toString().toUtf8();
|
||||
// passing nullptr as the channel makes the message invalid but we
|
||||
// don't check for that anyways
|
||||
auto message = Communi::IrcMessage::fromData(content, nullptr);
|
||||
auto privMsg = dynamic_cast<Communi::IrcPrivateMessage *>(message);
|
||||
assert(privMsg);
|
||||
|
||||
MessageParseArgs args;
|
||||
TwitchMessageBuilder builder(&channel, privMsg, args);
|
||||
if (!builder.isIgnored()) {
|
||||
messages.push_back(builder.build());
|
||||
}
|
||||
}
|
||||
|
||||
return messages;
|
||||
}
|
||||
std::pair<Outcome, UsernameSet> parseChatters(const QJsonObject &jsonRoot)
|
||||
{
|
||||
static QStringList categories = {"moderators", "staff", "admins",
|
||||
"global_mods", "viewers"};
|
||||
|
||||
auto usernames = UsernameSet();
|
||||
|
||||
// parse json
|
||||
QJsonObject jsonCategories = jsonRoot.value("chatters").toObject();
|
||||
|
||||
for (const auto &category : categories) {
|
||||
for (auto jsonCategory : jsonCategories.value(category).toArray()) {
|
||||
usernames.insert(jsonCategory.toString());
|
||||
}
|
||||
}
|
||||
|
||||
return {Success, std::move(usernames)};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TwitchChannel::TwitchChannel(const QString &name,
|
||||
TwitchBadges &globalTwitchBadges, BttvEmotes &bttv,
|
||||
FfzEmotes &ffz)
|
||||
: Channel(name, Channel::Type::Twitch)
|
||||
, subscriptionUrl_("https://www.twitch.tv/subs/" + name)
|
||||
, channelUrl_("https://twitch.tv/" + name)
|
||||
, popoutPlayerUrl_("https://player.twitch.tv/?channel=" + name)
|
||||
, globalTwitchBadges_(globalTwitchBadges)
|
||||
, globalBttv_(bttv)
|
||||
, globalFfz_(ffz)
|
||||
, bttvEmotes_(std::make_shared<EmoteMap>())
|
||||
, ffzEmotes_(std::make_shared<EmoteMap>())
|
||||
, mod_(false)
|
||||
{
|
||||
Log("[TwitchChannel:{}] Opened", name);
|
||||
|
||||
// this->refreshChannelEmotes();
|
||||
// this->refreshViewerList();
|
||||
log("[TwitchChannel:{}] Opened", name);
|
||||
|
||||
this->tabHighlightRequested.connect([](HighlightState state) {});
|
||||
this->liveStatusChanged.connect([this]() {
|
||||
@@ -48,22 +99,22 @@ TwitchChannel::TwitchChannel(const QString &name)
|
||||
[=] { this->setMod(false); });
|
||||
|
||||
// pubsub
|
||||
this->userStateChanged.connect([=] { this->refreshPubsub(); });
|
||||
this->managedConnect(getApp()->accounts->twitch.currentUserChanged,
|
||||
[=] { this->refreshPubsub(); });
|
||||
this->refreshPubsub();
|
||||
this->userStateChanged.connect([this] { this->refreshPubsub(); });
|
||||
|
||||
// room id loaded -> refresh live status
|
||||
this->roomIdChanged.connect([this]() {
|
||||
this->refreshPubsub();
|
||||
this->refreshLiveStatus();
|
||||
this->loadBadges();
|
||||
this->loadCheerEmotes();
|
||||
this->refreshBadges();
|
||||
this->refreshCheerEmotes();
|
||||
});
|
||||
|
||||
// timers
|
||||
QObject::connect(&this->chattersListTimer_, &QTimer::timeout,
|
||||
[=] { this->refreshViewerList(); });
|
||||
[=] { this->refreshChatters(); });
|
||||
this->chattersListTimer_.start(5 * 60 * 1000);
|
||||
|
||||
QObject::connect(&this->liveStatusTimer_, &QTimer::timeout,
|
||||
@@ -77,11 +128,17 @@ TwitchChannel::TwitchChannel(const QString &name)
|
||||
// debugging
|
||||
#if 0
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
this->addMessage(makeSystemMessage("asdf"));
|
||||
this->addMessage(makeSystemMessage("asef"));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void TwitchChannel::initialize()
|
||||
{
|
||||
this->refreshChatters();
|
||||
this->refreshChannelEmotes();
|
||||
}
|
||||
|
||||
bool TwitchChannel::isEmpty() const
|
||||
{
|
||||
return this->getName().isEmpty();
|
||||
@@ -94,15 +151,17 @@ bool TwitchChannel::canSendMessage() const
|
||||
|
||||
void TwitchChannel::refreshChannelEmotes()
|
||||
{
|
||||
loadBttvChannelEmotes(
|
||||
this->getName(), [this, weak = weakOf<Channel>(this)](auto &&emoteMap) {
|
||||
if (auto shared = weak.lock()) //
|
||||
*this->bttvEmotes_.access() = emoteMap;
|
||||
});
|
||||
getApp()->emotes->ffz.loadChannelEmotes(
|
||||
BttvEmotes::loadChannel(
|
||||
this->getName(), [this, weak = weakOf<Channel>(this)](auto &&emoteMap) {
|
||||
if (auto shared = weak.lock())
|
||||
*this->ffzEmotes_.access() = emoteMap;
|
||||
this->bttvEmotes_.set(
|
||||
std::make_shared<EmoteMap>(std::move(emoteMap)));
|
||||
});
|
||||
FfzEmotes::loadChannel(
|
||||
this->getName(), [this, weak = weakOf<Channel>(this)](auto &&emoteMap) {
|
||||
if (auto shared = weak.lock())
|
||||
this->ffzEmotes_.set(
|
||||
std::make_shared<EmoteMap>(std::move(emoteMap)));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -119,7 +178,7 @@ void TwitchChannel::sendMessage(const QString &message)
|
||||
return;
|
||||
}
|
||||
|
||||
Log("[TwitchChannel:{}] Send message: {}", this->getName(), message);
|
||||
log("[TwitchChannel:{}] Send message: {}", this->getName(), message);
|
||||
|
||||
// Do last message processing
|
||||
QString parsedMessage = app->emotes->emojis.replaceShortCodes(message);
|
||||
@@ -170,9 +229,7 @@ bool TwitchChannel::isBroadcaster() const
|
||||
|
||||
void TwitchChannel::addRecentChatter(const MessagePtr &message)
|
||||
{
|
||||
assert(!message->loginName.isEmpty());
|
||||
|
||||
this->completionModel.addUser(message->displayName);
|
||||
this->chatters_.access()->insert(message->displayName);
|
||||
}
|
||||
|
||||
void TwitchChannel::addJoinedUser(const QString &user)
|
||||
@@ -231,14 +288,14 @@ void TwitchChannel::addPartedUser(const QString &user)
|
||||
}
|
||||
}
|
||||
|
||||
QString TwitchChannel::getRoomId() const
|
||||
QString TwitchChannel::roomId() const
|
||||
{
|
||||
return this->roomID_.get();
|
||||
return *this->roomID_.access();
|
||||
}
|
||||
|
||||
void TwitchChannel::setRoomId(const QString &id)
|
||||
{
|
||||
this->roomID_.set(id);
|
||||
(*this->roomID_.access()) = id;
|
||||
this->roomIdChanged.invoke();
|
||||
this->loadRecentMessages();
|
||||
}
|
||||
@@ -262,52 +319,70 @@ bool TwitchChannel::isLive() const
|
||||
}
|
||||
|
||||
AccessGuard<const TwitchChannel::StreamStatus>
|
||||
TwitchChannel::accessStreamStatus() const
|
||||
TwitchChannel::accessStreamStatus() const
|
||||
{
|
||||
return this->streamStatus_.accessConst();
|
||||
}
|
||||
|
||||
boost::optional<EmotePtr> TwitchChannel::getBttvEmote(
|
||||
const EmoteName &name) const
|
||||
AccessGuard<const UsernameSet> TwitchChannel::accessChatters() const
|
||||
{
|
||||
auto emotes = this->bttvEmotes_.access();
|
||||
return this->chatters_.accessConst();
|
||||
}
|
||||
|
||||
const TwitchBadges &TwitchChannel::globalTwitchBadges() const
|
||||
{
|
||||
return this->globalTwitchBadges_;
|
||||
}
|
||||
|
||||
const BttvEmotes &TwitchChannel::globalBttv() const
|
||||
{
|
||||
return this->globalBttv_;
|
||||
}
|
||||
|
||||
const FfzEmotes &TwitchChannel::globalFfz() const
|
||||
{
|
||||
return this->globalFfz_;
|
||||
}
|
||||
|
||||
boost::optional<EmotePtr> TwitchChannel::bttvEmote(const EmoteName &name) const
|
||||
{
|
||||
auto emotes = this->bttvEmotes_.get();
|
||||
auto it = emotes->find(name);
|
||||
|
||||
if (it == emotes->end()) return boost::none;
|
||||
return it->second;
|
||||
}
|
||||
|
||||
boost::optional<EmotePtr> TwitchChannel::getFfzEmote(
|
||||
const EmoteName &name) const
|
||||
boost::optional<EmotePtr> TwitchChannel::ffzEmote(const EmoteName &name) const
|
||||
{
|
||||
auto emotes = this->bttvEmotes_.access();
|
||||
auto emotes = this->ffzEmotes_.get();
|
||||
auto it = emotes->find(name);
|
||||
|
||||
if (it == emotes->end()) return boost::none;
|
||||
return it->second;
|
||||
}
|
||||
|
||||
AccessGuard<const EmoteMap> TwitchChannel::accessBttvEmotes() const
|
||||
std::shared_ptr<const EmoteMap> TwitchChannel::bttvEmotes() const
|
||||
{
|
||||
return this->bttvEmotes_.accessConst();
|
||||
return this->bttvEmotes_.get();
|
||||
}
|
||||
|
||||
AccessGuard<const EmoteMap> TwitchChannel::accessFfzEmotes() const
|
||||
std::shared_ptr<const EmoteMap> TwitchChannel::ffzEmotes() const
|
||||
{
|
||||
return this->ffzEmotes_.accessConst();
|
||||
return this->ffzEmotes_.get();
|
||||
}
|
||||
|
||||
const QString &TwitchChannel::getSubscriptionUrl()
|
||||
const QString &TwitchChannel::subscriptionUrl()
|
||||
{
|
||||
return this->subscriptionUrl_;
|
||||
}
|
||||
|
||||
const QString &TwitchChannel::getChannelUrl()
|
||||
const QString &TwitchChannel::channelUrl()
|
||||
{
|
||||
return this->channelUrl_;
|
||||
}
|
||||
|
||||
const QString &TwitchChannel::getPopoutPlayerUrl()
|
||||
const QString &TwitchChannel::popoutPlayerUrl()
|
||||
{
|
||||
return this->popoutPlayerUrl_;
|
||||
}
|
||||
@@ -347,16 +422,16 @@ void TwitchChannel::setLive(bool newLiveStatus)
|
||||
|
||||
void TwitchChannel::refreshLiveStatus()
|
||||
{
|
||||
auto roomID = this->getRoomId();
|
||||
auto roomID = this->roomId();
|
||||
|
||||
if (roomID.isEmpty()) {
|
||||
Log("[TwitchChannel:{}] Refreshing live status (Missing ID)",
|
||||
log("[TwitchChannel:{}] Refreshing live status (Missing ID)",
|
||||
this->getName());
|
||||
this->setLive(false);
|
||||
return;
|
||||
}
|
||||
|
||||
Log("[TwitchChannel:{}] Refreshing live status", this->getName());
|
||||
log("[TwitchChannel:{}] Refreshing live status", this->getName());
|
||||
|
||||
QString url("https://api.twitch.tv/kraken/streams/" + roomID);
|
||||
|
||||
@@ -368,7 +443,7 @@ void TwitchChannel::refreshLiveStatus()
|
||||
//>>>>>>> 9bfbdefd2f0972a738230d5b95a009f73b1dd933
|
||||
|
||||
request.onSuccess(
|
||||
[this, weak = this->weak_from_this()](auto result) -> Outcome {
|
||||
[this, weak = weakOf<Channel>(this)](auto result) -> Outcome {
|
||||
ChannelPtr shared = weak.lock();
|
||||
if (!shared) return Failure;
|
||||
|
||||
@@ -381,12 +456,12 @@ void TwitchChannel::refreshLiveStatus()
|
||||
Outcome TwitchChannel::parseLiveStatus(const rapidjson::Document &document)
|
||||
{
|
||||
if (!document.IsObject()) {
|
||||
Log("[TwitchChannel:refreshLiveStatus] root is not an object");
|
||||
log("[TwitchChannel:refreshLiveStatus] root is not an object");
|
||||
return Failure;
|
||||
}
|
||||
|
||||
if (!document.HasMember("stream")) {
|
||||
Log("[TwitchChannel:refreshLiveStatus] Missing stream in root");
|
||||
log("[TwitchChannel:refreshLiveStatus] Missing stream in root");
|
||||
return Failure;
|
||||
}
|
||||
|
||||
@@ -400,7 +475,7 @@ Outcome TwitchChannel::parseLiveStatus(const rapidjson::Document &document)
|
||||
|
||||
if (!stream.HasMember("viewers") || !stream.HasMember("game") ||
|
||||
!stream.HasMember("channel") || !stream.HasMember("created_at")) {
|
||||
Log("[TwitchChannel:refreshLiveStatus] Missing members in stream");
|
||||
log("[TwitchChannel:refreshLiveStatus] Missing members in stream");
|
||||
this->setLive(false);
|
||||
return Failure;
|
||||
}
|
||||
@@ -408,7 +483,7 @@ Outcome TwitchChannel::parseLiveStatus(const rapidjson::Document &document)
|
||||
const rapidjson::Value &streamChannel = stream["channel"];
|
||||
|
||||
if (!streamChannel.IsObject() || !streamChannel.HasMember("status")) {
|
||||
Log("[TwitchChannel:refreshLiveStatus] Missing member \"status\" in "
|
||||
log("[TwitchChannel:refreshLiveStatus] Missing member \"status\" in "
|
||||
"channel");
|
||||
return Failure;
|
||||
}
|
||||
@@ -458,53 +533,31 @@ void TwitchChannel::loadRecentMessages()
|
||||
"https://tmi.twitch.tv/api/rooms/%1/recent_messages?client_id=" +
|
||||
getDefaultClientID();
|
||||
|
||||
NetworkRequest request(genericURL.arg(this->getRoomId()));
|
||||
NetworkRequest request(genericURL.arg(this->roomId()));
|
||||
request.makeAuthorizedV5(getDefaultClientID());
|
||||
request.setCaller(QThread::currentThread());
|
||||
// can't be concurrent right now due to SignalVector
|
||||
// request.setExecuteConcurrently(true);
|
||||
|
||||
request.onSuccess(
|
||||
[this, weak = weakOf<Channel>(this)](auto result) -> Outcome {
|
||||
ChannelPtr shared = weak.lock();
|
||||
if (!shared) return Failure;
|
||||
request.onSuccess([that = this](auto result) -> Outcome {
|
||||
auto messages = parseRecentMessages(result.parseJson(), *that);
|
||||
|
||||
return this->parseRecentMessages(result.parseJson());
|
||||
});
|
||||
// postToThread([that, weak = weakOf<Channel>(that),
|
||||
// messages = std::move(messages)]() mutable {
|
||||
that->addMessagesAtStart(messages);
|
||||
// });
|
||||
|
||||
return Success;
|
||||
});
|
||||
|
||||
request.execute();
|
||||
}
|
||||
|
||||
Outcome TwitchChannel::parseRecentMessages(const QJsonObject &jsonRoot)
|
||||
{
|
||||
QJsonArray jsonMessages = jsonRoot.value("messages").toArray();
|
||||
if (jsonMessages.empty()) return Failure;
|
||||
|
||||
std::vector<MessagePtr> messages;
|
||||
|
||||
for (const auto jsonMessage : jsonMessages) {
|
||||
auto content = jsonMessage.toString().toUtf8();
|
||||
// passing nullptr as the channel makes the message invalid but we don't
|
||||
// check for that anyways
|
||||
auto message = Communi::IrcMessage::fromData(content, nullptr);
|
||||
auto privMsg = dynamic_cast<Communi::IrcPrivateMessage *>(message);
|
||||
assert(privMsg);
|
||||
|
||||
MessageParseArgs args;
|
||||
TwitchMessageBuilder builder(this, privMsg, args);
|
||||
if (!builder.isIgnored()) {
|
||||
messages.push_back(builder.build());
|
||||
}
|
||||
}
|
||||
|
||||
this->addMessagesAtStart(messages);
|
||||
|
||||
return Success;
|
||||
}
|
||||
|
||||
void TwitchChannel::refreshPubsub()
|
||||
{
|
||||
// listen to moderation actions
|
||||
if (!this->hasModRights()) return;
|
||||
auto roomId = this->getRoomId();
|
||||
auto roomId = this->roomId();
|
||||
if (roomId.isEmpty()) return;
|
||||
|
||||
auto account = getApp()->accounts->twitch.getCurrent();
|
||||
@@ -512,7 +565,7 @@ void TwitchChannel::refreshPubsub()
|
||||
account);
|
||||
}
|
||||
|
||||
void TwitchChannel::refreshViewerList()
|
||||
void TwitchChannel::refreshChatters()
|
||||
{
|
||||
// setting?
|
||||
const auto streamStatus = this->accessStreamStatus();
|
||||
@@ -530,39 +583,26 @@ void TwitchChannel::refreshViewerList()
|
||||
|
||||
request.setCaller(QThread::currentThread());
|
||||
request.onSuccess(
|
||||
[this, weak = this->weak_from_this()](auto result) -> Outcome {
|
||||
[this, weak = weakOf<Channel>(this)](auto result) -> Outcome {
|
||||
// channel still exists?
|
||||
auto shared = weak.lock();
|
||||
if (!shared) return Failure;
|
||||
|
||||
return this->parseViewerList(result.parseJson());
|
||||
auto pair = parseChatters(result.parseJson());
|
||||
if (pair.first) {
|
||||
*this->chatters_.access() = std::move(pair.second);
|
||||
}
|
||||
|
||||
return pair.first;
|
||||
});
|
||||
|
||||
request.execute();
|
||||
}
|
||||
|
||||
Outcome TwitchChannel::parseViewerList(const QJsonObject &jsonRoot)
|
||||
{
|
||||
static QStringList categories = {"moderators", "staff", "admins",
|
||||
"global_mods", "viewers"};
|
||||
|
||||
// parse json
|
||||
QJsonObject jsonCategories = jsonRoot.value("chatters").toObject();
|
||||
|
||||
for (const auto &category : categories) {
|
||||
for (const auto jsonCategory :
|
||||
jsonCategories.value(category).toArray()) {
|
||||
this->completionModel.addUser(jsonCategory.toString());
|
||||
}
|
||||
}
|
||||
|
||||
return Success;
|
||||
}
|
||||
|
||||
void TwitchChannel::loadBadges()
|
||||
void TwitchChannel::refreshBadges()
|
||||
{
|
||||
auto url = Url{"https://badges.twitch.tv/v1/badges/channels/" +
|
||||
this->getRoomId() + "/display?language=en"};
|
||||
this->roomId() + "/display?language=en"};
|
||||
NetworkRequest req(url.string);
|
||||
req.setCaller(QThread::currentThread());
|
||||
|
||||
@@ -604,9 +644,9 @@ void TwitchChannel::loadBadges()
|
||||
req.execute();
|
||||
}
|
||||
|
||||
void TwitchChannel::loadCheerEmotes()
|
||||
void TwitchChannel::refreshCheerEmotes()
|
||||
{
|
||||
auto url = Url{"https://api.twitch.tv/kraken/bits/actions?channel_id=" +
|
||||
/*auto url = Url{"https://api.twitch.tv/kraken/bits/actions?channel_id=" +
|
||||
this->getRoomId()};
|
||||
auto request = NetworkRequest::twitchRequest(url.string);
|
||||
request.setCaller(QThread::currentThread());
|
||||
@@ -614,6 +654,7 @@ void TwitchChannel::loadCheerEmotes()
|
||||
request.onSuccess(
|
||||
[this, weak = weakOf<Channel>(this)](auto result) -> Outcome {
|
||||
auto cheerEmoteSets = ParseCheermoteSets(result.parseRapidJson());
|
||||
std::vector<CheerEmoteSet> emoteSets;
|
||||
|
||||
for (auto &set : cheerEmoteSets) {
|
||||
auto cheerEmoteSet = CheerEmoteSet();
|
||||
@@ -656,16 +697,18 @@ void TwitchChannel::loadCheerEmotes()
|
||||
return lhs.minBits < rhs.minBits; //
|
||||
});
|
||||
|
||||
this->cheerEmoteSets_.emplace_back(cheerEmoteSet);
|
||||
emoteSets.emplace_back(cheerEmoteSet);
|
||||
}
|
||||
*this->cheerEmoteSets_.access() = std::move(emoteSets);
|
||||
|
||||
return Success;
|
||||
});
|
||||
|
||||
request.execute();
|
||||
*/
|
||||
}
|
||||
|
||||
boost::optional<EmotePtr> TwitchChannel::getTwitchBadge(
|
||||
boost::optional<EmotePtr> TwitchChannel::twitchBadge(
|
||||
const QString &set, const QString &version) const
|
||||
{
|
||||
auto badgeSets = this->badgeSets_.access();
|
||||
|
||||
@@ -1,22 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include <IrcConnection>
|
||||
|
||||
#include "common/Aliases.hpp"
|
||||
#include "common/Atomic.hpp"
|
||||
#include "common/Channel.hpp"
|
||||
#include "common/Common.hpp"
|
||||
#include "common/MutexValue.hpp"
|
||||
#include "common/Outcome.hpp"
|
||||
#include "common/UniqueAccess.hpp"
|
||||
#include "messages/Emote.hpp"
|
||||
#include "singletons/Emotes.hpp"
|
||||
#include "util/ConcurrentMap.hpp"
|
||||
|
||||
#include <pajlada/signals/signalholder.hpp>
|
||||
#include "common/UsernameSet.hpp"
|
||||
#include "providers/twitch/TwitchEmotes.hpp"
|
||||
|
||||
#include <rapidjson/document.h>
|
||||
#include <IrcConnection>
|
||||
#include <QColor>
|
||||
#include <QRegularExpression>
|
||||
#include <boost/optional.hpp>
|
||||
#include <mutex>
|
||||
#include <pajlada/signals/signalholder.hpp>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
struct Emote;
|
||||
using EmotePtr = std::shared_ptr<const Emote>;
|
||||
class EmoteMap;
|
||||
|
||||
class TwitchBadges;
|
||||
class FfzEmotes;
|
||||
class BttvEmotes;
|
||||
|
||||
class TwitchServer;
|
||||
|
||||
class TwitchChannel final : public Channel, pajlada::Signals::SignalHolder
|
||||
@@ -32,11 +42,6 @@ public:
|
||||
QString streamType;
|
||||
};
|
||||
|
||||
struct UserState {
|
||||
bool mod;
|
||||
bool broadcaster;
|
||||
};
|
||||
|
||||
struct RoomModes {
|
||||
bool submode = false;
|
||||
bool r9k = false;
|
||||
@@ -46,107 +51,104 @@ public:
|
||||
QString broadcasterLang;
|
||||
};
|
||||
|
||||
void refreshChannelEmotes();
|
||||
void initialize();
|
||||
|
||||
// Channel methods
|
||||
virtual bool isEmpty() const override;
|
||||
virtual bool canSendMessage() const override;
|
||||
virtual void sendMessage(const QString &message) override;
|
||||
|
||||
// Auto completion
|
||||
void addRecentChatter(const MessagePtr &message) final;
|
||||
void addJoinedUser(const QString &user);
|
||||
void addPartedUser(const QString &user);
|
||||
|
||||
// Twitch data
|
||||
bool isLive() const;
|
||||
virtual bool isMod() const override;
|
||||
void setMod(bool value);
|
||||
virtual bool isBroadcaster() const override;
|
||||
|
||||
QString getRoomId() const;
|
||||
void setRoomId(const QString &id);
|
||||
// Data
|
||||
const QString &subscriptionUrl();
|
||||
const QString &channelUrl();
|
||||
const QString &popoutPlayerUrl();
|
||||
bool isLive() const;
|
||||
QString roomId() const;
|
||||
AccessGuard<const RoomModes> accessRoomModes() const;
|
||||
void setRoomModes(const RoomModes &roomModes_);
|
||||
AccessGuard<const StreamStatus> accessStreamStatus() const;
|
||||
AccessGuard<const UsernameSet> accessChatters() const;
|
||||
|
||||
boost::optional<EmotePtr> getBttvEmote(const EmoteName &name) const;
|
||||
boost::optional<EmotePtr> getFfzEmote(const EmoteName &name) const;
|
||||
AccessGuard<const EmoteMap> accessBttvEmotes() const;
|
||||
AccessGuard<const EmoteMap> accessFfzEmotes() const;
|
||||
const QString &getSubscriptionUrl();
|
||||
const QString &getChannelUrl();
|
||||
const QString &getPopoutPlayerUrl();
|
||||
// Emotes
|
||||
const TwitchBadges &globalTwitchBadges() const;
|
||||
const BttvEmotes &globalBttv() const;
|
||||
const FfzEmotes &globalFfz() const;
|
||||
boost::optional<EmotePtr> bttvEmote(const EmoteName &name) const;
|
||||
boost::optional<EmotePtr> ffzEmote(const EmoteName &name) const;
|
||||
std::shared_ptr<const EmoteMap> bttvEmotes() const;
|
||||
std::shared_ptr<const EmoteMap> ffzEmotes() const;
|
||||
|
||||
boost::optional<EmotePtr> getTwitchBadge(const QString &set,
|
||||
const QString &version) const;
|
||||
void refreshChannelEmotes();
|
||||
|
||||
// Badges
|
||||
boost::optional<EmotePtr> twitchBadge(const QString &set,
|
||||
const QString &version) const;
|
||||
|
||||
// Signals
|
||||
pajlada::Signals::NoArgSignal roomIdChanged;
|
||||
pajlada::Signals::NoArgSignal liveStatusChanged;
|
||||
pajlada::Signals::NoArgSignal userStateChanged;
|
||||
pajlada::Signals::NoArgSignal liveStatusChanged;
|
||||
pajlada::Signals::NoArgSignal roomModesChanged;
|
||||
pajlada::Signals::Signal<HighlightState> tabHighlightRequested;
|
||||
|
||||
protected:
|
||||
void addRecentChatter(const MessagePtr &message) override;
|
||||
|
||||
private:
|
||||
struct NameOptions {
|
||||
QString displayName;
|
||||
QString localizedName;
|
||||
};
|
||||
|
||||
struct CheerEmote {
|
||||
// a Cheermote indicates one tier
|
||||
QColor color;
|
||||
int minBits;
|
||||
|
||||
EmotePtr animatedEmote;
|
||||
EmotePtr staticEmote;
|
||||
};
|
||||
|
||||
struct CheerEmoteSet {
|
||||
QRegularExpression regex;
|
||||
std::vector<CheerEmote> cheerEmotes;
|
||||
};
|
||||
|
||||
explicit TwitchChannel(const QString &channelName);
|
||||
explicit TwitchChannel(const QString &channelName,
|
||||
TwitchBadges &globalTwitchBadges,
|
||||
BttvEmotes &globalBttv, FfzEmotes &globalFfz);
|
||||
|
||||
// Methods
|
||||
void refreshLiveStatus();
|
||||
Outcome parseLiveStatus(const rapidjson::Document &document);
|
||||
void refreshPubsub();
|
||||
void refreshViewerList();
|
||||
Outcome parseViewerList(const QJsonObject &jsonRoot);
|
||||
void refreshChatters();
|
||||
void refreshBadges();
|
||||
void refreshCheerEmotes();
|
||||
void loadRecentMessages();
|
||||
Outcome parseRecentMessages(const QJsonObject &jsonRoot);
|
||||
|
||||
void addJoinedUser(const QString &user);
|
||||
void addPartedUser(const QString &user);
|
||||
void setLive(bool newLiveStatus);
|
||||
void setMod(bool value);
|
||||
void setRoomId(const QString &id);
|
||||
void setRoomModes(const RoomModes &roomModes_);
|
||||
|
||||
void loadBadges();
|
||||
void loadCheerEmotes();
|
||||
|
||||
// Twitch data
|
||||
UniqueAccess<StreamStatus> streamStatus_;
|
||||
UniqueAccess<UserState> userState_;
|
||||
UniqueAccess<RoomModes> roomModes_;
|
||||
|
||||
UniqueAccess<EmoteMap> bttvEmotes_;
|
||||
UniqueAccess<EmoteMap> ffzEmotes_;
|
||||
// Data
|
||||
const QString subscriptionUrl_;
|
||||
const QString channelUrl_;
|
||||
const QString popoutPlayerUrl_;
|
||||
UniqueAccess<StreamStatus> streamStatus_;
|
||||
UniqueAccess<RoomModes> roomModes_;
|
||||
UniqueAccess<UsernameSet> chatters_; // maps 2 char prefix to set of names
|
||||
|
||||
// Emotes
|
||||
TwitchBadges &globalTwitchBadges_;
|
||||
BttvEmotes &globalBttv_;
|
||||
FfzEmotes &globalFfz_;
|
||||
Atomic<std::shared_ptr<const EmoteMap>> bttvEmotes_;
|
||||
Atomic<std::shared_ptr<const EmoteMap>> ffzEmotes_;
|
||||
|
||||
// Badges
|
||||
UniqueAccess<std::map<QString, std::map<QString, EmotePtr>>>
|
||||
badgeSets_; // "subscribers": { "0": ... "3": ... "6": ...
|
||||
UniqueAccess<std::vector<CheerEmoteSet>> cheerEmoteSets_;
|
||||
|
||||
bool mod_ = false;
|
||||
MutexValue<QString> roomID_;
|
||||
UniqueAccess<QString> roomID_;
|
||||
|
||||
UniqueAccess<QStringList> joinedUsers_;
|
||||
bool joinedUsersMergeQueued_ = false;
|
||||
UniqueAccess<QStringList> partedUsers_;
|
||||
bool partedUsersMergeQueued_ = false;
|
||||
|
||||
// "subscribers": { "0": ... "3": ... "6": ...
|
||||
UniqueAccess<std::map<QString, std::map<QString, EmotePtr>>> badgeSets_;
|
||||
std::vector<CheerEmoteSet> cheerEmoteSets_;
|
||||
|
||||
// --
|
||||
QByteArray messageSuffix_;
|
||||
QString lastSentMessage_;
|
||||
@@ -155,6 +157,8 @@ private:
|
||||
QTimer chattersListTimer_;
|
||||
|
||||
friend class TwitchServer;
|
||||
friend class TwitchMessageBuilder;
|
||||
friend class IrcMessageHandler;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "common/NetworkRequest.hpp"
|
||||
#include "debug/Benchmark.hpp"
|
||||
#include "debug/Log.hpp"
|
||||
#include "messages/Emote.hpp"
|
||||
#include "messages/Image.hpp"
|
||||
#include "util/RapidjsonHelpers.hpp"
|
||||
|
||||
|
||||
@@ -1,20 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include <QColor>
|
||||
#include <QRegularExpression>
|
||||
#include <QString>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "common/Emotemap.hpp"
|
||||
#include "common/Aliases.hpp"
|
||||
#include "common/UniqueAccess.hpp"
|
||||
#include "messages/Emote.hpp"
|
||||
#include "providers/twitch/EmoteValue.hpp"
|
||||
#include "providers/twitch/TwitchAccount.hpp"
|
||||
#include "providers/twitch/TwitchEmotes.hpp"
|
||||
#include "util/ConcurrentMap.hpp"
|
||||
|
||||
#define TWITCH_EMOTE_TEMPLATE \
|
||||
"https://static-cdn.jtvnw.net/emoticons/v1/{id}/{scale}"
|
||||
|
||||
namespace chatterino {
|
||||
struct Emote;
|
||||
using EmotePtr = std::shared_ptr<const Emote>;
|
||||
|
||||
struct CheerEmote {
|
||||
QColor color;
|
||||
int minBits;
|
||||
|
||||
EmotePtr animatedEmote;
|
||||
EmotePtr staticEmote;
|
||||
};
|
||||
|
||||
struct CheerEmoteSet {
|
||||
QRegularExpression regex;
|
||||
std::vector<CheerEmote> cheerEmotes;
|
||||
};
|
||||
|
||||
class TwitchEmotes
|
||||
{
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace chatterino {
|
||||
bool trimChannelName(const QString &channelName, QString &outChannelName)
|
||||
{
|
||||
if (channelName.length() < 3) {
|
||||
Log("channel name length below 3");
|
||||
log("channel name length below 3");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
#include "controllers/highlights/HighlightController.hpp"
|
||||
#include "controllers/ignores/IgnoreController.hpp"
|
||||
#include "debug/Log.hpp"
|
||||
#include "messages/Message.hpp"
|
||||
#include "providers/twitch/TwitchBadges.hpp"
|
||||
#include "providers/twitch/TwitchChannel.hpp"
|
||||
#include "singletons/Emotes.hpp"
|
||||
#include "singletons/Resources.hpp"
|
||||
@@ -12,6 +14,7 @@
|
||||
#include "singletons/Theme.hpp"
|
||||
#include "singletons/WindowManager.hpp"
|
||||
#include "util/IrcHelpers.hpp"
|
||||
#include "widgets/Window.hpp"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDebug>
|
||||
@@ -31,8 +34,7 @@ TwitchMessageBuilder::TwitchMessageBuilder(
|
||||
, originalMessage_(_ircMessage->content())
|
||||
, action_(_ircMessage->isAction())
|
||||
{
|
||||
auto app = getApp();
|
||||
this->usernameColor_ = app->themes->messages.textColors.system;
|
||||
this->usernameColor_ = getApp()->themes->messages.textColors.system;
|
||||
}
|
||||
|
||||
TwitchMessageBuilder::TwitchMessageBuilder(
|
||||
@@ -46,8 +48,7 @@ TwitchMessageBuilder::TwitchMessageBuilder(
|
||||
, originalMessage_(content)
|
||||
, action_(isAction)
|
||||
{
|
||||
auto app = getApp();
|
||||
this->usernameColor_ = app->themes->messages.textColors.system;
|
||||
this->usernameColor_ = getApp()->themes->messages.textColors.system;
|
||||
}
|
||||
|
||||
bool TwitchMessageBuilder::isIgnored() const
|
||||
@@ -57,20 +58,20 @@ bool TwitchMessageBuilder::isIgnored() const
|
||||
// TODO(pajlada): Do we need to check if the phrase is valid first?
|
||||
for (const auto &phrase : app->ignores->phrases.getVector()) {
|
||||
if (phrase.isMatch(this->originalMessage_)) {
|
||||
Log("Blocking message because it contains ignored phrase {}",
|
||||
log("Blocking message because it contains ignored phrase {}",
|
||||
phrase.getPattern());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (app->settings->enableTwitchIgnoredUsers &&
|
||||
if (getSettings()->enableTwitchIgnoredUsers &&
|
||||
this->tags.contains("user-id")) {
|
||||
auto sourceUserID = this->tags.value("user-id").toString();
|
||||
|
||||
for (const auto &user :
|
||||
app->accounts->twitch.getCurrent()->getIgnores()) {
|
||||
if (sourceUserID == user.id) {
|
||||
Log("Blocking message because it's from blocked user {}",
|
||||
log("Blocking message because it's from blocked user {}",
|
||||
user.name);
|
||||
return true;
|
||||
}
|
||||
@@ -82,8 +83,6 @@ bool TwitchMessageBuilder::isIgnored() const
|
||||
|
||||
MessagePtr TwitchMessageBuilder::build()
|
||||
{
|
||||
auto app = getApp();
|
||||
|
||||
// PARSING
|
||||
this->parseUsername();
|
||||
|
||||
@@ -91,13 +90,6 @@ MessagePtr TwitchMessageBuilder::build()
|
||||
this->senderIsBroadcaster = true;
|
||||
}
|
||||
|
||||
//#ifdef XD
|
||||
// if (this->originalMessage.length() > 100) {
|
||||
// this->message->flags.has(MessageFlag::Collapsed);
|
||||
// this->emplace<EmoteElement>(getApp()->resources->badgeCollapsed,
|
||||
// MessageElementFlag::Collapsed);
|
||||
// }
|
||||
//#endif
|
||||
this->message().flags.has(MessageFlag::Collapsed);
|
||||
|
||||
// PARSING
|
||||
@@ -203,11 +195,7 @@ void TwitchMessageBuilder::addWords(
|
||||
|
||||
// split words
|
||||
for (auto &variant : getApp()->emotes->emojis.parse(word)) {
|
||||
boost::apply_visitor(/*overloaded{[&](EmotePtr arg) {
|
||||
this->addTextOrEmoji(arg); },
|
||||
[&](const QString &arg) {
|
||||
this->addTextOrEmoji(arg); }}*/
|
||||
[&](auto &&arg) { this->addTextOrEmoji(arg); },
|
||||
boost::apply_visitor([&](auto &&arg) { this->addTextOrEmoji(arg); },
|
||||
variant);
|
||||
}
|
||||
|
||||
@@ -289,7 +277,7 @@ void TwitchMessageBuilder::addTextOrEmoji(const QString &string_)
|
||||
}
|
||||
|
||||
// if (!linkString.isEmpty()) {
|
||||
// if (getApp()->settings->lowercaseLink) {
|
||||
// if (getSettings()->lowercaseLink) {
|
||||
// QRegularExpression httpRegex("\\bhttps?://",
|
||||
// QRegularExpression::CaseInsensitiveOption); QRegularExpression
|
||||
// ftpRegex("\\bftps?://",
|
||||
@@ -343,7 +331,7 @@ void TwitchMessageBuilder::parseRoomID()
|
||||
if (iterator != std::end(this->tags)) {
|
||||
this->roomID_ = iterator.value().toString();
|
||||
|
||||
if (this->twitchChannel->getRoomId().isEmpty()) {
|
||||
if (this->twitchChannel->roomId().isEmpty()) {
|
||||
this->twitchChannel->setRoomId(this->roomID_);
|
||||
}
|
||||
}
|
||||
@@ -447,36 +435,36 @@ void TwitchMessageBuilder::appendUsername()
|
||||
// IrcManager::getInstance().getUser().getUserName();
|
||||
} else if (this->args.isReceivedWhisper) {
|
||||
// Sender username
|
||||
this->emplace<TextElement>(usernameText, MessageElementFlag::Text,
|
||||
this->emplace<TextElement>(usernameText, MessageElementFlag::Username,
|
||||
this->usernameColor_,
|
||||
FontStyle::ChatMediumBold)
|
||||
->setLink({Link::UserInfo, this->userName});
|
||||
->setLink({Link::UserWhisper, this->message().displayName});
|
||||
|
||||
auto currentUser = app->accounts->twitch.getCurrent();
|
||||
|
||||
// Separator
|
||||
this->emplace<TextElement>("->", MessageElementFlag::Text,
|
||||
this->emplace<TextElement>("->", MessageElementFlag::Username,
|
||||
app->themes->messages.textColors.system,
|
||||
FontStyle::ChatMedium);
|
||||
|
||||
QColor selfColor = currentUser->color;
|
||||
QColor selfColor = currentUser->color();
|
||||
if (!selfColor.isValid()) {
|
||||
selfColor = app->themes->messages.textColors.system;
|
||||
}
|
||||
|
||||
// Your own username
|
||||
this->emplace<TextElement>(currentUser->getUserName() + ":",
|
||||
MessageElementFlag::Text, selfColor,
|
||||
MessageElementFlag::Username, selfColor,
|
||||
FontStyle::ChatMediumBold);
|
||||
} else {
|
||||
if (!this->action_) {
|
||||
usernameText += ":";
|
||||
}
|
||||
|
||||
this->emplace<TextElement>(usernameText, MessageElementFlag::Text,
|
||||
this->emplace<TextElement>(usernameText, MessageElementFlag::Username,
|
||||
this->usernameColor_,
|
||||
FontStyle::ChatMediumBold)
|
||||
->setLink({Link::UserInfo, this->userName});
|
||||
->setLink({Link::UserInfo, this->message().displayName});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -492,16 +480,16 @@ void TwitchMessageBuilder::parseHighlights(bool isPastMsg)
|
||||
QString currentUsername = currentUser->getUserName();
|
||||
|
||||
if (this->ircMessage->nick() == currentUsername) {
|
||||
currentUser->color = this->usernameColor_;
|
||||
currentUser->setColor(this->usernameColor_);
|
||||
// Do nothing. Highlights cannot be triggered by yourself
|
||||
return;
|
||||
}
|
||||
|
||||
// update the media player url if necessary
|
||||
QUrl highlightSoundUrl;
|
||||
if (app->settings->customHighlightSound) {
|
||||
if (getSettings()->customHighlightSound) {
|
||||
highlightSoundUrl =
|
||||
QUrl::fromLocalFile(app->settings->pathHighlightSound.getValue());
|
||||
QUrl::fromLocalFile(getSettings()->pathHighlightSound.getValue());
|
||||
} else {
|
||||
highlightSoundUrl = QUrl("qrc:/sounds/ping2.wav");
|
||||
}
|
||||
@@ -519,10 +507,10 @@ void TwitchMessageBuilder::parseHighlights(bool isPastMsg)
|
||||
std::vector<HighlightPhrase> userHighlights =
|
||||
app->highlights->highlightedUsers.getVector();
|
||||
|
||||
if (app->settings->enableHighlightsSelf && currentUsername.size() > 0) {
|
||||
if (getSettings()->enableHighlightsSelf && currentUsername.size() > 0) {
|
||||
HighlightPhrase selfHighlight(
|
||||
currentUsername, app->settings->enableHighlightTaskbar,
|
||||
app->settings->enableHighlightSound, false);
|
||||
currentUsername, getSettings()->enableHighlightTaskbar,
|
||||
getSettings()->enableHighlightSound, false);
|
||||
activeHighlights.emplace_back(std::move(selfHighlight));
|
||||
}
|
||||
|
||||
@@ -535,7 +523,7 @@ void TwitchMessageBuilder::parseHighlights(bool isPastMsg)
|
||||
if (!app->highlights->blacklistContains(this->ircMessage->nick())) {
|
||||
for (const HighlightPhrase &highlight : activeHighlights) {
|
||||
if (highlight.isMatch(this->originalMessage_)) {
|
||||
Log("Highlight because {} matches {}", this->originalMessage_,
|
||||
log("Highlight because {} matches {}", this->originalMessage_,
|
||||
highlight.getPattern());
|
||||
doHighlight = true;
|
||||
|
||||
@@ -557,7 +545,7 @@ void TwitchMessageBuilder::parseHighlights(bool isPastMsg)
|
||||
}
|
||||
for (const HighlightPhrase &userHighlight : userHighlights) {
|
||||
if (userHighlight.isMatch(this->ircMessage->nick())) {
|
||||
Log("Highlight because user {} sent a message",
|
||||
log("Highlight because user {} sent a message",
|
||||
this->ircMessage->nick());
|
||||
doHighlight = true;
|
||||
|
||||
@@ -581,7 +569,7 @@ void TwitchMessageBuilder::parseHighlights(bool isPastMsg)
|
||||
|
||||
if (!isPastMsg) {
|
||||
if (playSound &&
|
||||
(!hasFocus || app->settings->highlightAlwaysPlaySound)) {
|
||||
(!hasFocus || getSettings()->highlightAlwaysPlaySound)) {
|
||||
player->play();
|
||||
}
|
||||
|
||||
@@ -637,18 +625,22 @@ void TwitchMessageBuilder::appendTwitchEmote(
|
||||
|
||||
Outcome TwitchMessageBuilder::tryAppendEmote(const EmoteName &name)
|
||||
{
|
||||
// Special channels, like /whispers and /channels return here
|
||||
// This means they will not render any BTTV or FFZ emotes
|
||||
if (this->twitchChannel == nullptr) {
|
||||
return Failure;
|
||||
}
|
||||
|
||||
auto flags = MessageElementFlags();
|
||||
auto emote = boost::optional<EmotePtr>{};
|
||||
|
||||
if ((emote = getApp()->emotes->bttv.getGlobalEmote(name))) {
|
||||
if ((emote = this->twitchChannel->globalBttv().emote(name))) {
|
||||
flags = MessageElementFlag::BttvEmote;
|
||||
} else if (twitchChannel &&
|
||||
(emote = this->twitchChannel->getBttvEmote(name))) {
|
||||
} else if ((emote = this->twitchChannel->bttvEmote(name))) {
|
||||
flags = MessageElementFlag::BttvEmote;
|
||||
} else if ((emote = getApp()->emotes->ffz.getGlobalEmote(name))) {
|
||||
} else if ((emote = this->twitchChannel->globalFfz().emote(name))) {
|
||||
flags = MessageElementFlag::FfzEmote;
|
||||
} else if (twitchChannel &&
|
||||
(emote = this->twitchChannel->getFfzEmote(name))) {
|
||||
} else if ((emote = this->twitchChannel->ffzEmote(name))) {
|
||||
flags = MessageElementFlag::FfzEmote;
|
||||
}
|
||||
|
||||
@@ -661,39 +653,22 @@ Outcome TwitchMessageBuilder::tryAppendEmote(const EmoteName &name)
|
||||
}
|
||||
|
||||
// fourtf: this is ugly
|
||||
// maybe put the individual badges into a map instead of this
|
||||
// mess
|
||||
void TwitchMessageBuilder::appendTwitchBadges()
|
||||
{
|
||||
auto app = getApp();
|
||||
|
||||
auto iterator = this->tags.find("badges");
|
||||
if (iterator == this->tags.end()) return;
|
||||
|
||||
if (iterator == this->tags.end()) {
|
||||
// No badges in this message
|
||||
return;
|
||||
}
|
||||
|
||||
QStringList badges = iterator.value().toString().split(',');
|
||||
|
||||
for (QString badge : badges) {
|
||||
if (badge.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (QString badge : iterator.value().toString().split(',')) {
|
||||
if (badge.startsWith("bits/")) {
|
||||
// if (!app->resources->dynamicBadgesLoaded) {
|
||||
// // Do nothing
|
||||
// continue;
|
||||
// }
|
||||
|
||||
QString cheerAmount = badge.mid(5);
|
||||
QString tooltip = QString("Twitch cheer ") + cheerAmount;
|
||||
|
||||
// Try to fetch channel-specific bit badge
|
||||
try {
|
||||
if (twitchChannel)
|
||||
if (const auto &badge = this->twitchChannel->getTwitchBadge(
|
||||
if (const auto &badge = this->twitchChannel->twitchBadge(
|
||||
"bits", cheerAmount)) {
|
||||
this->emplace<EmoteElement>(
|
||||
badge.get(), MessageElementFlag::BadgeVanity)
|
||||
@@ -705,53 +680,46 @@ void TwitchMessageBuilder::appendTwitchBadges()
|
||||
}
|
||||
|
||||
// Use default bit badge
|
||||
// try {
|
||||
// const auto &badge =
|
||||
// app->resources->badgeSets.at("bits").versions.at(cheerAmount);
|
||||
// this->emplace<ImageElement>(badge.badgeImage1x,
|
||||
// MessageElementFlag::BadgeVanity)
|
||||
// ->setTooltip(tooltip);
|
||||
//} catch (const std::out_of_range &) {
|
||||
// Log("No default bit badge for version {} found", cheerAmount);
|
||||
// continue;
|
||||
//}
|
||||
if (auto badge = this->twitchChannel->globalTwitchBadges().badge(
|
||||
"bits", cheerAmount)) {
|
||||
this->emplace<EmoteElement>(badge.get(),
|
||||
MessageElementFlag::BadgeVanity)
|
||||
->setTooltip(tooltip);
|
||||
}
|
||||
} else if (badge == "staff/1") {
|
||||
this->emplace<ImageElement>(
|
||||
Image::fromNonOwningPixmap(&app->resources->twitch.staff),
|
||||
Image::fromPixmap(app->resources->twitch.staff),
|
||||
MessageElementFlag::BadgeGlobalAuthority)
|
||||
->setTooltip("Twitch Staff");
|
||||
} else if (badge == "admin/1") {
|
||||
this->emplace<ImageElement>(
|
||||
Image::fromNonOwningPixmap(&app->resources->twitch.admin),
|
||||
Image::fromPixmap(app->resources->twitch.admin),
|
||||
MessageElementFlag::BadgeGlobalAuthority)
|
||||
->setTooltip("Twitch Admin");
|
||||
} else if (badge == "global_mod/1") {
|
||||
this->emplace<ImageElement>(
|
||||
Image::fromNonOwningPixmap(
|
||||
&app->resources->twitch.globalmod),
|
||||
Image::fromPixmap(app->resources->twitch.globalmod),
|
||||
MessageElementFlag::BadgeGlobalAuthority)
|
||||
->setTooltip("Twitch Global Moderator");
|
||||
} else if (badge == "moderator/1") {
|
||||
// TODO: Implement custom FFZ moderator badge
|
||||
this->emplace<ImageElement>(
|
||||
Image::fromNonOwningPixmap(
|
||||
&app->resources->twitch.moderator),
|
||||
Image::fromPixmap(app->resources->twitch.moderator),
|
||||
MessageElementFlag::BadgeChannelAuthority)
|
||||
->setTooltip("Twitch Channel Moderator");
|
||||
} else if (badge == "turbo/1") {
|
||||
this->emplace<ImageElement>(
|
||||
Image::fromNonOwningPixmap(&app->resources->twitch.turbo),
|
||||
Image::fromPixmap(app->resources->twitch.turbo),
|
||||
MessageElementFlag::BadgeGlobalAuthority)
|
||||
->setTooltip("Twitch Turbo Subscriber");
|
||||
} else if (badge == "broadcaster/1") {
|
||||
this->emplace<ImageElement>(
|
||||
Image::fromNonOwningPixmap(
|
||||
&app->resources->twitch.broadcaster),
|
||||
Image::fromPixmap(app->resources->twitch.broadcaster),
|
||||
MessageElementFlag::BadgeChannelAuthority)
|
||||
->setTooltip("Twitch Broadcaster");
|
||||
} else if (badge == "premium/1") {
|
||||
this->emplace<ImageElement>(
|
||||
Image::fromNonOwningPixmap(&app->resources->twitch.prime),
|
||||
Image::fromPixmap(app->resources->twitch.prime),
|
||||
MessageElementFlag::BadgeVanity)
|
||||
->setTooltip("Twitch Prime Subscriber");
|
||||
} else if (badge.startsWith("partner/")) {
|
||||
@@ -759,8 +727,8 @@ void TwitchMessageBuilder::appendTwitchBadges()
|
||||
switch (index) {
|
||||
case 1: {
|
||||
this->emplace<ImageElement>(
|
||||
Image::fromNonOwningPixmap(
|
||||
&app->resources->twitch.verified, 0.25),
|
||||
Image::fromPixmap(app->resources->twitch.verified,
|
||||
0.25),
|
||||
MessageElementFlag::BadgeVanity)
|
||||
->setTooltip("Twitch Verified");
|
||||
} break;
|
||||
@@ -771,80 +739,30 @@ void TwitchMessageBuilder::appendTwitchBadges()
|
||||
} break;
|
||||
}
|
||||
} else if (badge.startsWith("subscriber/")) {
|
||||
// if (channelResources.loaded == false) {
|
||||
// // qDebug() << "Channel resources are not loaded,
|
||||
// can't add the subscriber
|
||||
// // badge";
|
||||
// continue;
|
||||
// }
|
||||
if (auto badgeEmote = this->twitchChannel->twitchBadge(
|
||||
"subscriber", badge.mid(11))) {
|
||||
this->emplace<EmoteElement>(
|
||||
badgeEmote.get(), MessageElementFlag::BadgeSubscription)
|
||||
->setTooltip((*badgeEmote)->tooltip.string);
|
||||
continue;
|
||||
}
|
||||
|
||||
// auto badgeSetIt = channelResources.badgeSets.find("subscriber");
|
||||
// if (badgeSetIt == channelResources.badgeSets.end()) {
|
||||
// // Fall back to default badge
|
||||
// this->emplace<ImageElement>(app->resources->badgeSubscriber,
|
||||
// MessageElementFlag::BadgeSubscription)
|
||||
// ->setTooltip("Twitch Subscriber");
|
||||
// continue;
|
||||
//}
|
||||
|
||||
// const auto &badgeSet = badgeSetIt->second;
|
||||
|
||||
// std::string versionKey = badge.mid(11).toStdString();
|
||||
|
||||
// auto badgeVersionIt = badgeSet.versions.find(versionKey);
|
||||
|
||||
// if (badgeVersionIt == badgeSet.versions.end()) {
|
||||
// // Fall back to default badge
|
||||
// this->emplace<ImageElement>(app->resources->badgeSubscriber,
|
||||
// MessageElementFlag::BadgeSubscription)
|
||||
// ->setTooltip("Twitch Subscriber");
|
||||
// continue;
|
||||
//}
|
||||
|
||||
// auto &badgeVersion = badgeVersionIt->second;
|
||||
|
||||
// this->emplace<ImageElement>(badgeVersion.badgeImage1x,
|
||||
// MessageElementFlag::BadgeSubscription)
|
||||
// ->setTooltip("Twitch " +
|
||||
// QString::fromStdString(badgeVersion.title));
|
||||
// use default subscriber badge if custom one not found
|
||||
this->emplace<ImageElement>(
|
||||
Image::fromPixmap(app->resources->twitch.subscriber, 0.25),
|
||||
MessageElementFlag::BadgeSubscription)
|
||||
->setTooltip("Twitch Subscriber");
|
||||
} else {
|
||||
// if (!app->resources->dynamicBadgesLoaded) {
|
||||
// // Do nothing
|
||||
// continue;
|
||||
//}
|
||||
auto splits = badge.split('/');
|
||||
if (splits.size() != 2) continue;
|
||||
|
||||
// QStringList parts = badge.split('/');
|
||||
|
||||
// if (parts.length() != 2) {
|
||||
// qDebug() << "Bad number of parts: " << parts.length() << " in
|
||||
// " << parts; continue;
|
||||
//}
|
||||
|
||||
// MessageElementFlags badgeType =
|
||||
// MessageElementFlag::BadgeVanity;
|
||||
|
||||
// std::string badgeSetKey = parts[0].toStdString();
|
||||
// std::string versionKey = parts[1].toStdString();
|
||||
|
||||
// try {
|
||||
// auto &badgeSet = app->resources->badgeSets.at(badgeSetKey);
|
||||
|
||||
// try {
|
||||
// auto &badgeVersion = badgeSet.versions.at(versionKey);
|
||||
|
||||
// this->emplace<ImageElement>(badgeVersion.badgeImage1x,
|
||||
// badgeType)
|
||||
// ->setTooltip("Twitch " +
|
||||
// QString::fromStdString(badgeVersion.title));
|
||||
// } catch (const std::exception &e) {
|
||||
// qDebug() << "Exception caught:" << e.what()
|
||||
// << "when trying to fetch badge version " <<
|
||||
// versionKey.c_str();
|
||||
// }
|
||||
//} catch (const std::exception &e) {
|
||||
// qDebug() << "No badge set with key" << badgeSetKey.c_str()
|
||||
// << ". Exception: " << e.what();
|
||||
//}
|
||||
if (auto badgeEmote =
|
||||
this->twitchChannel->twitchBadge(splits[0], splits[1])) {
|
||||
this->emplace<EmoteElement>(badgeEmote.get(),
|
||||
MessageElementFlag::BadgeVanity)
|
||||
->setTooltip((*badgeEmote)->tooltip.string);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/Aliases.hpp"
|
||||
#include "common/Outcome.hpp"
|
||||
#include "messages/MessageBuilder.hpp"
|
||||
#include "messages/MessageParseArgs.hpp"
|
||||
#include "singletons/Emotes.hpp"
|
||||
|
||||
#include <IrcMessage>
|
||||
|
||||
#include <QString>
|
||||
#include <QVariant>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
struct Emote;
|
||||
using EmotePtr = std::shared_ptr<const Emote>;
|
||||
|
||||
class Channel;
|
||||
class TwitchChannel;
|
||||
|
||||
|
||||
@@ -8,235 +8,235 @@ namespace chatterino {
|
||||
|
||||
namespace {
|
||||
|
||||
template <typename Type>
|
||||
inline bool ReadValue(const rapidjson::Value &object, const char *key,
|
||||
Type &out)
|
||||
{
|
||||
if (!object.HasMember(key)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto &value = object[key];
|
||||
|
||||
if (!value.Is<Type>()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
out = value.Get<Type>();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool ReadValue<QString>(const rapidjson::Value &object, const char *key,
|
||||
QString &out)
|
||||
{
|
||||
if (!object.HasMember(key)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto &value = object[key];
|
||||
|
||||
if (!value.IsString()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
out = value.GetString();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool ReadValue<std::vector<QString>>(const rapidjson::Value &object,
|
||||
const char *key,
|
||||
std::vector<QString> &out)
|
||||
{
|
||||
if (!object.HasMember(key)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto &value = object[key];
|
||||
|
||||
if (!value.IsArray()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const rapidjson::Value &innerValue : value.GetArray()) {
|
||||
if (!innerValue.IsString()) {
|
||||
template <typename Type>
|
||||
inline bool ReadValue(const rapidjson::Value &object, const char *key,
|
||||
Type &out)
|
||||
{
|
||||
if (!object.HasMember(key)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
out.emplace_back(innerValue.GetString());
|
||||
}
|
||||
const auto &value = object[key];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Parse a single cheermote set (or "action") from the twitch api
|
||||
inline bool ParseSingleCheermoteSet(JSONCheermoteSet &set,
|
||||
const rapidjson::Value &action)
|
||||
{
|
||||
if (!action.IsObject()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ReadValue(action, "prefix", set.prefix)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ReadValue(action, "scales", set.scales)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ReadValue(action, "backgrounds", set.backgrounds)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ReadValue(action, "states", set.states)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ReadValue(action, "type", set.type)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ReadValue(action, "updated_at", set.updatedAt)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ReadValue(action, "priority", set.priority)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Tiers
|
||||
if (!action.HasMember("tiers")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto &tiersValue = action["tiers"];
|
||||
|
||||
if (!tiersValue.IsArray()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const rapidjson::Value &tierValue : tiersValue.GetArray()) {
|
||||
JSONCheermoteSet::CheermoteTier tier;
|
||||
|
||||
if (!tierValue.IsObject()) {
|
||||
if (!value.Is<Type>()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ReadValue(tierValue, "min_bits", tier.minBits)) {
|
||||
out = value.Get<Type>();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool ReadValue<QString>(const rapidjson::Value &object,
|
||||
const char *key, QString &out)
|
||||
{
|
||||
if (!object.HasMember(key)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ReadValue(tierValue, "id", tier.id)) {
|
||||
const auto &value = object[key];
|
||||
|
||||
if (!value.IsString()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ReadValue(tierValue, "color", tier.color)) {
|
||||
out = value.GetString();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool ReadValue<std::vector<QString>>(const rapidjson::Value &object,
|
||||
const char *key,
|
||||
std::vector<QString> &out)
|
||||
{
|
||||
if (!object.HasMember(key)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Images
|
||||
if (!tierValue.HasMember("images")) {
|
||||
const auto &value = object[key];
|
||||
|
||||
if (!value.IsArray()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto &imagesValue = tierValue["images"];
|
||||
|
||||
if (!imagesValue.IsObject()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read images object
|
||||
for (const auto &imageBackgroundValue : imagesValue.GetObject()) {
|
||||
QString background = imageBackgroundValue.name.GetString();
|
||||
bool backgroundExists = false;
|
||||
for (const auto &bg : set.backgrounds) {
|
||||
if (background == bg) {
|
||||
backgroundExists = true;
|
||||
break;
|
||||
}
|
||||
for (const rapidjson::Value &innerValue : value.GetArray()) {
|
||||
if (!innerValue.IsString()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!backgroundExists) {
|
||||
continue;
|
||||
out.emplace_back(innerValue.GetString());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Parse a single cheermote set (or "action") from the twitch api
|
||||
inline bool ParseSingleCheermoteSet(JSONCheermoteSet &set,
|
||||
const rapidjson::Value &action)
|
||||
{
|
||||
if (!action.IsObject()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ReadValue(action, "prefix", set.prefix)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ReadValue(action, "scales", set.scales)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ReadValue(action, "backgrounds", set.backgrounds)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ReadValue(action, "states", set.states)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ReadValue(action, "type", set.type)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ReadValue(action, "updated_at", set.updatedAt)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ReadValue(action, "priority", set.priority)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Tiers
|
||||
if (!action.HasMember("tiers")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto &tiersValue = action["tiers"];
|
||||
|
||||
if (!tiersValue.IsArray()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const rapidjson::Value &tierValue : tiersValue.GetArray()) {
|
||||
JSONCheermoteSet::CheermoteTier tier;
|
||||
|
||||
if (!tierValue.IsObject()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const rapidjson::Value &imageBackgroundStates =
|
||||
imageBackgroundValue.value;
|
||||
if (!imageBackgroundStates.IsObject()) {
|
||||
continue;
|
||||
if (!ReadValue(tierValue, "min_bits", tier.minBits)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read each key which represents a background
|
||||
for (const auto &imageBackgroundState :
|
||||
imageBackgroundStates.GetObject()) {
|
||||
QString state = imageBackgroundState.name.GetString();
|
||||
bool stateExists = false;
|
||||
for (const auto &_state : set.states) {
|
||||
if (state == _state) {
|
||||
stateExists = true;
|
||||
if (!ReadValue(tierValue, "id", tier.id)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ReadValue(tierValue, "color", tier.color)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Images
|
||||
if (!tierValue.HasMember("images")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto &imagesValue = tierValue["images"];
|
||||
|
||||
if (!imagesValue.IsObject()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read images object
|
||||
for (const auto &imageBackgroundValue : imagesValue.GetObject()) {
|
||||
QString background = imageBackgroundValue.name.GetString();
|
||||
bool backgroundExists = false;
|
||||
for (const auto &bg : set.backgrounds) {
|
||||
if (background == bg) {
|
||||
backgroundExists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!stateExists) {
|
||||
if (!backgroundExists) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const rapidjson::Value &imageScalesValue =
|
||||
imageBackgroundState.value;
|
||||
if (!imageScalesValue.IsObject()) {
|
||||
const rapidjson::Value &imageBackgroundStates =
|
||||
imageBackgroundValue.value;
|
||||
if (!imageBackgroundStates.IsObject()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Read each key which represents a scale
|
||||
for (const auto &imageScaleValue :
|
||||
imageScalesValue.GetObject()) {
|
||||
QString scale = imageScaleValue.name.GetString();
|
||||
bool scaleExists = false;
|
||||
for (const auto &_scale : set.scales) {
|
||||
if (scale == _scale) {
|
||||
scaleExists = true;
|
||||
// Read each key which represents a background
|
||||
for (const auto &imageBackgroundState :
|
||||
imageBackgroundStates.GetObject()) {
|
||||
QString state = imageBackgroundState.name.GetString();
|
||||
bool stateExists = false;
|
||||
for (const auto &_state : set.states) {
|
||||
if (state == _state) {
|
||||
stateExists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!scaleExists) {
|
||||
if (!stateExists) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const rapidjson::Value &imageScaleURLValue =
|
||||
imageScaleValue.value;
|
||||
if (!imageScaleURLValue.IsString()) {
|
||||
const rapidjson::Value &imageScalesValue =
|
||||
imageBackgroundState.value;
|
||||
if (!imageScalesValue.IsObject()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
QString url = imageScaleURLValue.GetString();
|
||||
// Read each key which represents a scale
|
||||
for (const auto &imageScaleValue :
|
||||
imageScalesValue.GetObject()) {
|
||||
QString scale = imageScaleValue.name.GetString();
|
||||
bool scaleExists = false;
|
||||
for (const auto &_scale : set.scales) {
|
||||
if (scale == _scale) {
|
||||
scaleExists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool ok = false;
|
||||
qreal scaleNumber = scale.toFloat(&ok);
|
||||
if (!ok) {
|
||||
continue;
|
||||
if (!scaleExists) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const rapidjson::Value &imageScaleURLValue =
|
||||
imageScaleValue.value;
|
||||
if (!imageScaleURLValue.IsString()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
QString url = imageScaleURLValue.GetString();
|
||||
|
||||
bool ok = false;
|
||||
qreal scaleNumber = scale.toFloat(&ok);
|
||||
if (!ok) {
|
||||
continue;
|
||||
}
|
||||
|
||||
qreal chatterinoScale = 1 / scaleNumber;
|
||||
|
||||
auto image = Image::fromUrl({url}, chatterinoScale);
|
||||
|
||||
// TODO(pajlada): Fill in name and tooltip
|
||||
tier.images[background][state][scale] = image;
|
||||
}
|
||||
|
||||
qreal chatterinoScale = 1 / scaleNumber;
|
||||
|
||||
auto image = Image::fromUrl({url}, chatterinoScale);
|
||||
|
||||
// TODO(pajlada): Fill in name and tooltip
|
||||
tier.images[background][state][scale] = image;
|
||||
}
|
||||
}
|
||||
|
||||
set.tiers.emplace_back(tier);
|
||||
}
|
||||
|
||||
set.tiers.emplace_back(tier);
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
// Look through the results of
|
||||
|
||||
@@ -7,12 +7,12 @@
|
||||
#include "providers/twitch/IrcMessageHandler.hpp"
|
||||
#include "providers/twitch/PubsubClient.hpp"
|
||||
#include "providers/twitch/TwitchAccount.hpp"
|
||||
#include "providers/twitch/TwitchChannel.hpp"
|
||||
#include "providers/twitch/TwitchHelpers.hpp"
|
||||
#include "providers/twitch/TwitchMessageBuilder.hpp"
|
||||
#include "util/PostToThread.hpp"
|
||||
|
||||
#include <IrcCommand>
|
||||
|
||||
#include <cassert>
|
||||
|
||||
// using namespace Communi;
|
||||
@@ -39,6 +39,10 @@ void TwitchServer::initialize(Settings &settings, Paths &paths)
|
||||
{
|
||||
getApp()->accounts->twitch.currentUserChanged.connect(
|
||||
[this]() { postToThread([this] { this->connect(); }); });
|
||||
|
||||
this->twitchBadges.loadTwitchBadges();
|
||||
this->bttv.loadEmotes();
|
||||
this->ffz.loadEmotes();
|
||||
}
|
||||
|
||||
void TwitchServer::initializeConnection(IrcConnection *connection, bool isRead,
|
||||
@@ -79,10 +83,12 @@ void TwitchServer::initializeConnection(IrcConnection *connection, bool isRead,
|
||||
|
||||
std::shared_ptr<Channel> TwitchServer::createChannel(const QString &channelName)
|
||||
{
|
||||
TwitchChannel *channel = new TwitchChannel(channelName);
|
||||
auto channel = std::shared_ptr<TwitchChannel>(new TwitchChannel(
|
||||
channelName, this->twitchBadges, this->bttv, this->ffz));
|
||||
channel->initialize();
|
||||
|
||||
channel->sendMessageSignal.connect(
|
||||
[this, channel](auto &chan, auto &msg, bool &sent) {
|
||||
[this, channel = channel.get()](auto &chan, auto &msg, bool &sent) {
|
||||
this->onMessageSendRequested(channel, msg, sent);
|
||||
});
|
||||
|
||||
@@ -175,7 +181,7 @@ std::shared_ptr<Channel> TwitchServer::getChannelOrEmptyByID(
|
||||
auto twitchChannel = std::dynamic_pointer_cast<TwitchChannel>(channel);
|
||||
if (!twitchChannel) continue;
|
||||
|
||||
if (twitchChannel->getRoomId() == channelId) {
|
||||
if (twitchChannel->roomId() == channelId) {
|
||||
return twitchChannel;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/MutexValue.hpp"
|
||||
#include "common/Atomic.hpp"
|
||||
#include "common/Channel.hpp"
|
||||
#include "common/Singleton.hpp"
|
||||
#include "pajlada/signals/signalholder.hpp"
|
||||
#include "providers/bttv/BttvEmotes.hpp"
|
||||
#include "providers/ffz/FfzEmotes.hpp"
|
||||
#include "providers/irc/AbstractIrcServer.hpp"
|
||||
#include "providers/twitch/TwitchAccount.hpp"
|
||||
#include "providers/twitch/TwitchChannel.hpp"
|
||||
#include "providers/twitch/TwitchBadges.hpp"
|
||||
|
||||
#include <chrono>
|
||||
#include <memory>
|
||||
@@ -14,8 +17,8 @@ namespace chatterino {
|
||||
|
||||
class Settings;
|
||||
class Paths;
|
||||
|
||||
class PubSub;
|
||||
class TwitchChannel;
|
||||
|
||||
class TwitchServer final : public AbstractIrcServer, public Singleton
|
||||
{
|
||||
@@ -29,7 +32,7 @@ public:
|
||||
|
||||
std::shared_ptr<Channel> getChannelOrEmptyByID(const QString &channelID);
|
||||
|
||||
MutexValue<QString> lastUserThatWhisperedMe;
|
||||
Atomic<QString> lastUserThatWhisperedMe;
|
||||
|
||||
const ChannelPtr whispersChannel;
|
||||
const ChannelPtr mentionsChannel;
|
||||
@@ -66,6 +69,9 @@ private:
|
||||
std::chrono::steady_clock::time_point lastErrorTimeAmount_;
|
||||
|
||||
bool singleConnection_ = false;
|
||||
TwitchBadges twitchBadges;
|
||||
BttvEmotes bttv;
|
||||
FfzEmotes ffz;
|
||||
|
||||
pajlada::Signals::SignalHolder signalHolder_;
|
||||
};
|
||||
|
||||
@@ -34,43 +34,43 @@ struct TwitchUser {
|
||||
namespace pajlada {
|
||||
namespace Settings {
|
||||
|
||||
template <>
|
||||
struct Deserialize<chatterino::TwitchUser> {
|
||||
static chatterino::TwitchUser get(const rapidjson::Value &value,
|
||||
bool *error = nullptr)
|
||||
{
|
||||
using namespace chatterino;
|
||||
template <>
|
||||
struct Deserialize<chatterino::TwitchUser> {
|
||||
static chatterino::TwitchUser get(const rapidjson::Value &value,
|
||||
bool *error = nullptr)
|
||||
{
|
||||
using namespace chatterino;
|
||||
|
||||
TwitchUser user;
|
||||
TwitchUser user;
|
||||
|
||||
if (!value.IsObject()) {
|
||||
PAJLADA_REPORT_ERROR(error)
|
||||
PAJLADA_THROW_EXCEPTION(
|
||||
"Deserialized rapidjson::Value is wrong type");
|
||||
return user;
|
||||
}
|
||||
|
||||
if (!rj::getSafe(value, "_id", user.id)) {
|
||||
PAJLADA_REPORT_ERROR(error)
|
||||
PAJLADA_THROW_EXCEPTION("Missing ID key");
|
||||
return user;
|
||||
}
|
||||
|
||||
if (!rj::getSafe(value, "name", user.name)) {
|
||||
PAJLADA_REPORT_ERROR(error)
|
||||
PAJLADA_THROW_EXCEPTION("Missing name key");
|
||||
return user;
|
||||
}
|
||||
|
||||
if (!rj::getSafe(value, "display_name", user.displayName)) {
|
||||
PAJLADA_REPORT_ERROR(error)
|
||||
PAJLADA_THROW_EXCEPTION("Missing display name key");
|
||||
return user;
|
||||
}
|
||||
|
||||
if (!value.IsObject()) {
|
||||
PAJLADA_REPORT_ERROR(error)
|
||||
PAJLADA_THROW_EXCEPTION(
|
||||
"Deserialized rapidjson::Value is wrong type");
|
||||
return user;
|
||||
}
|
||||
|
||||
if (!rj::getSafe(value, "_id", user.id)) {
|
||||
PAJLADA_REPORT_ERROR(error)
|
||||
PAJLADA_THROW_EXCEPTION("Missing ID key");
|
||||
return user;
|
||||
}
|
||||
|
||||
if (!rj::getSafe(value, "name", user.name)) {
|
||||
PAJLADA_REPORT_ERROR(error)
|
||||
PAJLADA_THROW_EXCEPTION("Missing name key");
|
||||
return user;
|
||||
}
|
||||
|
||||
if (!rj::getSafe(value, "display_name", user.displayName)) {
|
||||
PAJLADA_REPORT_ERROR(error)
|
||||
PAJLADA_THROW_EXCEPTION("Missing display name key");
|
||||
return user;
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace Settings
|
||||
} // namespace pajlada
|
||||
|
||||
Reference in New Issue
Block a user