mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 14:17:12 +02:00
Added api flag support of userpic display for sponsored messages.
This commit is contained in:
parent
dc8b693f1d
commit
9ddbc75638
8 changed files with 27 additions and 4 deletions
|
@ -164,6 +164,7 @@ void SponsoredMessages::append(
|
|||
.isExactPost = exactPost,
|
||||
.isRecommended = data.is_recommended(),
|
||||
.userpic = { .location = peer->userpicLocation() },
|
||||
.isForceUserpicDisplay = data.is_show_peer_photo(),
|
||||
};
|
||||
};
|
||||
const auto from = [&]() -> SponsoredFrom {
|
||||
|
@ -195,6 +196,7 @@ void SponsoredMessages::append(
|
|||
.isChannel = data.is_channel(),
|
||||
.isPublic = data.is_public(),
|
||||
.userpic = std::move(userpic),
|
||||
.isForceUserpicDisplay = message.data().is_show_peer_photo(),
|
||||
};
|
||||
}, [&](const MTPDchatInviteAlready &data) {
|
||||
const auto chat = _session->data().processChat(data.vchat());
|
||||
|
|
|
@ -32,6 +32,7 @@ struct SponsoredFrom {
|
|||
bool isExactPost = false;
|
||||
bool isRecommended = false;
|
||||
ImageWithLocation userpic;
|
||||
bool isForceUserpicDisplay = false;
|
||||
};
|
||||
|
||||
struct SponsoredMessage {
|
||||
|
|
|
@ -703,6 +703,8 @@ bool HistoryInner::canHaveFromUserpics() const {
|
|||
&& !_peer->isRepliesChat()
|
||||
&& !_isChatWide) {
|
||||
return false;
|
||||
} else if (_canHaveFromUserpicsSponsored) {
|
||||
return true;
|
||||
} else if (_peer->isChannel() && !_peer->isMegagroup()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -999,8 +1001,7 @@ void HistoryInner::paintEvent(QPaintEvent *e) {
|
|||
: yShown(top + height / 2);
|
||||
if (markShown) {
|
||||
if (isSponsored) {
|
||||
session().data().sponsoredMessages().view(
|
||||
item->fullId());
|
||||
session().data().sponsoredMessages().view(item->fullId());
|
||||
} else if (isUnread) {
|
||||
readTill = item;
|
||||
}
|
||||
|
@ -3789,6 +3790,10 @@ void HistoryInner::clearChooseReportReason() {
|
|||
_chooseForReportReason = std::nullopt;
|
||||
}
|
||||
|
||||
void HistoryInner::setCanHaveFromUserpicsSponsored(bool value) {
|
||||
_canHaveFromUserpicsSponsored = value;
|
||||
}
|
||||
|
||||
// -1 if should not be visible, -2 if bad history()
|
||||
int HistoryInner::itemTop(const HistoryItem *item) const {
|
||||
if (!item) {
|
||||
|
|
|
@ -175,6 +175,8 @@ public:
|
|||
void setChooseReportReason(Ui::ReportReason reason);
|
||||
void clearChooseReportReason();
|
||||
|
||||
void setCanHaveFromUserpicsSponsored(bool value);
|
||||
|
||||
// -1 if should not be visible, -2 if bad history()
|
||||
int itemTop(const HistoryItem *item) const;
|
||||
int itemTop(const Element *view) const;
|
||||
|
@ -473,6 +475,7 @@ private:
|
|||
bool _pressWasInactive = false;
|
||||
bool _recountedAfterPendingResizedItems = false;
|
||||
bool _useCornerReaction = false;
|
||||
bool _canHaveFromUserpicsSponsored = false;
|
||||
|
||||
QPoint _trippleClickPoint;
|
||||
base::Timer _trippleClickTimer;
|
||||
|
|
|
@ -134,6 +134,7 @@ struct HistoryMessageSponsored : public RuntimeComponent<HistoryMessageSponsored
|
|||
std::unique_ptr<HiddenSenderInfo> sender;
|
||||
Type type = Type::User;
|
||||
bool recommended = false;
|
||||
bool isForceUserpicDisplay = false;
|
||||
};
|
||||
|
||||
class ReplyToMessagePointer final {
|
||||
|
|
|
@ -1741,6 +1741,7 @@ void HistoryMessage::setSponsoredFrom(const Data::SponsoredFrom &from) {
|
|||
from.title,
|
||||
false);
|
||||
sponsored->recommended = from.isRecommended;
|
||||
sponsored->isForceUserpicDisplay = from.isForceUserpicDisplay;
|
||||
if (from.userpic.location.valid()) {
|
||||
sponsored->sender->customUserpic.set(
|
||||
&history()->session(),
|
||||
|
|
|
@ -297,6 +297,9 @@ HistoryWidget::HistoryWidget(
|
|||
if (_history
|
||||
&& _history->loadedAtBottom()
|
||||
&& session().data().sponsoredMessages().append(_history)) {
|
||||
if (_list) {
|
||||
_list->setCanHaveFromUserpicsSponsored(true);
|
||||
}
|
||||
_scroll->contentAdded();
|
||||
}
|
||||
}, lifetime());
|
||||
|
|
|
@ -1573,8 +1573,15 @@ bool Message::hasFromPhoto() const {
|
|||
case Context::Replies: {
|
||||
const auto item = message();
|
||||
if (item->isPost()) {
|
||||
return item->isSponsored()
|
||||
&& item->history()->peer->isMegagroup();
|
||||
if (item->isSponsored()) {
|
||||
if (item->history()->peer->isMegagroup()) {
|
||||
return true;
|
||||
}
|
||||
if (const auto info = item->Get<HistoryMessageSponsored>()) {
|
||||
return info->isForceUserpicDisplay;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (item->isEmpty()
|
||||
|| (context() == Context::Replies && item->isDiscussionPost())) {
|
||||
|
|
Loading…
Add table
Reference in a new issue