mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Fixed build.
This commit is contained in:
parent
fe24d09009
commit
2d1701cf86
3 changed files with 12 additions and 8 deletions
|
@ -2,13 +2,14 @@
|
|||
|
||||
#include "common/Common.hpp"
|
||||
#include "common/NetworkRequest.hpp"
|
||||
#include "messages/Link.hpp"
|
||||
|
||||
#include <QString>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
void LinkResolver::getLinkInfo(const QString url,
|
||||
std::function<void(QString)> successCallback)
|
||||
std::function<void(QString, Link)> successCallback)
|
||||
{
|
||||
QString requestUrl("https://braize.pajlada.com/chatterino/link_resolver/" +
|
||||
QUrl::toPercentEncoding(url, "", "/:"));
|
||||
|
@ -16,23 +17,24 @@ void LinkResolver::getLinkInfo(const QString url,
|
|||
NetworkRequest request(requestUrl);
|
||||
request.setCaller(QThread::currentThread());
|
||||
request.setTimeout(30000);
|
||||
request.onSuccess([successCallback](auto result) mutable -> Outcome {
|
||||
request.onSuccess([successCallback, url](auto result) mutable -> Outcome {
|
||||
auto root = result.parseJson();
|
||||
auto statusCode = root.value("status").toInt();
|
||||
QString response = QString();
|
||||
QString linkString = url;
|
||||
if (statusCode == 200) {
|
||||
response = root.value("tooltip").toString();
|
||||
url = root.value("link").toString();
|
||||
linkString = root.value("link").toString();
|
||||
} else {
|
||||
response = root.value("message").toString();
|
||||
}
|
||||
successCallback(QUrl::fromPercentEncoding(response.toUtf8()), url);
|
||||
successCallback(QUrl::fromPercentEncoding(response.toUtf8()), Link(Link::Url, linkString));
|
||||
|
||||
return Success;
|
||||
});
|
||||
|
||||
request.onError([successCallback](auto result) {
|
||||
successCallback("No link info found");
|
||||
request.onError([successCallback, url](auto result) {
|
||||
successCallback("No link info found", Link(Link::Url, url));
|
||||
|
||||
return true;
|
||||
});
|
||||
|
|
|
@ -3,13 +3,15 @@
|
|||
#include <QString>
|
||||
#include <functional>
|
||||
|
||||
#include "messages/Link.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class LinkResolver
|
||||
{
|
||||
public:
|
||||
static void getLinkInfo(const QString url,
|
||||
std::function<void(QString)> callback);
|
||||
std::function<void(QString, Link)> callback);
|
||||
|
||||
private:
|
||||
};
|
||||
|
|
|
@ -281,7 +281,7 @@ void TwitchMessageBuilder::addTextOrEmoji(const QString &string_)
|
|||
|
||||
LinkResolver::getLinkInfo(
|
||||
linkString, [linkMELowercase, linkMEOriginal](QString tooltipText,
|
||||
QString originalLink) {
|
||||
Link originalLink) {
|
||||
if (!tooltipText.isEmpty()) {
|
||||
linkMELowercase->setTooltip(tooltipText)
|
||||
->setLink(originalLink);
|
||||
|
|
Loading…
Reference in a new issue