Add channel badges and emotes to LogsPopup (#576)

* Add channel badges and emotes to LogsPopup

* Move roomID stuff to seperate function

* Use onSuccess
This commit is contained in:
DatGuy1 2018-07-23 15:50:09 +03:00 committed by fourtf
parent f33cc884b2
commit f060907678
2 changed files with 41 additions and 10 deletions

View file

@ -35,7 +35,7 @@ void LogsPopup::setInfo(ChannelPtr channel, QString userName)
this->channel_ = channel; this->channel_ = channel;
this->userName_ = userName; this->userName_ = userName;
this->setWindowTitle(this->userName_ + "'s logs in #" + this->channel_->name); this->setWindowTitle(this->userName_ + "'s logs in #" + this->channel_->name);
this->getLogviewerLogs(); this->getRoomID();
} }
void LogsPopup::setMessages(std::vector<MessagePtr> &messages) void LogsPopup::setMessages(std::vector<MessagePtr> &messages)
@ -46,6 +46,35 @@ void LogsPopup::setMessages(std::vector<MessagePtr> &messages)
this->channelView_->setChannel(logsChannel); this->channelView_->setChannel(logsChannel);
} }
void LogsPopup::getRoomID()
{
TwitchChannel *twitchChannel = dynamic_cast<TwitchChannel *>(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() void LogsPopup::getLogviewerLogs()
{ {
TwitchChannel *twitchChannel = dynamic_cast<TwitchChannel *>(this->channel_.get()); TwitchChannel *twitchChannel = dynamic_cast<TwitchChannel *>(this->channel_.get());
@ -55,7 +84,7 @@ void LogsPopup::getLogviewerLogs()
QString channelName = twitchChannel->name; QString channelName = twitchChannel->name;
QString url = QString("https://cbenni.com/api/logs/%1/?nick=%2&before=500") auto url = QString("https://cbenni.com/api/logs/%1/?nick=%2&before=500")
.arg(channelName, this->userName_); .arg(channelName, this->userName_);
NetworkRequest req(url); NetworkRequest req(url);
@ -69,7 +98,6 @@ void LogsPopup::getLogviewerLogs()
req.onSuccess([this, channelName](auto result) { req.onSuccess([this, channelName](auto result) {
auto data = result.parseJson(); auto data = result.parseJson();
std::vector<MessagePtr> messages; std::vector<MessagePtr> messages;
ChannelPtr logsChannel(new Channel("logs", Channel::Type::None));
QJsonValue before = data.value("before"); QJsonValue before = data.value("before");
@ -80,11 +108,12 @@ void LogsPopup::getLogviewerLogs()
// Hacky way to fix the timestamp // Hacky way to fix the timestamp
message.insert(1, "historical=1;"); message.insert(1, "historical=1;");
message.insert(1, QString("tmi-sent-ts=%10000;").arg(messageObject["time"].toInt())); message.insert(1, QString("tmi-sent-ts=%10000;").arg(messageObject["time"].toInt()));
message.insert(1, QString("room-id=%1;").arg(this->roomID_));
MessageParseArgs args; MessageParseArgs args;
auto ircMessage = Communi::IrcMessage::fromData(message.toUtf8(), nullptr); auto ircMessage = Communi::IrcMessage::fromData(message.toUtf8(), nullptr);
auto privMsg = static_cast<Communi::IrcPrivateMessage *>(ircMessage); auto privMsg = static_cast<Communi::IrcPrivateMessage *>(ircMessage);
TwitchMessageBuilder builder(logsChannel.get(), privMsg, args); TwitchMessageBuilder builder(this->channel_.get(), privMsg, args);
messages.push_back(builder.build()); messages.push_back(builder.build());
}; };
this->setMessages(messages); this->setMessages(messages);

View file

@ -16,15 +16,17 @@ public:
void setInfo(std::shared_ptr<Channel> channel, QString userName); void setInfo(std::shared_ptr<Channel> channel, QString userName);
private: private:
void initLayout();
void setMessages(std::vector<MessagePtr> &messages);
void getOverrustleLogs();
void getLogviewerLogs();
ChannelView *channelView_ = nullptr; ChannelView *channelView_ = nullptr;
ChannelPtr channel_ = Channel::getEmpty(); ChannelPtr channel_ = Channel::getEmpty();
QString userName_; QString userName_;
int roomID_;
void initLayout();
void setMessages(std::vector<MessagePtr> &messages);
void getRoomID();
void getOverrustleLogs();
void getLogviewerLogs();
}; };
} // namespace chatterino } // namespace chatterino