mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Merge pull request #702 from 23rd/patch-10-unshort-links
Added option of auto unshort links.
This commit is contained in:
commit
e332564e01
7 changed files with 43 additions and 7 deletions
|
@ -61,6 +61,12 @@ MessageElementFlags MessageElement::getFlags() const
|
||||||
return this->flags_;
|
return this->flags_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MessageElement *MessageElement::updateLink()
|
||||||
|
{
|
||||||
|
this->linkChanged.invoke();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
// IMAGE
|
// IMAGE
|
||||||
ImageElement::ImageElement(ImagePtr image, MessageElementFlags flags)
|
ImageElement::ImageElement(ImagePtr image, MessageElementFlags flags)
|
||||||
: MessageElement(flags)
|
: MessageElement(flags)
|
||||||
|
@ -152,6 +158,15 @@ void TextElement::addToContainer(MessageLayoutContainer &container,
|
||||||
color, this->style_, container.getScale()))
|
color, this->style_, container.getScale()))
|
||||||
->setLink(this->getLink());
|
->setLink(this->getLink());
|
||||||
e->setTrailingSpace(trailingSpace);
|
e->setTrailingSpace(trailingSpace);
|
||||||
|
|
||||||
|
// If URL link was changed,
|
||||||
|
// Should update it in MessageLayoutElement too!
|
||||||
|
if (this->getLink().type == Link::Url) {
|
||||||
|
this->linkChanged.connect(
|
||||||
|
[this, e]() {
|
||||||
|
e->setLink(this->getLink());
|
||||||
|
});
|
||||||
|
}
|
||||||
return e;
|
return e;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <pajlada/signals/signalholder.hpp>
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
class Channel;
|
class Channel;
|
||||||
|
@ -128,6 +129,7 @@ public:
|
||||||
const Link &getLink() const;
|
const Link &getLink() const;
|
||||||
bool hasTrailingSpace() const;
|
bool hasTrailingSpace() const;
|
||||||
MessageElementFlags getFlags() const;
|
MessageElementFlags getFlags() const;
|
||||||
|
MessageElement *updateLink();
|
||||||
|
|
||||||
virtual void addToContainer(MessageLayoutContainer &container,
|
virtual void addToContainer(MessageLayoutContainer &container,
|
||||||
MessageElementFlags flags) = 0;
|
MessageElementFlags flags) = 0;
|
||||||
|
@ -135,6 +137,7 @@ public:
|
||||||
protected:
|
protected:
|
||||||
MessageElement(MessageElementFlags flags);
|
MessageElement(MessageElementFlags flags);
|
||||||
bool trailingSpace = true;
|
bool trailingSpace = true;
|
||||||
|
pajlada::Signals::NoArgSignal linkChanged;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Link link_;
|
Link link_;
|
||||||
|
|
|
@ -2,13 +2,15 @@
|
||||||
|
|
||||||
#include "common/Common.hpp"
|
#include "common/Common.hpp"
|
||||||
#include "common/NetworkRequest.hpp"
|
#include "common/NetworkRequest.hpp"
|
||||||
|
#include "messages/Link.hpp"
|
||||||
|
#include "singletons/Settings.hpp"
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
|
|
||||||
void LinkResolver::getLinkInfo(const QString url,
|
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/" +
|
QString requestUrl("https://braize.pajlada.com/chatterino/link_resolver/" +
|
||||||
QUrl::toPercentEncoding(url, "", "/:"));
|
QUrl::toPercentEncoding(url, "", "/:"));
|
||||||
|
@ -16,22 +18,26 @@ void LinkResolver::getLinkInfo(const QString url,
|
||||||
NetworkRequest request(requestUrl);
|
NetworkRequest request(requestUrl);
|
||||||
request.setCaller(QThread::currentThread());
|
request.setCaller(QThread::currentThread());
|
||||||
request.setTimeout(30000);
|
request.setTimeout(30000);
|
||||||
request.onSuccess([successCallback](auto result) mutable -> Outcome {
|
request.onSuccess([successCallback, url](auto result) mutable -> Outcome {
|
||||||
auto root = result.parseJson();
|
auto root = result.parseJson();
|
||||||
auto statusCode = root.value("status").toInt();
|
auto statusCode = root.value("status").toInt();
|
||||||
QString response = QString();
|
QString response = QString();
|
||||||
|
QString linkString = url;
|
||||||
if (statusCode == 200) {
|
if (statusCode == 200) {
|
||||||
response = root.value("tooltip").toString();
|
response = root.value("tooltip").toString();
|
||||||
|
if (getSettings()->enableUnshortLinks) {
|
||||||
|
linkString = root.value("link").toString();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
response = root.value("message").toString();
|
response = root.value("message").toString();
|
||||||
}
|
}
|
||||||
successCallback(QUrl::fromPercentEncoding(response.toUtf8()));
|
successCallback(QUrl::fromPercentEncoding(response.toUtf8()), Link(Link::Url, linkString));
|
||||||
|
|
||||||
return Success;
|
return Success;
|
||||||
});
|
});
|
||||||
|
|
||||||
request.onError([successCallback](auto result) {
|
request.onError([successCallback, url](auto result) {
|
||||||
successCallback("No link info found");
|
successCallback("No link info found", Link(Link::Url, url));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,13 +3,15 @@
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
|
#include "messages/Link.hpp"
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
|
|
||||||
class LinkResolver
|
class LinkResolver
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static void getLinkInfo(const QString url,
|
static void getLinkInfo(const QString url,
|
||||||
std::function<void(QString)> callback);
|
std::function<void(QString, Link)> callback);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|
|
@ -280,11 +280,17 @@ void TwitchMessageBuilder::addTextOrEmoji(const QString &string_)
|
||||||
->setLink(link);
|
->setLink(link);
|
||||||
|
|
||||||
LinkResolver::getLinkInfo(
|
LinkResolver::getLinkInfo(
|
||||||
linkString, [linkMELowercase, linkMEOriginal](QString tooltipText) {
|
linkString, [linkMELowercase, linkMEOriginal, linkString]
|
||||||
|
(QString tooltipText, Link originalLink) {
|
||||||
if (!tooltipText.isEmpty()) {
|
if (!tooltipText.isEmpty()) {
|
||||||
linkMELowercase->setTooltip(tooltipText);
|
linkMELowercase->setTooltip(tooltipText);
|
||||||
linkMEOriginal->setTooltip(tooltipText);
|
linkMEOriginal->setTooltip(tooltipText);
|
||||||
}
|
}
|
||||||
|
if (originalLink.value != linkString &&
|
||||||
|
!originalLink.value.isEmpty()) {
|
||||||
|
linkMELowercase->setLink(originalLink)->updateLink();
|
||||||
|
linkMEOriginal->setLink(originalLink)->updateLink();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -104,6 +104,7 @@ public:
|
||||||
/// Links
|
/// Links
|
||||||
BoolSetting linksDoubleClickOnly = {"/links/doubleClickToOpen", false};
|
BoolSetting linksDoubleClickOnly = {"/links/doubleClickToOpen", false};
|
||||||
BoolSetting enableLinkInfoTooltip = {"/links/linkInfoTooltip", false};
|
BoolSetting enableLinkInfoTooltip = {"/links/linkInfoTooltip", false};
|
||||||
|
BoolSetting enableUnshortLinks = {"/links/unshortLinks", false};
|
||||||
BoolSetting enableLowercaseLink = {"/links/linkLowercase", true};
|
BoolSetting enableLowercaseLink = {"/links/linkLowercase", true};
|
||||||
|
|
||||||
/// Ingored Users
|
/// Ingored Users
|
||||||
|
|
|
@ -53,6 +53,9 @@ FeelPage::FeelPage()
|
||||||
form->addRow("",
|
form->addRow("",
|
||||||
this->createCheckBox("Show link info in tooltips",
|
this->createCheckBox("Show link info in tooltips",
|
||||||
getSettings()->enableLinkInfoTooltip));
|
getSettings()->enableLinkInfoTooltip));
|
||||||
|
form->addRow("",
|
||||||
|
this->createCheckBox("Auto unshort links (requires restart)",
|
||||||
|
getSettings()->enableUnshortLinks));
|
||||||
}
|
}
|
||||||
|
|
||||||
layout->addSpacing(16);
|
layout->addSpacing(16);
|
||||||
|
|
Loading…
Reference in a new issue