diff --git a/Telegram/SourceFiles/dialogs/ui/dialogs_layout.cpp b/Telegram/SourceFiles/dialogs/ui/dialogs_layout.cpp index bfca480a29..5299b648c9 100644 --- a/Telegram/SourceFiles/dialogs/ui/dialogs_layout.cpp +++ b/Telegram/SourceFiles/dialogs/ui/dialogs_layout.cpp @@ -326,6 +326,13 @@ void PaintRow( context.st->padding.top(), context.width, context.st->photoSize); + } else if (!from && hiddenSenderInfo) { + hiddenSenderInfo->emptyUserpic.paintCircle( + p, + context.st->padding.left(), + context.st->padding.top(), + context.width, + context.st->photoSize); } else if (!(flags & Flag::AllowUserOnline)) { PaintUserpic( p, diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index 45277c41c8..11abf78a89 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -1255,6 +1255,27 @@ void HistoryInner::paintEvent(QPaintEvent *e) { width(), st::msgPhotoSize, context.paused); + } else if (const auto info = item->hiddenSenderInfo()) { + if (info->customUserpic.empty()) { + info->emptyUserpic.paintCircle( + p, + st::historyPhotoLeft, + userpicTop, + width(), + st::msgPhotoSize); + } else { + auto &userpic = _hiddenSenderUserpics[item->id]; + const auto valid = info->paintCustomUserpic( + p, + userpic, + st::historyPhotoLeft, + userpicTop, + width(), + st::msgPhotoSize); + if (!valid) { + info->customUserpic.load(&session(), item->fullId()); + } + } } else { Unexpected("Corrupt forwarded information in message."); } diff --git a/Telegram/SourceFiles/history/history_item_components.cpp b/Telegram/SourceFiles/history/history_item_components.cpp index b0af2462fa..2fee9928f2 100644 --- a/Telegram/SourceFiles/history/history_item_components.cpp +++ b/Telegram/SourceFiles/history/history_item_components.cpp @@ -116,7 +116,12 @@ HiddenSenderInfo::HiddenSenderInfo( std::optional colorIndex) : name(name) , colorIndex(colorIndex.value_or( - Data::DecideColorIndex(Data::FakePeerIdForJustName(name)))) { + Data::DecideColorIndex(Data::FakePeerIdForJustName(name)))) +, emptyUserpic( + Ui::EmptyUserpic::UserpicColor(this->colorIndex), + (external + ? Ui::EmptyUserpic::ExternalName() + : name)) { Expects(!name.isEmpty()); const auto parts = name.trimmed().split(' ', Qt::SkipEmptyParts); @@ -148,6 +153,35 @@ ClickHandlerPtr HiddenSenderInfo::ForwardClickHandler() { return hidden; } +bool HiddenSenderInfo::paintCustomUserpic( + Painter &p, + Ui::PeerUserpicView &view, + int x, + int y, + int outerWidth, + int size) const { + Expects(!customUserpic.empty()); + + auto valid = true; + if (!customUserpic.isCurrentView(view.cloud)) { + view.cloud = customUserpic.createView(); + valid = false; + } + const auto image = *view.cloud; + if (image.isNull()) { + emptyUserpic.paintCircle(p, x, y, outerWidth, size); + return valid; + } + Ui::ValidateUserpicCache( + view, + image.isNull() ? nullptr : &image, + image.isNull() ? &emptyUserpic : nullptr, + size * style::DevicePixelRatio(), + false); + p.drawImage(QRect(x, y, size, size), view.cached); + return valid; +} + void HistoryMessageForwarded::create(const HistoryMessageVia *via) const { auto phrase = TextWithEntities(); const auto fromChannel = originalSender diff --git a/Telegram/SourceFiles/history/history_item_components.h b/Telegram/SourceFiles/history/history_item_components.h index 4503f74166..0cce4e499d 100644 --- a/Telegram/SourceFiles/history/history_item_components.h +++ b/Telegram/SourceFiles/history/history_item_components.h @@ -97,10 +97,19 @@ public: QString firstName; QString lastName; uint8 colorIndex = 0; + Ui::EmptyUserpic emptyUserpic; + mutable Data::CloudImage customUserpic; [[nodiscard]] static ClickHandlerPtr ForwardClickHandler(); [[nodiscard]] const Ui::Text::String &nameText() const; + [[nodiscard]] bool paintCustomUserpic( + Painter &p, + Ui::PeerUserpicView &view, + int x, + int y, + int outerWidth, + int size) const; inline bool operator==(const HiddenSenderInfo &other) const { return name == other.name; diff --git a/Telegram/SourceFiles/history/view/controls/history_view_draft_options.cpp b/Telegram/SourceFiles/history/view/controls/history_view_draft_options.cpp index b415a72e55..9c7ce70c5a 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_draft_options.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_draft_options.cpp @@ -376,6 +376,28 @@ void PreviewWrap::paintEvent(QPaintEvent *e) { userpicTop, width(), st::msgPhotoSize); + } else if (const auto info = item->hiddenSenderInfo()) { + if (info->customUserpic.empty()) { + info->emptyUserpic.paintCircle( + p, + st::historyPhotoLeft, + userpicTop, + width(), + st::msgPhotoSize); + } else { + const auto valid = info->paintCustomUserpic( + p, + _userpic, + st::historyPhotoLeft, + userpicTop, + width(), + st::msgPhotoSize); + if (!valid) { + info->customUserpic.load( + &item->history()->session(), + item->fullId()); + } + } } else { Unexpected("Corrupt forwarded information in message."); } diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index ff973ed117..08332097f3 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -2181,6 +2181,27 @@ void ListWidget::paintEvent(QPaintEvent *e) { userpicTop, view->width(), st::msgPhotoSize); + } else if (const auto info = item->hiddenSenderInfo()) { + if (info->customUserpic.empty()) { + info->emptyUserpic.paintCircle( + p, + st::historyPhotoLeft, + userpicTop, + view->width(), + st::msgPhotoSize); + } else { + auto &userpic = _hiddenSenderUserpics[item->id]; + const auto valid = info->paintCustomUserpic( + p, + userpic, + st::historyPhotoLeft, + userpicTop, + view->width(), + st::msgPhotoSize); + if (!valid) { + info->customUserpic.load(session, item->fullId()); + } + } } else { Unexpected("Corrupt forwarded information in message."); }