From f0609076784a33647f30f042837a8d940843993f Mon Sep 17 00:00:00 2001 From: DatGuy1 Date: Mon, 23 Jul 2018 15:50:09 +0300 Subject: [PATCH] Add channel badges and emotes to LogsPopup (#576) * Add channel badges and emotes to LogsPopup * Move roomID stuff to seperate function * Use onSuccess --- src/widgets/dialogs/LogsPopup.cpp | 39 +++++++++++++++++++++++++++---- src/widgets/dialogs/LogsPopup.hpp | 12 ++++++---- 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/src/widgets/dialogs/LogsPopup.cpp b/src/widgets/dialogs/LogsPopup.cpp index a2afb9301..288f37acb 100644 --- a/src/widgets/dialogs/LogsPopup.cpp +++ b/src/widgets/dialogs/LogsPopup.cpp @@ -35,7 +35,7 @@ void LogsPopup::setInfo(ChannelPtr channel, QString userName) this->channel_ = channel; this->userName_ = userName; this->setWindowTitle(this->userName_ + "'s logs in #" + this->channel_->name); - this->getLogviewerLogs(); + this->getRoomID(); } void LogsPopup::setMessages(std::vector &messages) @@ -46,6 +46,35 @@ void LogsPopup::setMessages(std::vector &messages) this->channelView_->setChannel(logsChannel); } +void LogsPopup::getRoomID() +{ + TwitchChannel *twitchChannel = dynamic_cast(this->channel_.get()); + if (twitchChannel == nullptr) { + return; + } + + QString channelName = twitchChannel->name; + + QString url = QString("https://cbenni.com/api/channel/%1").arg(channelName); + + NetworkRequest req(url); + req.setCaller(QThread::currentThread()); + + req.onError([this](int errorCode) { + this->getOverrustleLogs(); + return true; + }); + + req.onSuccess([this, channelName](auto result) { + auto data = result.parseJson(); + this->roomID_ = data.value("channel")["id"].toInt(); + this->getLogviewerLogs(); + return true; + }); + + req.execute(); +} + void LogsPopup::getLogviewerLogs() { TwitchChannel *twitchChannel = dynamic_cast(this->channel_.get()); @@ -55,8 +84,8 @@ void LogsPopup::getLogviewerLogs() QString channelName = twitchChannel->name; - QString url = QString("https://cbenni.com/api/logs/%1/?nick=%2&before=500") - .arg(channelName, this->userName_); + auto url = QString("https://cbenni.com/api/logs/%1/?nick=%2&before=500") + .arg(channelName, this->userName_); NetworkRequest req(url); req.setCaller(QThread::currentThread()); @@ -69,7 +98,6 @@ void LogsPopup::getLogviewerLogs() req.onSuccess([this, channelName](auto result) { auto data = result.parseJson(); std::vector messages; - ChannelPtr logsChannel(new Channel("logs", Channel::Type::None)); QJsonValue before = data.value("before"); @@ -80,11 +108,12 @@ void LogsPopup::getLogviewerLogs() // Hacky way to fix the timestamp message.insert(1, "historical=1;"); message.insert(1, QString("tmi-sent-ts=%10000;").arg(messageObject["time"].toInt())); + message.insert(1, QString("room-id=%1;").arg(this->roomID_)); MessageParseArgs args; auto ircMessage = Communi::IrcMessage::fromData(message.toUtf8(), nullptr); auto privMsg = static_cast(ircMessage); - TwitchMessageBuilder builder(logsChannel.get(), privMsg, args); + TwitchMessageBuilder builder(this->channel_.get(), privMsg, args); messages.push_back(builder.build()); }; this->setMessages(messages); diff --git a/src/widgets/dialogs/LogsPopup.hpp b/src/widgets/dialogs/LogsPopup.hpp index 90c7f9b0c..5ec39102e 100644 --- a/src/widgets/dialogs/LogsPopup.hpp +++ b/src/widgets/dialogs/LogsPopup.hpp @@ -16,15 +16,17 @@ public: void setInfo(std::shared_ptr channel, QString userName); private: - void initLayout(); - void setMessages(std::vector &messages); - void getOverrustleLogs(); - void getLogviewerLogs(); - ChannelView *channelView_ = nullptr; ChannelPtr channel_ = Channel::getEmpty(); QString userName_; + int roomID_; + + void initLayout(); + void setMessages(std::vector &messages); + void getRoomID(); + void getOverrustleLogs(); + void getLogviewerLogs(); }; } // namespace chatterino