removed namespaces

This commit is contained in:
fourtf
2018-06-26 17:06:17 +02:00
parent 2df0566492
commit 54eb07e116
132 changed files with 805 additions and 823 deletions
+12 -12
View File
@@ -21,7 +21,7 @@ void BTTVEmotes::loadGlobalEmotes()
{
QString url("https://api.betterttv.net/2/emotes");
util::NetworkRequest req(url);
NetworkRequest req(url);
req.setCaller(QThread::currentThread());
req.setTimeout(30000);
req.setUseQuickLoadCache(true);
@@ -35,12 +35,12 @@ void BTTVEmotes::loadGlobalEmotes()
QString id = emote.toObject().value("id").toString();
QString code = emote.toObject().value("code").toString();
util::EmoteData emoteData;
emoteData.image1x = new messages::Image(getEmoteLink(urlTemplate, id, "1x"), 1, code,
EmoteData emoteData;
emoteData.image1x = new chatterino::Image(getEmoteLink(urlTemplate, id, "1x"), 1, code,
code + "<br />Global BTTV Emote");
emoteData.image2x = new messages::Image(getEmoteLink(urlTemplate, id, "2x"), 0.5, code,
emoteData.image2x = new chatterino::Image(getEmoteLink(urlTemplate, id, "2x"), 0.5, code,
code + "<br />Global BTTV Emote");
emoteData.image3x = new messages::Image(getEmoteLink(urlTemplate, id, "3x"), 0.25, code,
emoteData.image3x = new chatterino::Image(getEmoteLink(urlTemplate, id, "3x"), 0.25, code,
code + "<br />Global BTTV Emote");
emoteData.pageLink = "https://manage.betterttv.net/emotes/" + id;
@@ -52,15 +52,15 @@ void BTTVEmotes::loadGlobalEmotes()
});
}
void BTTVEmotes::loadChannelEmotes(const QString &channelName, std::weak_ptr<util::EmoteMap> _map)
void BTTVEmotes::loadChannelEmotes(const QString &channelName, std::weak_ptr<EmoteMap> _map)
{
printf("[BTTVEmotes] Reload BTTV Channel Emotes for channel %s\n", qPrintable(channelName));
QString url("https://api.betterttv.net/2/channels/" + channelName);
debug::Log("Request bttv channel emotes for {}", channelName);
Log("Request bttv channel emotes for {}", channelName);
util::NetworkRequest req(url);
NetworkRequest req(url);
req.setCaller(QThread::currentThread());
req.setTimeout(3000);
req.setUseQuickLoadCache(true);
@@ -86,21 +86,21 @@ void BTTVEmotes::loadChannelEmotes(const QString &channelName, std::weak_ptr<uti
// emoteObject.value("imageType").toString();
auto emote = this->channelEmoteCache.getOrAdd(id, [&] {
util::EmoteData emoteData;
EmoteData emoteData;
QString link = linkTemplate;
link.detach();
emoteData.image1x =
new messages::Image(link.replace("{{id}}", id).replace("{{image}}", "1x"), 1,
new chatterino::Image(link.replace("{{id}}", id).replace("{{image}}", "1x"), 1,
code, code + "<br />Channel BTTV Emote");
link = linkTemplate;
link.detach();
emoteData.image2x =
new messages::Image(link.replace("{{id}}", id).replace("{{image}}", "2x"), 0.5,
new chatterino::Image(link.replace("{{id}}", id).replace("{{image}}", "2x"), 0.5,
code, code + "<br />Channel BTTV Emote");
link = linkTemplate;
link.detach();
emoteData.image3x =
new messages::Image(link.replace("{{id}}", id).replace("{{image}}", "3x"), 0.25,
new chatterino::Image(link.replace("{{id}}", id).replace("{{image}}", "3x"), 0.25,
code, code + "<br />Channel BTTV Emote");
emoteData.pageLink = "https://manage.betterttv.net/emotes/" + id;
+4 -4
View File
@@ -11,18 +11,18 @@ namespace chatterino {
class BTTVEmotes
{
public:
util::EmoteMap globalEmotes;
EmoteMap globalEmotes;
SignalVector<QString> globalEmoteCodes;
util::EmoteMap channelEmotes;
EmoteMap channelEmotes;
std::map<QString, SignalVector<QString>> channelEmoteCodes;
void loadGlobalEmotes();
void loadChannelEmotes(const QString &channelName,
std::weak_ptr<util::EmoteMap> channelEmoteMap);
std::weak_ptr<EmoteMap> channelEmoteMap);
private:
util::EmoteMap channelEmoteCache;
EmoteMap channelEmoteCache;
};
} // namespace chatterino
+8 -8
View File
@@ -111,7 +111,7 @@ void Emojis::loadEmojis()
rapidjson::ParseResult result = root.Parse(data.toUtf8(), data.length());
if (result.Code() != rapidjson::kParseErrorNone) {
debug::Log("JSON parse error: {} ({})", rapidjson::GetParseError_En(result.Code()),
Log("JSON parse error: {} ({})", rapidjson::GetParseError_En(result.Code()),
result.Offset());
return;
}
@@ -138,7 +138,7 @@ void Emojis::loadEmojis()
auto toneNameIt = toneNames.find(tone);
if (toneNameIt == toneNames.end()) {
debug::Log("Tone with key {} does not exist in tone names map", tone);
Log("Tone with key {} does not exist in tone names map", tone);
continue;
}
@@ -206,7 +206,7 @@ void Emojis::loadEmojiSet()
auto app = getApp();
app->settings->emojiSet.connect([=](const auto &emojiSet, auto) {
debug::Log("Using emoji set {}", emojiSet);
Log("Using emoji set {}", emojiSet);
this->emojis.each([=](const auto &name, std::shared_ptr<EmojiData> &emoji) {
QString emojiSetToUse = emojiSet;
// clang-format off
@@ -260,13 +260,13 @@ void Emojis::loadEmojiSet()
urlPrefix = it->second;
}
QString url = urlPrefix + code + ".png";
emoji->emoteData.image1x = new messages::Image(
emoji->emoteData.image1x = new chatterino::Image(
url, 0.35, emoji->value, ":" + emoji->shortCodes[0] + ":<br/>Emoji");
});
});
}
void Emojis::parse(std::vector<std::tuple<util::EmoteData, QString>> &parsedWords,
void Emojis::parse(std::vector<std::tuple<EmoteData, QString>> &parsedWords,
const QString &text)
{
int lastParsedEmojiEndIndex = 0;
@@ -328,13 +328,13 @@ void Emojis::parse(std::vector<std::tuple<util::EmoteData, QString>> &parsedWord
if (charactersFromLastParsedEmoji > 0) {
// Add characters inbetween emojis
parsedWords.emplace_back(util::EmoteData(), text.mid(lastParsedEmojiEndIndex,
parsedWords.emplace_back(EmoteData(), text.mid(lastParsedEmojiEndIndex,
charactersFromLastParsedEmoji));
}
// Push the emoji as a word to parsedWords
parsedWords.push_back(
std::tuple<util::EmoteData, QString>(matchedEmoji->emoteData, QString()));
std::tuple<EmoteData, QString>(matchedEmoji->emoteData, QString()));
lastParsedEmojiEndIndex = currentParsedEmojiEndIndex;
@@ -343,7 +343,7 @@ void Emojis::parse(std::vector<std::tuple<util::EmoteData, QString>> &parsedWord
if (lastParsedEmojiEndIndex < text.length()) {
// Add remaining characters
parsedWords.emplace_back(util::EmoteData(), text.mid(lastParsedEmojiEndIndex));
parsedWords.emplace_back(EmoteData(), text.mid(lastParsedEmojiEndIndex));
}
}
+3 -3
View File
@@ -26,10 +26,10 @@ struct EmojiData {
std::vector<EmojiData> variations;
util::EmoteData emoteData;
EmoteData emoteData;
};
using EmojiMap = util::ConcurrentMap<QString, std::shared_ptr<EmojiData>>;
using EmojiMap = ConcurrentMap<QString, std::shared_ptr<EmojiData>>;
class Emojis
{
@@ -51,7 +51,7 @@ private:
public:
QString replaceShortCodes(const QString &text);
void parse(std::vector<std::tuple<util::EmoteData, QString>> &parsedWords, const QString &text);
void parse(std::vector<std::tuple<EmoteData, QString>> &parsedWords, const QString &text);
private:
/// Emojis
+9 -9
View File
@@ -21,7 +21,7 @@ QString getEmoteLink(const QJsonObject &urls, const QString &emoteScale)
}
void fillInEmoteData(const QJsonObject &urls, const QString &code, const QString &tooltip,
util::EmoteData &emoteData)
EmoteData &emoteData)
{
QString url1x = getEmoteLink(urls, "1");
QString url2x = getEmoteLink(urls, "2");
@@ -29,14 +29,14 @@ void fillInEmoteData(const QJsonObject &urls, const QString &code, const QString
assert(!url1x.isEmpty());
emoteData.image1x = new messages::Image(url1x, 1, code, tooltip);
emoteData.image1x = new chatterino::Image(url1x, 1, code, tooltip);
if (!url2x.isEmpty()) {
emoteData.image2x = new messages::Image(url2x, 0.5, code, tooltip);
emoteData.image2x = new chatterino::Image(url2x, 0.5, code, tooltip);
}
if (!url3x.isEmpty()) {
emoteData.image3x = new messages::Image(url3x, 0.25, code, tooltip);
emoteData.image3x = new chatterino::Image(url3x, 0.25, code, tooltip);
}
}
@@ -46,7 +46,7 @@ void FFZEmotes::loadGlobalEmotes()
{
QString url("https://api.frankerfacez.com/v1/set/global");
util::NetworkRequest req(url);
NetworkRequest req(url);
req.setCaller(QThread::currentThread());
req.setTimeout(30000);
req.setUseQuickLoadCache(true);
@@ -64,7 +64,7 @@ void FFZEmotes::loadGlobalEmotes()
int id = object.value("id").toInt();
QJsonObject urls = object.value("urls").toObject();
util::EmoteData emoteData;
EmoteData emoteData;
fillInEmoteData(urls, code, code + "<br/>Global FFZ Emote", emoteData);
emoteData.pageLink =
QString("https://www.frankerfacez.com/emoticon/%1-%2").arg(id).arg(code);
@@ -78,13 +78,13 @@ void FFZEmotes::loadGlobalEmotes()
});
}
void FFZEmotes::loadChannelEmotes(const QString &channelName, std::weak_ptr<util::EmoteMap> _map)
void FFZEmotes::loadChannelEmotes(const QString &channelName, std::weak_ptr<EmoteMap> _map)
{
printf("[FFZEmotes] Reload FFZ Channel Emotes for channel %s\n", qPrintable(channelName));
QString url("https://api.frankerfacez.com/v1/room/" + channelName);
util::NetworkRequest req(url);
NetworkRequest req(url);
req.setCaller(QThread::currentThread());
req.setTimeout(3000);
req.setUseQuickLoadCache(true);
@@ -113,7 +113,7 @@ void FFZEmotes::loadChannelEmotes(const QString &channelName, std::weak_ptr<util
QJsonObject urls = emoteObject.value("urls").toObject();
auto emote = this->channelEmoteCache.getOrAdd(id, [id, &code, &urls] {
util::EmoteData emoteData;
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);
+4 -4
View File
@@ -11,18 +11,18 @@ namespace chatterino {
class FFZEmotes
{
public:
util::EmoteMap globalEmotes;
EmoteMap globalEmotes;
SignalVector<QString> globalEmoteCodes;
util::EmoteMap channelEmotes;
EmoteMap channelEmotes;
std::map<QString, SignalVector<QString>> channelEmoteCodes;
void loadGlobalEmotes();
void loadChannelEmotes(const QString &channelName,
std::weak_ptr<util::EmoteMap> channelEmoteMap);
std::weak_ptr<EmoteMap> channelEmoteMap);
private:
util::ConcurrentMap<int, util::EmoteData> channelEmoteCache;
ConcurrentMap<int, EmoteData> channelEmoteCache;
};
} // namespace chatterino
+1 -1
View File
@@ -126,7 +126,7 @@ std::shared_ptr<Channel> AbstractIrcServer::getOrAddChannel(const QString &dirty
chan->destroyed.connect([this, clojuresInCppAreShit] {
// fourtf: issues when the server itself is destroyed
debug::Log("[AbstractIrcServer::addChannel] {} was destroyed", clojuresInCppAreShit);
Log("[AbstractIrcServer::addChannel] {} was destroyed", clojuresInCppAreShit);
this->channels.remove(clojuresInCppAreShit);
if (this->readConnection_) {
+18 -18
View File
@@ -46,7 +46,7 @@ void IrcMessageHandler::addMessage(Communi::IrcMessage *_message, const QString
return;
}
messages::MessageParseArgs args;
chatterino::MessageParseArgs args;
if (isSub) {
args.trimSubscriberUsername = true;
}
@@ -58,13 +58,13 @@ void IrcMessageHandler::addMessage(Communi::IrcMessage *_message, const QString
TwitchMessageBuilder builder(chan.get(), _message, args, content, isAction);
if (isSub || !builder.isIgnored()) {
messages::MessagePtr msg = builder.build();
chatterino::MessagePtr msg = builder.build();
if (isSub) {
msg->flags |= messages::Message::Subscription;
msg->flags &= ~messages::Message::Highlighted;
msg->flags |= chatterino::Message::Subscription;
msg->flags &= ~chatterino::Message::Highlighted;
} else {
if (msg->flags & messages::Message::Highlighted) {
if (msg->flags & chatterino::Message::Highlighted) {
server.mentionsChannel->addMessage(msg);
getApp()->highlights->addHighlight(msg);
}
@@ -85,7 +85,7 @@ void IrcMessageHandler::handleRoomStateMessage(Communi::IrcMessage *message)
return;
}
auto chan = app->twitch.server->getChannelOrEmpty(chanName);
TwitchChannel *twitchChannel = dynamic_cast<twitch::TwitchChannel *>(chan.get());
TwitchChannel *twitchChannel = dynamic_cast<TwitchChannel *>(chan.get());
if (twitchChannel) {
// room-id
@@ -140,7 +140,7 @@ void IrcMessageHandler::handleClearChatMessage(Communi::IrcMessage *message)
auto chan = app->twitch.server->getChannelOrEmpty(chanName);
if (chan->isEmpty()) {
debug::Log("[IrcMessageHandler:handleClearChatMessage] Twitch channel {} not found",
Log("[IrcMessageHandler:handleClearChatMessage] Twitch channel {} not found",
chanName);
return;
}
@@ -190,7 +190,7 @@ void IrcMessageHandler::handleUserStateMessage(Communi::IrcMessage *message)
return;
}
twitch::TwitchChannel *tc = dynamic_cast<twitch::TwitchChannel *>(c.get());
TwitchChannel *tc = dynamic_cast<TwitchChannel *>(c.get());
if (tc != nullptr) {
tc->setMod(_mod == "1");
}
@@ -200,20 +200,20 @@ void IrcMessageHandler::handleUserStateMessage(Communi::IrcMessage *message)
void IrcMessageHandler::handleWhisperMessage(Communi::IrcMessage *message)
{
auto app = getApp();
debug::Log("Received whisper!");
messages::MessageParseArgs args;
Log("Received whisper!");
chatterino::MessageParseArgs args;
args.isReceivedWhisper = true;
auto c = app->twitch.server->whispersChannel.get();
twitch::TwitchMessageBuilder builder(c, message, args, message->parameter(1), false);
TwitchMessageBuilder builder(c, message, args, message->parameter(1), false);
if (!builder.isIgnored()) {
messages::MessagePtr _message = builder.build();
_message->flags |= messages::Message::DoNotTriggerNotification;
chatterino::MessagePtr _message = builder.build();
_message->flags |= chatterino::Message::DoNotTriggerNotification;
if (_message->flags & messages::Message::Highlighted) {
if (_message->flags & chatterino::Message::Highlighted) {
app->twitch.server->mentionsChannel->addMessage(_message);
}
@@ -254,9 +254,9 @@ void IrcMessageHandler::handleUserNoticeMessage(Communi::IrcMessage *message, Tw
if (it != tags.end()) {
auto newMessage =
messages::Message::createSystemMessage(util::parseTagString(it.value().toString()));
chatterino::Message::createSystemMessage(parseTagString(it.value().toString()));
newMessage->flags |= messages::Message::Subscription;
newMessage->flags |= chatterino::Message::Subscription;
QString channelName;
@@ -311,7 +311,7 @@ void IrcMessageHandler::handleNoticeMessage(Communi::IrcNoticeMessage *message)
auto channel = app->twitch.server->getChannelOrEmpty(channelName);
if (channel->isEmpty()) {
debug::Log("[IrcManager:handleNoticeMessage] Channel {} not found in channel manager ",
Log("[IrcManager:handleNoticeMessage] Channel {} not found in channel manager ",
channelName);
return;
}
@@ -338,7 +338,7 @@ void IrcMessageHandler::handleWriteConnectionNoticeMessage(Communi::IrcNoticeMes
return;
}
debug::Log("Showing notice message from write connection with message id '{}'", msgID);
Log("Showing notice message from write connection with message id '{}'", msgID);
}
this->handleNoticeMessage(message);
+43 -43
View File
@@ -107,7 +107,7 @@ void PubSubClient::handlePong()
{
assert(this->awaitingPong);
debug::Log("Got pong!");
Log("Got pong!");
this->awaitingPong = false;
}
@@ -141,7 +141,7 @@ void PubSubClient::ping()
}
if (self->awaitingPong) {
debug::Log("No pong respnose, disconnect!");
Log("No pong respnose, disconnect!");
// TODO(pajlada): Label this connection as "disconnect me"
}
});
@@ -161,7 +161,7 @@ bool PubSubClient::send(const char *payload)
this->websocketClient.send(this->handle, payload, websocketpp::frame::opcode::text, ec);
if (ec) {
debug::Log("Error sending message {}: {}", payload, ec.message());
Log("Error sending message {}: {}", payload, ec.message());
// TODO(pajlada): Check which error code happened and maybe gracefully handle it
return false;
@@ -198,26 +198,26 @@ PubSub::PubSub()
action.state = ModeChangedAction::State::On;
if (!data.HasMember("args")) {
debug::Log("Missing required args member");
Log("Missing required args member");
return;
}
const auto &args = data["args"];
if (!args.IsArray()) {
debug::Log("args member must be an array");
Log("args member must be an array");
return;
}
if (args.Size() == 0) {
debug::Log("Missing duration argument in slowmode on");
Log("Missing duration argument in slowmode on");
return;
}
const auto &durationArg = args[0];
if (!durationArg.IsString()) {
debug::Log("Duration arg must be a string");
Log("Duration arg must be a string");
return;
}
@@ -299,7 +299,7 @@ PubSub::PubSub()
return;
}
} catch (const std::runtime_error &ex) {
debug::Log("Error parsing moderation action: {}", ex.what());
Log("Error parsing moderation action: {}", ex.what());
}
action.modded = false;
@@ -323,7 +323,7 @@ PubSub::PubSub()
return;
}
} catch (const std::runtime_error &ex) {
debug::Log("Error parsing moderation action: {}", ex.what());
Log("Error parsing moderation action: {}", ex.what());
}
action.modded = true;
@@ -363,7 +363,7 @@ PubSub::PubSub()
this->sig.moderation.userBanned.invoke(action);
} catch (const std::runtime_error &ex) {
debug::Log("Error parsing moderation action: {}", ex.what());
Log("Error parsing moderation action: {}", ex.what());
}
};
@@ -392,7 +392,7 @@ PubSub::PubSub()
this->sig.moderation.userBanned.invoke(action);
} catch (const std::runtime_error &ex) {
debug::Log("Error parsing moderation action: {}", ex.what());
Log("Error parsing moderation action: {}", ex.what());
}
};
@@ -417,7 +417,7 @@ PubSub::PubSub()
this->sig.moderation.userUnbanned.invoke(action);
} catch (const std::runtime_error &ex) {
debug::Log("Error parsing moderation action: {}", ex.what());
Log("Error parsing moderation action: {}", ex.what());
}
};
@@ -442,7 +442,7 @@ PubSub::PubSub()
this->sig.moderation.userUnbanned.invoke(action);
} catch (const std::runtime_error &ex) {
debug::Log("Error parsing moderation action: {}", ex.what());
Log("Error parsing moderation action: {}", ex.what());
}
};
@@ -468,7 +468,7 @@ void PubSub::addClient()
auto con = this->websocketClient.get_connection(TWITCH_PUBSUB_URL, ec);
if (ec) {
debug::Log("Unable to establish connection: {}", ec.message());
Log("Unable to establish connection: {}", ec.message());
return;
}
@@ -480,13 +480,13 @@ void PubSub::start()
this->mainThread.reset(new std::thread(std::bind(&PubSub::runThread, this)));
}
void PubSub::listenToWhispers(std::shared_ptr<providers::twitch::TwitchAccount> account)
void PubSub::listenToWhispers(std::shared_ptr<TwitchAccount> account)
{
assert(account != nullptr);
std::string userID = account->getUserId().toStdString();
debug::Log("Connection open!");
Log("Connection open!");
websocketpp::lib::error_code ec;
std::vector<std::string> topics({"whispers." + userID});
@@ -494,7 +494,7 @@ void PubSub::listenToWhispers(std::shared_ptr<providers::twitch::TwitchAccount>
this->listen(std::move(createListenMessage(topics, account)));
if (ec) {
debug::Log("Unable to send message to websocket server: {}", ec.message());
Log("Unable to send message to websocket server: {}", ec.message());
return;
}
}
@@ -508,7 +508,7 @@ void PubSub::unlistenAllModerationActions()
}
void PubSub::listenToChannelModerationActions(
const QString &channelID, std::shared_ptr<providers::twitch::TwitchAccount> account)
const QString &channelID, std::shared_ptr<TwitchAccount> account)
{
assert(!channelID.isEmpty());
assert(account != nullptr);
@@ -518,17 +518,17 @@ void PubSub::listenToChannelModerationActions(
std::string topic(fS("chat_moderator_actions.{}.{}", userID, channelID));
if (this->isListeningToTopic(topic)) {
debug::Log("We are already listening to topic {}", topic);
Log("We are already listening to topic {}", topic);
return;
}
debug::Log("Listen to topic {}", topic);
Log("Listen to topic {}", topic);
this->listenToTopic(topic, account);
}
void PubSub::listenToTopic(const std::string &topic,
std::shared_ptr<providers::twitch::TwitchAccount> account)
std::shared_ptr<TwitchAccount> account)
{
auto message = createListenMessage({topic}, account);
@@ -538,17 +538,17 @@ void PubSub::listenToTopic(const std::string &topic,
void PubSub::listen(rapidjson::Document &&msg)
{
if (this->tryListen(msg)) {
debug::Log("Successfully listened!");
Log("Successfully listened!");
return;
}
debug::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)
{
debug::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)) {
@@ -580,20 +580,20 @@ void PubSub::onMessage(websocketpp::connection_hdl hdl, WebsocketMessagePtr webs
rapidjson::ParseResult res = msg.Parse(payload.c_str());
if (!res) {
debug::Log("Error parsing message '{}' from PubSub: {}", payload,
Log("Error parsing message '{}' from PubSub: {}", payload,
rapidjson::GetParseError_En(res.Code()));
return;
}
if (!msg.IsObject()) {
debug::Log("Error parsing message '{}' from PubSub. Root object is not an object", payload);
Log("Error parsing message '{}' from PubSub. Root object is not an object", payload);
return;
}
std::string type;
if (!rj::getSafe(msg, "type", type)) {
debug::Log("Missing required string member `type` in message root");
Log("Missing required string member `type` in message root");
return;
}
@@ -601,14 +601,14 @@ void PubSub::onMessage(websocketpp::connection_hdl hdl, WebsocketMessagePtr webs
this->handleListenResponse(msg);
} else if (type == "MESSAGE") {
if (!msg.HasMember("data")) {
debug::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()) {
debug::Log("Member `data` must be an object");
Log("Member `data` must be an object");
return;
}
@@ -624,7 +624,7 @@ void PubSub::onMessage(websocketpp::connection_hdl hdl, WebsocketMessagePtr webs
client.second->handlePong();
} else {
debug::Log("Unknown message type: {}", type);
Log("Unknown message type: {}", type);
}
}
@@ -666,7 +666,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) {
debug::Log("Exception caught in OnTLSInit: {}", e.what());
Log("Exception caught in OnTLSInit: {}", e.what());
}
return ctx;
@@ -681,12 +681,12 @@ void PubSub::handleListenResponse(const rapidjson::Document &msg)
rj::getSafe(msg, "nonce", nonce);
if (error.empty()) {
debug::Log("Successfully listened to nonce {}", nonce);
Log("Successfully listened to nonce {}", nonce);
// Nothing went wrong
return;
}
debug::Log("PubSub error: {} on nonce {}", error, nonce);
Log("PubSub error: {} on nonce {}", error, nonce);
return;
}
}
@@ -696,14 +696,14 @@ void PubSub::handleMessageResponse(const rapidjson::Value &outerData)
QString topic;
if (!rj::getSafe(outerData, "topic", topic)) {
debug::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)) {
debug::Log("Expected string message in outerData");
Log("Expected string message in outerData");
return;
}
@@ -712,7 +712,7 @@ void PubSub::handleMessageResponse(const rapidjson::Value &outerData)
rapidjson::ParseResult res = msg.Parse(payload.c_str());
if (!res) {
debug::Log("Error parsing message '{}' from PubSub: {}", payload,
Log("Error parsing message '{}' from PubSub: {}", payload,
rapidjson::GetParseError_En(res.Code()));
return;
}
@@ -721,7 +721,7 @@ void PubSub::handleMessageResponse(const rapidjson::Value &outerData)
std::string whisperType;
if (!rj::getSafe(msg, "type", whisperType)) {
debug::Log("Bad whisper data");
Log("Bad whisper data");
return;
}
@@ -732,7 +732,7 @@ void PubSub::handleMessageResponse(const rapidjson::Value &outerData)
} else if (whisperType == "thread") {
// Handle thread?
} else {
debug::Log("Invalid whisper type: {}", whisperType);
Log("Invalid whisper type: {}", whisperType);
assert(false);
return;
}
@@ -744,30 +744,30 @@ void PubSub::handleMessageResponse(const rapidjson::Value &outerData)
std::string moderationAction;
if (!rj::getSafe(data, "moderation_action", moderationAction)) {
debug::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()) {
debug::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 {
debug::Log("Unknown topic: {}", topic);
Log("Unknown topic: {}", topic);
return;
}
}
void PubSub::runThread()
{
debug::Log("Start pubsub manager thread");
Log("Start pubsub manager thread");
this->websocketClient.run();
debug::Log("Done with pubsub manager thread");
Log("Done with pubsub manager thread");
}
} // namespace chatterino
+3 -3
View File
@@ -117,18 +117,18 @@ public:
} whisper;
} sig;
void listenToWhispers(std::shared_ptr<providers::twitch::TwitchAccount> account);
void listenToWhispers(std::shared_ptr<TwitchAccount> account);
void unlistenAllModerationActions();
void listenToChannelModerationActions(
const QString &channelID, std::shared_ptr<providers::twitch::TwitchAccount> account);
const QString &channelID, std::shared_ptr<TwitchAccount> account);
std::vector<std::unique_ptr<rapidjson::Document>> requests;
private:
void listenToTopic(const std::string &topic,
std::shared_ptr<providers::twitch::TwitchAccount> account);
std::shared_ptr<TwitchAccount> account);
void listen(rapidjson::Document &&msg);
bool tryListen(rapidjson::Document &msg);
+1 -1
View File
@@ -32,7 +32,7 @@ bool getTargetUser(const rapidjson::Value &data, ActionUser &user)
}
rapidjson::Document createListenMessage(const std::vector<std::string> &topicsVec,
std::shared_ptr<providers::twitch::TwitchAccount> account)
std::shared_ptr<TwitchAccount> account)
{
rapidjson::Document msg(rapidjson::kObjectType);
auto &a = msg.GetAllocator();
+3 -3
View File
@@ -20,7 +20,7 @@ bool getCreatedByUser(const rapidjson::Value &data, ActionUser &user);
bool getTargetUser(const rapidjson::Value &data, ActionUser &user);
rapidjson::Document createListenMessage(const std::vector<std::string> &topicsVec,
std::shared_ptr<providers::twitch::TwitchAccount> account);
std::shared_ptr<TwitchAccount> account);
rapidjson::Document createUnlistenMessage(const std::vector<std::string> &topicsVec);
// Create timer using given ioService
@@ -32,7 +32,7 @@ void runAfter(boost::asio::io_service &ioService, Duration duration, Callback cb
timer->async_wait([timer, cb](const boost::system::error_code &ec) {
if (ec) {
debug::Log("Error in runAfter: {}", ec.message());
Log("Error in runAfter: {}", ec.message());
return;
}
@@ -48,7 +48,7 @@ void runAfter(std::shared_ptr<boost::asio::steady_timer> timer, Duration duratio
timer->async_wait([timer, cb](const boost::system::error_code &ec) {
if (ec) {
debug::Log("Error in runAfter: {}", ec.message());
Log("Error in runAfter: {}", ec.message());
return;
}
+11 -11
View File
@@ -10,7 +10,7 @@ namespace chatterino {
TwitchAccount::TwitchAccount(const QString &_username, const QString &_oauthToken,
const QString &_oauthClient, const QString &_userID)
: controllers::accounts::Account(ProviderId::Twitch)
: Account(ProviderId::Twitch)
, oauthClient(_oauthClient)
, oauthToken(_oauthToken)
, userName(_username)
@@ -75,8 +75,8 @@ void TwitchAccount::loadIgnores()
{
QString url("https://api.twitch.tv/kraken/users/" + this->getUserId() + "/blocks");
util::NetworkRequest req(url);
req.setRequestType(util::NetworkRequest::GetRequest);
NetworkRequest req(url);
req.setRequestType(NetworkRequest::GetRequest);
req.setCaller(QThread::currentThread());
req.makeAuthorizedV5(this->getOAuthClient(), this->getOAuthToken());
req.onSuccess([=](const rapidjson::Document &document) {
@@ -119,7 +119,7 @@ void TwitchAccount::loadIgnores()
void TwitchAccount::ignore(const QString &targetName,
std::function<void(IgnoreResult, const QString &)> onFinished)
{
util::twitch::getUserID(targetName, QThread::currentThread(), [=](QString targetUserID) {
getUserID(targetName, QThread::currentThread(), [=](QString targetUserID) {
this->ignoreByID(targetUserID, targetName, onFinished); //
});
}
@@ -130,8 +130,8 @@ void TwitchAccount::ignoreByID(const QString &targetUserID, const QString &targe
QString url("https://api.twitch.tv/kraken/users/" + this->getUserId() + "/blocks/" +
targetUserID);
util::NetworkRequest req(url);
req.setRequestType(util::NetworkRequest::PutRequest);
NetworkRequest req(url);
req.setRequestType(NetworkRequest::PutRequest);
req.setCaller(QThread::currentThread());
req.makeAuthorizedV5(this->getOAuthClient(), this->getOAuthToken());
@@ -179,7 +179,7 @@ void TwitchAccount::ignoreByID(const QString &targetUserID, const QString &targe
void TwitchAccount::unignore(const QString &targetName,
std::function<void(UnignoreResult, const QString &message)> onFinished)
{
util::twitch::getUserID(targetName, QThread::currentThread(), [=](QString targetUserID) {
getUserID(targetName, QThread::currentThread(), [=](QString targetUserID) {
this->unignoreByID(targetUserID, targetName, onFinished); //
});
}
@@ -191,8 +191,8 @@ void TwitchAccount::unignoreByID(
QString url("https://api.twitch.tv/kraken/users/" + this->getUserId() + "/blocks/" +
targetUserID);
util::NetworkRequest req(url);
req.setRequestType(util::NetworkRequest::DeleteRequest);
NetworkRequest req(url);
req.setRequestType(NetworkRequest::DeleteRequest);
req.setCaller(QThread::currentThread());
req.makeAuthorizedV5(this->getOAuthClient(), this->getOAuthToken());
@@ -226,8 +226,8 @@ void TwitchAccount::checkFollow(const QString targetUserID,
QString url("https://api.twitch.tv/kraken/users/" + this->getUserId() + "/follows/channels/" +
targetUserID);
util::NetworkRequest req(url);
req.setRequestType(util::NetworkRequest::GetRequest);
NetworkRequest req(url);
req.setRequestType(NetworkRequest::GetRequest);
req.setCaller(QThread::currentThread());
req.makeAuthorizedV5(this->getOAuthClient(), this->getOAuthToken());
+1 -1
View File
@@ -27,7 +27,7 @@ enum FollowResult {
FollowResult_Failed,
};
class TwitchAccount : public controllers::accounts::Account
class TwitchAccount : public Account
{
public:
TwitchAccount(const QString &username, const QString &oauthToken, const QString &oauthClient,
@@ -92,18 +92,18 @@ void TwitchAccountManager::reloadUsers()
switch (this->addUser(userData)) {
case AddUserResponse::UserAlreadyExists: {
debug::Log("User {} already exists", userData.username);
Log("User {} already exists", userData.username);
// Do nothing
} break;
case AddUserResponse::UserValuesUpdated: {
debug::Log("User {} already exists, and values updated!", userData.username);
Log("User {} already exists, and values updated!", userData.username);
if (userData.username == this->getCurrent()->getUserName()) {
debug::Log("It was the current user, so we need to reconnect stuff!");
Log("It was the current user, so we need to reconnect stuff!");
this->currentUserChanged.invoke();
}
} break;
case AddUserResponse::UserAdded: {
debug::Log("Added user {}", userData.username);
Log("Added user {}", userData.username);
listUpdated = true;
} break;
}
@@ -122,11 +122,11 @@ void TwitchAccountManager::load()
QString newUsername(QString::fromStdString(newValue));
auto user = this->findUserByUsername(newUsername);
if (user) {
debug::Log("[AccountManager:currentUsernameChanged] User successfully updated to {}",
Log("[AccountManager:currentUsernameChanged] User successfully updated to {}",
newUsername);
this->currentUser = user;
} else {
debug::Log(
Log(
"[AccountManager:currentUsernameChanged] User successfully updated to anonymous");
this->currentUser = this->anonymousUser;
}
@@ -1,8 +1,8 @@
#pragma once
#include "common/SignalVector2.hpp"
#include "providers/twitch/TwitchAccount.hpp"
#include "util/SharedPtrElementLess.hpp"
#include "common/SignalVector2.hpp"
#include <pajlada/settings/setting.hpp>
@@ -15,8 +15,8 @@
//
namespace chatterino {
class AccountController;
}
class TwitchAccountManager
{
@@ -47,8 +47,7 @@ public:
pajlada::Signals::NoArgSignal currentUserChanged;
pajlada::Signals::NoArgSignal userListUpdated;
util::SortedSignalVector<std::shared_ptr<TwitchAccount>,
util::SharedPtrElementLess<TwitchAccount>>
SortedSignalVector<std::shared_ptr<TwitchAccount>, SharedPtrElementLess<TwitchAccount>>
accounts;
private:
@@ -65,7 +64,7 @@ private:
std::shared_ptr<TwitchAccount> anonymousUser;
mutable std::mutex mutex;
friend class chatterino::controllers::accounts::AccountController;
friend class chatterino::AccountController;
};
} // namespace chatterino
+24 -24
View File
@@ -19,15 +19,15 @@ namespace chatterino {
TwitchChannel::TwitchChannel(const QString &channelName, Communi::IrcConnection *_readConnection)
: Channel(channelName, Channel::Twitch)
, bttvChannelEmotes(new util::EmoteMap)
, ffzChannelEmotes(new util::EmoteMap)
, bttvChannelEmotes(new EmoteMap)
, ffzChannelEmotes(new EmoteMap)
, subscriptionURL("https://www.twitch.tv/subs/" + name)
, channelURL("https://twitch.tv/" + name)
, popoutPlayerURL("https://player.twitch.tv/?channel=" + name)
, mod(false)
, readConnection(_readConnection)
{
debug::Log("[TwitchChannel:{}] Opened", this->name);
Log("[TwitchChannel:{}] Opened", this->name);
this->startRefreshLiveStatusTimer(60 * 1000);
@@ -83,7 +83,7 @@ TwitchChannel::TwitchChannel(const QString &channelName, Communi::IrcConnection
}
}
util::twitch::get("https://tmi.twitch.tv/group/user/" + this->name + "/chatters",
get("https://tmi.twitch.tv/group/user/" + this->name + "/chatters",
QThread::currentThread(), refreshChatters);
};
@@ -95,7 +95,7 @@ TwitchChannel::TwitchChannel(const QString &channelName, Communi::IrcConnection
#if 0
for (int i = 0; i < 1000; i++) {
this->addMessage(messages::Message::createSystemMessage("asdf"));
this->addMessage(chatterino::Message::createSystemMessage("asdf"));
}
#endif
}
@@ -130,7 +130,7 @@ void TwitchChannel::reloadChannelEmotes()
{
auto app = getApp();
debug::Log("[TwitchChannel:{}] Reloading channel emotes", this->name);
Log("[TwitchChannel:{}] Reloading channel emotes", this->name);
app->emotes->bttv.loadChannelEmotes(this->name, this->bttvChannelEmotes);
app->emotes->ffz.loadChannelEmotes(this->name, this->ffzChannelEmotes);
@@ -144,12 +144,12 @@ void TwitchChannel::sendMessage(const QString &message)
// XXX: It would be nice if we could add a link here somehow that opened the "account
// manager" dialog
this->addMessage(
messages::Message::createSystemMessage("You need to log in to send messages. You can "
chatterino::Message::createSystemMessage("You need to log in to send messages. You can "
"link your Twitch account in the settings."));
return;
}
debug::Log("[TwitchChannel:{}] Send message: {}", this->name, message);
Log("[TwitchChannel:{}] Send message: {}", this->name, message);
// Do last message processing
QString parsedMessage = app->emotes->emojis.replaceShortCodes(message);
@@ -204,7 +204,7 @@ bool TwitchChannel::hasModRights()
return this->isMod() || this->isBroadcaster();
}
void TwitchChannel::addRecentChatter(const std::shared_ptr<messages::Message> &message)
void TwitchChannel::addRecentChatter(const std::shared_ptr<chatterino::Message> &message)
{
assert(!message->loginName.isEmpty());
@@ -233,9 +233,9 @@ void TwitchChannel::addJoinedUser(const QString &user)
QTimer::singleShot(500, &this->object, [this] {
std::lock_guard<std::mutex> guard(this->joinedUserMutex);
auto message = messages::Message::createSystemMessage("Users joined: " +
auto message = chatterino::Message::createSystemMessage("Users joined: " +
this->joinedUsers.join(", "));
message->flags |= messages::Message::Collapsed;
message->flags |= chatterino::Message::Collapsed;
this->addMessage(message);
this->joinedUsers.clear();
this->joinedUsersMergeQueued = false;
@@ -262,9 +262,9 @@ void TwitchChannel::addPartedUser(const QString &user)
QTimer::singleShot(500, &this->object, [this] {
std::lock_guard<std::mutex> guard(this->partedUserMutex);
auto message = messages::Message::createSystemMessage("Users parted: " +
auto message = chatterino::Message::createSystemMessage("Users parted: " +
this->partedUsers.join(", "));
message->flags |= messages::Message::Collapsed;
message->flags |= chatterino::Message::Collapsed;
this->addMessage(message);
this->partedUsers.clear();
@@ -321,18 +321,18 @@ void TwitchChannel::setLive(bool newLiveStatus)
void TwitchChannel::refreshLiveStatus()
{
if (this->roomID.isEmpty()) {
debug::Log("[TwitchChannel:{}] Refreshing live status (Missing ID)", this->name);
Log("[TwitchChannel:{}] Refreshing live status (Missing ID)", this->name);
this->setLive(false);
return;
}
debug::Log("[TwitchChannel:{}] Refreshing live status", this->name);
Log("[TwitchChannel:{}] Refreshing live status", this->name);
QString url("https://api.twitch.tv/kraken/streams/" + this->roomID);
std::weak_ptr<Channel> weak = this->shared_from_this();
util::twitch::get2(url, QThread::currentThread(), false, [weak](const rapidjson::Document &d) {
get2(url, QThread::currentThread(), false, [weak](const rapidjson::Document &d) {
ChannelPtr shared = weak.lock();
if (!shared) {
@@ -342,12 +342,12 @@ void TwitchChannel::refreshLiveStatus()
TwitchChannel *channel = dynamic_cast<TwitchChannel *>(shared.get());
if (!d.IsObject()) {
debug::Log("[TwitchChannel:refreshLiveStatus] root is not an object");
Log("[TwitchChannel:refreshLiveStatus] root is not an object");
return;
}
if (!d.HasMember("stream")) {
debug::Log("[TwitchChannel:refreshLiveStatus] Missing stream in root");
Log("[TwitchChannel:refreshLiveStatus] Missing stream in root");
return;
}
@@ -361,7 +361,7 @@ void TwitchChannel::refreshLiveStatus()
if (!stream.HasMember("viewers") || !stream.HasMember("game") ||
!stream.HasMember("channel") || !stream.HasMember("created_at")) {
debug::Log("[TwitchChannel:refreshLiveStatus] Missing members in stream");
Log("[TwitchChannel:refreshLiveStatus] Missing members in stream");
channel->setLive(false);
return;
}
@@ -369,7 +369,7 @@ void TwitchChannel::refreshLiveStatus()
const rapidjson::Value &streamChannel = stream["channel"];
if (!streamChannel.IsObject() || !streamChannel.HasMember("status")) {
debug::Log("[TwitchChannel:refreshLiveStatus] Missing member \"status\" in channel");
Log("[TwitchChannel:refreshLiveStatus] Missing member \"status\" in channel");
return;
}
@@ -432,7 +432,7 @@ void TwitchChannel::fetchRecentMessages()
std::weak_ptr<Channel> weak = this->shared_from_this();
util::twitch::get(genericURL.arg(roomID), QThread::currentThread(), [weak](QJsonObject obj) {
get(genericURL.arg(roomID), QThread::currentThread(), [weak](QJsonObject obj) {
ChannelPtr shared = weak.lock();
if (!shared) {
@@ -449,15 +449,15 @@ void TwitchChannel::fetchRecentMessages()
return;
}
std::vector<messages::MessagePtr> messages;
std::vector<chatterino::MessagePtr> messages;
for (const QJsonValueRef _msg : msgArray) {
QByteArray content = _msg.toString().toUtf8();
auto msg = Communi::IrcMessage::fromData(content, readConnection);
auto privMsg = static_cast<Communi::IrcPrivateMessage *>(msg);
messages::MessageParseArgs args;
twitch::TwitchMessageBuilder builder(channel, privMsg, args);
chatterino::MessageParseArgs args;
TwitchMessageBuilder builder(channel, privMsg, args);
if (!builder.isIgnored()) {
messages.push_back(builder.build());
}
+3 -3
View File
@@ -60,12 +60,12 @@ public:
bool isBroadcaster() const override;
bool hasModRights();
void addRecentChatter(const std::shared_ptr<messages::Message> &message) final;
void addRecentChatter(const std::shared_ptr<chatterino::Message> &message) final;
void addJoinedUser(const QString &user);
void addPartedUser(const QString &user);
const std::shared_ptr<chatterino::util::EmoteMap> bttvChannelEmotes;
const std::shared_ptr<chatterino::util::EmoteMap> ffzChannelEmotes;
const std::shared_ptr<EmoteMap> bttvChannelEmotes;
const std::shared_ptr<EmoteMap> ffzChannelEmotes;
const QString subscriptionURL;
const QString channelURL;
+28 -28
View File
@@ -1,10 +1,10 @@
#include "providers/twitch/TwitchEmotes.hpp"
#include "common/UrlFetch.hpp"
#include "debug/Benchmark.hpp"
#include "debug/Log.hpp"
#include "messages/Image.hpp"
#include "debug/Benchmark.hpp"
#include "util/RapidjsonHelpers.hpp"
#include "common/UrlFetch.hpp"
#define TWITCH_EMOTE_TEMPLATE "https://static-cdn.jtvnw.net/emoticons/v1/{id}/{scale}"
@@ -47,19 +47,19 @@ QString cleanUpCode(const QString &dirtyEmoteCode)
void loadSetData(std::shared_ptr<TwitchEmotes::EmoteSet> emoteSet)
{
debug::Log("Load twitch emote set data for {}", emoteSet->key);
util::NetworkRequest req("https://braize.pajlada.com/chatterino/twitchemotes/set/" +
emoteSet->key + "/");
Log("Load twitch emote set data for {}", emoteSet->key);
NetworkRequest req("https://braize.pajlada.com/chatterino/twitchemotes/set/" + emoteSet->key +
"/");
req.setRequestType(util::NetworkRequest::GetRequest);
req.setRequestType(NetworkRequest::GetRequest);
req.onError([](int errorCode) -> bool {
debug::Log("Emote sets on ERROR {}", errorCode);
Log("Emote sets on ERROR {}", errorCode);
return true;
});
req.onSuccess([emoteSet](const rapidjson::Document &root) -> bool {
debug::Log("Emote sets on success");
Log("Emote sets on success");
if (!root.IsObject()) {
return false;
}
@@ -99,7 +99,7 @@ TwitchEmotes::TwitchEmotes()
// id is used for lookup
// emoteName is used for giving a name to the emote in case it doesn't exist
util::EmoteData TwitchEmotes::getEmoteById(const QString &id, const QString &emoteName)
EmoteData TwitchEmotes::getEmoteById(const QString &id, const QString &emoteName)
{
QString _emoteName = emoteName;
_emoteName.replace("<", "&lt;");
@@ -121,18 +121,18 @@ util::EmoteData TwitchEmotes::getEmoteById(const QString &id, const QString &emo
}
return _twitchEmoteFromCache.getOrAdd(id, [&emoteName, &_emoteName, &id] {
util::EmoteData newEmoteData;
EmoteData newEmoteData;
auto cleanCode = cleanUpCode(emoteName);
newEmoteData.image1x = new messages::Image(getEmoteLink(id, "1.0"), 1, emoteName,
_emoteName + "<br/>Twitch Emote 1x");
newEmoteData.image1x = new chatterino::Image(getEmoteLink(id, "1.0"), 1, emoteName,
_emoteName + "<br/>Twitch Emote 1x");
newEmoteData.image1x->setCopyString(cleanCode);
newEmoteData.image2x = new messages::Image(getEmoteLink(id, "2.0"), .5, emoteName,
_emoteName + "<br/>Twitch Emote 2x");
newEmoteData.image2x = new chatterino::Image(getEmoteLink(id, "2.0"), .5, emoteName,
_emoteName + "<br/>Twitch Emote 2x");
newEmoteData.image2x->setCopyString(cleanCode);
newEmoteData.image3x = new messages::Image(getEmoteLink(id, "3.0"), .25, emoteName,
_emoteName + "<br/>Twitch Emote 3x");
newEmoteData.image3x = new chatterino::Image(getEmoteLink(id, "3.0"), .25, emoteName,
_emoteName + "<br/>Twitch Emote 3x");
newEmoteData.image3x->setCopyString(cleanCode);
@@ -142,21 +142,21 @@ util::EmoteData TwitchEmotes::getEmoteById(const QString &id, const QString &emo
void TwitchEmotes::refresh(const std::shared_ptr<TwitchAccount> &user)
{
debug::Log("Loading Twitch emotes for user {}", user->getUserName());
Log("Loading Twitch emotes for user {}", user->getUserName());
const auto &roomID = user->getUserId();
const auto &clientID = user->getOAuthClient();
const auto &oauthToken = user->getOAuthToken();
if (clientID.isEmpty() || oauthToken.isEmpty()) {
debug::Log("Missing Client ID or OAuth token");
Log("Missing Client ID or OAuth token");
return;
}
TwitchAccountEmoteData &emoteData = this->emotes[roomID];
if (emoteData.filled) {
debug::Log("Emotes are already loaded for room id {}", roomID);
Log("Emotes are already loaded for room id {}", roomID);
return;
}
@@ -183,7 +183,7 @@ void TwitchEmotes::refresh(const std::shared_ptr<TwitchAccount> &user)
emoteSet->emotes.emplace_back(id, cleanCode);
emoteData.emoteCodes.push_back(cleanCode);
util::EmoteData emote = this->getEmoteById(id, code);
EmoteData emote = this->getEmoteById(id, code);
emoteData.emotes.insert(code, emote);
}
@@ -193,13 +193,13 @@ void TwitchEmotes::refresh(const std::shared_ptr<TwitchAccount> &user)
emoteData.filled = true;
};
util::twitch::getAuthorized(url, clientID, oauthToken, QThread::currentThread(), loadEmotes);
getAuthorized(url, clientID, oauthToken, QThread::currentThread(), loadEmotes);
}
void TwitchEmotes::loadSetData(std::shared_ptr<TwitchEmotes::EmoteSet> emoteSet)
{
if (!emoteSet) {
debug::Log("null emote set sent");
Log("null emote set sent");
return;
}
@@ -211,14 +211,14 @@ void TwitchEmotes::loadSetData(std::shared_ptr<TwitchEmotes::EmoteSet> emoteSet)
return;
}
debug::Log("Load twitch emote set data for {}..", emoteSet->key);
util::NetworkRequest req("https://braize.pajlada.com/chatterino/twitchemotes/set/" +
emoteSet->key + "/");
Log("Load twitch emote set data for {}..", emoteSet->key);
NetworkRequest req("https://braize.pajlada.com/chatterino/twitchemotes/set/" + emoteSet->key +
"/");
req.setRequestType(util::NetworkRequest::GetRequest);
req.setRequestType(NetworkRequest::GetRequest);
req.onError([](int errorCode) -> bool {
debug::Log("Emote sets on ERROR {}", errorCode);
Log("Emote sets on ERROR {}", errorCode);
return true;
});
@@ -238,7 +238,7 @@ void TwitchEmotes::loadSetData(std::shared_ptr<TwitchEmotes::EmoteSet> emoteSet)
return false;
}
debug::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);
+5 -5
View File
@@ -17,10 +17,10 @@ class TwitchEmotes
public:
TwitchEmotes();
util::EmoteData getEmoteById(const QString &id, const QString &emoteName);
EmoteData getEmoteById(const QString &id, const QString &emoteName);
/// Twitch emotes
void refresh(const std::shared_ptr<providers::twitch::TwitchAccount> &user);
void refresh(const std::shared_ptr<TwitchAccount> &user);
struct TwitchEmote {
TwitchEmote(const QString &_id, const QString &_code)
@@ -50,7 +50,7 @@ public:
std::vector<QString> emoteCodes;
util::EmoteMap emotes;
EmoteMap emotes;
bool filled = false;
};
@@ -62,10 +62,10 @@ private:
void loadSetData(std::shared_ptr<TwitchEmotes::EmoteSet> emoteSet);
// emote code
util::ConcurrentMap<QString, providers::twitch::EmoteValue *> _twitchEmotes;
ConcurrentMap<QString, EmoteValue *> _twitchEmotes;
// emote id
util::ConcurrentMap<QString, util::EmoteData> _twitchEmoteFromCache;
ConcurrentMap<QString, EmoteData> _twitchEmoteFromCache;
};
} // namespace chatterino
+1 -1
View File
@@ -6,7 +6,7 @@ namespace chatterino {
bool trimChannelName(const QString &channelName, QString &outChannelName)
{
if (channelName.length() < 3) {
debug::Log("channel name length below 3");
Log("channel name length below 3");
return false;
}
+24 -29
View File
@@ -18,13 +18,11 @@
#include <QDebug>
#include <QMediaPlayer>
using namespace chatterino::messages;
namespace chatterino {
TwitchMessageBuilder::TwitchMessageBuilder(Channel *_channel,
const Communi::IrcPrivateMessage *_ircMessage,
const messages::MessageParseArgs &_args)
const chatterino::MessageParseArgs &_args)
: channel(_channel)
, twitchChannel(dynamic_cast<TwitchChannel *>(_channel))
, ircMessage(_ircMessage)
@@ -39,8 +37,8 @@ TwitchMessageBuilder::TwitchMessageBuilder(Channel *_channel,
TwitchMessageBuilder::TwitchMessageBuilder(Channel *_channel,
const Communi::IrcMessage *_ircMessage,
const messages::MessageParseArgs &_args, QString content,
bool isAction)
const chatterino::MessageParseArgs &_args,
QString content, bool isAction)
: channel(_channel)
, twitchChannel(dynamic_cast<TwitchChannel *>(_channel))
, ircMessage(_ircMessage)
@@ -60,8 +58,7 @@ 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)) {
debug::Log("Blocking message because it contains ignored phrase {}",
phrase.getPattern());
Log("Blocking message because it contains ignored phrase {}", phrase.getPattern());
return true;
}
}
@@ -71,7 +68,7 @@ bool TwitchMessageBuilder::isIgnored() const
for (const auto &user : app->accounts->twitch.getCurrent()->getIgnores()) {
if (sourceUserID == user.id) {
debug::Log("Blocking message because it's from blocked user {}", user.name);
Log("Blocking message because it's from blocked user {}", user.name);
return true;
}
}
@@ -82,7 +79,7 @@ bool TwitchMessageBuilder::isIgnored() const
for (const auto &user : app->accounts->twitch.getCurrent()->getIgnores()) {
if (sourceUserID == user.id) {
debug::Log("Blocking message because it's from blocked user {}", user.name);
Log("Blocking message because it's from blocked user {}", user.name);
return true;
}
}
@@ -167,7 +164,7 @@ MessagePtr TwitchMessageBuilder::build()
}
// twitch emotes
std::vector<std::pair<long, util::EmoteData>> twitchEmotes;
std::vector<std::pair<long, EmoteData>> twitchEmotes;
iterator = this->tags.find("emotes");
if (iterator != this->tags.end()) {
@@ -205,13 +202,13 @@ MessagePtr TwitchMessageBuilder::build()
}
// split words
std::vector<std::tuple<util::EmoteData, QString>> parsed;
std::vector<std::tuple<EmoteData, QString>> parsed;
// Parse emojis and take all non-emojis and put them in parsed as full text-words
app->emotes->emojis.parse(parsed, split);
for (const auto &tuple : parsed) {
const util::EmoteData &emoteData = std::get<0>(tuple);
const EmoteData &emoteData = std::get<0>(tuple);
if (!emoteData.isValid()) { // is text
QString string = std::get<1>(tuple);
@@ -334,7 +331,7 @@ void TwitchMessageBuilder::appendUsername()
auto iterator = this->tags.find("display-name");
if (iterator != this->tags.end()) {
QString displayName = util::parseTagString(iterator.value().toString()).trimmed();
QString displayName = parseTagString(iterator.value().toString()).trimmed();
if (QString::compare(displayName, this->userName, Qt::CaseInsensitive) == 0) {
username = displayName;
@@ -449,13 +446,11 @@ void TwitchMessageBuilder::parseHighlights()
// TODO: This vector should only be rebuilt upon highlights being changed
// fourtf: should be implemented in the HighlightsController
std::vector<controllers::highlights::HighlightPhrase> activeHighlights =
app->highlights->phrases.getVector();
std::vector<HighlightPhrase> activeHighlights = app->highlights->phrases.getVector();
if (app->settings->enableHighlightsSelf && currentUsername.size() > 0) {
controllers::highlights::HighlightPhrase selfHighlight(
currentUsername, app->settings->enableHighlightTaskbar,
app->settings->enableHighlightSound, false);
HighlightPhrase selfHighlight(currentUsername, app->settings->enableHighlightTaskbar,
app->settings->enableHighlightSound, false);
activeHighlights.emplace_back(std::move(selfHighlight));
}
@@ -466,10 +461,10 @@ void TwitchMessageBuilder::parseHighlights()
bool hasFocus = (QApplication::focusWidget() != nullptr);
if (!blackList.contains(this->ircMessage->nick(), Qt::CaseInsensitive)) {
for (const controllers::highlights::HighlightPhrase &highlight : activeHighlights) {
for (const HighlightPhrase &highlight : activeHighlights) {
if (highlight.isMatch(this->originalMessage)) {
debug::Log("Highlight because {} matches {}", this->originalMessage,
highlight.getPattern());
Log("Highlight because {} matches {}", this->originalMessage,
highlight.getPattern());
doHighlight = true;
if (highlight.getAlert()) {
@@ -506,7 +501,7 @@ void TwitchMessageBuilder::parseHighlights()
void TwitchMessageBuilder::appendTwitchEmote(const Communi::IrcMessage *ircMessage,
const QString &emote,
std::vector<std::pair<long int, util::EmoteData>> &vec)
std::vector<std::pair<long int, EmoteData>> &vec)
{
auto app = getApp();
if (!emote.contains(':')) {
@@ -539,15 +534,15 @@ void TwitchMessageBuilder::appendTwitchEmote(const Communi::IrcMessage *ircMessa
QString name = this->originalMessage.mid(start, end - start + 1);
vec.push_back(std::pair<long int, util::EmoteData>(
start, app->emotes->twitch.getEmoteById(id, name)));
vec.push_back(
std::pair<long int, EmoteData>(start, app->emotes->twitch.getEmoteById(id, name)));
}
}
bool TwitchMessageBuilder::tryAppendEmote(QString &emoteString)
{
auto app = getApp();
util::EmoteData emoteData;
EmoteData emoteData;
auto appendEmote = [&](MessageElement::Flags flags) {
this->emplace<EmoteElement>(emoteData, flags);
@@ -621,7 +616,7 @@ void TwitchMessageBuilder::appendTwitchBadges()
this->emplace<ImageElement>(badge.badgeImage1x, MessageElement::BadgeVanity)
->setTooltip(tooltip);
} catch (const std::out_of_range &) {
debug::Log("No default bit badge for version {} found", versionKey);
Log("No default bit badge for version {} found", versionKey);
continue;
}
} else if (badge == "staff/1") {
@@ -768,7 +763,7 @@ bool TwitchMessageBuilder::tryParseCheermote(const QString &string)
bool ok = false;
int numBits = amount.toInt(&ok);
if (!ok) {
debug::Log("Error parsing bit amount in tryParseCheermote");
Log("Error parsing bit amount in tryParseCheermote");
return false;
}
@@ -785,8 +780,8 @@ bool TwitchMessageBuilder::tryParseCheermote(const QString &string)
}
if (savedIt == cheermoteSet.cheermotes.end()) {
debug::Log("Error getting a cheermote from a cheermote set for the bit amount {}",
numBits);
Log("Error getting a cheermote from a cheermote set for the bit amount {}",
numBits);
return false;
}
@@ -14,7 +14,7 @@ namespace chatterino {
class Channel;
class TwitchChannel;
class TwitchMessageBuilder : public messages::MessageBuilder
class TwitchMessageBuilder : public chatterino::MessageBuilder
{
public:
enum UsernameDisplayMode : int {
@@ -26,22 +26,22 @@ public:
TwitchMessageBuilder() = delete;
explicit TwitchMessageBuilder(Channel *_channel, const Communi::IrcPrivateMessage *_ircMessage,
const messages::MessageParseArgs &_args);
const chatterino::MessageParseArgs &_args);
explicit TwitchMessageBuilder(Channel *_channel, const Communi::IrcMessage *_ircMessage,
const messages::MessageParseArgs &_args, QString content,
const chatterino::MessageParseArgs &_args, QString content,
bool isAction);
Channel *channel;
TwitchChannel *twitchChannel;
const Communi::IrcMessage *ircMessage;
messages::MessageParseArgs args;
chatterino::MessageParseArgs args;
const QVariantMap tags;
QString messageID;
QString userName;
bool isIgnored() const;
messages::MessagePtr build();
chatterino::MessagePtr build();
private:
QString roomID;
@@ -60,7 +60,7 @@ private:
void parseHighlights();
void appendTwitchEmote(const Communi::IrcMessage *ircMessage, const QString &emote,
std::vector<std::pair<long, util::EmoteData>> &vec);
std::vector<std::pair<long, EmoteData>> &vec);
bool tryAppendEmote(QString &emoteString);
void appendTwitchBadges();
+4 -4
View File
@@ -29,10 +29,10 @@ TwitchServer::TwitchServer()
void TwitchServer::initialize()
{
getApp()->accounts->twitch.currentUserChanged.connect(
[this]() { util::postToThread([this] { this->connect(); }); });
[this]() { postToThread([this] { this->connect(); }); });
}
void TwitchServer::initializeConnection(providers::irc::IrcConnection *connection, bool isRead,
void TwitchServer::initializeConnection(IrcConnection *connection, bool isRead,
bool isWrite)
{
std::shared_ptr<TwitchAccount> account = getApp()->accounts->twitch.getCurrent();
@@ -196,7 +196,7 @@ void TwitchServer::onMessageSendRequested(TwitchChannel *channel, const QString
if (!lastMessage.empty() && lastMessage.back() + minMessageOffset > now) {
if (this->lastErrorTimeSpeed_ + 30s < now) {
auto errorMessage =
messages::Message::createSystemMessage("sending messages too fast");
chatterino::Message::createSystemMessage("sending messages too fast");
channel->addMessage(errorMessage);
@@ -214,7 +214,7 @@ void TwitchServer::onMessageSendRequested(TwitchChannel *channel, const QString
if (lastMessage.size() >= maxMessageCount) {
if (this->lastErrorTimeAmount_ + 30s < now) {
auto errorMessage =
messages::Message::createSystemMessage("sending too many messages");
chatterino::Message::createSystemMessage("sending too many messages");
channel->addMessage(errorMessage);
+3 -4
View File
@@ -11,7 +11,7 @@
namespace chatterino {
class TwitchServer final : public irc::AbstractIrcServer
class TwitchServer final : public AbstractIrcServer
{
public:
TwitchServer();
@@ -23,15 +23,14 @@ public:
std::shared_ptr<Channel> getChannelOrEmptyByID(const QString &channelID);
util::MutexValue<QString> lastUserThatWhisperedMe;
MutexValue<QString> lastUserThatWhisperedMe;
const ChannelPtr whispersChannel;
const ChannelPtr mentionsChannel;
IndirectChannel watchingChannel;
protected:
void initializeConnection(providers::irc::IrcConnection *connection, bool isRead,
bool isWrite) override;
void initializeConnection(IrcConnection *connection, bool isRead, bool isWrite) override;
std::shared_ptr<Channel> createChannel(const QString &channelName) override;
void privateMessageReceived(Communi::IrcPrivateMessage *message) override;