mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-09-05 17:06:03 +00:00
Allow sending just webpage preview.
This commit is contained in:
@@ -601,6 +601,12 @@ MessageLinksParser::MessageLinksParser(not_null<Ui::InputField*> field)
|
||||
_lifetime = _field->changes(
|
||||
) | rpl::start_with_next([=] {
|
||||
const auto length = _field->getTextWithTags().text.size();
|
||||
if (!length) {
|
||||
_lastLength = 0;
|
||||
_timer.cancel();
|
||||
parse();
|
||||
return;
|
||||
}
|
||||
const auto timeout = (std::abs(length - _lastLength) > 2)
|
||||
? 0
|
||||
: kParseLinksTimeout;
|
||||
@@ -652,6 +658,7 @@ void MessageLinksParser::parse() {
|
||||
const auto &tags = textWithTags.tags;
|
||||
const auto &markdownTags = _field->getMarkdownTags();
|
||||
if (_disabled || text.isEmpty()) {
|
||||
_ranges = {};
|
||||
_list = QStringList();
|
||||
return;
|
||||
}
|
||||
@@ -663,7 +670,7 @@ void MessageLinksParser::parse() {
|
||||
|| (tag == Ui::InputField::kTagSpoiler);
|
||||
};
|
||||
|
||||
auto ranges = QVector<LinkRange>();
|
||||
_ranges.clear();
|
||||
|
||||
auto tag = tags.begin();
|
||||
const auto tagsEnd = tags.end();
|
||||
@@ -672,7 +679,7 @@ void MessageLinksParser::parse() {
|
||||
|
||||
if (Ui::InputField::IsValidMarkdownLink(tag->id)
|
||||
&& !TextUtilities::IsMentionLink(tag->id)) {
|
||||
ranges.push_back({ tag->offset, tag->length, tag->id });
|
||||
_ranges.push_back({ tag->offset, tag->length, tag->id });
|
||||
}
|
||||
++tag;
|
||||
};
|
||||
@@ -782,20 +789,18 @@ void MessageLinksParser::parse() {
|
||||
processTagsBefore(domainOffset);
|
||||
if (!hasTagsIntersection(range.start + range.length)) {
|
||||
if (markdownTagsAllow(range.start, range.length)) {
|
||||
ranges.push_back(range);
|
||||
_ranges.push_back(range);
|
||||
}
|
||||
}
|
||||
offset = matchOffset = p - start;
|
||||
}
|
||||
processTagsBefore(Ui::kQFixedMax);
|
||||
|
||||
apply(text, ranges);
|
||||
applyRanges(text);
|
||||
}
|
||||
|
||||
void MessageLinksParser::apply(
|
||||
const QString &text,
|
||||
const QVector<LinkRange> &ranges) {
|
||||
const auto count = int(ranges.size());
|
||||
void MessageLinksParser::applyRanges(const QString &text) {
|
||||
const auto count = int(_ranges.size());
|
||||
const auto current = _list.current();
|
||||
const auto computeLink = [&](const LinkRange &range) {
|
||||
return range.custom.isEmpty()
|
||||
@@ -807,7 +812,7 @@ void MessageLinksParser::apply(
|
||||
return true;
|
||||
}
|
||||
for (auto i = 0; i != count; ++i) {
|
||||
if (computeLink(ranges[i]) != current[i]) {
|
||||
if (computeLink(_ranges[i]) != current[i]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -818,7 +823,7 @@ void MessageLinksParser::apply(
|
||||
}
|
||||
auto parsed = QStringList();
|
||||
parsed.reserve(count);
|
||||
for (const auto &range : ranges) {
|
||||
for (const auto &range : _ranges) {
|
||||
parsed.push_back(computeLink(range).toString());
|
||||
}
|
||||
_list = std::move(parsed);
|
||||
|
Reference in New Issue
Block a user