diff --git a/Telegram/SourceFiles/api/api_chat_invite.cpp b/Telegram/SourceFiles/api/api_chat_invite.cpp index fdf14757d..d9e1bec68 100644 --- a/Telegram/SourceFiles/api/api_chat_invite.cpp +++ b/Telegram/SourceFiles/api/api_chat_invite.cpp @@ -280,7 +280,7 @@ void ConfirmInviteBox::prepare() { auto name = new Ui::FlatLabel(this, st::confirmInviteUserName); name->resizeToWidth(st::confirmInviteUserPhotoSize + padding); name->setText(participant.user->firstName.isEmpty() - ? participant.user->name + ? participant.user->name() : participant.user->firstName); name->moveToLeft(left + (padding / 2), st::confirmInviteUserNameTop); left += _userWidth; diff --git a/Telegram/SourceFiles/api/api_sending.cpp b/Telegram/SourceFiles/api/api_sending.cpp index 73e3b0dfd..6c2f78d07 100644 --- a/Telegram/SourceFiles/api/api_sending.cpp +++ b/Telegram/SourceFiles/api/api_sending.cpp @@ -103,7 +103,7 @@ void SendExistingMedia( sendFlags |= MTPmessages_SendMedia::Flag::f_send_as; } const auto messagePostAuthor = peer->isBroadcast() - ? session->user()->name + ? session->user()->name() : QString(); auto caption = TextWithEntities{ @@ -290,7 +290,7 @@ bool SendDice(MessageToSend &message) { sendFlags |= MTPmessages_SendMedia::Flag::f_send_as; } const auto messagePostAuthor = peer->isBroadcast() - ? session->user()->name + ? session->user()->name() : QString(); const auto replyTo = message.action.replyTo; @@ -423,7 +423,7 @@ void SendConfirmedFile( ? PeerId() : session->userPeerId(); const auto messagePostAuthor = peer->isBroadcast() - ? session->user()->name + ? session->user()->name() : QString(); const auto media = MTPMessageMedia([&] { diff --git a/Telegram/SourceFiles/api/api_who_reacted.cpp b/Telegram/SourceFiles/api/api_who_reacted.cpp index 48958e6d3..1af33f570 100644 --- a/Telegram/SourceFiles/api/api_who_reacted.cpp +++ b/Telegram/SourceFiles/api/api_who_reacted.cpp @@ -426,12 +426,12 @@ void RegenerateParticipants(not_null state, int small, int large) { const auto id = peer->id.value; const auto was = ranges::find(old, id, &Ui::WhoReadParticipant::id); if (was != end(old)) { - was->name = peer->name; + was->name = peer->name(); now.push_back(std::move(*was)); continue; } now.push_back({ - .name = peer->name, + .name = peer->name(), .reaction = userpic.reaction, .userpicLarge = GenerateUserpic(userpic, large), .userpicKey = userpic.uniqueKey, diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index 47b7b4785..b89078fc2 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -3199,7 +3199,7 @@ void ApiWrap::forwardMessages( ? PeerId(0) : self->id; const auto messagePostAuthor = peer->isBroadcast() - ? self->name + ? self->name() : QString(); history->addNewLocalMessage( newId.msg, @@ -3282,7 +3282,7 @@ void ApiWrap::sendSharedContact( ? PeerId() : _session->userPeerId(); const auto messagePostAuthor = peer->isBroadcast() - ? _session->user()->name + ? _session->user()->name() : QString(); const auto viaBotId = UserId(); const auto item = history->addNewLocalMessage( @@ -3545,7 +3545,7 @@ void ApiWrap::sendMessage(MessageToSend &&message) { sendFlags |= MTPmessages_SendMessage::Flag::f_send_as; } const auto messagePostAuthor = peer->isBroadcast() - ? _session->user()->name + ? _session->user()->name() : QString(); if (action.options.scheduled) { flags |= MessageFlag::IsOrWasScheduled; @@ -3693,7 +3693,7 @@ void ApiWrap::sendInlineResult( sendFlags |= MTPmessages_SendInlineBotResult::Flag::f_send_as; } const auto messagePostAuthor = peer->isBroadcast() - ? _session->user()->name + ? _session->user()->name() : QString(); _session->data().registerMessageRandomId(randomId, newId); diff --git a/Telegram/SourceFiles/boxes/add_contact_box.cpp b/Telegram/SourceFiles/boxes/add_contact_box.cpp index 87ce676f8..9d444dd44 100644 --- a/Telegram/SourceFiles/boxes/add_contact_box.cpp +++ b/Telegram/SourceFiles/boxes/add_contact_box.cpp @@ -1091,7 +1091,7 @@ void SetupChannelBox::save() { MTP_string(_sentUsername) )).done([=] { _channel->setName( - TextUtilities::SingleLine(_channel->name), + TextUtilities::SingleLine(_channel->name()), _sentUsername); closeBox(); }).fail([=](const MTP::Error &error) { @@ -1239,7 +1239,7 @@ void SetupChannelBox::updateFail(UsernameResult result) { if ((result == UsernameResult::Ok) || (_sentUsername == _channel->username)) { _channel->setName( - TextUtilities::SingleLine(_channel->name), + TextUtilities::SingleLine(_channel->name()), TextUtilities::SingleLine(_sentUsername)); closeBox(); } else if (result == UsernameResult::Invalid) { diff --git a/Telegram/SourceFiles/boxes/choose_filter_box.cpp b/Telegram/SourceFiles/boxes/choose_filter_box.cpp index 0471998de..d7fdaabbe 100644 --- a/Telegram/SourceFiles/boxes/choose_filter_box.cpp +++ b/Telegram/SourceFiles/boxes/choose_filter_box.cpp @@ -69,7 +69,7 @@ void ChangeFilterById( MTP_flags(MTPmessages_UpdateDialogFilter::Flag::f_filter), MTP_int(filter.id()), filter.tl() - )).done([=, chat = history->peer->name, filterName = filter.title()] { + )).done([=, chat = history->peer->name(), name = filter.title()]{ // Since only the primary window has dialogs list, // We can safely show toast there. if (const auto controller = Core::App().primaryWindow()) { @@ -80,7 +80,7 @@ void ChangeFilterById( lt_chat, Ui::Text::Bold(chat), lt_folder, - Ui::Text::Bold(filterName), + Ui::Text::Bold(name), Ui::Text::WithEntities); Ui::Toast::Show( Window::Show(controller).toastParent(), diff --git a/Telegram/SourceFiles/boxes/delete_messages_box.cpp b/Telegram/SourceFiles/boxes/delete_messages_box.cpp index 79db2c7ef..87af104aa 100644 --- a/Telegram/SourceFiles/boxes/delete_messages_box.cpp +++ b/Telegram/SourceFiles/boxes/delete_messages_box.cpp @@ -120,20 +120,29 @@ void DeleteMessagesBox::prepare() { : peer->isSelf() ? tr::lng_sure_delete_saved_messages(tr::now) : peer->isUser() - ? tr::lng_sure_delete_history(tr::now, lt_contact, peer->name) + ? tr::lng_sure_delete_history( + tr::now, + lt_contact, + peer->name()) : tr::lng_sure_delete_group_history( tr::now, lt_group, - peer->name); + peer->name()); details = Ui::Text::RichLangValue(details.text); deleteStyle = &st::attentionBoxButton; } else { details.text = peer->isSelf() ? tr::lng_sure_delete_saved_messages(tr::now) : peer->isUser() - ? tr::lng_sure_delete_history(tr::now, lt_contact, peer->name) + ? tr::lng_sure_delete_history( + tr::now, + lt_contact, + peer->name()) : peer->isChat() - ? tr::lng_sure_delete_and_exit(tr::now, lt_group, peer->name) + ? tr::lng_sure_delete_and_exit( + tr::now, + lt_group, + peer->name()) : peer->isMegagroup() ? tr::lng_sure_leave_group(tr::now) : tr::lng_sure_leave_channel(tr::now); @@ -189,7 +198,7 @@ void DeleteMessagesBox::prepare() { tr::lng_delete_all_from_user( tr::now, lt_user, - Ui::Text::Bold(_moderateFrom->name), + Ui::Text::Bold(_moderateFrom->name()), Ui::Text::WithEntities), false, st::defaultBoxCheckbox); diff --git a/Telegram/SourceFiles/boxes/filters/edit_filter_box.cpp b/Telegram/SourceFiles/boxes/filters/edit_filter_box.cpp index 27acc6bf1..175dbeb08 100644 --- a/Telegram/SourceFiles/boxes/filters/edit_filter_box.cpp +++ b/Telegram/SourceFiles/boxes/filters/edit_filter_box.cpp @@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "chat_helpers/emoji_suggestions_widget.h" #include "ui/layers/generic_box.h" #include "ui/text/text_utilities.h" +#include "ui/text/text_options.h" #include "ui/widgets/buttons.h" #include "ui/widgets/input_fields.h" #include "ui/effects/panel_animation.h" @@ -82,6 +83,7 @@ private: struct PeerButton { not_null history; std::shared_ptr userpic; + Ui::Text::String name; Button button; }; @@ -208,7 +210,7 @@ int FilterChatsPreview::resizeGetHeight(int newWidth) { for (const auto &[flag, button] : _removeFlag) { moveNextButton(button.get()); } - for (const auto &[history, userpic, button] : _removePeer) { + for (const auto &[history, userpic, name, button] : _removePeer) { moveNextButton(button.get()); } return top; @@ -240,7 +242,7 @@ void FilterChatsPreview::paintEvent(QPaintEvent *e) { FilterChatsTypeName(flag)); top += st.height; } - for (auto &[history, userpic, button] : _removePeer) { + for (auto &[history, userpic, name, button] : _removePeer) { const auto savedMessages = history->peer->isSelf(); const auto repliesMessages = history->peer->isRepliesChat(); if (savedMessages || repliesMessages) { @@ -276,7 +278,13 @@ void FilterChatsPreview::paintEvent(QPaintEvent *e) { width(), st.photoSize); p.setPen(st::contactsNameFg); - history->peer->nameText().drawLeftElided( + if (name.isEmpty()) { + name.setText( + st::msgNameStyle, + history->peer->name(), + Ui::NameTextOptions()); + } + name.drawLeftElided( p, nameLeft, top + nameTop, diff --git a/Telegram/SourceFiles/boxes/mute_settings_box.cpp b/Telegram/SourceFiles/boxes/mute_settings_box.cpp index 07da7ca13..e7b779ef3 100644 --- a/Telegram/SourceFiles/boxes/mute_settings_box.cpp +++ b/Telegram/SourceFiles/boxes/mute_settings_box.cpp @@ -46,7 +46,7 @@ void MuteSettingsBox::prepare() { icon->moveToLeft(st::boxPadding.left(), y); object_ptr title(this, st::muteChatTitle); - title->setText(_peer->name); + title->setText(_peer->name()); title->moveToLeft( st::boxPadding.left() + st::muteChatTitleLeft, y + (icon->height() / 2) - (title->height() / 2)); diff --git a/Telegram/SourceFiles/boxes/peer_list_box.cpp b/Telegram/SourceFiles/boxes/peer_list_box.cpp index 4fc36e825..d81ba849e 100644 --- a/Telegram/SourceFiles/boxes/peer_list_box.cpp +++ b/Telegram/SourceFiles/boxes/peer_list_box.cpp @@ -613,7 +613,7 @@ void PeerListRow::elementsPaint( } QString PeerListRow::generateName() { - return peer()->name; + return peer()->name(); } QString PeerListRow::generateShortName() { diff --git a/Telegram/SourceFiles/boxes/peers/add_bot_to_chat_box.cpp b/Telegram/SourceFiles/boxes/peers/add_bot_to_chat_box.cpp index 014c10036..ffc32993d 100644 --- a/Telegram/SourceFiles/boxes/peers/add_bot_to_chat_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/add_bot_to_chat_box.cpp @@ -207,9 +207,15 @@ void AddBotToGroupBoxController::shareBotGame(not_null chat) { }); auto confirmText = [chat] { if (chat->isUser()) { - return tr::lng_bot_sure_share_game(tr::now, lt_user, chat->name); + return tr::lng_bot_sure_share_game( + tr::now, + lt_user, + chat->name()); } - return tr::lng_bot_sure_share_game_group(tr::now, lt_group, chat->name); + return tr::lng_bot_sure_share_game_group( + tr::now, + lt_group, + chat->name()); }(); _controller->show( Ui::MakeConfirmBox({ @@ -320,7 +326,7 @@ void AddBotToGroupBoxController::addBotToGroup(not_null chat) { }); controller->show( Ui::MakeConfirmBox({ - tr::lng_bot_sure_invite(tr::now, lt_group, chat->name), + tr::lng_bot_sure_invite(tr::now, lt_group, chat->name()), std::move(callback), }), Ui::LayerOption::KeepOther); diff --git a/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp b/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp index 22be3088f..419e9cf2d 100644 --- a/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp @@ -262,16 +262,16 @@ void AddParticipantsBoxController::inviteSelectedUsers( ? tr::lng_participant_invite_sure( tr::now, lt_user, - { users.front()->name }, + { users.front()->name()}, lt_group, - { _peer->name }, + { _peer->name()}, Ui::Text::RichLangValue) : tr::lng_participant_invite_sure_many( tr::now, lt_count, int(users.size()), lt_group, - { _peer->name }, + { _peer->name() }, Ui::Text::RichLangValue); Ui::ConfirmBox(box, { .text = std::move(text), @@ -834,7 +834,7 @@ void AddSpecialBoxController::kickUser( : tr::lng_profile_sure_kick_channel)( tr::now, lt_user, - participant->name); + participant->name()); _editBox = showBox(Ui::MakeConfirmBox({ text, kickUserSure })); return; } diff --git a/Telegram/SourceFiles/boxes/peers/edit_linked_chat_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_linked_chat_box.cpp index b2d675d3e..d127053c0 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_linked_chat_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_linked_chat_box.cpp @@ -134,9 +134,9 @@ void Controller::choose(not_null chat) { auto text = tr::lng_manage_discussion_group_sure( tr::now, lt_group, - Ui::Text::Bold(chat->name), + Ui::Text::Bold(chat->name()), lt_channel, - Ui::Text::Bold(_channel->name), + Ui::Text::Bold(_channel->name()), Ui::Text::WithEntities); if (!_channel->isPublic()) { text.append( @@ -170,9 +170,9 @@ void Controller::choose(not_null chat) { auto text = tr::lng_manage_discussion_group_sure( tr::now, lt_group, - Ui::Text::Bold(chat->name), + Ui::Text::Bold(chat->name()), lt_channel, - Ui::Text::Bold(_channel->name), + Ui::Text::Bold(_channel->name()), Ui::Text::WithEntities); if (!_channel->isPublic()) { text.append("\n\n" + tr::lng_manage_linked_channel_private(tr::now)); @@ -212,13 +212,13 @@ object_ptr SetupAbout( return tr::lng_manage_linked_channel_about( tr::now, lt_channel, - Ui::Text::Bold(chat->name), + Ui::Text::Bold(chat->name()), Ui::Text::WithEntities); } else if (chat != nullptr) { return tr::lng_manage_discussion_group_about_chosen( tr::now, lt_group, - Ui::Text::Bold(chat->name), + Ui::Text::Bold(chat->name()), Ui::Text::WithEntities); } return tr::lng_manage_discussion_group_about( @@ -257,7 +257,7 @@ object_ptr SetupCreateGroup( Box( navigation, GroupInfoBox::Type::Megagroup, - channel->name + " Chat", + channel->name() + " Chat", guarded), Ui::LayerOption::KeepOther); }); diff --git a/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp index bcf9c0efe..0e28840b6 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp @@ -99,7 +99,7 @@ EditParticipantBox::Inner::Inner( _userPhoto->setPointerCursor(false); _userName.setText( st::rightsNameStyle, - _user->name, + _user->name(), Ui::NameTextOptions()); } @@ -394,7 +394,7 @@ void EditAdminBox::prepare() { phrase( tr::now, lt_group, - Ui::Text::Bold(peer()->name), + Ui::Text::Bold(peer()->name()), Ui::Text::WithEntities), crl::guard(this, [=] { finishAddAdmin(); }) }), Ui::LayerOption::KeepOther); @@ -542,7 +542,7 @@ void EditAdminBox::transferOwnership() { .text = tr::lng_rights_transfer_about( tr::now, lt_group, - Ui::Text::Bold(peer()->name), + Ui::Text::Bold(peer()->name()), lt_user, Ui::Text::Bold(user()->shortName()), Ui::Text::RichLangValue), diff --git a/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp index 50e68a880..a94da0a59 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp @@ -1298,7 +1298,7 @@ void ParticipantsBoxController::rebuildChatAdmins( list.emplace_back(creator); } ranges::sort(list, [](not_null a, not_null b) { - return (a->name.compare(b->name, Qt::CaseInsensitive) < 0); + return (a->name().compare(b->name(), Qt::CaseInsensitive) < 0); }); const auto same = [&] { @@ -1723,7 +1723,7 @@ void ParticipantsBoxController::kickParticipant(not_null participant) : tr::lng_profile_sure_kick_channel)( tr::now, lt_user, - user ? user->firstName : participant->name); + user ? user->firstName : participant->name()); _editBox = showBox( Ui::MakeConfirmBox({ .text = text, @@ -1967,7 +1967,7 @@ void ParticipantsBoxController::refreshCustomStatus( row->setCustomStatus(tr::lng_channel_admin_status_promoted_by( tr::now, lt_user, - by->name)); + by->name())); } else { if (_additional.isCreator(user)) { row->setCustomStatus( @@ -1984,7 +1984,7 @@ void ParticipantsBoxController::refreshCustomStatus( : tr::lng_channel_banned_status_restricted_by)( tr::now, lt_user, - by ? by->name : "Unknown")); + by ? by->name() : "Unknown")); } } diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp index 814d7132b..c0bee7bb6 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp @@ -473,7 +473,7 @@ object_ptr Controller::createTitleEdit() { (_isGroup ? tr::lng_dlg_new_group_name : tr::lng_dlg_new_channel_name)(), - _peer->name), + _peer->name()), st::editPeerTitleMargins); result->entity()->setMaxLength(Ui::EditPeer::kMaxGroupChannelTitle); result->entity()->setInstantReplaces(Ui::InstantReplaces::Default()); @@ -769,15 +769,13 @@ void Controller::fillLinkedChatButton() { auto label = isGroup ? _linkedChatUpdates.events( ) | rpl::map([](ChannelData *chat) { - return chat ? chat->name : QString(); + return chat ? chat->name() : QString(); }) | rpl::type_erased() : rpl::combine( tr::lng_manage_discussion_group_add(), _linkedChatUpdates.events() ) | rpl::map([=](const QString &add, ChannelData *chat) { - return chat - ? chat->name - : add; + return chat ? chat->name() : add; }) | rpl::type_erased(); AddButtonWithText( _controls.buttonsLayout, @@ -1388,14 +1386,14 @@ void Controller::saveUsername() { MTP_string(*_savingData.username) )).done([=] { channel->setName( - TextUtilities::SingleLine(channel->name), + TextUtilities::SingleLine(channel->name()), *_savingData.username); continueSave(); }).fail([=](const MTP::Error &error) { const auto &type = error.type(); if (type == qstr("USERNAME_NOT_MODIFIED")) { channel->setName( - TextUtilities::SingleLine(channel->name), + TextUtilities::SingleLine(channel->name()), TextUtilities::SingleLine(*_savingData.username)); continueSave(); return; @@ -1450,7 +1448,7 @@ void Controller::saveLinkedChat() { } void Controller::saveTitle() { - if (!_savingData.title || *_savingData.title == _peer->name) { + if (!_savingData.title || *_savingData.title == _peer->name()) { return continueSave(); } diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_invite_link.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_invite_link.cpp index e3b09b2a4..3b8e4a188 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_invite_link.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_invite_link.cpp @@ -809,7 +809,7 @@ void Controller::processRequest( : tr::lng_group_requests_was_added)( tr::now, lt_user, - Ui::Text::Bold(user->name), + Ui::Text::Bold(user->name()), Ui::Text::WithEntities) }); } @@ -1164,7 +1164,7 @@ object_ptr ShareInviteLinkBox( auto text = TextWithEntities(); if (result.size() > 1) { text.append( - Ui::Text::Bold(error.second->name) + Ui::Text::Bold(error.second->name()) ).append("\n\n"); } text.append(error.first); diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_requests_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_requests_box.cpp index 696571219..7ade95901 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_requests_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_requests_box.cpp @@ -388,7 +388,7 @@ void RequestsBoxController::processRequest( : tr::lng_group_requests_was_added)( tr::now, lt_user, - Ui::Text::Bold(user->name), + Ui::Text::Bold(user->name()), Ui::Text::WithEntities) }); } diff --git a/Telegram/SourceFiles/boxes/peers/prepare_short_info_box.cpp b/Telegram/SourceFiles/boxes/peers/prepare_short_info_box.cpp index 17ccc4969..a78c4b10e 100644 --- a/Telegram/SourceFiles/boxes/peers/prepare_short_info_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/prepare_short_info_box.cpp @@ -209,7 +209,7 @@ void ProcessFullPhoto( const auto user = peer->asUser(); const auto username = peer->userName(); return PeerShortInfoFields{ - .name = peer->name, + .name = peer->name(), .phone = user ? Ui::FormatPhone(user->phone()) : QString(), .link = ((user || username.isEmpty()) ? QString() diff --git a/Telegram/SourceFiles/boxes/premium_limits_box.cpp b/Telegram/SourceFiles/boxes/premium_limits_box.cpp index cbd5a637a..dda1ae2d0 100644 --- a/Telegram/SourceFiles/boxes/premium_limits_box.cpp +++ b/Telegram/SourceFiles/boxes/premium_limits_box.cpp @@ -356,7 +356,7 @@ void PublicsController::rowRightActionClicked(not_null row) { lt_link, peer->session().createInternalLink(peer->userName()), lt_group, - peer->name); + peer->name()); const auto confirmText = tr::lng_channels_too_much_public_revoke( tr::now); const auto closeBox = _closeBox; @@ -929,7 +929,7 @@ void AccountsLimitBox( && account->session().premiumPossible(); }) | ranges::views::transform([&](not_null account) { const auto user = account->session().user(); - return Args::Entry{ user->name, PaintUserpicCallback(user, false) }; + return Args::Entry{ user->name(), PaintUserpicCallback(user, false)}; }) | ranges::views::take(defaultLimit) | ranges::to_vector; const auto premiumPossible = !promotePossible.empty(); diff --git a/Telegram/SourceFiles/boxes/share_box.cpp b/Telegram/SourceFiles/boxes/share_box.cpp index f47cfca12..ddd06cb7d 100644 --- a/Telegram/SourceFiles/boxes/share_box.cpp +++ b/Telegram/SourceFiles/boxes/share_box.cpp @@ -726,7 +726,7 @@ void ShareBox::Inner::updateChatName( ? tr::lng_saved_messages(tr::now) : peer->isRepliesChat() ? tr::lng_replies_messages(tr::now) - : peer->name; + : peer->name(); chat->name.setText(_st.item.nameStyle, text, Ui::NameTextOptions()); } @@ -1306,7 +1306,7 @@ void FastShareMessage( auto text = TextWithEntities(); if (result.size() > 1) { text.append( - Ui::Text::Bold(error.second->name) + Ui::Text::Bold(error.second->name()) ).append("\n\n"); } text.append(error.first); @@ -1386,7 +1386,7 @@ void FastShareMessage( tr::lng_restricted_send_voice_messages( tr::now, lt_user, - peer->name)); + peer->name())); } } finish(); diff --git a/Telegram/SourceFiles/boxes/url_auth_box.cpp b/Telegram/SourceFiles/boxes/url_auth_box.cpp index 1a05510fd..17efefea1 100644 --- a/Telegram/SourceFiles/boxes/url_auth_box.cpp +++ b/Telegram/SourceFiles/boxes/url_auth_box.cpp @@ -277,7 +277,7 @@ not_null UrlAuthBox::setupContent( lt_domain, Ui::Text::Bold(domain), lt_user, - Ui::Text::Bold(session->user()->name), + Ui::Text::Bold(session->user()->name()), Ui::Text::WithEntities)); const auto allow = bot ? addCheckbox(tr::lng_url_auth_allow_messages( diff --git a/Telegram/SourceFiles/calls/calls_call.cpp b/Telegram/SourceFiles/calls/calls_call.cpp index 7aab722c8..6894d5d90 100644 --- a/Telegram/SourceFiles/calls/calls_call.cpp +++ b/Telegram/SourceFiles/calls/calls_call.cpp @@ -1277,11 +1277,13 @@ void Call::setFailedQueued(const QString &error) { void Call::handleRequestError(const QString &error) { const auto inform = (error == u"USER_PRIVACY_RESTRICTED"_q) - ? tr::lng_call_error_not_available(tr::now, lt_user, _user->name) + ? tr::lng_call_error_not_available(tr::now, lt_user, _user->name()) : (error == u"PARTICIPANT_VERSION_OUTDATED"_q) - ? tr::lng_call_error_outdated(tr::now, lt_user, _user->name) + ? tr::lng_call_error_outdated(tr::now, lt_user, _user->name()) : (error == u"CALL_PROTOCOL_LAYER_INVALID"_q) - ? Lang::Hard::CallErrorIncompatible().replace("{user}", _user->name) + ? Lang::Hard::CallErrorIncompatible().replace( + "{user}", + _user->name()) : QString(); if (!inform.isEmpty()) { Ui::show(Ui::MakeInformBox(inform)); @@ -1291,7 +1293,9 @@ void Call::handleRequestError(const QString &error) { void Call::handleControllerError(const QString &error) { const auto inform = (error == u"ERROR_INCOMPATIBLE"_q) - ? Lang::Hard::CallErrorIncompatible().replace("{user}", _user->name) + ? Lang::Hard::CallErrorIncompatible().replace( + "{user}", + _user->name()) : (error == u"ERROR_AUDIO_IO"_q) ? tr::lng_call_error_audio_io(tr::now) : QString(); diff --git a/Telegram/SourceFiles/calls/calls_emoji_fingerprint.cpp b/Telegram/SourceFiles/calls/calls_emoji_fingerprint.cpp index 05a4d0982..023499d2f 100644 --- a/Telegram/SourceFiles/calls/calls_emoji_fingerprint.cpp +++ b/Telegram/SourceFiles/calls/calls_emoji_fingerprint.cpp @@ -188,7 +188,7 @@ object_ptr CreateFingerprintAndSignalBars( tr::lng_call_fingerprint_tooltip( tr::now, lt_user, - call->user()->name)); + call->user()->name())); raw->setMouseTracking(true); raw->events( ) | rpl::start_with_next([=](not_null e) { diff --git a/Telegram/SourceFiles/calls/calls_instance.cpp b/Telegram/SourceFiles/calls/calls_instance.cpp index a01e06d08..405972c2c 100644 --- a/Telegram/SourceFiles/calls/calls_instance.cpp +++ b/Telegram/SourceFiles/calls/calls_instance.cpp @@ -193,8 +193,10 @@ void Instance::startOutgoingCall(not_null user, bool video) { if (user->callsStatus() == UserData::CallsStatus::Private) { // Request full user once more to refresh the setting in case it was changed. user->session().api().requestFullPeer(user); - Ui::show(Ui::MakeInformBox( - tr::lng_call_error_not_available(tr::now, lt_user, user->name))); + Ui::show(Ui::MakeInformBox(tr::lng_call_error_not_available( + tr::now, + lt_user, + user->name()))); return; } requestPermissionsOrFail(crl::guard(this, [=] { diff --git a/Telegram/SourceFiles/calls/calls_panel.cpp b/Telegram/SourceFiles/calls/calls_panel.cpp index 42e059b70..6a07e63e2 100644 --- a/Telegram/SourceFiles/calls/calls_panel.cpp +++ b/Telegram/SourceFiles/calls/calls_panel.cpp @@ -124,7 +124,7 @@ void Panel::replaceCall(not_null call) { void Panel::initWindow() { window()->setAttribute(Qt::WA_OpaquePaintEvent); window()->setAttribute(Qt::WA_NoSystemBackground); - window()->setTitle(_user->name); + window()->setTitle(_user->name()); window()->setTitleStyle(st::callTitle); window()->events( @@ -473,7 +473,10 @@ void Panel::reinitWithCall(Call *call) { case ErrorType::NoCamera: return tr::lng_call_error_no_camera(tr::now); case ErrorType::NotVideoCall: - return tr::lng_call_error_camera_outdated(tr::now, lt_user, _user->name); + return tr::lng_call_error_camera_outdated( + tr::now, + lt_user, + _user->name()); case ErrorType::NotStartedCall: return tr::lng_call_error_camera_not_started(tr::now); //case ErrorType::NoMicrophone: @@ -490,7 +493,7 @@ void Panel::reinitWithCall(Call *call) { }); }, _callLifetime); - _name->setText(_user->name); + _name->setText(_user->name()); updateStatusText(_call->state()); _answerHangupRedial->raise(); @@ -552,7 +555,7 @@ void Panel::initLayout() { // _user may change for the same Panel. return (_call != nullptr) && (update.peer == _user); }) | rpl::start_with_next([=](const Data::PeerUpdate &update) { - _name->setText(_call->user()->name); + _name->setText(_call->user()->name()); updateControlsGeometry(); }, widget()->lifetime()); diff --git a/Telegram/SourceFiles/calls/calls_top_bar.cpp b/Telegram/SourceFiles/calls/calls_top_bar.cpp index 342ab059a..da26bc1be 100644 --- a/Telegram/SourceFiles/calls/calls_top_bar.cpp +++ b/Telegram/SourceFiles/calls/calls_top_bar.cpp @@ -644,14 +644,14 @@ void TopBar::updateInfoLabels() { void TopBar::setInfoLabels() { if (const auto call = _call.get()) { const auto user = call->user(); - const auto fullName = user->name; + const auto fullName = user->name(); const auto shortName = user->firstName; _fullInfoLabel->setText(fullName); _shortInfoLabel->setText(shortName); } else if (const auto group = _groupCall.get()) { const auto peer = group->peer(); const auto real = peer->groupCall(); - const auto name = peer->name; + const auto name = peer->name(); const auto text = _isGroupConnecting.current() ? tr::lng_group_call_connecting(tr::now) : (real && real->id() == group->id() && !real->title().isEmpty()) diff --git a/Telegram/SourceFiles/calls/calls_userpic.cpp b/Telegram/SourceFiles/calls/calls_userpic.cpp index a72a1fb77..cca9a096c 100644 --- a/Telegram/SourceFiles/calls/calls_userpic.cpp +++ b/Telegram/SourceFiles/calls/calls_userpic.cpp @@ -197,7 +197,7 @@ void Userpic::createCache(Image *image) { Painter p(&filled); Ui::EmptyUserpic( Data::PeerUserpicColor(_peer->id), - _peer->name + _peer->name() ).paint(p, 0, 0, size, size); } //_userPhoto = Images::PixmapFast(Images::Round( diff --git a/Telegram/SourceFiles/calls/group/calls_choose_join_as.cpp b/Telegram/SourceFiles/calls/group/calls_choose_join_as.cpp index 2c3b6e0ce..c2b2121ee 100644 --- a/Telegram/SourceFiles/calls/group/calls_choose_join_as.cpp +++ b/Telegram/SourceFiles/calls/group/calls_choose_join_as.cpp @@ -288,7 +288,7 @@ void ChooseJoinAsBox( } const auto name = !existing->title().isEmpty() ? existing->title() - : peer->name; + : peer->name(); return (peer->isBroadcast() ? tr::lng_group_call_join_confirm_channel : tr::lng_group_call_join_confirm)( diff --git a/Telegram/SourceFiles/calls/group/calls_group_invite_controller.cpp b/Telegram/SourceFiles/calls/group/calls_group_invite_controller.cpp index 9b02b9554..5a9f72d2c 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_invite_controller.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_invite_controller.cpp @@ -238,7 +238,7 @@ object_ptr PrepareInviteBox( finish(); return; } - const auto name = peer->name; + const auto name = peer->name(); const auto text = (nonMembers.size() == 1) ? tr::lng_group_call_add_to_group_one( tr::now, diff --git a/Telegram/SourceFiles/calls/group/calls_group_menu.cpp b/Telegram/SourceFiles/calls/group/calls_group_menu.cpp index 875845f03..4fe0137b0 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_menu.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_menu.cpp @@ -527,7 +527,7 @@ void FillMenu( if (const auto real = resolveReal()) { showBox(Box( EditGroupCallTitleBox, - peer->name, + peer->name(), real->title(), livestream, done)); diff --git a/Telegram/SourceFiles/calls/group/calls_group_panel.cpp b/Telegram/SourceFiles/calls/group/calls_group_panel.cpp index 3de65526e..c75ac1982 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_panel.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_panel.cpp @@ -1430,7 +1430,7 @@ void Panel::kickParticipant(not_null participantPeer) { : tr::lng_group_call_remove_channel)( tr::now, lt_channel, - participantPeer->name) + participantPeer->name()) : (_peer->isBroadcast() ? tr::lng_profile_sure_kick_channel : tr::lng_profile_sure_kick)( @@ -1668,7 +1668,7 @@ void Panel::setupEmptyRtmp() { (_call->rtmpInfo().url.isEmpty() ? tr::lng_group_call_no_stream( lt_group, - rpl::single(_peer->name)) + rpl::single(_peer->name())) : tr::lng_group_call_no_stream_admin()), _controlsBackgroundColor.color()); _emptyRtmp->setAttribute(Qt::WA_TransparentForMouseEvents); diff --git a/Telegram/SourceFiles/calls/group/calls_group_settings.cpp b/Telegram/SourceFiles/calls/group/calls_group_settings.cpp index a9d803679..dd4745a35 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_settings.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_settings.cpp @@ -156,7 +156,7 @@ object_ptr ShareInviteLinkBox( auto text = TextWithEntities(); if (result.size() > 1) { text.append( - Ui::Text::Bold(error.second->name) + Ui::Text::Bold(error.second->name()) ).append("\n\n"); } text.append(error.first); diff --git a/Telegram/SourceFiles/calls/group/calls_group_toasts.cpp b/Telegram/SourceFiles/calls/group/calls_group_toasts.cpp index c54b00266..4abaab3ec 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_toasts.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_toasts.cpp @@ -54,7 +54,7 @@ void Toasts::setupJoinAsChanged() { : tr::lng_group_call_join_as_changed)( tr::now, lt_name, - Ui::Text::Bold(_call->joinAs()->name), + Ui::Text::Bold(_call->joinAs()->name()), Ui::Text::WithEntities)); }, _lifetime); } @@ -66,7 +66,7 @@ void Toasts::setupTitleChanged() { }) | rpl::map([=] { const auto peer = _call->peer(); return peer->groupCall()->title().isEmpty() - ? peer->name + ? peer->name() : peer->groupCall()->title(); }) | rpl::start_with_next([=](const QString &title) { _panel->showToast((_call->peer()->isBroadcast() @@ -90,7 +90,7 @@ void Toasts::setupAllowedToSpeak() { const auto real = _call->lookupReal(); const auto name = (real && !real->title().isEmpty()) ? real->title() - : _call->peer()->name; + : _call->peer()->name(); Ui::ShowMultilineToast({ .text = tr::lng_group_call_can_speak( tr::now, diff --git a/Telegram/SourceFiles/calls/group/calls_group_viewport_opengl.cpp b/Telegram/SourceFiles/calls/group/calls_group_viewport_opengl.cpp index e4ff684f2..a7b9b7b9e 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_viewport_opengl.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_viewport_opengl.cpp @@ -1230,9 +1230,9 @@ void Viewport::RendererGL::validateDatas() { const auto index = (j - begin(_tileData)); _tileDataIndices[i] = index; const auto peer = tiles[i]->row()->peer(); - if (peer != j->peer - || peer->nameVersion != j->nameVersion - || width != j->nameRect.width()) { + if ((j->peer != peer) + || (j->nameVersion != peer->nameVersion()) + || (j->nameRect.width() != width)) { const auto nameTop = pausedBottom + index * nameHeight; j->nameRect = QRect(0, nameTop, width, nameHeight); requests.push_back({ .index = i, .updating = true }); @@ -1279,7 +1279,7 @@ void Viewport::RendererGL::validateDatas() { }); } const auto nameTop = pausedBottom + index * nameHeight; - _tileData[index].nameVersion = peer->nameVersion; + _tileData[index].nameVersion = peer->nameVersion(); _tileData[index].nameRect = QRect( 0, nameTop, diff --git a/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp b/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp index 819972b4f..8930c8ca0 100644 --- a/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp +++ b/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp @@ -937,7 +937,10 @@ void FieldAutocomplete::Inner::paintEvent(QPaintEvent *e) { auto firstwidth = st::mentionFont->width(first); auto secondwidth = st::mentionFont->width(second); auto unamewidth = firstwidth + secondwidth; - auto namewidth = user->nameText().maxWidth(); + if (row.name.isEmpty()) { + row.name.setText(st::msgNameStyle, user->name(), Ui::NameTextOptions()); + } + auto namewidth = row.name.maxWidth(); if (mentionwidth < unamewidth + namewidth) { namewidth = (mentionwidth * namewidth) / (namewidth + unamewidth); unamewidth = mentionwidth - namewidth; @@ -956,7 +959,7 @@ void FieldAutocomplete::Inner::paintEvent(QPaintEvent *e) { user->paintUserpicLeft(p, row.userpic, st::mentionPadding.left(), i * st::mentionHeight + st::mentionPadding.top(), width(), st::mentionPhotoSize); p.setPen(selected ? st::mentionNameFgOver : st::mentionNameFg); - user->nameText().drawElided(p, 2 * st::mentionPadding.left() + st::mentionPhotoSize, i * st::mentionHeight + st::mentionTop, namewidth); + row.name.drawElided(p, 2 * st::mentionPadding.left() + st::mentionPhotoSize, i * st::mentionHeight + st::mentionTop, namewidth); p.setFont(st::mentionFont); p.setPen(selected ? st::mentionFgOverActive : st::mentionFgActive); diff --git a/Telegram/SourceFiles/chat_helpers/field_autocomplete.h b/Telegram/SourceFiles/chat_helpers/field_autocomplete.h index abfb65fb2..aff798543 100644 --- a/Telegram/SourceFiles/chat_helpers/field_autocomplete.h +++ b/Telegram/SourceFiles/chat_helpers/field_autocomplete.h @@ -135,6 +135,7 @@ private: struct MentionRow { not_null user; + Ui::Text::String name; std::shared_ptr userpic; }; diff --git a/Telegram/SourceFiles/core/click_handler_types.cpp b/Telegram/SourceFiles/core/click_handler_types.cpp index 6705a69ca..a4bdf6756 100644 --- a/Telegram/SourceFiles/core/click_handler_types.cpp +++ b/Telegram/SourceFiles/core/click_handler_types.cpp @@ -175,7 +175,7 @@ void BotGameUrlClickHandler::onClick(ClickContext context) const { .text = tr::lng_allow_bot_pass( tr::now, lt_bot_name, - _bot->name), + _bot->name()), .confirmed = callback, .confirmText = tr::lng_allow_bot(), })); @@ -238,7 +238,7 @@ auto MentionNameClickHandler::getTextEntity() const -> TextEntity { QString MentionNameClickHandler::tooltip() const { if (const auto user = _session->data().userLoaded(_userId)) { - const auto name = user->name; + const auto name = user->name(); if (name != _text) { return name; } diff --git a/Telegram/SourceFiles/data/data_channel.cpp b/Telegram/SourceFiles/data/data_channel.cpp index 85221a847..1140b8468 100644 --- a/Telegram/SourceFiles/data/data_channel.cpp +++ b/Telegram/SourceFiles/data/data_channel.cpp @@ -97,14 +97,20 @@ void ChannelData::setPhoto(const MTPChatPhoto &photo) { }); } -void ChannelData::setName(const QString &newName, const QString &newUsername) { - updateNameDelayed(newName.isEmpty() ? name : newName, QString(), newUsername); +void ChannelData::setName( + const QString &newName, + const QString &newUsername) { + updateNameDelayed(newName.isEmpty() ? name() : newName, {}, newUsername); } void ChannelData::setAccessHash(uint64 accessHash) { access = accessHash; - input = MTP_inputPeerChannel(MTP_long(peerToChannel(id).bare), MTP_long(accessHash)); - inputChannel = MTP_inputChannel(MTP_long(peerToChannel(id).bare), MTP_long(accessHash)); + input = MTP_inputPeerChannel( + MTP_long(peerToChannel(id).bare), + MTP_long(accessHash)); + inputChannel = MTP_inputChannel( + MTP_long(peerToChannel(id).bare), + MTP_long(accessHash)); } void ChannelData::setInviteLink(const QString &newInviteLink) { @@ -377,7 +383,7 @@ void ChannelData::markForbidden() { : MTPDchannelForbidden::Flag::f_broadcast), MTP_long(peerToChannel(id).bare), MTP_long(access), - MTP_string(name), + MTP_string(name()), MTPint())); } diff --git a/Telegram/SourceFiles/data/data_chat.cpp b/Telegram/SourceFiles/data/data_chat.cpp index f5f272d99..6dd5a8852 100644 --- a/Telegram/SourceFiles/data/data_chat.cpp +++ b/Telegram/SourceFiles/data/data_chat.cpp @@ -116,7 +116,7 @@ bool ChatData::anyoneCanAddMembers() const { } void ChatData::setName(const QString &newName) { - updateNameDelayed(newName.isEmpty() ? name : newName, QString(), QString()); + updateNameDelayed(newName.isEmpty() ? name() : newName, {}, {}); } void ChatData::applyEditAdmin(not_null user, bool isAdmin) { diff --git a/Telegram/SourceFiles/data/data_folder.cpp b/Telegram/SourceFiles/data/data_folder.cpp index 1ede84514..cb3f51a60 100644 --- a/Telegram/SourceFiles/data/data_folder.cpp +++ b/Telegram/SourceFiles/data/data_folder.cpp @@ -135,6 +135,10 @@ void Folder::unregisterOne(not_null history) { reorderLastHistories(); } +int Folder::chatListNameVersion() const { + return 1; +} + void Folder::oneListMessageChanged(HistoryItem *from, HistoryItem *to) { if (!applyChatListMessage(to) && _chatListMessage == from) { computeChatListMessage(); diff --git a/Telegram/SourceFiles/data/data_folder.h b/Telegram/SourceFiles/data/data_folder.h index d1d1019f1..a79e8b8ed 100644 --- a/Telegram/SourceFiles/data/data_folder.h +++ b/Telegram/SourceFiles/data/data_folder.h @@ -81,6 +81,8 @@ private: bool applyChatListMessage(HistoryItem *item); void computeChatListMessage(); + int chatListNameVersion() const override; + void reorderLastHistories(); void updateChatListEntryPostponed(); diff --git a/Telegram/SourceFiles/data/data_peer.cpp b/Telegram/SourceFiles/data/data_peer.cpp index e88826cfb..18433abed 100644 --- a/Telegram/SourceFiles/data/data_peer.cpp +++ b/Telegram/SourceFiles/data/data_peer.cpp @@ -142,7 +142,6 @@ void PeerClickHandler::onClick(ClickContext context) const { PeerData::PeerData(not_null owner, PeerId id) : id(id) , _owner(owner) { - _nameText.setText(st::msgNameStyle, QString(), Ui::NameTextOptions()); } Data::Session &PeerData::owner() const { @@ -161,7 +160,7 @@ void PeerData::updateNameDelayed( const QString &newName, const QString &newNameOrPhone, const QString &newUsername) { - if (name == newName && nameVersion > 1) { + if (_name == newName && _nameVersion > 1) { if (isUser()) { if (asUser()->nameOrPhone == newNameOrPhone && asUser()->username == newUsername) { @@ -175,13 +174,12 @@ void PeerData::updateNameDelayed( return; } } - name = newName; - _nameText.setText(st::msgNameStyle, name, Ui::NameTextOptions()); + _name = newName; _userpicEmpty = nullptr; auto flags = UpdateFlag::None | UpdateFlag::None; auto oldFirstLetters = base::flat_set(); - const auto nameUpdated = (nameVersion++ > 1); + const auto nameUpdated = (_nameVersion++ > 1); if (nameUpdated) { oldFirstLetters = nameFirstLetters(); flags |= UpdateFlag::Name; @@ -216,7 +214,7 @@ not_null PeerData::ensureEmptyUserpic() const { if (!_userpicEmpty) { _userpicEmpty = std::make_unique( Data::PeerUserpicColor(id), - name); + name()); } return _userpicEmpty.get(); } @@ -564,14 +562,14 @@ void PeerData::fillNames() { } }; - appendToIndex(name); + appendToIndex(name()); const auto appendTranslit = !toIndexList.isEmpty() && cRussianLetters().match(toIndexList.front()).hasMatch(); if (appendTranslit) { appendToIndex(translitRusEng(toIndexList.front())); } if (const auto user = asUser()) { - if (user->nameOrPhone != name) { + if (user->nameOrPhone != name()) { appendToIndex(user->nameOrPhone); } appendToIndex(user->username); @@ -732,29 +730,33 @@ not_null PeerData::migrateToOrMe() const { return this; } -const Ui::Text::String &PeerData::topBarNameText() const { +const QString &PeerData::topBarNameText() const { if (const auto to = migrateTo()) { return to->topBarNameText(); } else if (const auto user = asUser()) { - if (!user->phoneText.isEmpty()) { - return user->phoneText; + if (!user->nameOrPhone.isEmpty()) { + return user->nameOrPhone; } } - return _nameText; + return _name; } -const Ui::Text::String &PeerData::nameText() const { +int PeerData::nameVersion() const { + return _nameVersion; +} + +const QString &PeerData::name() const { if (const auto to = migrateTo()) { - return to->nameText(); + return to->name(); } - return _nameText; + return _name; } const QString &PeerData::shortName() const { if (const auto user = asUser()) { return user->firstName.isEmpty() ? user->lastName : user->firstName; } - return name; + return _name; } QString PeerData::userName() const { @@ -1138,7 +1140,7 @@ std::optional RestrictionError( : tr::lng_restricted_send_video_messages)( tr::now, lt_user, - user->name); + user->name()); } } return std::nullopt; diff --git a/Telegram/SourceFiles/data/data_peer.h b/Telegram/SourceFiles/data/data_peer.h index 89341ad5d..27ec1c03b 100644 --- a/Telegram/SourceFiles/data/data_peer.h +++ b/Telegram/SourceFiles/data/data_peer.h @@ -241,9 +241,10 @@ public: return (_lastFullUpdate != 0); } - [[nodiscard]] const Ui::Text::String &nameText() const; + [[nodiscard]] int nameVersion() const; + [[nodiscard]] const QString &name() const; [[nodiscard]] const QString &shortName() const; - [[nodiscard]] const Ui::Text::String &topBarNameText() const; + [[nodiscard]] const QString &topBarNameText() const; [[nodiscard]] QString userName() const; [[nodiscard]] const base::flat_set &nameWords() const { @@ -409,11 +410,8 @@ public: [[nodiscard]] const QString &themeEmoji() const; const PeerId id; - QString name; MTPinputPeer input = MTP_inputPeerEmpty(); - int nameVersion = 1; - protected: void updateNameDelayed( const QString &newName, @@ -440,7 +438,6 @@ private: bool _userpicHasVideo = false; mutable std::unique_ptr _userpicEmpty; - Ui::Text::String _nameText; Data::PeerNotifySettings _notify; @@ -450,6 +447,9 @@ private: crl::time _lastFullUpdate = 0; + QString _name; + int _nameVersion = 1; + TimeId _ttlPeriod = 0; Settings _settings = PeerSettings(PeerSetting::Unknown); diff --git a/Telegram/SourceFiles/data/data_sponsored_messages.cpp b/Telegram/SourceFiles/data/data_sponsored_messages.cpp index fa9182ee7..10e69d37b 100644 --- a/Telegram/SourceFiles/data/data_sponsored_messages.cpp +++ b/Telegram/SourceFiles/data/data_sponsored_messages.cpp @@ -155,7 +155,7 @@ void SponsoredMessages::append( const auto channel = peer->asChannel(); return SponsoredFrom{ .peer = peer, - .title = peer->name, + .title = peer->name(), .isBroadcast = (channel && channel->isBroadcast()), .isMegagroup = (channel && channel->isMegagroup()), .isChannel = (channel != nullptr), diff --git a/Telegram/SourceFiles/data/data_user.cpp b/Telegram/SourceFiles/data/data_user.cpp index 6ba5c3069..945fd949d 100644 --- a/Telegram/SourceFiles/data/data_user.cpp +++ b/Telegram/SourceFiles/data/data_user.cpp @@ -165,13 +165,7 @@ void UserData::setBotInfo(const MTPBotInfo &info) { } void UserData::setNameOrPhone(const QString &newNameOrPhone) { - if (nameOrPhone != newNameOrPhone) { - nameOrPhone = newNameOrPhone; - phoneText.setText( - st::msgNameStyle, - nameOrPhone, - Ui::NameTextOptions()); - } + nameOrPhone = newNameOrPhone; } void UserData::madeAction(TimeId when) { diff --git a/Telegram/SourceFiles/data/data_user.h b/Telegram/SourceFiles/data/data_user.h index 3693b0f06..3f1ac2f90 100644 --- a/Telegram/SourceFiles/data/data_user.h +++ b/Telegram/SourceFiles/data/data_user.h @@ -123,7 +123,6 @@ public: QString username; [[nodiscard]] const QString &phone() const; QString nameOrPhone; - Ui::Text::String phoneText; TimeId onlineTill = 0; enum class ContactStatus : char { diff --git a/Telegram/SourceFiles/dialogs/dialogs_entry.cpp b/Telegram/SourceFiles/dialogs/dialogs_entry.cpp index a9a707f58..2c85eb42f 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_entry.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_entry.cpp @@ -16,6 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mainwidget.h" #include "main/main_session.h" #include "main/main_session_settings.h" +#include "ui/text/text_options.h" #include "history/history_item.h" #include "history/history.h" #include "styles/style_dialogs.h" // st::dialogsTextWidthMin @@ -163,6 +164,18 @@ void Entry::notifyUnreadStateChange(const UnreadState &wasState) { } } +const Ui::Text::String &Entry::chatListNameText() const { + const auto version = chatListNameVersion(); + if (_chatListNameVersion < version) { + _chatListNameVersion = version; + _chatListNameText.setText( + st::msgNameStyle, + chatListName(), + Ui::NameTextOptions()); + } + return _chatListNameText; +} + void Entry::setChatListExistence(bool exists) { if (exists && _sortKeyInChatList) { owner().refreshChatListEntry(this); diff --git a/Telegram/SourceFiles/dialogs/dialogs_entry.h b/Telegram/SourceFiles/dialogs/dialogs_entry.h index bff8ad2a5..2975a456b 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_entry.h +++ b/Telegram/SourceFiles/dialogs/dialogs_entry.h @@ -187,6 +187,8 @@ public: return _timeId; } + [[nodiscard]] const Ui::Text::String &chatListNameText() const; + protected: void notifyUnreadStateChange(const UnreadState &wasState); auto unreadStateChangeNotifier(bool required) { @@ -208,6 +210,8 @@ private: void pinnedIndexChanged(FilterId filterId, int was, int now); [[nodiscard]] uint64 computeSortPosition(FilterId filterId) const; + [[nodiscard]] virtual int chatListNameVersion() const = 0; + void setChatListExistence(bool exists); not_null mainChatListLink(FilterId filterId) const; Row *maybeMainChatListLink(FilterId filterId) const; @@ -217,6 +221,8 @@ private: uint64 _sortKeyInChatList = 0; uint64 _sortKeyByDate = 0; base::flat_map _pinnedIndex; + mutable Ui::Text::String _chatListNameText; + mutable int _chatListNameVersion = 0; TimeId _timeId = 0; bool _isTopPromoted = false; const bool _isFolder = false; diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp index f8c46f8de..166d8db7c 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp @@ -121,6 +121,7 @@ struct InnerWidget::PeerSearchResult { PeerSearchResult(not_null peer) : peer(peer) { } not_null peer; + mutable Ui::Text::String name; BasicRow row; }; @@ -781,6 +782,13 @@ void InnerWidget::paintPeerSearchResult( auto namewidth = fullWidth - nameleft - st::dialogsPadding.x(); QRect rectForName(nameleft, st::dialogsPadding.y() + st::dialogsNameTop, namewidth, st::msgNameFont->height); + if (result->name.isEmpty()) { + result->name.setText( + st::msgNameStyle, + peer->name(), + Ui::NameTextOptions()); + } + // draw chat icon if (auto chatTypeIcon = Ui::ChatTypeIcon(peer, active, selected)) { chatTypeIcon->paint(p, rectForName.topLeft(), fullWidth); @@ -806,7 +814,7 @@ void InnerWidget::paintPeerSearchResult( peer, p, rectForName, - peer->nameText().maxWidth(), + result->name.maxWidth(), fullWidth, badgeStyle); rectForName.setWidth(rectForName.width() - badgeWidth); @@ -833,7 +841,7 @@ void InnerWidget::paintPeerSearchResult( } p.setPen(active ? st::dialogsTextFgActive : st::dialogsNameFg); - peer->nameText().drawElided(p, rectForName.left(), rectForName.top(), rectForName.width()); + result->name.drawElided(p, rectForName.left(), rectForName.top(), rectForName.width()); } void InnerWidget::paintSearchInChat(Painter &p) const { @@ -2427,7 +2435,7 @@ void InnerWidget::refreshSearchInChatLabel() { } else if (peer->isRepliesChat()) { return tr::lng_replies_messages(tr::now); } - return peer->name; + return peer->name(); } return QString(); }(); @@ -2437,7 +2445,7 @@ void InnerWidget::refreshSearchInChatLabel() { dialog, Ui::DialogTextOptions()); } - const auto from = _searchFromPeer ? _searchFromPeer->name : QString(); + const auto from = _searchFromPeer ? _searchFromPeer->name() : QString(); if (!from.isEmpty()) { const auto fromUserText = tr::lng_dlg_search_from( tr::now, diff --git a/Telegram/SourceFiles/dialogs/dialogs_row.cpp b/Telegram/SourceFiles/dialogs/dialogs_row.cpp index f2953d94e..164f3ce87 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_row.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_row.cpp @@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_folder.h" #include "data/data_peer_values.h" #include "history/history.h" +#include "history/history_item.h" #include "lang/lang_keys.h" #include "mainwidget.h" #include "styles/style_dialogs.h" @@ -41,7 +42,7 @@ namespace { list.size() - (throwAwayLastName ? 1 : 0) ); const auto wrapName = [](not_null history) { - const auto name = history->peer->name; + const auto name = history->peer->name(); return TextWithEntities{ .text = name, .entities = (history->unreadCount() > 0) @@ -343,4 +344,15 @@ FakeRow::FakeRow(Key searchInChat, not_null item) , _item(item) { } +const Ui::Text::String &FakeRow::name() const { + if (_name.isEmpty()) { + const auto from = _searchInChat + ? _item->displayFrom() + : nullptr; + const auto peer = from ? from : _item->history()->peer.get(); + _name.setText(st::msgNameStyle, peer->name(), Ui::NameTextOptions()); + } + return _name; +} + } // namespace Dialogs diff --git a/Telegram/SourceFiles/dialogs/dialogs_row.h b/Telegram/SourceFiles/dialogs/dialogs_row.h index 407082581..94fec8115 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_row.h +++ b/Telegram/SourceFiles/dialogs/dialogs_row.h @@ -158,6 +158,7 @@ public: [[nodiscard]] Ui::MessageView &itemView() const { return _itemView; } + [[nodiscard]] const Ui::Text::String &name() const; private: friend class Ui::RowPainter; @@ -165,6 +166,7 @@ private: Key _searchInChat; not_null _item; mutable Ui::MessageView _itemView; + mutable Ui::Text::String _name; }; diff --git a/Telegram/SourceFiles/dialogs/ui/dialogs_layout.cpp b/Telegram/SourceFiles/dialogs/ui/dialogs_layout.cpp index 6d3561628..46f79c5d4 100644 --- a/Telegram/SourceFiles/dialogs/ui/dialogs_layout.cpp +++ b/Telegram/SourceFiles/dialogs/ui/dialogs_layout.cpp @@ -311,6 +311,7 @@ void paintRow( VideoUserpic *videoUserpic, FilterId filterId, PeerData *from, + const Ui::Text::String &fromName, const HiddenSenderInfo *hiddenSenderInfo, HistoryItem *item, const Data::Draft *draft, @@ -590,7 +591,7 @@ void paintRow( from, p, rectForName, - from->nameText().maxWidth(), + fromName.maxWidth(), fullWidth, badgeStyle); rectForName.setWidth(rectForName.width() - badgeWidth); @@ -600,14 +601,14 @@ void paintRow( : selected ? st::dialogsNameFgOver : st::dialogsNameFg); - from->nameText().drawElided(p, rectForName.left(), rectForName.top(), rectForName.width()); + fromName.drawElided(p, rectForName.left(), rectForName.top(), rectForName.width()); } else if (hiddenSenderInfo) { p.setPen(active ? st::dialogsNameFgActive : selected ? st::dialogsNameFgOver : st::dialogsNameFg); - hiddenSenderInfo->nameText.drawElided(p, rectForName.left(), rectForName.top(), rectForName.width()); + hiddenSenderInfo->nameText().drawElided(p, rectForName.left(), rectForName.top(), rectForName.width()); } else { p.setPen(active ? st::dialogsNameFgActive @@ -958,6 +959,7 @@ void RowPainter::paint( videoUserpic, filterId, from, + entry->chatListNameText(), nullptr, item, cloudDraft, @@ -1092,6 +1094,7 @@ void RowPainter::paint( nullptr, FilterId(), from, + row->name(), hiddenSenderInfo, item, cloudDraft, diff --git a/Telegram/SourceFiles/dialogs/ui/dialogs_layout.h b/Telegram/SourceFiles/dialogs/ui/dialogs_layout.h index 060adf690..b492a791a 100644 --- a/Telegram/SourceFiles/dialogs/ui/dialogs_layout.h +++ b/Telegram/SourceFiles/dialogs/ui/dialogs_layout.h @@ -18,10 +18,10 @@ class BasicRow; namespace Dialogs::Ui { -class VideoUserpic; - using namespace ::Ui; +class VideoUserpic; + const style::icon *ChatTypeIcon( not_null peer, bool active, diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_filter.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_filter.cpp index 6030ca61a..c04662ba2 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_filter.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_filter.cpp @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/checkbox.h" #include "ui/effects/ripple_animation.h" +#include "ui/text/text_options.h" #include "lang/lang_keys.h" #include "data/data_peer_values.h" #include "data/data_channel.h" @@ -62,6 +63,7 @@ private: const not_null _user; std::shared_ptr _userpic; + Ui::Text::String _name; QString _statusText; bool _statusOnline = false; @@ -113,11 +115,14 @@ void UserCheckbox::paintEvent(QPaintEvent *e) { auto userpicTop = 0; _user->paintUserpicLeft(p, _userpic, userpicLeft, userpicTop, width(), st::contactsPhotoSize); + if (_name.isEmpty()) { + _name.setText(st::msgNameStyle, _user->name(), Ui::NameTextOptions()); + } auto nameLeft = userpicLeft + st::contactsPhotoSize + st::contactsPadding.left(); auto nameTop = userpicTop + st::contactsNameTop; auto nameWidth = width() - nameLeft - st::contactsPadding.right(); p.setPen(st::contactsNameFg); - _user->nameText().drawLeftElided(p, nameLeft, nameTop, nameWidth, width()); + _name.drawLeftElided(p, nameLeft, nameTop, nameWidth, width()); auto statusLeft = nameLeft; auto statusTop = userpicTop + st::contactsStatusTop; diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp index 9ba316fab..e1a7c860a 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp @@ -1429,7 +1429,7 @@ void InnerWidget::suggestRestrictParticipant( : tr::lng_profile_sure_kick)( tr::now, lt_user, - participant->name); + participant->name()); auto weakBox = std::make_shared>(); const auto sure = crl::guard(this, [=] { restrictParticipant( diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp index bf16173dd..aeb103b18 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp @@ -456,7 +456,7 @@ auto GenerateParticipantString( PeerId participantId) { // User name in "User name (@username)" format with entities. const auto peer = session->data().peer(participantId); - auto name = TextWithEntities { peer->name }; + auto name = TextWithEntities { peer->name()}; if (const auto user = peer->asUser()) { auto entityData = QString::number(user->id.value) + '.' @@ -706,7 +706,7 @@ void GenerateItems( return callback(OwnedItem(delegate, item), sentDate); }; - const auto fromName = from->name; + const auto fromName = from->name(); const auto fromLink = from->createOpenLink(); const auto fromLinkText = Ui::Text::Link(fromName, QString()); @@ -1120,7 +1120,7 @@ void GenerateItems( lt_from, fromLinkText, lt_chat, - Ui::Text::Link(now->name, QString()), + Ui::Text::Link(now->name(), QString()), Ui::Text::WithEntities); const auto chatLink = std::make_shared([=] { Ui::showPeerHistory(now, ShowAtUnreadMsgId); @@ -1237,7 +1237,7 @@ void GenerateItems( data.vparticipant()); const auto participantPeerLink = participantPeer->createOpenLink(); const auto participantPeerLinkText = Ui::Text::Link( - participantPeer->name, + participantPeer->name(), QString()); const auto text = (broadcast ? tr::lng_admin_log_muted_participant_channel @@ -1256,7 +1256,7 @@ void GenerateItems( data.vparticipant()); const auto participantPeerLink = participantPeer->createOpenLink(); const auto participantPeerLinkText = Ui::Text::Link( - participantPeer->name, + participantPeer->name(), QString()); const auto text = (broadcast ? tr::lng_admin_log_unmuted_participant_channel @@ -1360,7 +1360,7 @@ void GenerateItems( data.vparticipant()); const auto participantPeerLink = participantPeer->createOpenLink(); const auto participantPeerLinkText = Ui::Text::Link( - participantPeer->name, + participantPeer->name(), QString()); const auto volume = data.vparticipant().match([&]( const MTPDgroupCallParticipant &data) { @@ -1433,7 +1433,7 @@ void GenerateItems( lt_link, linkText, lt_user, - Ui::Text::Link(user->name, QString()), + Ui::Text::Link(user->name(), QString()), Ui::Text::WithEntities), data.vinvite(), user->createOpenLink()); diff --git a/Telegram/SourceFiles/history/history.cpp b/Telegram/SourceFiles/history/history.cpp index b043f2e6e..af5d9f0ad 100644 --- a/Telegram/SourceFiles/history/history.cpp +++ b/Telegram/SourceFiles/history/history.cpp @@ -72,7 +72,7 @@ History::History(not_null owner, PeerId peerId) , cloudDraftTextCache(st::dialogsTextWidthMin) , _delegateMixin(HistoryInner::DelegateMixin()) , _mute(owner->notifySettings().isMuted(peer)) -, _chatListNameSortKey(owner->nameSortKey(peer->name)) +, _chatListNameSortKey(owner->nameSortKey(peer->name())) , _sendActionPainter(this) { if (const auto user = peer->asUser()) { if (user->isBot()) { @@ -1823,6 +1823,10 @@ void History::setFolderPointer(Data::Folder *folder) { session().changes().historyUpdated(this, UpdateFlag::Folder); } +int History::chatListNameVersion() const { + return peer->nameVersion(); +} + void History::applyPinnedUpdate(const MTPDupdateDialogPinned &data) { const auto folderId = data.vfolder_id().value_or_empty(); if (!folderKnown()) { @@ -2034,7 +2038,7 @@ bool History::chatListMessageKnown() const { } const QString &History::chatListName() const { - return peer->name; + return peer->name(); } const QString &History::chatListNameSortKey() const { @@ -2042,7 +2046,7 @@ const QString &History::chatListNameSortKey() const { } void History::refreshChatListNameSortKey() { - _chatListNameSortKey = owner().nameSortKey(peer->name); + _chatListNameSortKey = owner().nameSortKey(peer->name()); } const base::flat_set &History::chatListNameWords() const { diff --git a/Telegram/SourceFiles/history/history.h b/Telegram/SourceFiles/history/history.h index c5e8d562e..948ccf2d9 100644 --- a/Telegram/SourceFiles/history/history.h +++ b/Telegram/SourceFiles/history/history.h @@ -597,6 +597,8 @@ private: void setFolderPointer(Data::Folder *folder); + int chatListNameVersion() const override; + const std::unique_ptr _delegateMixin; Flags _flags = 0; diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index cb19cae57..7dd367148 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -2607,7 +2607,7 @@ TextForMimeData HistoryInner::getSelectedText() const { not_null item, TextForMimeData &&unwrapped) { const auto i = texts.emplace(item->position(), Part{ - .name = item->author()->name, + .name = item->author()->name(), .time = ItemDateTime(item).toString(timeFormat), .unwrapped = std::move(unwrapped), }).first; diff --git a/Telegram/SourceFiles/history/history_inner_widget.h b/Telegram/SourceFiles/history/history_inner_widget.h index 85fb58afa..b813913b6 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.h +++ b/Telegram/SourceFiles/history/history_inner_widget.h @@ -53,6 +53,7 @@ class PathShiftGradient; } // namespace Ui namespace Dialogs::Ui { +using namespace ::Ui; class VideoUserpic; } // namespace Dialogs::Ui diff --git a/Telegram/SourceFiles/history/history_item.h b/Telegram/SourceFiles/history/history_item.h index 96d25e988..0f53f8e85 100644 --- a/Telegram/SourceFiles/history/history_item.h +++ b/Telegram/SourceFiles/history/history_item.h @@ -63,7 +63,7 @@ enum class Context : char; class ElementDelegate; } // namespace HistoryView -struct HiddenSenderInfo; +class HiddenSenderInfo; class History; [[nodiscard]] MessageFlags FlagsFromMTP( diff --git a/Telegram/SourceFiles/history/history_item_components.cpp b/Telegram/SourceFiles/history/history_item_components.cpp index 6c4de1490..fd91d202b 100644 --- a/Telegram/SourceFiles/history/history_item_components.cpp +++ b/Telegram/SourceFiles/history/history_item_components.cpp @@ -102,7 +102,6 @@ HiddenSenderInfo::HiddenSenderInfo(const QString &name, bool external) : name)) { Expects(!name.isEmpty()); - nameText.setText(st::msgNameStyle, name, Ui::NameTextOptions()); const auto parts = name.trimmed().split(' ', Qt::SkipEmptyParts); firstName = parts[0]; for (const auto &part : parts.mid(1)) { @@ -113,6 +112,13 @@ HiddenSenderInfo::HiddenSenderInfo(const QString &name, bool external) } } +const Ui::Text::String &HiddenSenderInfo::nameText() const { + if (_nameText.isEmpty()) { + _nameText.setText(st::msgNameStyle, name, Ui::NameTextOptions()); + } + return _nameText; +} + ClickHandlerPtr HiddenSenderInfo::ForwardClickHandler() { static const auto hidden = std::make_shared([]( ClickContext context) { @@ -153,7 +159,9 @@ void HistoryMessageForwarded::create(const HistoryMessageVia *via) const { && originalSender->isChannel() && !originalSender->isMegagroup(); const auto name = TextWithEntities{ - .text = originalSender ? originalSender->name : hiddenSenderInfo->name + .text = (originalSender + ? originalSender->name() + : hiddenSenderInfo->name) }; if (!originalAuthor.isEmpty()) { phrase = tr::lng_forwarded_signed( @@ -342,13 +350,13 @@ QString HistoryMessageReply::replyToFromName( if (const auto user = replyToVia ? peer->asUser() : nullptr) { return user->firstName; } - return peer->name; + return peer->name(); } bool HistoryMessageReply::isNameUpdated( not_null holder) const { if (const auto from = replyToFrom(holder)) { - if (from->nameVersion > replyToVersion) { + if (replyToVersion < from->nameVersion()) { updateName(holder); return true; } @@ -361,9 +369,9 @@ void HistoryMessageReply::updateName( if (const auto name = replyToFromName(holder); !name.isEmpty()) { replyToName.setText(st::fwdTextStyle, name, Ui::NameTextOptions()); if (const auto from = replyToFrom(holder)) { - replyToVersion = from->nameVersion; + replyToVersion = from->nameVersion(); } else { - replyToVersion = replyToMsg->author()->nameVersion; + replyToVersion = replyToMsg->author()->nameVersion(); } bool hasPreview = replyToMsg->media() ? replyToMsg->media()->hasReplyPreview() : false; int32 previewSkip = hasPreview ? (st::msgReplyBarSize.height() + st::msgReplyBarSkip - st::msgReplyBarSize.width() - st::msgReplyBarPos.x()) : 0; diff --git a/Telegram/SourceFiles/history/history_item_components.h b/Telegram/SourceFiles/history/history_item_components.h index c52ea92bb..9417982b4 100644 --- a/Telegram/SourceFiles/history/history_item_components.h +++ b/Telegram/SourceFiles/history/history_item_components.h @@ -70,19 +70,20 @@ struct HistoryMessageEdited : public RuntimeComponent { diff --git a/Telegram/SourceFiles/history/history_item_text.cpp b/Telegram/SourceFiles/history/history_item_text.cpp index e5abe929e..d0b5e97d8 100644 --- a/Telegram/SourceFiles/history/history_item_text.cpp +++ b/Telegram/SourceFiles/history/history_item_text.cpp @@ -19,7 +19,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL TextForMimeData WrapAsReply( TextForMimeData &&text, not_null to) { - const auto name = to->author()->name; + const auto name = to->author()->name(); auto result = TextForMimeData(); result.reserve( tr::lng_in_reply_to(tr::now).size() diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp index 149dfa3cd..2ed2fa906 100644 --- a/Telegram/SourceFiles/history/history_message.cpp +++ b/Telegram/SourceFiles/history/history_message.cpp @@ -1022,8 +1022,6 @@ void HistoryMessage::createComponents(CreateConfig &&config) { } else { _flags &= ~MessageFlag::HasReplyMarkup; } - const auto from = displayFrom(); - _fromNameVersion = from ? from->nameVersion : 1; } bool HistoryMessage::checkRepliesPts( @@ -1914,7 +1912,7 @@ QString HistoryMessage::notificationHeader() const { if (out() && isFromScheduled() && !_history->peer->isSelf()) { return tr::lng_from_you(tr::now); } else if (!_history->peer->isUser() && !isPost()) { - return from()->name; + return from()->name(); } return QString(); } diff --git a/Telegram/SourceFiles/history/history_message.h b/Telegram/SourceFiles/history/history_message.h index 5754fca77..0b75679b7 100644 --- a/Telegram/SourceFiles/history/history_message.h +++ b/Telegram/SourceFiles/history/history_message.h @@ -275,8 +275,6 @@ private: [[nodiscard]] bool checkRepliesPts( const HistoryMessageRepliesData &data) const; - mutable int _fromNameVersion = 0; - friend class HistoryView::Element; friend class HistoryView::Message; diff --git a/Telegram/SourceFiles/history/history_service.cpp b/Telegram/SourceFiles/history/history_service.cpp index 9a10d285c..02135e316 100644 --- a/Telegram/SourceFiles/history/history_service.cpp +++ b/Telegram/SourceFiles/history/history_service.cpp @@ -128,7 +128,7 @@ void HistoryService::setMessageByAction(const MTPmessageAction &action) { lt_from, fromLinkText(), // Link 1. lt_user, - Ui::Text::Link(u->name, 2), // Link 2. + Ui::Text::Link(u->name(), 2), // Link 2. Ui::Text::WithEntities); } } else if (users.isEmpty()) { @@ -146,7 +146,7 @@ void HistoryService::setMessageByAction(const MTPmessageAction &action) { auto user = history()->owner().user(users[i].v); result.links.push_back(user->createOpenLink()); - auto linkText = Ui::Text::Link(user->name, 2 + i); + auto linkText = Ui::Text::Link(user->name(), 2 + i); if (i == 0) { result.text = linkText; } else if (i + 1 == l) { @@ -256,7 +256,7 @@ void HistoryService::setMessageByAction(const MTPmessageAction &action) { lt_from, fromLinkText(), // Link 1. lt_user, - Ui::Text::Link(user->name, 2), // Link 2. + Ui::Text::Link(user->name(), 2), // Link 2. Ui::Text::WithEntities); } return result; @@ -367,7 +367,7 @@ void HistoryService::setMessageByAction(const MTPmessageAction &action) { result.text = tr::lng_action_secure_values_sent( tr::now, lt_user, - Ui::Text::Link(history()->peer->name, QString()), // Link 1. + Ui::Text::Link(history()->peer->name(), QString()), // Link 1. lt_documents, { .text = documents.join(", ") }, Ui::Text::WithEntities); @@ -415,14 +415,14 @@ void HistoryService::setMessageByAction(const MTPmessageAction &action) { lt_distance, { .text = distance }, lt_user, - Ui::Text::Link(toPeer->name, QString()), // Link 1. + Ui::Text::Link(toPeer->name(), QString()), // Link 1. Ui::Text::WithEntities); } else if (toId == selfId) { result.links.push_back(fromPeer->createOpenLink()); return tr::lng_action_proximity_reached_you( tr::now, lt_from, - Ui::Text::Link(fromPeer->name, QString()), // Link 1. + Ui::Text::Link(fromPeer->name(), QString()), // Link 1. lt_distance, { .text = distance }, Ui::Text::WithEntities); @@ -432,11 +432,11 @@ void HistoryService::setMessageByAction(const MTPmessageAction &action) { return tr::lng_action_proximity_reached( tr::now, lt_from, - Ui::Text::Link(fromPeer->name, 1), // Link 1. + Ui::Text::Link(fromPeer->name(), 1), // Link 1. lt_distance, { .text = distance }, lt_user, - Ui::Text::Link(toPeer->name, 2), // Link 2. + Ui::Text::Link(toPeer->name(), 2), // Link 2. Ui::Text::WithEntities); } }(); @@ -629,7 +629,7 @@ void HistoryService::setMessageByAction(const MTPmessageAction &action) { : tr::lng_action_gift_received)( tr::now, lt_user, - Ui::Text::Link(peer->name, 1), // Link 1. + Ui::Text::Link(peer->name(), 1), // Link 1. lt_cost, { Ui::FillAmountAndCurrency(amount, currency) }, Ui::Text::WithEntities); @@ -854,7 +854,7 @@ HistoryService::PreparedText HistoryService::prepareInvitedToCallText( lt_from, fromLinkText(), // Link 1. lt_user, - Ui::Text::Link(user->name, ++linkIndex), // Link N. + Ui::Text::Link(user->name(), ++linkIndex), // Link N. lt_chat, chatText, Ui::Text::WithEntities); @@ -873,7 +873,7 @@ HistoryService::PreparedText HistoryService::prepareInvitedToCallText( auto user = owner->user(users[i].v); result.links.push_back(user->createOpenLink()); - auto linkText = Ui::Text::Link(user->name, ++linkIndex); + auto linkText = Ui::Text::Link(user->name(), ++linkIndex); if (i == 0) { result.text = linkText; } else if (i + 1 == l) { @@ -1098,7 +1098,7 @@ HistoryService::PreparedText HistoryService::preparePaymentSentText() { lt_amount, { .text = payment->amount }, lt_user, - { .text = history()->peer->name }, + { .text = history()->peer->name() }, Ui::Text::WithEntities); } } else { @@ -1109,7 +1109,7 @@ HistoryService::PreparedText HistoryService::preparePaymentSentText() { lt_amount, { .text = payment->amount }, lt_user, - { .text = history()->peer->name }, + { .text = history()->peer->name() }, lt_invoice, invoiceTitle, Ui::Text::WithEntities); @@ -1256,7 +1256,7 @@ ItemPreview HistoryService::toPreview(ToPreviewOptions options) const { TextWithEntities HistoryService::inReplyText() const { auto result = HistoryService::notificationText(); - const auto &name = author()->name; + const auto &name = author()->name(); TextUtilities::Trim(result); if (result.text.startsWith(name)) { result = Ui::Text::Mid(result, name.size()); @@ -1272,7 +1272,7 @@ std::unique_ptr HistoryService::createView( } TextWithEntities HistoryService::fromLinkText() const { - return Ui::Text::Link(_from->name, 1); + return Ui::Text::Link(_from->name(), 1); } ClickHandlerPtr HistoryService::fromLink() const { @@ -1628,7 +1628,7 @@ HistoryService::PreparedText GenerateJoinedText( : tr::lng_action_add_you)( tr::now, lt_from, - Ui::Text::Link(inviter->name, QString()), + Ui::Text::Link(inviter->name(), QString()), Ui::Text::WithEntities); return result; } else if (history->peer->isMegagroup()) { @@ -1643,7 +1643,7 @@ HistoryService::PreparedText GenerateJoinedText( result.text = tr::lng_action_user_joined( tr::now, lt_from, - Ui::Text::Link(self->name, QString()), + Ui::Text::Link(self->name(), QString()), Ui::Text::WithEntities); return result; } diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 7606fec3c..dd0ed303e 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -1365,7 +1365,7 @@ void HistoryWidget::insertMention(UserData *user) { if (user->username.isEmpty()) { replacement = user->firstName; if (replacement.isEmpty()) { - replacement = user->name; + replacement = user->name(); } entityTag = PrepareMentionTag(user); } else { @@ -7522,9 +7522,9 @@ void HistoryWidget::updateForwardingTexts() { if (!insertedPeers.contains(from)) { insertedPeers.emplace(from); names.push_back(from->shortName()); - fullname = from->name; + fullname = from->name(); } - version += from->nameVersion; + version += from->nameVersion(); } else if (const auto info = item->hiddenSenderInfo()) { if (!insertedNames.contains(info->name)) { insertedNames.emplace(info->name); @@ -7588,7 +7588,7 @@ void HistoryWidget::checkForwardingInfo() { if (keepNames) { for (const auto item : _toForward.items) { if (const auto from = item->senderOriginal()) { - version += from->nameVersion; + version += from->nameVersion(); } else if (const auto info = item->hiddenSenderInfo()) { ++version; } else { @@ -7617,9 +7617,11 @@ void HistoryWidget::updateReplyToName() { }(); _replyToName.setText( st::msgNameStyle, - from->name, + from->name(), Ui::NameTextOptions()); - _replyToNameVersion = (_replyEditMsg ? _replyEditMsg : _kbReplyTo)->author()->nameVersion; + _replyToNameVersion = (_replyEditMsg + ? _replyEditMsg + : _kbReplyTo)->author()->nameVersion(); } void HistoryWidget::updateField() { @@ -7639,7 +7641,10 @@ void HistoryWidget::drawField(Painter &p, const QRect &rect) { auto hasForward = readyToForward(); auto drawMsgText = (_editMsgId || _replyToId) ? _replyEditMsg : _kbReplyTo; if (_editMsgId || _replyToId || (!hasForward && _kbReplyTo)) { - if (!_editMsgId && drawMsgText && drawMsgText->author()->nameVersion > _replyToNameVersion) { + if (!_editMsgId + && drawMsgText + && (_replyToNameVersion + < drawMsgText->author()->nameVersion())) { updateReplyToName(); } backy -= st::historyReplyHeight; diff --git a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp index f1846b521..902d9abaa 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp @@ -709,12 +709,12 @@ void FieldHeader::paintEditOrReplyToMessage(Painter &p) { const auto user = _shownMessage->displayFrom() ? _shownMessage->displayFrom() : _shownMessage->author().get(); - if (user->nameVersion > _shownMessageNameVersion) { + if (_shownMessageNameVersion < user->nameVersion()) { _shownMessageName.setText( st::msgNameStyle, - user->name, + user->name(), Ui::NameTextOptions()); - _shownMessageNameVersion = user->nameVersion; + _shownMessageNameVersion = user->nameVersion(); } } @@ -1476,7 +1476,7 @@ void ComposeControls::initAutocomplete() { const auto insertMention = [=](not_null user) { if (user->username.isEmpty()) { _field->insertTag( - user->firstName.isEmpty() ? user->name : user->firstName, + user->firstName.isEmpty() ? user->name() : user->firstName, PrepareMentionTag(user)); } else { _field->insertTag('@' + user->username); diff --git a/Telegram/SourceFiles/history/view/history_view_contact_status.cpp b/Telegram/SourceFiles/history/view/history_view_contact_status.cpp index 47e03e760..490712ac4 100644 --- a/Telegram/SourceFiles/history/view/history_view_contact_status.cpp +++ b/Telegram/SourceFiles/history/view/history_view_contact_status.cpp @@ -467,7 +467,7 @@ void ContactStatus::setupShareHandler(not_null user) { Ui::Text::WithEntities( Ui::FormatPhone(user->session().user()->phone())), lt_user, - Ui::Text::Bold(user->name), + Ui::Text::Bold(user->name()), Ui::Text::WithEntities), .confirmed = share, .confirmText = tr::lng_box_ok(), diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index 987f1c7a5..9b7fbd410 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -1964,11 +1964,11 @@ TextForMimeData ListWidget::getSelectedText() const { TextForMimeData &&unwrapped) { auto time = ItemDateTime(item).toString(timeFormat); auto part = TextForMimeData(); - auto size = item->author()->name.size() + auto size = item->author()->name().size() + time.size() + unwrapped.expanded.size(); part.reserve(size); - part.append(item->author()->name).append(time); + part.append(item->author()->name()).append(time); part.append(std::move(unwrapped)); texts.emplace_back(std::move(item), std::move(part)); fullSize += size; diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index 1438480e8..b3d036ead 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -539,9 +539,10 @@ QSize Message::performCountOptimalSize() { // They will be added in resizeGetHeight() anyway. if (displayFromName()) { const auto from = item->displayFrom(); + validateFromNameText(from); const auto &name = from - ? from->nameText() - : item->hiddenSenderInfo()->nameText; + ? _fromName + : item->hiddenSenderInfo()->nameText(); auto namew = st::msgPadding.left() + name.maxWidth() + st::msgPadding.right(); @@ -746,7 +747,7 @@ void Message::draw(Painter &p, const PaintContext &context) const { if (bubble) { if (displayFromName() && item->displayFrom() - && item->displayFrom()->nameVersion > item->_fromNameVersion) { + && (_fromNameVersion < item->displayFrom()->nameVersion())) { fromNameUpdated(g.width()); } @@ -1095,14 +1096,15 @@ void Message::paintFromName( : item->isSponsored() ? st->boxTextFgGood() : stm->msgServiceFg); - return &from->nameText(); + validateFromNameText(from); + return &_fromName; } else if (const auto info = item->hiddenSenderInfo()) { p.setPen(!service ? FromNameFg(context, info->colorPeerId) : item->isSponsored() ? st->boxTextFgGood() : stm->msgServiceFg); - return &info->nameText; + return &info->nameText(); } else { Unexpected("Corrupt sender information in message."); } @@ -1698,9 +1700,10 @@ bool Message::getStateFromName( const auto from = item->displayFrom(); const auto nameText = [&]() -> const Ui::Text::String * { if (from) { - return &from->nameText(); + validateFromNameText(from); + return &_fromName; } else if (const auto info = item->hiddenSenderInfo()) { - return &info->nameText; + return &info->nameText(); } else { Unexpected("Corrupt forwarded information in message."); } @@ -2203,6 +2206,17 @@ void Message::refreshReactions() { } } +void Message::validateFromNameText(PeerData *from) const { + const auto version = from ? from->nameVersion() : 0; + if (_fromNameVersion < version) { + _fromNameVersion = version; + _fromName.setText( + st::msgNameStyle, + from->name(), + Ui::NameTextOptions()); + } +} + void Message::itemDataChanged() { const auto wasInfo = _bottomInfo.currentSize(); const auto wasReactions = _reactions @@ -2738,14 +2752,14 @@ void Message::fromNameUpdated(int width) const { width -= st::msgPadding.right() + replyWidth; } const auto from = item->displayFrom(); - item->_fromNameVersion = from ? from->nameVersion : 1; + validateFromNameText(from); if (const auto via = item->Get()) { if (!displayForwardedFrom()) { const auto nameText = [&]() -> const Ui::Text::String * { if (from) { - return &from->nameText(); - } else if (const auto info = item->hiddenSenderInfo()) { - return &info->nameText; + return &_fromName; + } else if (const auto info = item->hiddenSenderInfo()) { + return &info->nameText(); } else { Unexpected("Corrupted forwarded information in message."); } diff --git a/Telegram/SourceFiles/history/view/history_view_message.h b/Telegram/SourceFiles/history/view/history_view_message.h index 1bbf929d2..bef81fc92 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.h +++ b/Telegram/SourceFiles/history/view/history_view_message.h @@ -243,6 +243,7 @@ private: void refreshRightBadge(); void refreshReactions(); + void validateFromNameText(PeerData *from) const; mutable ClickHandlerPtr _rightActionLink; mutable ClickHandlerPtr _fastReplyLink; @@ -250,7 +251,9 @@ private: std::unique_ptr _reactions; mutable std::unique_ptr _comments; + mutable Ui::Text::String _fromName; Ui::Text::String _rightBadge; + mutable int _fromNameVersion = 0; int _bubbleWidthLimit = 0; BottomInfo _bottomInfo; diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp index 9524930c2..4f9d75c88 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp @@ -105,7 +105,9 @@ rpl::producer RootViewContent( const auto sender = (item && item->discussionPostOriginalSender()) ? item->discussionPostOriginalSender() : history->peer.get(); - content.title = sender->name.isEmpty() ? "Message" : sender->name; + content.title = sender->name().isEmpty() + ? "Message" + : sender->name(); return std::move(content); }); } diff --git a/Telegram/SourceFiles/history/view/history_view_requests_bar.cpp b/Telegram/SourceFiles/history/view/history_view_requests_bar.cpp index a64b7b04c..067593a9f 100644 --- a/Telegram/SourceFiles/history/view/history_view_requests_bar.cpp +++ b/Telegram/SourceFiles/history/view/history_view_requests_bar.cpp @@ -160,7 +160,7 @@ rpl::producer RequestsBarContentByPeer( if (count == 1 && !state->users.empty()) { const auto user = state->users.front(); state->current.nameShort = user->shortName(); - state->current.nameFull = user->name; + state->current.nameFull = user->name(); } else { state->current.nameShort = state->current.nameFull diff --git a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp index efa1f952c..2f0c42a45 100644 --- a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp @@ -519,7 +519,13 @@ void TopBarWidget::paintTopBar(Painter &p) { } } else if (const auto history = _activeChat.key.history()) { const auto peer = history->peer; - const auto &text = peer->topBarNameText(); + if (_titleNameVersion < peer->nameVersion()) { + _titleNameVersion = peer->nameVersion(); + _title.setText( + st::msgNameStyle, + peer->topBarNameText(), + Ui::NameTextOptions()); + } const auto badgeStyle = Ui::PeerBadgeStyle{ &st::dialogsVerifiedIcon, &st::dialogsPremiumIcon, @@ -533,13 +539,13 @@ void TopBarWidget::paintTopBar(Painter &p) { nametop, availableWidth, st::msgNameStyle.font->height), - text.maxWidth(), + _title.maxWidth(), width(), badgeStyle); const auto namewidth = availableWidth - badgeWidth; p.setPen(st::dialogsNameFg); - peer->topBarNameText().drawElided( + _title.drawElided( p, nameleft, nametop, @@ -692,6 +698,7 @@ void TopBarWidget::setActiveChat( update(); if (peerChanged) { + _titleNameVersion = 0; _emojiInteractionSeen = nullptr; _activeChatLifetime.destroy(); if (const auto history = _activeChat.key.history()) { diff --git a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.h b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.h index 83626b752..30db1eefa 100644 --- a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.h +++ b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.h @@ -159,6 +159,9 @@ private: std::unique_ptr _emojiInteractionSeen; rpl::lifetime _activeChatLifetime; + Ui::Text::String _title; + int _titleNameVersion = 0; + int _selectedCount = 0; bool _canDelete = false; bool _canForward = false; diff --git a/Telegram/SourceFiles/info/profile/info_profile_values.cpp b/Telegram/SourceFiles/info/profile/info_profile_values.cpp index 9c83b157e..db3f0e8fb 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_values.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_values.cpp @@ -78,7 +78,7 @@ rpl::producer NameValue(not_null peer) { peer, UpdateFlag::Name ) | rpl::map([=] { - return peer->name; + return peer->name(); }) | Ui::Text::ToWithEntities(); } diff --git a/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp b/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp index b8c328294..a12e94445 100644 --- a/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp +++ b/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp @@ -744,7 +744,7 @@ void AttachWebView::confirmOpen( .text = tr::lng_allow_bot_webview( tr::now, lt_bot_name, - Ui::Text::Bold(_bot->name), + Ui::Text::Bold(_bot->name()), Ui::Text::RichLangValue), .confirmed = callback, .confirmText = tr::lng_box_ok(), @@ -828,7 +828,7 @@ void AttachWebView::show( &AttachWebViewBot::user); const auto name = (attached != end(_attachBots)) ? attached->name - : _bot->name; + : _bot->name(); const auto hasSettings = (attached != end(_attachBots)) && !attached->inactive && attached->hasSettings; diff --git a/Telegram/SourceFiles/media/player/media_player_widget.cpp b/Telegram/SourceFiles/media/player/media_player_widget.cpp index 8ac213f77..9d6e2b8e1 100644 --- a/Telegram/SourceFiles/media/player/media_player_widget.cpp +++ b/Telegram/SourceFiles/media/player/media_player_widget.cpp @@ -1015,7 +1015,7 @@ void Widget::handleSongChange() { if (document->isVoiceMessage() || document->isVideoMessage()) { if (const auto item = document->owner().message(current.contextId())) { const auto name = (!item->out() || item->isPost()) - ? item->fromOriginal()->name + ? item->fromOriginal()->name() : tr::lng_from_you(tr::now); const auto date = [item] { const auto parsed = ItemDateTime(item); diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp index 766c65336..dec7be453 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp @@ -2233,12 +2233,14 @@ void OverlayWidget::refreshFromLabel() { _fromName = info->name; } else { Assert(_from != nullptr); - const auto from = _from->migrateTo() ? _from->migrateTo() : _from; - _fromName = from->name; + const auto from = _from->migrateTo() + ? _from->migrateTo() + : _from; + _fromName = from->name(); } } else { _from = _user; - _fromName = _user ? _user->name : QString(); + _fromName = _user ? _user->name() : QString(); } } diff --git a/Telegram/SourceFiles/overview/overview_layout.cpp b/Telegram/SourceFiles/overview/overview_layout.cpp index 1b6ce5654..c42dd19a7 100644 --- a/Telegram/SourceFiles/overview/overview_layout.cpp +++ b/Telegram/SourceFiles/overview/overview_layout.cpp @@ -663,8 +663,8 @@ void Voice::paint(Painter &p, const QRect &clip, TextSelection selection, const } } const auto showPause = updateStatusText(); - const auto nameVersion = parent()->fromOriginal()->nameVersion; - if (nameVersion > _nameVersion) { + const auto nameVersion = parent()->fromOriginal()->nameVersion(); + if (_nameVersion < nameVersion) { updateName(); } const auto radial = isRadialAnimation(); @@ -879,18 +879,31 @@ const style::RoundCheckbox &Voice::checkboxStyle() const { } void Voice::updateName() { - auto version = 0; if (const auto forwarded = parent()->Get()) { if (parent()->fromOriginal()->isChannel()) { - _name.setText(st::semiboldTextStyle, tr::lng_forwarded_channel(tr::now, lt_channel, parent()->fromOriginal()->name), Ui::NameTextOptions()); + _name.setText( + st::semiboldTextStyle, + tr::lng_forwarded_channel( + tr::now, + lt_channel, + parent()->fromOriginal()->name()), + Ui::NameTextOptions()); } else { - _name.setText(st::semiboldTextStyle, tr::lng_forwarded(tr::now, lt_user, parent()->fromOriginal()->name), Ui::NameTextOptions()); + _name.setText( + st::semiboldTextStyle, + tr::lng_forwarded( + tr::now, + lt_user, + parent()->fromOriginal()->name()), + Ui::NameTextOptions()); } } else { - _name.setText(st::semiboldTextStyle, parent()->from()->name, Ui::NameTextOptions()); + _name.setText( + st::semiboldTextStyle, + parent()->from()->name(), + Ui::NameTextOptions()); } - version = parent()->fromOriginal()->nameVersion; - _nameVersion = version; + _nameVersion = parent()->fromOriginal()->nameVersion(); } int Voice::duration() const { diff --git a/Telegram/SourceFiles/passport/passport_panel_form.cpp b/Telegram/SourceFiles/passport/passport_panel_form.cpp index 364b74171..3978e0763 100644 --- a/Telegram/SourceFiles/passport/passport_panel_form.cpp +++ b/Telegram/SourceFiles/passport/passport_panel_form.cpp @@ -85,7 +85,7 @@ not_null PanelForm::setupContent() { inner, object_ptr( inner, - tr::lng_passport_request1(tr::now, lt_bot, bot->name), + tr::lng_passport_request1(tr::now, lt_bot, bot->name()), st::passportPasswordLabelBold)), st::passportFormAbout1Padding)->entity(); @@ -154,7 +154,7 @@ not_null PanelForm::setupContent() { lt_policy, tr::lng_passport_policy( lt_bot, - rpl::single(bot->name) + rpl::single(bot->name()) ) | Ui::Text::ToLink(policyUrl), lt_bot, rpl::single('@' + bot->username) | Ui::Text::ToWithEntities(), diff --git a/Telegram/SourceFiles/passport/passport_panel_password.cpp b/Telegram/SourceFiles/passport/passport_panel_password.cpp index d5f8e8273..bb9736a3b 100644 --- a/Telegram/SourceFiles/passport/passport_panel_password.cpp +++ b/Telegram/SourceFiles/passport/passport_panel_password.cpp @@ -38,7 +38,7 @@ PanelAskPassword::PanelAskPassword( tr::lng_passport_request1( tr::now, lt_bot, - _controller->bot()->name), + _controller->bot()->name()), st::passportPasswordLabelBold) , _about2( this, @@ -179,7 +179,7 @@ void PanelNoPassword::setupContent() { tr::lng_passport_request1( tr::now, lt_bot, - _controller->bot()->name), + _controller->bot()->name()), st::passportPasswordLabelBold)), st::passportPasswordAbout1Padding)->entity(); diff --git a/Telegram/SourceFiles/payments/payments_checkout_process.cpp b/Telegram/SourceFiles/payments/payments_checkout_process.cpp index 79f538bc6..efd2ffd39 100644 --- a/Telegram/SourceFiles/payments/payments_checkout_process.cpp +++ b/Telegram/SourceFiles/payments/payments_checkout_process.cpp @@ -316,7 +316,7 @@ void CheckoutProcess::handleFormUpdate(const FormUpdate &update) { }, [&](const BotTrustRequired &data) { UnregisterPaymentStart(this); _submitState = SubmitState::Validated; - _panel->showWarning(data.bot->name, data.provider->name); + _panel->showWarning(data.bot->name(), data.provider->name()); if (const auto box = _enterPasswordBox.data()) { box->closeBox(); } diff --git a/Telegram/SourceFiles/payments/payments_form.cpp b/Telegram/SourceFiles/payments/payments_form.cpp index 33ebc7555..9ca0f9682 100644 --- a/Telegram/SourceFiles/payments/payments_form.cpp +++ b/Telegram/SourceFiles/payments/payments_form.cpp @@ -418,13 +418,13 @@ void Form::processDetails(const MTPDpayments_paymentForm &data) { } if (const auto botId = _details.botId) { if (const auto bot = _session->data().userLoaded(botId)) { - _invoice.cover.seller = bot->name; + _invoice.cover.seller = bot->name(); _details.termsBotUsername = bot->username; } } if (const auto providerId = _details.providerId) { if (const auto bot = _session->data().userLoaded(providerId)) { - _invoice.provider = bot->name; + _invoice.provider = bot->name(); } } } @@ -456,7 +456,7 @@ void Form::processDetails(const MTPDpayments_paymentReceipt &data) { } if (_details.botId) { if (const auto bot = _session->data().userLoaded(_details.botId)) { - _invoice.cover.seller = bot->name; + _invoice.cover.seller = bot->name(); } } } diff --git a/Telegram/SourceFiles/profile/profile_block_peer_list.cpp b/Telegram/SourceFiles/profile/profile_block_peer_list.cpp index 2ac656960..953fc4188 100644 --- a/Telegram/SourceFiles/profile/profile_block_peer_list.cpp +++ b/Telegram/SourceFiles/profile/profile_block_peer_list.cpp @@ -99,7 +99,7 @@ void PeerListWidget::paintItem(Painter &p, int x, int y, Item *item, bool select if (item->name.isEmpty()) { item->name.setText( st::msgNameStyle, - item->peer->name, + item->peer->name(), Ui::NameTextOptions()); } int nameLeft = x + _st.namePosition.x(); diff --git a/Telegram/SourceFiles/settings/settings_information.cpp b/Telegram/SourceFiles/settings/settings_information.cpp index 942f09d9c..30124c018 100644 --- a/Telegram/SourceFiles/settings/settings_information.cpp +++ b/Telegram/SourceFiles/settings/settings_information.cpp @@ -599,11 +599,11 @@ void SetupAccountsWrap( const auto user = session->user(); auto text = rpl::single( - user->name + user->name() ) | rpl::then(session->changes().realtimeNameUpdates( user ) | rpl::map([=] { - return user->name; + return user->name(); })); auto result = object_ptr( parent, diff --git a/Telegram/SourceFiles/settings/settings_information.h b/Telegram/SourceFiles/settings/settings_information.h index 5eb771f07..2fea258aa 100644 --- a/Telegram/SourceFiles/settings/settings_information.h +++ b/Telegram/SourceFiles/settings/settings_information.h @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "settings/settings_common.h" namespace Dialogs::Ui { +using namespace ::Ui; struct UnreadBadgeStyle; } // namespace Dialogs::Ui diff --git a/Telegram/SourceFiles/settings/settings_premium.cpp b/Telegram/SourceFiles/settings/settings_premium.cpp index 3a1f23868..c37b79cc9 100644 --- a/Telegram/SourceFiles/settings/settings_premium.cpp +++ b/Telegram/SourceFiles/settings/settings_premium.cpp @@ -770,7 +770,7 @@ QPointer Premium::createPinnedToTop( lt_count, rpl::single(float64(gift.months)), lt_user, - rpl::single(Ui::Text::Bold(peer->name)), + rpl::single(Ui::Text::Bold(peer->name())), Ui::Text::RichLangValue); } } diff --git a/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp b/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp index cd4bac5a1..531b4c84d 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp +++ b/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp @@ -218,7 +218,7 @@ struct ForwardedTooltip { const auto phrase = tr::lng_forwarded( tr::now, lt_user, - view->history()->session().user()->name); + view->history()->session().user()->name()); const auto kReplacementPosition = QChar(0x0001); const auto possiblePosition = tr::lng_forwarded( tr::now, diff --git a/Telegram/SourceFiles/storage/serialize_peer.cpp b/Telegram/SourceFiles/storage/serialize_peer.cpp index c3c5da852..b1f9e0823 100644 --- a/Telegram/SourceFiles/storage/serialize_peer.cpp +++ b/Telegram/SourceFiles/storage/serialize_peer.cpp @@ -128,7 +128,7 @@ uint32 peerSize(not_null peer) { + sizeof(qint32) // contact + sizeof(qint32); // botInfoVersion } else if (const auto chat = peer->asChat()) { - result += stringSize(chat->name) + result += stringSize(chat->name()) + sizeof(qint32) // count + sizeof(qint32) // date + sizeof(qint32) // version @@ -137,7 +137,7 @@ uint32 peerSize(not_null peer) { + sizeof(quint32) // flags + stringSize(chat->inviteLink()); } else if (const auto channel = peer->asChannel()) { - result += stringSize(channel->name) + result += stringSize(channel->name()) + sizeof(quint64) // access + sizeof(qint32) // date + sizeof(qint32) // version @@ -175,7 +175,7 @@ void writePeer(QDataStream &stream, not_null peer) { auto field1 = qint32(uint32(chat->creator.bare & 0xFFFFFFFFULL)); auto field2 = qint32(uint32(chat->creator.bare >> 32) << 8); stream - << chat->name + << chat->name() << qint32(chat->count) << qint32(chat->date) << qint32(chat->version()) @@ -185,7 +185,7 @@ void writePeer(QDataStream &stream, not_null peer) { << chat->inviteLink(); } else if (const auto channel = peer->asChannel()) { stream - << channel->name + << channel->name() << quint64(channel->access) << qint32(channel->date) << qint32(0) // legacy - version diff --git a/Telegram/SourceFiles/window/notifications_manager.cpp b/Telegram/SourceFiles/window/notifications_manager.cpp index 0b253f868..58ad1b9e1 100644 --- a/Telegram/SourceFiles/window/notifications_manager.cpp +++ b/Telegram/SourceFiles/window/notifications_manager.cpp @@ -874,7 +874,7 @@ QString Manager::addTargetAccountName( ? (title + accountNameSeparator() + (session->user()->username.isEmpty() - ? session->user()->name + ? session->user()->name() : session->user()->username)) : title; } @@ -994,10 +994,10 @@ void NativeManager::doShowNotification(NotificationFields &&fields) { ? AppName.utf16() : (scheduled && peer->isSelf()) ? tr::lng_notification_reminder(tr::now) - : peer->name; + : peer->name(); const auto fullTitle = addTargetAccountName(title, &peer->session()); const auto subtitle = reactionFrom - ? (reactionFrom != peer ? reactionFrom->name : QString()) + ? (reactionFrom != peer ? reactionFrom->name() : QString()) : options.hideNameAndPhoto ? QString() : item->notificationHeader(); diff --git a/Telegram/SourceFiles/window/notifications_manager_default.cpp b/Telegram/SourceFiles/window/notifications_manager_default.cpp index 89d7b29fc..b2d863610 100644 --- a/Telegram/SourceFiles/window/notifications_manager_default.cpp +++ b/Telegram/SourceFiles/window/notifications_manager_default.cpp @@ -86,7 +86,7 @@ Manager::QueuedNotification::QueuedNotification(NotificationFields &&fields) , author(!fields.reactionFrom ? fields.item->notificationHeader() : (fields.reactionFrom != peer) - ? fields.reactionFrom->name + ? fields.reactionFrom->name() : QString()) , item((fields.forwardedCount < 2) ? fields.item.get() : nullptr) , forwardedCount(fields.forwardedCount) @@ -922,7 +922,7 @@ void Notification::updateNotifyDisplay() { ? qsl("Telegram Desktop") : reminder ? tr::lng_notification_reminder(tr::now) - : _history->peer->nameText().toString(); + : _history->peer->name(); const auto fullTitle = manager()->addTargetAccountName( title, &_history->session()); diff --git a/Telegram/SourceFiles/window/window_main_menu.cpp b/Telegram/SourceFiles/window/window_main_menu.cpp index 272d742e8..777a69f8a 100644 --- a/Telegram/SourceFiles/window/window_main_menu.cpp +++ b/Telegram/SourceFiles/window/window_main_menu.cpp @@ -22,6 +22,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/wrap/vertical_layout_reorder.h" #include "ui/text/format_values.h" // Ui::FormatPhone #include "ui/text/text_utilities.h" +#include "ui/text/text_options.h" #include "ui/special_buttons.h" #include "ui/empty_userpic.h" #include "dialogs/ui/dialogs_layout.h" @@ -765,7 +766,14 @@ void MainMenu::paintEvent(QPaintEvent *e) { p.setFont(st::semiboldFont); p.setPen(st::windowBoldFg); - _controller->session().user()->nameText().drawLeftElided( + const auto user = _controller->session().user(); + if (_nameVersion < user->nameVersion()) { + _name.setText( + st::msgNameStyle, + user->name(), + Ui::NameTextOptions()); + } + _name.drawLeftElided( p, st::mainMenuCoverNameLeft, st::mainMenuCoverNameTop, diff --git a/Telegram/SourceFiles/window/window_main_menu.h b/Telegram/SourceFiles/window/window_main_menu.h index fcb9a2875..df08e222e 100644 --- a/Telegram/SourceFiles/window/window_main_menu.h +++ b/Telegram/SourceFiles/window/window_main_menu.h @@ -66,6 +66,8 @@ private: const not_null _controller; object_ptr _userpicButton; + Ui::Text::String _name; + int _nameVersion = 0; object_ptr _toggleAccounts; object_ptr _resetScaleButton = { nullptr }; object_ptr _scroll; diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index d9210d99a..c3becab69 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -950,7 +950,7 @@ void PeerMenuDeleteContact( const auto text = tr::lng_sure_delete_contact( tr::now, lt_contact, - user->name); + user->name()); const auto deleteSure = [=](Fn &&close) { close(); user->session().api().request(MTPcontacts_DeleteContacts( @@ -992,8 +992,8 @@ void PeerMenuShareContactBox( return; } auto recipient = peer->isUser() - ? peer->name - : '\xAB' + peer->name + '\xBB'; + ? peer->name() + : '\xAB' + peer->name() + '\xBB'; navigation->parentController()->show( Ui::MakeConfirmBox({ .text = tr::lng_forward_share_contact( @@ -1084,7 +1084,7 @@ void PeerMenuBlockUserBox( : v::get(suggestReport); const auto user = peer->asUser(); - const auto name = user ? user->shortName() : peer->name; + const auto name = user ? user->shortName() : peer->name(); if (user) { box->addRow(object_ptr( box, @@ -1130,7 +1130,7 @@ void PeerMenuBlockUserBox( tr::lng_delete_all_from_user( tr::now, lt_user, - Ui::Text::Bold(peer->name), + Ui::Text::Bold(peer->name()), Ui::Text::WithEntities), true, st::defaultBoxCheckbox))