removed old NetworkRequest api
This commit is contained in:
@@ -91,45 +91,43 @@ void LogsPopup::getLogviewerLogs(const QString &roomID)
|
||||
auto url = QString("https://cbenni.com/api/logs/%1/?nick=%2&before=500")
|
||||
.arg(this->channelName_, this->userName_);
|
||||
|
||||
NetworkRequest req(url);
|
||||
req.setCaller(this);
|
||||
NetworkRequest(url)
|
||||
.caller(this)
|
||||
.onError([this](int errorCode) {
|
||||
this->getOverrustleLogs();
|
||||
return true;
|
||||
})
|
||||
.onSuccess([this, roomID](auto result) -> Outcome {
|
||||
auto data = result.parseJson();
|
||||
std::vector<MessagePtr> messages;
|
||||
|
||||
req.onError([this](int errorCode) {
|
||||
this->getOverrustleLogs();
|
||||
return true;
|
||||
});
|
||||
QJsonValue before = data.value("before");
|
||||
|
||||
req.onSuccess([this, roomID](auto result) -> Outcome {
|
||||
auto data = result.parseJson();
|
||||
std::vector<MessagePtr> messages;
|
||||
for (auto i : before.toArray())
|
||||
{
|
||||
auto messageObject = i.toObject();
|
||||
QString message = messageObject.value("text").toString();
|
||||
|
||||
QJsonValue before = data.value("before");
|
||||
// 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(roomID));
|
||||
|
||||
for (auto i : before.toArray())
|
||||
{
|
||||
auto messageObject = i.toObject();
|
||||
QString message = messageObject.value("text").toString();
|
||||
MessageParseArgs args;
|
||||
auto ircMessage =
|
||||
Communi::IrcMessage::fromData(message.toUtf8(), nullptr);
|
||||
auto privMsg =
|
||||
static_cast<Communi::IrcPrivateMessage *>(ircMessage);
|
||||
TwitchMessageBuilder builder(this->channel_.get(), privMsg,
|
||||
args);
|
||||
messages.push_back(builder.build());
|
||||
}
|
||||
this->setMessages(messages);
|
||||
|
||||
// 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(roomID));
|
||||
|
||||
MessageParseArgs args;
|
||||
auto ircMessage =
|
||||
Communi::IrcMessage::fromData(message.toUtf8(), nullptr);
|
||||
auto privMsg =
|
||||
static_cast<Communi::IrcPrivateMessage *>(ircMessage);
|
||||
TwitchMessageBuilder builder(this->channel_.get(), privMsg, args);
|
||||
messages.push_back(builder.build());
|
||||
}
|
||||
this->setMessages(messages);
|
||||
|
||||
return Success;
|
||||
});
|
||||
|
||||
req.execute();
|
||||
return Success;
|
||||
})
|
||||
.execute();
|
||||
}
|
||||
|
||||
void LogsPopup::getOverrustleLogs()
|
||||
@@ -138,57 +136,56 @@ void LogsPopup::getOverrustleLogs()
|
||||
QString("https://overrustlelogs.net/api/v1/stalk/%1/%2.json?limit=500")
|
||||
.arg(this->channelName_, this->userName_);
|
||||
|
||||
NetworkRequest req(url);
|
||||
req.setCaller(this);
|
||||
req.onError([this](int errorCode) {
|
||||
auto box = new QMessageBox(
|
||||
QMessageBox::Information, "Error getting logs",
|
||||
"No logs could be found for channel " + this->channelName_);
|
||||
box->setAttribute(Qt::WA_DeleteOnClose);
|
||||
box->show();
|
||||
box->raise();
|
||||
NetworkRequest(url)
|
||||
.caller(this)
|
||||
.onError([this](int errorCode) {
|
||||
auto box = new QMessageBox(
|
||||
QMessageBox::Information, "Error getting logs",
|
||||
"No logs could be found for channel " + this->channelName_);
|
||||
box->setAttribute(Qt::WA_DeleteOnClose);
|
||||
box->show();
|
||||
box->raise();
|
||||
|
||||
static QSet<int> closeButtons{
|
||||
QMessageBox::Ok,
|
||||
QMessageBox::Close,
|
||||
};
|
||||
if (closeButtons.contains(box->exec()))
|
||||
{
|
||||
this->close();
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
req.onSuccess([this](auto result) -> Outcome {
|
||||
auto data = result.parseJson();
|
||||
std::vector<MessagePtr> messages;
|
||||
if (data.contains("lines"))
|
||||
{
|
||||
QJsonArray dataMessages = data.value("lines").toArray();
|
||||
for (auto i : dataMessages)
|
||||
static QSet<int> closeButtons{
|
||||
QMessageBox::Ok,
|
||||
QMessageBox::Close,
|
||||
};
|
||||
if (closeButtons.contains(box->exec()))
|
||||
{
|
||||
QJsonObject singleMessage = i.toObject();
|
||||
QTime timeStamp = QDateTime::fromSecsSinceEpoch(
|
||||
singleMessage.value("timestamp").toInt())
|
||||
.time();
|
||||
|
||||
MessageBuilder builder;
|
||||
builder.emplace<TimestampElement>(timeStamp);
|
||||
builder.emplace<TextElement>(this->userName_,
|
||||
MessageElementFlag::Username,
|
||||
MessageColor::System);
|
||||
builder.emplace<TextElement>(
|
||||
singleMessage.value("text").toString(),
|
||||
MessageElementFlag::Text, MessageColor::Text);
|
||||
messages.push_back(builder.release());
|
||||
this->close();
|
||||
}
|
||||
}
|
||||
this->setMessages(messages);
|
||||
|
||||
return Success;
|
||||
});
|
||||
return true;
|
||||
})
|
||||
.onSuccess([this](auto result) -> Outcome {
|
||||
auto data = result.parseJson();
|
||||
std::vector<MessagePtr> messages;
|
||||
if (data.contains("lines"))
|
||||
{
|
||||
QJsonArray dataMessages = data.value("lines").toArray();
|
||||
for (auto i : dataMessages)
|
||||
{
|
||||
QJsonObject singleMessage = i.toObject();
|
||||
QTime timeStamp =
|
||||
QDateTime::fromSecsSinceEpoch(
|
||||
singleMessage.value("timestamp").toInt())
|
||||
.time();
|
||||
|
||||
req.execute();
|
||||
MessageBuilder builder;
|
||||
builder.emplace<TimestampElement>(timeStamp);
|
||||
builder.emplace<TextElement>(this->userName_,
|
||||
MessageElementFlag::Username,
|
||||
MessageColor::System);
|
||||
builder.emplace<TextElement>(
|
||||
singleMessage.value("text").toString(),
|
||||
MessageElementFlag::Text, MessageColor::Text);
|
||||
messages.push_back(builder.release());
|
||||
}
|
||||
}
|
||||
this->setMessages(messages);
|
||||
|
||||
return Success;
|
||||
})
|
||||
.execute();
|
||||
}
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -350,26 +350,24 @@ void UserInfoPopup::updateUserData()
|
||||
|
||||
QString url("https://api.twitch.tv/kraken/channels/" + id);
|
||||
|
||||
auto request = NetworkRequest::twitchRequest(url);
|
||||
request.setCaller(this);
|
||||
NetworkRequest::twitchRequest(url)
|
||||
.caller(this)
|
||||
.onSuccess([this](auto result) -> Outcome {
|
||||
auto obj = result.parseJson();
|
||||
this->ui_.followerCountLabel->setText(
|
||||
TEXT_FOLLOWERS +
|
||||
QString::number(obj.value("followers").toInt()));
|
||||
this->ui_.viewCountLabel->setText(
|
||||
TEXT_VIEWS + QString::number(obj.value("views").toInt()));
|
||||
this->ui_.createdDateLabel->setText(
|
||||
TEXT_CREATED +
|
||||
obj.value("created_at").toString().section("T", 0, 0));
|
||||
|
||||
request.onSuccess([this](auto result) -> Outcome {
|
||||
auto obj = result.parseJson();
|
||||
this->ui_.followerCountLabel->setText(
|
||||
TEXT_FOLLOWERS +
|
||||
QString::number(obj.value("followers").toInt()));
|
||||
this->ui_.viewCountLabel->setText(
|
||||
TEXT_VIEWS + QString::number(obj.value("views").toInt()));
|
||||
this->ui_.createdDateLabel->setText(
|
||||
TEXT_CREATED +
|
||||
obj.value("created_at").toString().section("T", 0, 0));
|
||||
this->loadAvatar(QUrl(obj.value("logo").toString()));
|
||||
|
||||
this->loadAvatar(QUrl(obj.value("logo").toString()));
|
||||
|
||||
return Success;
|
||||
});
|
||||
|
||||
request.execute();
|
||||
return Success;
|
||||
})
|
||||
.execute();
|
||||
|
||||
// get follow state
|
||||
currentUser->checkFollow(id, [this, hack](auto result) {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/FlagsEnum.hpp"
|
||||
#include "messages/Image.hpp"
|
||||
#include "messages/LimitedQueue.hpp"
|
||||
#include "messages/LimitedQueueSnapshot.hpp"
|
||||
#include "messages/Selection.hpp"
|
||||
#include "messages/Image.hpp"
|
||||
#include "widgets/BaseWidget.hpp"
|
||||
|
||||
#include <QPaintEvent>
|
||||
|
||||
@@ -218,10 +218,10 @@ void GeneralPage::initLayout(SettingsLayout &layout)
|
||||
layout.addCheckbox("Hide moderated messages", s.hideModerated);
|
||||
layout.addCheckbox("Hide moderation messages", s.hideModerationActions);
|
||||
layout.addCheckbox("Colorize gray nicknames", s.colorizeNicknames);
|
||||
layout.addDropdown<int>(
|
||||
"Timeout stacking style", {"Stack", "Stack sparingly"},
|
||||
s.timeoutStackStyle, [](int index) { return index; },
|
||||
[](auto args) { return args.index; }, false);
|
||||
layout.addDropdown<int>("Timeout stacking style",
|
||||
{"Stack", "Stack sparingly"}, s.timeoutStackStyle,
|
||||
[](int index) { return index; },
|
||||
[](auto args) { return args.index; }, false);
|
||||
|
||||
layout.addTitle("Emotes");
|
||||
layout.addDropdown<float>(
|
||||
@@ -278,11 +278,11 @@ void GeneralPage::initLayout(SettingsLayout &layout)
|
||||
layout.addCheckbox("Double click links to open", s.linksDoubleClickOnly);
|
||||
layout.addCheckbox("Unshorten links", s.unshortLinks);
|
||||
layout.addCheckbox("Show live indicator in tabs", s.showTabLive);
|
||||
layout.addDropdown<int>(
|
||||
"Show emote preview in tooltip on hover",
|
||||
{"Don't show", "Always show", "Hold shift"}, s.emotesTooltipPreview,
|
||||
[](int index) { return index; }, [](auto args) { return args.index; },
|
||||
false);
|
||||
layout.addDropdown<int>("Show emote preview in tooltip on hover",
|
||||
{"Don't show", "Always show", "Hold shift"},
|
||||
s.emotesTooltipPreview,
|
||||
[](int index) { return index; },
|
||||
[](auto args) { return args.index; }, false);
|
||||
|
||||
layout.addCheckbox(
|
||||
"Only search for emote autocompletion at the start of emote names",
|
||||
|
||||
@@ -554,34 +554,31 @@ void Split::showViewerList()
|
||||
}
|
||||
auto loadingLabel = new QLabel("Loading...");
|
||||
|
||||
auto request = NetworkRequest::twitchRequest(
|
||||
"https://tmi.twitch.tv/group/user/" + this->getChannel()->getName() +
|
||||
"/chatters");
|
||||
NetworkRequest::twitchRequest("https://tmi.twitch.tv/group/user/" +
|
||||
this->getChannel()->getName() + "/chatters")
|
||||
.caller(this)
|
||||
.onSuccess([=](auto result) -> Outcome {
|
||||
auto obj = result.parseJson();
|
||||
QJsonObject chattersObj = obj.value("chatters").toObject();
|
||||
|
||||
request.setCaller(this);
|
||||
request.onSuccess([=](auto result) -> Outcome {
|
||||
auto obj = result.parseJson();
|
||||
QJsonObject chattersObj = obj.value("chatters").toObject();
|
||||
loadingLabel->hide();
|
||||
for (int i = 0; i < jsonLabels.size(); i++)
|
||||
{
|
||||
auto currentCategory =
|
||||
chattersObj.value(jsonLabels.at(i)).toArray();
|
||||
// If current category of chatters is empty, dont show this
|
||||
// category.
|
||||
if (currentCategory.empty())
|
||||
continue;
|
||||
|
||||
loadingLabel->hide();
|
||||
for (int i = 0; i < jsonLabels.size(); i++)
|
||||
{
|
||||
auto currentCategory =
|
||||
chattersObj.value(jsonLabels.at(i)).toArray();
|
||||
// If current category of chatters is empty, dont show this
|
||||
// category.
|
||||
if (currentCategory.empty())
|
||||
continue;
|
||||
chattersList->addItem(labelList.at(i));
|
||||
foreach (const QJsonValue &v, currentCategory)
|
||||
chattersList->addItem(v.toString());
|
||||
}
|
||||
|
||||
chattersList->addItem(labelList.at(i));
|
||||
foreach (const QJsonValue &v, currentCategory)
|
||||
chattersList->addItem(v.toString());
|
||||
}
|
||||
|
||||
return Success;
|
||||
});
|
||||
|
||||
request.execute();
|
||||
return Success;
|
||||
})
|
||||
.execute();
|
||||
|
||||
searchBar->setPlaceholderText("Search User...");
|
||||
QObject::connect(searchBar, &QLineEdit::textEdited, this, [=]() {
|
||||
|
||||
Reference in New Issue
Block a user