Fixed possible incorrect order of links in Ui.

This commit is contained in:
23rd 2022-02-03 23:37:55 +03:00
parent 4913288061
commit 80aa596310
3 changed files with 22 additions and 20 deletions

View File

@ -131,17 +131,17 @@ void HistoryMessageForwarded::create(const HistoryMessageVia *via) const {
phrase = tr::lng_forwarded_channel_via( phrase = tr::lng_forwarded_channel_via(
tr::now, tr::now,
lt_channel, lt_channel,
Ui::Text::Link(phrase.text, QString()), // Link 1. Ui::Text::Link(phrase.text, 1), // Link 1.
lt_inline_bot, lt_inline_bot,
Ui::Text::Link('@' + via->bot->username, {}), // Link 2. Ui::Text::Link('@' + via->bot->username, 2), // Link 2.
Ui::Text::WithEntities); Ui::Text::WithEntities);
} else { } else {
phrase = tr::lng_forwarded_via( phrase = tr::lng_forwarded_via(
tr::now, tr::now,
lt_user, lt_user,
Ui::Text::Link(phrase.text, QString()), // Link 1. Ui::Text::Link(phrase.text, 1), // Link 1.
lt_inline_bot, lt_inline_bot,
Ui::Text::Link('@' + via->bot->username, {}), // Link 2. Ui::Text::Link('@' + via->bot->username, 2), // Link 2.
Ui::Text::WithEntities); Ui::Text::WithEntities);
} }
} else { } else {

View File

@ -125,7 +125,7 @@ void HistoryService::setMessageByAction(const MTPmessageAction &action) {
lt_from, lt_from,
fromLinkText(), // Link 1. fromLinkText(), // Link 1.
lt_user, lt_user,
Ui::Text::Link(u->name, {}), // Link 2. Ui::Text::Link(u->name, 2), // Link 2.
Ui::Text::WithEntities); Ui::Text::WithEntities);
} }
} else if (users.isEmpty()) { } else if (users.isEmpty()) {
@ -253,7 +253,7 @@ void HistoryService::setMessageByAction(const MTPmessageAction &action) {
lt_from, lt_from,
fromLinkText(), // Link 1. fromLinkText(), // Link 1.
lt_user, lt_user,
Ui::Text::Link(user->name, {}), // Link 2. Ui::Text::Link(user->name, 2), // Link 2.
Ui::Text::WithEntities); Ui::Text::WithEntities);
} }
return result; return result;
@ -364,7 +364,7 @@ void HistoryService::setMessageByAction(const MTPmessageAction &action) {
result.text = tr::lng_action_secure_values_sent( result.text = tr::lng_action_secure_values_sent(
tr::now, tr::now,
lt_user, lt_user,
Ui::Text::Link(history()->peer->name, {}), // Link 1. Ui::Text::Link(history()->peer->name, QString()), // Link 1.
lt_documents, lt_documents,
{ .text = documents.join(", ") }, { .text = documents.join(", ") },
Ui::Text::WithEntities); Ui::Text::WithEntities);
@ -412,14 +412,14 @@ void HistoryService::setMessageByAction(const MTPmessageAction &action) {
lt_distance, lt_distance,
{ .text = distance }, { .text = distance },
lt_user, lt_user,
Ui::Text::Link(toPeer->name, {}), // Link 1. Ui::Text::Link(toPeer->name, QString()), // Link 1.
Ui::Text::WithEntities); Ui::Text::WithEntities);
} else if (toId == selfId) { } else if (toId == selfId) {
result.links.push_back(fromPeer->createOpenLink()); result.links.push_back(fromPeer->createOpenLink());
return tr::lng_action_proximity_reached_you( return tr::lng_action_proximity_reached_you(
tr::now, tr::now,
lt_from, lt_from,
Ui::Text::Link(fromPeer->name, {}), // Link 1. Ui::Text::Link(fromPeer->name, QString()), // Link 1.
lt_distance, lt_distance,
{ .text = distance }, { .text = distance },
Ui::Text::WithEntities); Ui::Text::WithEntities);
@ -429,11 +429,11 @@ void HistoryService::setMessageByAction(const MTPmessageAction &action) {
return tr::lng_action_proximity_reached( return tr::lng_action_proximity_reached(
tr::now, tr::now,
lt_from, lt_from,
Ui::Text::Link(fromPeer->name, {}), // Link 1. Ui::Text::Link(fromPeer->name, 1), // Link 1.
lt_distance, lt_distance,
{ .text = distance }, { .text = distance },
lt_user, lt_user,
Ui::Text::Link(toPeer->name, {}), // Link 2. Ui::Text::Link(toPeer->name, 2), // Link 2.
Ui::Text::WithEntities); Ui::Text::WithEntities);
} }
}(); }();
@ -796,10 +796,11 @@ HistoryService::PreparedText HistoryService::prepareInvitedToCallText(
Ui::Text::WithEntities); Ui::Text::WithEntities);
auto result = PreparedText{}; auto result = PreparedText{};
result.links.push_back(fromLink()); result.links.push_back(fromLink());
auto linkIndex = 1;
if (linkCallId) { if (linkCallId) {
const auto peer = history()->peer; const auto peer = history()->peer;
result.links.push_back(GroupCallClickHandler(peer, linkCallId)); result.links.push_back(GroupCallClickHandler(peer, linkCallId));
chatText = Ui::Text::Link(chatText.text, {}); chatText = Ui::Text::Link(chatText.text, ++linkIndex);
} }
if (users.size() == 1) { if (users.size() == 1) {
auto user = owner->user(users[0].v); auto user = owner->user(users[0].v);
@ -809,7 +810,7 @@ HistoryService::PreparedText HistoryService::prepareInvitedToCallText(
lt_from, lt_from,
fromLinkText(), // Link 1. fromLinkText(), // Link 1.
lt_user, lt_user,
Ui::Text::Link(user->name, {}), // Link N. Ui::Text::Link(user->name, ++linkIndex), // Link N.
lt_chat, lt_chat,
chatText, chatText,
Ui::Text::WithEntities); Ui::Text::WithEntities);
@ -828,7 +829,7 @@ HistoryService::PreparedText HistoryService::prepareInvitedToCallText(
auto user = owner->user(users[i].v); auto user = owner->user(users[i].v);
result.links.push_back(user->createOpenLink()); result.links.push_back(user->createOpenLink());
auto linkText = Ui::Text::Link(user->name, {}); auto linkText = Ui::Text::Link(user->name, ++linkIndex);
if (i == 0) { if (i == 0) {
result.text = linkText; result.text = linkText;
} else if (i + 1 == l) { } else if (i + 1 == l) {
@ -903,7 +904,8 @@ HistoryService::PreparedText HistoryService::preparePinnedText() {
} }
original = Ui::Text::Wrapped( original = Ui::Text::Wrapped(
std::move(original), std::move(original),
EntityType::CustomUrl); EntityType::CustomUrl,
Ui::Text::Link({}, 2).entities.front().data());
result.text = tr::lng_action_pinned_message( result.text = tr::lng_action_pinned_message(
tr::now, tr::now,
lt_from, lt_from,
@ -917,7 +919,7 @@ HistoryService::PreparedText HistoryService::preparePinnedText() {
lt_from, lt_from,
fromLinkText(), // Link 1. fromLinkText(), // Link 1.
lt_media, lt_media,
Ui::Text::Link(mediaText, {}), // Link 2. Ui::Text::Link(mediaText, 2), // Link 2.
Ui::Text::WithEntities); Ui::Text::WithEntities);
} }
} else if (pinned && pinned->msgId) { } else if (pinned && pinned->msgId) {
@ -928,7 +930,7 @@ HistoryService::PreparedText HistoryService::preparePinnedText() {
lt_from, lt_from,
fromLinkText(), // Link 1. fromLinkText(), // Link 1.
lt_media, lt_media,
Ui::Text::Link(tr::lng_contacts_loading(tr::now), {}), // Link 2. Ui::Text::Link(tr::lng_contacts_loading(tr::now), 2), // Link 2.
Ui::Text::WithEntities); Ui::Text::WithEntities);
} else { } else {
result.links.push_back(fromLink()); result.links.push_back(fromLink());
@ -1207,7 +1209,7 @@ std::unique_ptr<HistoryView::Element> HistoryService::createView(
} }
TextWithEntities HistoryService::fromLinkText() const { TextWithEntities HistoryService::fromLinkText() const {
return Ui::Text::Link(_from->name, {}); return Ui::Text::Link(_from->name, 1);
} }
ClickHandlerPtr HistoryService::fromLink() const { ClickHandlerPtr HistoryService::fromLink() const {

View File

@ -652,11 +652,11 @@ MainMenu::MainMenu(
tr::now, tr::now,
lt_version, lt_version,
currentVersionText()), currentVersionText()),
{}) // Link 1. 1) // Link 1.
.append(QChar(' ')) .append(QChar(' '))
.append(QChar(8211)) .append(QChar(8211))
.append(QChar(' ')) .append(QChar(' '))
.append(Ui::Text::Link(tr::lng_menu_about(tr::now), {}))); // Link 2. .append(Ui::Text::Link(tr::lng_menu_about(tr::now), 2))); // Link 2.
_version->setLink( _version->setLink(
1, 1,
std::make_shared<UrlClickHandler>(Core::App().changelogLink())); std::make_shared<UrlClickHandler>(Core::App().changelogLink()));