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_;
|
||||
}
|
||||
|
||||
MessageElement *MessageElement::updateLink()
|
||||
{
|
||||
this->linkChanged.invoke();
|
||||
return this;
|
||||
}
|
||||
|
||||
// IMAGE
|
||||
ImageElement::ImageElement(ImagePtr image, MessageElementFlags flags)
|
||||
: MessageElement(flags)
|
||||
|
@ -152,6 +158,15 @@ void TextElement::addToContainer(MessageLayoutContainer &container,
|
|||
color, this->style_, container.getScale()))
|
||||
->setLink(this->getLink());
|
||||
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;
|
||||
};
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <pajlada/signals/signalholder.hpp>
|
||||
|
||||
namespace chatterino {
|
||||
class Channel;
|
||||
|
@ -128,6 +129,7 @@ public:
|
|||
const Link &getLink() const;
|
||||
bool hasTrailingSpace() const;
|
||||
MessageElementFlags getFlags() const;
|
||||
MessageElement *updateLink();
|
||||
|
||||
virtual void addToContainer(MessageLayoutContainer &container,
|
||||
MessageElementFlags flags) = 0;
|
||||
|
@ -135,6 +137,7 @@ public:
|
|||
protected:
|
||||
MessageElement(MessageElementFlags flags);
|
||||
bool trailingSpace = true;
|
||||
pajlada::Signals::NoArgSignal linkChanged;
|
||||
|
||||
private:
|
||||
Link link_;
|
||||
|
|
|
@ -2,13 +2,15 @@
|
|||
|
||||
#include "common/Common.hpp"
|
||||
#include "common/NetworkRequest.hpp"
|
||||
#include "messages/Link.hpp"
|
||||
#include "singletons/Settings.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,22 +18,26 @@ 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();
|
||||
if (getSettings()->enableUnshortLinks) {
|
||||
linkString = root.value("link").toString();
|
||||
}
|
||||
} else {
|
||||
response = root.value("message").toString();
|
||||
}
|
||||
successCallback(QUrl::fromPercentEncoding(response.toUtf8()));
|
||||
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:
|
||||
};
|
||||
|
|
|
@ -280,11 +280,17 @@ void TwitchMessageBuilder::addTextOrEmoji(const QString &string_)
|
|||
->setLink(link);
|
||||
|
||||
LinkResolver::getLinkInfo(
|
||||
linkString, [linkMELowercase, linkMEOriginal](QString tooltipText) {
|
||||
linkString, [linkMELowercase, linkMEOriginal, linkString]
|
||||
(QString tooltipText, Link originalLink) {
|
||||
if (!tooltipText.isEmpty()) {
|
||||
linkMELowercase->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
|
||||
BoolSetting linksDoubleClickOnly = {"/links/doubleClickToOpen", false};
|
||||
BoolSetting enableLinkInfoTooltip = {"/links/linkInfoTooltip", false};
|
||||
BoolSetting enableUnshortLinks = {"/links/unshortLinks", false};
|
||||
BoolSetting enableLowercaseLink = {"/links/linkLowercase", true};
|
||||
|
||||
/// Ingored Users
|
||||
|
|
|
@ -53,6 +53,9 @@ FeelPage::FeelPage()
|
|||
form->addRow("",
|
||||
this->createCheckBox("Show link info in tooltips",
|
||||
getSettings()->enableLinkInfoTooltip));
|
||||
form->addRow("",
|
||||
this->createCheckBox("Auto unshort links (requires restart)",
|
||||
getSettings()->enableUnshortLinks));
|
||||
}
|
||||
|
||||
layout->addSpacing(16);
|
||||
|
|
Loading…
Reference in a new issue