diff --git a/Telegram/SourceFiles/data/data_session.cpp b/Telegram/SourceFiles/data/data_session.cpp index 2ff9d4fa7b..d789e2cf69 100644 --- a/Telegram/SourceFiles/data/data_session.cpp +++ b/Telegram/SourceFiles/data/data_session.cpp @@ -1775,6 +1775,7 @@ bool Session::checkEntitiesAndViewsUpdate(const MTPDmessage &data) { data.vreply_to_msg_id().v)); }); } + existing->setPostAuthor(data.vpost_author().value_or_empty()); existing->indexAsNewItem(); existing->contributeToSlowmode(data.vdate().v); requestItemTextRefresh(existing); diff --git a/Telegram/SourceFiles/history/history_item.h b/Telegram/SourceFiles/history/history_item.h index 4ee3cd5ef4..82b99f50c4 100644 --- a/Telegram/SourceFiles/history/history_item.h +++ b/Telegram/SourceFiles/history/history_item.h @@ -293,6 +293,8 @@ public: } virtual void setReplyToTop(MsgId replyToTop) { } + virtual void setPostAuthor(const QString &author) { + } virtual void setRealId(MsgId newId); virtual void incrementReplyToTopCounter() { } diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp index 5bb2fa68c4..1064eccfa0 100644 --- a/Telegram/SourceFiles/history/history_message.cpp +++ b/Telegram/SourceFiles/history/history_message.cpp @@ -1601,6 +1601,28 @@ void HistoryMessage::setViewsCount(int count) { void HistoryMessage::setForwardsCount(int count) { } +void HistoryMessage::setPostAuthor(const QString &author) { + auto msgsigned = Get(); + if (author.isEmpty()) { + if (!msgsigned) { + return; + } + RemoveComponents(HistoryMessageSigned::Bit()); + history()->owner().requestItemResize(this); + return; + } + if (!msgsigned) { + AddComponents(HistoryMessageSigned::Bit()); + msgsigned = Get(); + } else if (msgsigned->author == author) { + return; + } + msgsigned->author = author; + msgsigned->isAnonymousRank = !isDiscussionPost() + && this->author()->isMegagroup(); + history()->owner().requestItemResize(this); +} + void HistoryMessage::setReplies(const MTPMessageReplies &data) { data.match([&](const MTPDmessageReplies &data) { auto views = Get(); diff --git a/Telegram/SourceFiles/history/history_message.h b/Telegram/SourceFiles/history/history_message.h index a12dafcb59..4d9ec16802 100644 --- a/Telegram/SourceFiles/history/history_message.h +++ b/Telegram/SourceFiles/history/history_message.h @@ -129,6 +129,7 @@ public: void clearReplies() override; void changeRepliesCount(int delta, PeerId replier) override; void setReplyToTop(MsgId replyToTop) override; + void setPostAuthor(const QString &author) override; void setRealId(MsgId newId) override; void incrementReplyToTopCounter() override; diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index d94729fff4..9121cf3f4b 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -228,7 +228,6 @@ Message::Message( : Element(delegate, data, replacing) { initLogEntryOriginal(); initPsa(); - refreshRightBadge(); } Message::~Message() { @@ -287,7 +286,6 @@ void Message::applyGroupAdminChanges( const base::flat_set &changes) { if (!data()->out() && changes.contains(peerToUser(data()->author()->id))) { - refreshRightBadge(); history()->owner().requestViewResize(this); } } @@ -301,6 +299,7 @@ QSize Message::performCountOptimalSize() { updateMediaInBubbleState(); refreshEditedBadge(); + refreshRightBadge(); auto mediaOnBottom = (logEntryOriginal() != nullptr) || (media && media->isDisplayed() && media->isBubbleBottom()); @@ -783,74 +782,77 @@ void Message::paintFromName( QRect &trect, bool selected) const { const auto item = message(); - if (displayFromName()) { - const auto badgeWidth = _rightBadge.isEmpty() ? 0 : _rightBadge.maxWidth(); - const auto replyWidth = [&] { - if (isUnderCursor() && displayFastReply()) { - return st::msgFont->width(FastReplyText()); - } - return 0; - }(); - const auto rightWidth = replyWidth ? replyWidth : badgeWidth; - auto availableLeft = trect.left(); - auto availableWidth = trect.width(); - if (rightWidth) { - availableWidth -= st::msgPadding.right() + rightWidth; + if (!displayFromName()) { + return; + } + const auto badgeWidth = _rightBadge.isEmpty() ? 0 : _rightBadge.maxWidth(); + const auto replyWidth = [&] { + if (isUnderCursor() && displayFastReply()) { + return st::msgFont->width(FastReplyText()); } + return 0; + }(); + const auto rightWidth = replyWidth ? replyWidth : badgeWidth; + auto availableLeft = trect.left(); + auto availableWidth = trect.width(); + if (rightWidth) { + availableWidth -= st::msgPadding.right() + rightWidth; + } - p.setFont(st::msgNameFont); - const auto nameText = [&]() -> const Ui::Text::String * { - const auto from = item->displayFrom(); - if (hasOutLayout()) { - p.setPen(selected ? st::msgOutServiceFgSelected : st::msgOutServiceFg); - return &from->nameText(); - } else if (item->isPost()) { - p.setPen(selected ? st::msgInServiceFgSelected : st::msgInServiceFg); - return &from->nameText(); - } else if (from) { - p.setPen(FromNameFg(from->id, selected)); - return &from->nameText(); - } else if (const auto info = item->hiddenForwardedInfo()) { - p.setPen(FromNameFg(info->colorPeerId, selected)); - return &info->nameText; - } else { - Unexpected("Corrupt forwarded information in message."); - } - }(); - nameText->drawElided(p, availableLeft, trect.top(), availableWidth); - const auto skipWidth = nameText->maxWidth() + st::msgServiceFont->spacew; + p.setFont(st::msgNameFont); + const auto outbg = hasOutLayout(); + const auto nameText = [&]() -> const Ui::Text::String * { + const auto from = item->displayFrom(); + if (outbg) { + p.setPen(selected ? st::msgOutServiceFgSelected : st::msgOutServiceFg); + return &from->nameText(); + } else if (item->isPost()) { + p.setPen(selected ? st::msgInServiceFgSelected : st::msgInServiceFg); + return &from->nameText(); + } else if (from) { + p.setPen(FromNameFg(from->id, selected)); + return &from->nameText(); + } else if (const auto info = item->hiddenForwardedInfo()) { + p.setPen(FromNameFg(info->colorPeerId, selected)); + return &info->nameText; + } else { + Unexpected("Corrupt forwarded information in message."); + } + }(); + nameText->drawElided(p, availableLeft, trect.top(), availableWidth); + const auto skipWidth = nameText->maxWidth() + st::msgServiceFont->spacew; + availableLeft += skipWidth; + availableWidth -= skipWidth; + + auto via = item->Get(); + if (via && !displayForwardedFrom() && availableWidth > 0) { + p.setPen(selected ? (outbg ? st::msgOutServiceFgSelected : st::msgInServiceFgSelected) : (outbg ? st::msgOutServiceFg : st::msgInServiceFg)); + p.drawText(availableLeft, trect.top() + st::msgServiceFont->ascent, via->text); + auto skipWidth = via->width + st::msgServiceFont->spacew; availableLeft += skipWidth; availableWidth -= skipWidth; - - auto via = item->Get(); - if (via && !displayForwardedFrom() && availableWidth > 0) { - const auto outbg = hasOutLayout(); - p.setPen(selected ? (outbg ? st::msgOutServiceFgSelected : st::msgInServiceFgSelected) : (outbg ? st::msgOutServiceFg : st::msgInServiceFg)); - p.drawText(availableLeft, trect.top() + st::msgServiceFont->ascent, via->text); - auto skipWidth = via->width + st::msgServiceFont->spacew; - availableLeft += skipWidth; - availableWidth -= skipWidth; - } - if (rightWidth) { - p.setPen(selected ? st::msgInDateFgSelected : st::msgInDateFg); - p.setFont(ClickHandler::showAsActive(_fastReplyLink) - ? st::msgFont->underline() - : st::msgFont); - if (replyWidth) { - p.drawText( - trect.left() + trect.width() - rightWidth, - trect.top() + st::msgFont->ascent, - FastReplyText()); - } else { - _rightBadge.draw( - p, - trect.left() + trect.width() - rightWidth, - trect.top(), - rightWidth); - } - } - trect.setY(trect.y() + st::msgNameFont->height); } + if (rightWidth) { + p.setPen(outbg + ? (selected ? st::msgOutDateFgSelected : st::msgOutDateFg) + : (selected ? st::msgInDateFgSelected : st::msgInDateFg)); + p.setFont(ClickHandler::showAsActive(_fastReplyLink) + ? st::msgFont->underline() + : st::msgFont); + if (replyWidth) { + p.drawText( + trect.left() + trect.width() - rightWidth, + trect.top() + st::msgFont->ascent, + FastReplyText()); + } else { + _rightBadge.draw( + p, + trect.left() + trect.width() - rightWidth, + trect.top(), + rightWidth); + } + } + trect.setY(trect.y() + st::msgNameFont->height); } void Message::paintForwardedInfo(Painter &p, QRect &trect, bool selected) const {