mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-03-01 12:00:48 +00:00
Improve checks for a hidden webpage url.
This commit is contained in:
parent
c20ab0b93e
commit
a2b04c9d71
@ -3473,14 +3473,34 @@ QSize HistoryWebPage::countOptimalSize() {
|
|||||||
|
|
||||||
if (!_openl && !_data->url.isEmpty()) {
|
if (!_openl && !_data->url.isEmpty()) {
|
||||||
const auto previewOfHiddenUrl = [&] {
|
const auto previewOfHiddenUrl = [&] {
|
||||||
|
const auto simplify = [](const QString &url) {
|
||||||
|
auto result = url.toLower();
|
||||||
|
if (result.endsWith('/')) {
|
||||||
|
result.chop(1);
|
||||||
|
}
|
||||||
|
const auto prefixes = { qstr("http://"), qstr("https://") };
|
||||||
|
for (const auto &prefix : prefixes) {
|
||||||
|
if (result.startsWith(prefix)) {
|
||||||
|
result = result.mid(prefix.size());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
const auto simplified = simplify(_data->url);
|
||||||
const auto full = _parent->data()->originalText();
|
const auto full = _parent->data()->originalText();
|
||||||
for (const auto &entity : full.entities) {
|
for (const auto &entity : full.entities) {
|
||||||
if (entity.type() == EntityInTextCustomUrl
|
if (entity.type() != EntityInTextUrl) {
|
||||||
&& entity.data() == _data->url) {
|
continue;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
const auto link = full.text.mid(
|
||||||
|
entity.offset(),
|
||||||
|
entity.length());
|
||||||
|
if (simplify(link) == simplified) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}();
|
}();
|
||||||
_openl = previewOfHiddenUrl
|
_openl = previewOfHiddenUrl
|
||||||
? std::make_shared<HiddenUrlClickHandler>(_data->url)
|
? std::make_shared<HiddenUrlClickHandler>(_data->url)
|
||||||
|
Loading…
Reference in New Issue
Block a user