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.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,

View File

@ -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.");
}

View File

@ -116,7 +116,12 @@ HiddenSenderInfo::HiddenSenderInfo(
std::optional<uint8> 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

View File

@ -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;

View File

@ -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.");
}

View File

@ -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.");
}