fix another link-resolver related crash (non auto url unshort-related)

This commit is contained in:
Rasmus Karlsson 2018-10-24 11:36:36 +02:00
parent 6ee7b1ef1f
commit 5497fec839
4 changed files with 17 additions and 2 deletions

View file

@ -196,6 +196,11 @@ MessagePtr MessageBuilder::release()
return ptr;
}
std::weak_ptr<Message> MessageBuilder::weakOf()
{
return this->message_;
}
void MessageBuilder::append(std::unique_ptr<MessageElement> element)
{
this->message().elements.push_back(std::move(element));

View file

@ -43,6 +43,7 @@ public:
Message *operator->();
Message &message();
MessagePtr release();
std::weak_ptr<Message> weakOf();
void append(std::unique_ptr<MessageElement> element);
QString matchLink(const QString &string);

View file

@ -15,6 +15,8 @@ void LinkResolver::getLinkInfo(
QString requestUrl("https://braize.pajlada.com/chatterino/link_resolver/" +
QUrl::toPercentEncoding(url, "", "/:"));
// Uncomment to test crashes
// QTimer::singleShot(3000, [=]() {
NetworkRequest request(requestUrl);
request.setCaller(QThread::currentThread());
request.setTimeout(30000);
@ -48,6 +50,7 @@ void LinkResolver::getLinkInfo(
});
request.execute();
// });
}
} // namespace chatterino

View file

@ -544,8 +544,14 @@ void TwitchMessageBuilder::addTextOrEmoji(const QString &string_)
->setLink(link);
LinkResolver::getLinkInfo(
linkString, [linkMELowercase, linkMEOriginal, linkString](
QString tooltipText, Link originalLink) {
linkString,
[weakMessage = this->weakOf(), linkMELowercase, linkMEOriginal,
linkString](QString tooltipText, Link originalLink) {
auto shared = weakMessage.lock();
if (!shared)
{
return;
}
if (!tooltipText.isEmpty())
{
linkMELowercase->setTooltip(tooltipText);