Revert "Removed unused code of hidden sender userpics for sponsored messages."

This reverts commit 3f19dc0486.
This commit is contained in:
John Preston 2023-12-01 09:18:22 +04:00
parent 0e2131e6eb
commit fe12c3639b
6 changed files with 115 additions and 1 deletions

View file

@ -326,6 +326,13 @@ void PaintRow(
context.st->padding.top(), context.st->padding.top(),
context.width, context.width,
context.st->photoSize); 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)) { } else if (!(flags & Flag::AllowUserOnline)) {
PaintUserpic( PaintUserpic(
p, p,

View file

@ -1255,6 +1255,27 @@ void HistoryInner::paintEvent(QPaintEvent *e) {
width(), width(),
st::msgPhotoSize, st::msgPhotoSize,
context.paused); 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 { } else {
Unexpected("Corrupt forwarded information in message."); Unexpected("Corrupt forwarded information in message.");
} }

View file

@ -116,7 +116,12 @@ HiddenSenderInfo::HiddenSenderInfo(
std::optional<uint8> colorIndex) std::optional<uint8> colorIndex)
: name(name) : name(name)
, colorIndex(colorIndex.value_or( , 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()); Expects(!name.isEmpty());
const auto parts = name.trimmed().split(' ', Qt::SkipEmptyParts); const auto parts = name.trimmed().split(' ', Qt::SkipEmptyParts);
@ -148,6 +153,35 @@ ClickHandlerPtr HiddenSenderInfo::ForwardClickHandler() {
return hidden; 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 { void HistoryMessageForwarded::create(const HistoryMessageVia *via) const {
auto phrase = TextWithEntities(); auto phrase = TextWithEntities();
const auto fromChannel = originalSender const auto fromChannel = originalSender

View file

@ -97,10 +97,19 @@ public:
QString firstName; QString firstName;
QString lastName; QString lastName;
uint8 colorIndex = 0; uint8 colorIndex = 0;
Ui::EmptyUserpic emptyUserpic;
mutable Data::CloudImage customUserpic;
[[nodiscard]] static ClickHandlerPtr ForwardClickHandler(); [[nodiscard]] static ClickHandlerPtr ForwardClickHandler();
[[nodiscard]] const Ui::Text::String &nameText() const; [[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 { inline bool operator==(const HiddenSenderInfo &other) const {
return name == other.name; return name == other.name;

View file

@ -376,6 +376,28 @@ void PreviewWrap::paintEvent(QPaintEvent *e) {
userpicTop, userpicTop,
width(), width(),
st::msgPhotoSize); 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 { } else {
Unexpected("Corrupt forwarded information in message."); Unexpected("Corrupt forwarded information in message.");
} }

View file

@ -2181,6 +2181,27 @@ void ListWidget::paintEvent(QPaintEvent *e) {
userpicTop, userpicTop,
view->width(), view->width(),
st::msgPhotoSize); 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 { } else {
Unexpected("Corrupt forwarded information in message."); Unexpected("Corrupt forwarded information in message.");
} }