diff --git a/Telegram/SourceFiles/history/history_item_components.cpp b/Telegram/SourceFiles/history/history_item_components.cpp index e9ac1817c0..292f5d65a4 100644 --- a/Telegram/SourceFiles/history/history_item_components.cpp +++ b/Telegram/SourceFiles/history/history_item_components.cpp @@ -244,7 +244,7 @@ bool HistoryMessageReply::updateData( replyToMsg->inReplyText(), Ui::DialogTextOptions()); - updateName(); + updateName(holder); setReplyToLinkFrom(holder); if (!replyToMsg->Has()) { @@ -283,25 +283,60 @@ void HistoryMessageReply::clearData(not_null holder) { refreshReplyToMedia(); } -bool HistoryMessageReply::isNameUpdated() const { - if (replyToMsg && replyToMsg->author()->nameVersion > replyToVersion) { - updateName(); - return true; +PeerData *HistoryMessageReply::replyToFrom( + not_null holder) const { + if (!replyToMsg) { + return nullptr; + } else if (holder->Has()) { + if (const auto fwd = replyToMsg->Get()) { + return fwd->originalSender; + } + } + if (const auto from = replyToMsg->displayFrom()) { + return from; + } + return replyToMsg->author().get(); +} + +QString HistoryMessageReply::replyToFromName( + not_null holder) const { + if (!replyToMsg) { + return QString(); + } else if (holder->Has()) { + if (const auto fwd = replyToMsg->Get()) { + return fwd->originalSender + ? replyToFromName(fwd->originalSender) + : fwd->hiddenSenderInfo->name; + } + } + if (const auto from = replyToMsg->displayFrom()) { + return replyToFromName(from); + } + return replyToFromName(replyToMsg->author()); +} + +QString HistoryMessageReply::replyToFromName( + not_null peer) const { + if (const auto user = replyToVia ? peer->asUser() : nullptr) { + return user->firstName; + } + return peer->name; +} + +bool HistoryMessageReply::isNameUpdated( + not_null holder) const { + if (const auto from = replyToFrom(holder)) { + if (from->nameVersion > replyToVersion) { + updateName(holder); + return true; + } } return false; } -void HistoryMessageReply::updateName() const { - if (replyToMsg) { - const auto from = [&] { - if (const auto from = replyToMsg->displayFrom()) { - return from; - } - return replyToMsg->author().get(); - }(); - const auto name = (replyToVia && from->isUser()) - ? from->asUser()->firstName - : from->name; +void HistoryMessageReply::updateName( + not_null holder) const { + if (const auto name = replyToFromName(holder); !name.isEmpty()) { replyToName.setText(st::fwdTextStyle, name, Ui::NameTextOptions()); replyToVersion = replyToMsg->author()->nameVersion; bool hasPreview = replyToMsg->media() ? replyToMsg->media()->hasReplyPreview() : false; diff --git a/Telegram/SourceFiles/history/history_item_components.h b/Telegram/SourceFiles/history/history_item_components.h index 95a350d2ea..d594a7f6bd 100644 --- a/Telegram/SourceFiles/history/history_item_components.h +++ b/Telegram/SourceFiles/history/history_item_components.h @@ -154,8 +154,13 @@ struct HistoryMessageReply : public RuntimeComponent holder); - bool isNameUpdated() const; - void updateName() const; + [[nodiscard]] PeerData *replyToFrom( + not_null holder) const; + [[nodiscard]] QString replyToFromName( + not_null holder) const; + [[nodiscard]] QString replyToFromName(not_null peer) const; + [[nodiscard]] bool isNameUpdated(not_null holder) const; + void updateName(not_null holder) const; void resize(int width) const; void itemRemoved(HistoryMessage *holder, HistoryItem *removed); diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index 380cdc33b7..be923897f1 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -460,7 +460,7 @@ QSize Message::performCountOptimalSize() { forwarded->create(via); } if (reply) { - reply->updateName(); + reply->updateName(item); } auto mediaDisplayed = false; @@ -931,7 +931,7 @@ void Message::draw(Painter &p, const PaintContext &context) const { } if (const auto reply = displayedReply()) { - if (reply->isNameUpdated()) { + if (reply->isNameUpdated(message())) { const_cast(this)->setPendingResize(); } }