Show rank in anonymous outgoing messages.

This commit is contained in:
John Preston 2020-10-06 10:23:58 +03:00
parent 26c7a95a9f
commit 22a85016e3
5 changed files with 93 additions and 65 deletions

View file

@ -1775,6 +1775,7 @@ bool Session::checkEntitiesAndViewsUpdate(const MTPDmessage &data) {
data.vreply_to_msg_id().v)); data.vreply_to_msg_id().v));
}); });
} }
existing->setPostAuthor(data.vpost_author().value_or_empty());
existing->indexAsNewItem(); existing->indexAsNewItem();
existing->contributeToSlowmode(data.vdate().v); existing->contributeToSlowmode(data.vdate().v);
requestItemTextRefresh(existing); requestItemTextRefresh(existing);

View file

@ -293,6 +293,8 @@ public:
} }
virtual void setReplyToTop(MsgId replyToTop) { virtual void setReplyToTop(MsgId replyToTop) {
} }
virtual void setPostAuthor(const QString &author) {
}
virtual void setRealId(MsgId newId); virtual void setRealId(MsgId newId);
virtual void incrementReplyToTopCounter() { virtual void incrementReplyToTopCounter() {
} }

View file

@ -1601,6 +1601,28 @@ void HistoryMessage::setViewsCount(int count) {
void HistoryMessage::setForwardsCount(int count) { void HistoryMessage::setForwardsCount(int count) {
} }
void HistoryMessage::setPostAuthor(const QString &author) {
auto msgsigned = Get<HistoryMessageSigned>();
if (author.isEmpty()) {
if (!msgsigned) {
return;
}
RemoveComponents(HistoryMessageSigned::Bit());
history()->owner().requestItemResize(this);
return;
}
if (!msgsigned) {
AddComponents(HistoryMessageSigned::Bit());
msgsigned = Get<HistoryMessageSigned>();
} 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) { void HistoryMessage::setReplies(const MTPMessageReplies &data) {
data.match([&](const MTPDmessageReplies &data) { data.match([&](const MTPDmessageReplies &data) {
auto views = Get<HistoryMessageViews>(); auto views = Get<HistoryMessageViews>();

View file

@ -129,6 +129,7 @@ public:
void clearReplies() override; void clearReplies() override;
void changeRepliesCount(int delta, PeerId replier) override; void changeRepliesCount(int delta, PeerId replier) override;
void setReplyToTop(MsgId replyToTop) override; void setReplyToTop(MsgId replyToTop) override;
void setPostAuthor(const QString &author) override;
void setRealId(MsgId newId) override; void setRealId(MsgId newId) override;
void incrementReplyToTopCounter() override; void incrementReplyToTopCounter() override;

View file

@ -228,7 +228,6 @@ Message::Message(
: Element(delegate, data, replacing) { : Element(delegate, data, replacing) {
initLogEntryOriginal(); initLogEntryOriginal();
initPsa(); initPsa();
refreshRightBadge();
} }
Message::~Message() { Message::~Message() {
@ -287,7 +286,6 @@ void Message::applyGroupAdminChanges(
const base::flat_set<UserId> &changes) { const base::flat_set<UserId> &changes) {
if (!data()->out() if (!data()->out()
&& changes.contains(peerToUser(data()->author()->id))) { && changes.contains(peerToUser(data()->author()->id))) {
refreshRightBadge();
history()->owner().requestViewResize(this); history()->owner().requestViewResize(this);
} }
} }
@ -301,6 +299,7 @@ QSize Message::performCountOptimalSize() {
updateMediaInBubbleState(); updateMediaInBubbleState();
refreshEditedBadge(); refreshEditedBadge();
refreshRightBadge();
auto mediaOnBottom = (logEntryOriginal() != nullptr) auto mediaOnBottom = (logEntryOriginal() != nullptr)
|| (media && media->isDisplayed() && media->isBubbleBottom()); || (media && media->isDisplayed() && media->isBubbleBottom());
@ -783,7 +782,9 @@ void Message::paintFromName(
QRect &trect, QRect &trect,
bool selected) const { bool selected) const {
const auto item = message(); const auto item = message();
if (displayFromName()) { if (!displayFromName()) {
return;
}
const auto badgeWidth = _rightBadge.isEmpty() ? 0 : _rightBadge.maxWidth(); const auto badgeWidth = _rightBadge.isEmpty() ? 0 : _rightBadge.maxWidth();
const auto replyWidth = [&] { const auto replyWidth = [&] {
if (isUnderCursor() && displayFastReply()) { if (isUnderCursor() && displayFastReply()) {
@ -799,9 +800,10 @@ void Message::paintFromName(
} }
p.setFont(st::msgNameFont); p.setFont(st::msgNameFont);
const auto outbg = hasOutLayout();
const auto nameText = [&]() -> const Ui::Text::String * { const auto nameText = [&]() -> const Ui::Text::String * {
const auto from = item->displayFrom(); const auto from = item->displayFrom();
if (hasOutLayout()) { if (outbg) {
p.setPen(selected ? st::msgOutServiceFgSelected : st::msgOutServiceFg); p.setPen(selected ? st::msgOutServiceFgSelected : st::msgOutServiceFg);
return &from->nameText(); return &from->nameText();
} else if (item->isPost()) { } else if (item->isPost()) {
@ -824,7 +826,6 @@ void Message::paintFromName(
auto via = item->Get<HistoryMessageVia>(); auto via = item->Get<HistoryMessageVia>();
if (via && !displayForwardedFrom() && availableWidth > 0) { if (via && !displayForwardedFrom() && availableWidth > 0) {
const auto outbg = hasOutLayout();
p.setPen(selected ? (outbg ? st::msgOutServiceFgSelected : st::msgInServiceFgSelected) : (outbg ? st::msgOutServiceFg : st::msgInServiceFg)); p.setPen(selected ? (outbg ? st::msgOutServiceFgSelected : st::msgInServiceFgSelected) : (outbg ? st::msgOutServiceFg : st::msgInServiceFg));
p.drawText(availableLeft, trect.top() + st::msgServiceFont->ascent, via->text); p.drawText(availableLeft, trect.top() + st::msgServiceFont->ascent, via->text);
auto skipWidth = via->width + st::msgServiceFont->spacew; auto skipWidth = via->width + st::msgServiceFont->spacew;
@ -832,7 +833,9 @@ void Message::paintFromName(
availableWidth -= skipWidth; availableWidth -= skipWidth;
} }
if (rightWidth) { if (rightWidth) {
p.setPen(selected ? st::msgInDateFgSelected : st::msgInDateFg); p.setPen(outbg
? (selected ? st::msgOutDateFgSelected : st::msgOutDateFg)
: (selected ? st::msgInDateFgSelected : st::msgInDateFg));
p.setFont(ClickHandler::showAsActive(_fastReplyLink) p.setFont(ClickHandler::showAsActive(_fastReplyLink)
? st::msgFont->underline() ? st::msgFont->underline()
: st::msgFont); : st::msgFont);
@ -851,7 +854,6 @@ void Message::paintFromName(
} }
trect.setY(trect.y() + st::msgNameFont->height); trect.setY(trect.y() + st::msgNameFont->height);
} }
}
void Message::paintForwardedInfo(Painter &p, QRect &trect, bool selected) const { void Message::paintForwardedInfo(Painter &p, QRect &trect, bool selected) const {
if (displayForwardedFrom()) { if (displayForwardedFrom()) {