diff --git a/src/controllers/commands/CommandController.cpp b/src/controllers/commands/CommandController.cpp index f792938d6..e244a54b2 100644 --- a/src/controllers/commands/CommandController.cpp +++ b/src/controllers/commands/CommandController.cpp @@ -378,35 +378,34 @@ QString CommandController::execCommand(const QString &textNoEmoji, auto app = getApp(); auto logs = new LogsPopup(); - QString target; + QString target = words.at(1); - if (words.at(1).at(0) == "@") + if (target.at(0) == '@') { - target = words.at(1).mid(1); - } - else - { - target = words.at(1); + target = target.mid(1); } + logs->setTargetUserName(target); + + std::shared_ptr logsChannel = channel; + if (words.size() == 3) { QString channelName = words.at(2); - if (words.at(2).at(0) == "#") + if (words.at(2).at(0) == '#') { - channelName = words.at(2).mid(1); + channelName = channelName.mid(1); } - auto logsChannel = + + logs->setChannelName(channelName); + + logsChannel = app->twitch.server->getChannelOrEmpty(channelName); - if (logsChannel != nullptr) - { - logs->setInfo(logsChannel, target); - } - } - else - { - logs->setInfo(channel, target); } + + logs->setChannel(logsChannel); + + logs->getLogs(); logs->setAttribute(Qt::WA_DeleteOnClose); logs->show(); return ""; diff --git a/src/widgets/dialogs/LogsPopup.cpp b/src/widgets/dialogs/LogsPopup.cpp index 38e56fc57..2e305ace4 100644 --- a/src/widgets/dialogs/LogsPopup.cpp +++ b/src/widgets/dialogs/LogsPopup.cpp @@ -3,6 +3,7 @@ #include "IrcMessage" #include "common/Channel.hpp" #include "common/NetworkRequest.hpp" +#include "debug/Log.hpp" #include "providers/twitch/PartialTwitchUser.hpp" #include "providers/twitch/TwitchChannel.hpp" #include "providers/twitch/TwitchMessageBuilder.hpp" @@ -33,29 +34,47 @@ void LogsPopup::initLayout() this->setLayout(layout); } -void LogsPopup::setInfo(ChannelPtr channel, QString userName) +void LogsPopup::setChannelName(QString channelName) +{ + this->channelName_ = channelName; +} + +void LogsPopup::setChannel(std::shared_ptr channel) { this->channel_ = channel; +} + +void LogsPopup::setTargetUserName(QString userName) +{ this->userName_ = userName; +} - if (auto twitchChannel = - dynamic_cast(this->channel_.get())) +void LogsPopup::getLogs() +{ + if (this->channel_ && !this->channel_->isEmpty()) { - this->channelName_ = twitchChannel->getName(); + if (auto twitchChannel = + dynamic_cast(this->channel_.get())) + { + this->channelName_ = twitchChannel->getName(); + this->getLogviewerLogs(twitchChannel->roomId()); + + this->setWindowTitle(this->userName_ + "'s logs in #" + + this->channelName_); + return; + } } - else + + if (!this->channelName_.isEmpty()) { + PartialTwitchUser::byName(this->channelName_) + .getId( + [=](const QString &roomID) { this->getLogviewerLogs(roomID); }, + this); return; - } + } - // Get channel ID. - PartialTwitchUser::byName(this->channelName_) - .getId([=](const QString &roomID) { - this->getLogviewerLogs(roomID); - }, this); - - this->setWindowTitle(this->userName_ + "'s logs in #" + - this->channelName_); + log("Unable to get logs, no channel name or something specified"); } void LogsPopup::setMessages(std::vector &messages) @@ -68,7 +87,6 @@ void LogsPopup::setMessages(std::vector &messages) void LogsPopup::getLogviewerLogs(const QString &roomID) { - auto url = QString("https://cbenni.com/api/logs/%1/?nick=%2&before=500") .arg(this->channelName_, this->userName_); @@ -115,7 +133,6 @@ void LogsPopup::getLogviewerLogs(const QString &roomID) void LogsPopup::getOverrustleLogs() { - QString url = QString("https://overrustlelogs.net/api/v1/stalk/%1/%2.json?limit=500") .arg(this->channelName_, this->userName_); @@ -130,11 +147,11 @@ void LogsPopup::getOverrustleLogs() box->show(); box->raise(); - static QSet closeButtons { + static QSet closeButtons{ QMessageBox::Ok, QMessageBox::Close, }; - if (closeButtons.contains(box->exec())) + if (closeButtons.contains(box->exec())) { this->close(); } diff --git a/src/widgets/dialogs/LogsPopup.hpp b/src/widgets/dialogs/LogsPopup.hpp index 7bfa972c0..e66061d99 100644 --- a/src/widgets/dialogs/LogsPopup.hpp +++ b/src/widgets/dialogs/LogsPopup.hpp @@ -18,7 +18,11 @@ class LogsPopup : public BaseWindow public: LogsPopup(); - void setInfo(std::shared_ptr channel, QString userName); + void setChannelName(QString channelName); + void setChannel(std::shared_ptr channel); + void setTargetUserName(QString userName); + + void getLogs(); private: ChannelView *channelView_ = nullptr; diff --git a/src/widgets/dialogs/UserInfoPopup.cpp b/src/widgets/dialogs/UserInfoPopup.cpp index 534d495dc..09244b9b3 100644 --- a/src/widgets/dialogs/UserInfoPopup.cpp +++ b/src/widgets/dialogs/UserInfoPopup.cpp @@ -96,7 +96,9 @@ UserInfoPopup::UserInfoPopup() QObject::connect(viewLogs.getElement(), &Button::leftClicked, [this] { auto logs = new LogsPopup(); - logs->setInfo(this->channel_, this->userName_); + logs->setChannel(this->channel_); + logs->setTargetUserName(this->userName_); + logs->getLogs(); logs->setAttribute(Qt::WA_DeleteOnClose); logs->show(); });