From 294432ceed2b5c7b23528d8a204af81856b2d144 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Wed, 23 Nov 2022 14:13:01 +0300 Subject: [PATCH] Differentiated replies in groups by color. --- .../history/history_item_components.cpp | 40 +++++++++++++++---- .../history/history_item_components.h | 2 + .../history/view/history_view_message.cpp | 4 +- .../history/view/history_view_message.h | 4 ++ 4 files changed, 40 insertions(+), 10 deletions(-) diff --git a/Telegram/SourceFiles/history/history_item_components.cpp b/Telegram/SourceFiles/history/history_item_components.cpp index ea31941ff..f732c6d0c 100644 --- a/Telegram/SourceFiles/history/history_item_components.cpp +++ b/Telegram/SourceFiles/history/history_item_components.cpp @@ -19,6 +19,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/painter.h" #include "history/history.h" #include "history/history_message.h" +#include "history/view/history_view_message.h" // FromNameFg. #include "history/view/history_view_service_message.h" #include "history/view/media/history_view_document.h" #include "core/click_handler_types.h" @@ -45,6 +46,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace { const auto kPsaForwardedPrefix = "cloud_lng_forwarded_psa_"; +constexpr auto kReplyBarAlpha = 230. / 255.; } // namespace @@ -292,8 +294,16 @@ bool HistoryMessageReply::updateData( peerToUser(bot->id)); } } + + { + const auto peerId = replyToMsg->fullId().peer; + replyToColorKey = (peerIsChannel(peerId) || peerIsChat(peerId)) + ? replyToMsg->from()->id + : PeerId(0); + } } else if (force) { replyToMsgId = 0; + replyToColorKey = PeerId(0); } if (force) { holder->history()->owner().requestItemResize(holder); @@ -422,11 +432,23 @@ void HistoryMessageReply::paint( const auto st = context.st; const auto stm = context.messageStyle(); - const auto &bar = inBubble - ? stm->msgReplyBarColor - : st->msgImgReplyBarColor(); - QRect rbar(style::rtlrect(x + st::msgReplyBarPos.x(), y + st::msgReplyPadding.top() + st::msgReplyBarPos.y(), st::msgReplyBarSize.width(), st::msgReplyBarSize.height(), w + 2 * x)); - p.fillRect(rbar, bar); + { + const auto &bar = !inBubble + ? st->msgImgReplyBarColor() + : replyToColorKey + ? HistoryView::FromNameFg(context, replyToColorKey) + : stm->msgReplyBarColor; + const auto rbar = style::rtlrect( + x + st::msgReplyBarPos.x(), + y + st::msgReplyPadding.top() + st::msgReplyBarPos.y(), + st::msgReplyBarSize.width(), + st::msgReplyBarSize.height(), + w + 2 * x); + const auto opacity = p.opacity(); + p.setOpacity(opacity * kReplyBarAlpha); + p.fillRect(rbar, bar); + p.setOpacity(opacity); + } if (w > st::msgReplyBarSkip) { if (replyToMsg) { @@ -452,9 +474,11 @@ void HistoryMessageReply::paint( } } if (w > st::msgReplyBarSkip + previewSkip) { - p.setPen(inBubble - ? stm->msgServiceFg - : st->msgImgReplyBarColor()); + p.setPen(!inBubble + ? st->msgImgReplyBarColor() + : replyToColorKey + ? HistoryView::FromNameFg(context, replyToColorKey) + : stm->msgServiceFg); replyToName.drawLeftElided(p, x + st::msgReplyBarSkip + previewSkip, y + st::msgReplyPadding.top(), w - st::msgReplyBarSkip - previewSkip, w + 2 * x); if (replyToVia && w > st::msgReplyBarSkip + previewSkip + replyToName.maxWidth() + st::msgServiceFont->spacew) { p.setFont(st::msgServiceFont); diff --git a/Telegram/SourceFiles/history/history_item_components.h b/Telegram/SourceFiles/history/history_item_components.h index 0ccb6748e..9e69f3335 100644 --- a/Telegram/SourceFiles/history/history_item_components.h +++ b/Telegram/SourceFiles/history/history_item_components.h @@ -240,6 +240,8 @@ struct HistoryMessageReply PeerId replyToPeerId = 0; MsgId replyToMsgId = 0; MsgId replyToMsgTop = 0; + using ColorKey = PeerId; + ColorKey replyToColorKey = 0; DocumentId replyToDocumentId = 0; WebPageId replyToWebPageId = 0; ReplyToMessagePointer replyToMsg; diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index d48cff0e2..4b5bf0038 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -225,6 +225,8 @@ QString FastReplyText() { return tr::lng_fast_reply(tr::now); } +} // namespace + style::color FromNameFg( const Ui::ChatPaintContext &context, PeerId peerId) { @@ -256,8 +258,6 @@ style::color FromNameFg( } } -} // namespace - struct Message::CommentsButton { std::unique_ptr ripple; int rippleShift = 0; diff --git a/Telegram/SourceFiles/history/view/history_view_message.h b/Telegram/SourceFiles/history/view/history_view_message.h index aac1e775a..23375e7ef 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.h +++ b/Telegram/SourceFiles/history/view/history_view_message.h @@ -56,6 +56,10 @@ struct BottomRippleMask { int shift = 0; }; +[[nodiscard]] style::color FromNameFg( + const Ui::ChatPaintContext &context, + PeerId peerId); + class Message final : public Element { public: Message(