2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +00:00

Extract username from t.me/username searches.

This commit is contained in:
John Preston
2019-08-06 15:54:44 +01:00
parent 10e28913ca
commit f48732f813
4 changed files with 28 additions and 9 deletions

View File

@@ -23,7 +23,7 @@ using Key = details::SingleMessageSearchKey;
Key ExtractKey(const QString &query) {
const auto trimmed = query.trimmed();
const auto local = Core::TryConvertUrlToLocal(query);
const auto local = Core::TryConvertUrlToLocal(trimmed);
const auto check = local.isEmpty() ? trimmed : local;
const auto parse = [&] {
const auto delimeter = check.indexOf('?');
@@ -216,4 +216,20 @@ std::optional<HistoryItem*> SingleMessageSearch::performLookup(
return performLookupById(channelId, ready);
}
QString ConvertPeerSearchQuery(const QString &query) {
const auto trimmed = query.trimmed();
const auto local = Core::TryConvertUrlToLocal(trimmed);
const auto check = local.isEmpty() ? trimmed : local;
if (!check.startsWith(qstr("tg://resolve"), Qt::CaseInsensitive)) {
return query;
}
const auto delimeter = check.indexOf('?');
const auto params = (delimeter > 0)
? qthelp::url_parse_params(
check.mid(delimeter + 1),
qthelp::UrlParamNameTransform::ToLower)
: QMap<QString, QString>();
return params.value("domain", query);
}
} // namespace Api

View File

@@ -71,4 +71,6 @@ private:
};
[[nodiscard]] QString ConvertPeerSearchQuery(const QString &query);
} // namespace Api