mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 14:17:12 +02:00
Fix sponsored messages badge with BottomInfo.
This commit is contained in:
parent
b151d210bf
commit
be74f8f2bc
9 changed files with 44 additions and 61 deletions
|
@ -84,17 +84,6 @@ void HistoryMessageVia::resize(int32 availw) const {
|
|||
}
|
||||
}
|
||||
|
||||
HistoryMessageSponsored::HistoryMessageSponsored() {
|
||||
text.setText(
|
||||
st::msgDateTextStyle,
|
||||
tr::lng_sponsored(tr::now),
|
||||
Ui::NameTextOptions());
|
||||
}
|
||||
|
||||
int HistoryMessageSponsored::maxWidth() const {
|
||||
return text.maxWidth();
|
||||
}
|
||||
|
||||
HiddenSenderInfo::HiddenSenderInfo(const QString &name, bool external)
|
||||
: name(name)
|
||||
, colorPeerId(Data::FakePeerIdForJustName(name))
|
||||
|
|
|
@ -68,15 +68,6 @@ struct HistoryMessageEdited : public RuntimeComponent<HistoryMessageEdited, Hist
|
|||
TimeId date = 0;
|
||||
};
|
||||
|
||||
struct HistoryMessageSponsored : public RuntimeComponent<
|
||||
HistoryMessageSponsored,
|
||||
HistoryItem> {
|
||||
HistoryMessageSponsored();
|
||||
int maxWidth() const;
|
||||
|
||||
Ui::Text::String text;
|
||||
};
|
||||
|
||||
struct HiddenSenderInfo {
|
||||
HiddenSenderInfo(const QString &name, bool external);
|
||||
|
||||
|
|
|
@ -433,7 +433,6 @@ struct HistoryMessage::CreateConfig {
|
|||
HistoryMessageMarkupData markup;
|
||||
HistoryMessageRepliesData replies;
|
||||
bool imported = false;
|
||||
bool sponsored = false;
|
||||
|
||||
// For messages created from existing messages (forwarded).
|
||||
const HistoryMessageReplyMarkup *inlineMarkup = nullptr;
|
||||
|
@ -787,9 +786,6 @@ void HistoryMessage::createComponentsHelper(
|
|||
config.markup = std::move(markup);
|
||||
if (flags & MessageFlag::HasPostAuthor) config.author = postAuthor;
|
||||
if (flags & MessageFlag::HasViews) config.viewsCount = 1;
|
||||
if (flags & MessageFlag::IsSponsored) {
|
||||
config.sponsored = true;
|
||||
}
|
||||
|
||||
createComponents(std::move(config));
|
||||
}
|
||||
|
@ -1095,9 +1091,6 @@ void HistoryMessage::createComponents(CreateConfig &&config) {
|
|||
if (config.editDate != TimeId(0)) {
|
||||
mask |= HistoryMessageEdited::Bit();
|
||||
}
|
||||
if (config.sponsored) {
|
||||
mask |= HistoryMessageSponsored::Bit();
|
||||
}
|
||||
if (config.originalDate != 0) {
|
||||
mask |= HistoryMessageForwarded::Bit();
|
||||
}
|
||||
|
|
|
@ -242,7 +242,9 @@ void BottomInfo::layoutDateText() {
|
|||
const auto name = _authorElided
|
||||
? st::msgDateFont->elided(author, maxWidth - afterAuthorWidth)
|
||||
: author;
|
||||
const auto full = name + date;
|
||||
const auto full = (_data.flags & Data::Flag::Sponsored)
|
||||
? tr::lng_sponsored(tr::now)
|
||||
: name + date;
|
||||
_authorEditedDate.setText(
|
||||
st::msgDateTextStyle,
|
||||
full,
|
||||
|
@ -336,6 +338,9 @@ BottomInfo::Data BottomInfoDataFromMessage(not_null<Message*> message) {
|
|||
if (message->context() == Context::Replies) {
|
||||
result.flags |= Flag::RepliesContext;
|
||||
}
|
||||
if (item->isSponsored()) {
|
||||
result.flags |= Flag::Sponsored;
|
||||
}
|
||||
if (const auto msgsigned = item->Get<HistoryMessageSigned>()) {
|
||||
if (!msgsigned->isAnonymousRank) {
|
||||
result.author = msgsigned->author;
|
||||
|
|
|
@ -29,6 +29,7 @@ public:
|
|||
OutLayout = 0x02,
|
||||
Sending = 0x04,
|
||||
RepliesContext = 0x08,
|
||||
Sponsored = 0x10,
|
||||
//Unread, // We don't want to pass and update it in Date for now.
|
||||
};
|
||||
friend inline constexpr bool is_flag_type(Flag) { return true; };
|
||||
|
|
|
@ -606,16 +606,21 @@ void Message::draw(Painter &p, const PaintContext &context) const {
|
|||
auto inner = g;
|
||||
paintCommentsButton(p, inner, context);
|
||||
|
||||
const auto needDrawInfo = needInfoDisplay();
|
||||
auto trect = inner.marginsRemoved(st::msgPadding);
|
||||
if (_viewButton) {
|
||||
const auto belowInfo = _viewButton->belowMessageInfo();
|
||||
const auto infoHeight = _bottomInfo.size().height();
|
||||
const auto heightMargins = QMargins(0, 0, 0, infoHeight);
|
||||
_viewButton->draw(
|
||||
p,
|
||||
_viewButton->countRect(inner),
|
||||
_viewButton->countRect(belowInfo
|
||||
? inner
|
||||
: inner - heightMargins),
|
||||
context);
|
||||
// Inner should contain _viewButton height, because info is
|
||||
// painted below the _viewButton.
|
||||
//
|
||||
// inner.setHeight(inner.height() - _viewButton->height());
|
||||
if (belowInfo) {
|
||||
inner.setHeight(inner.height() - _viewButton->height());
|
||||
}
|
||||
trect.setHeight(trect.height() - _viewButton->height());
|
||||
if (mediaDisplayed) {
|
||||
trect.setHeight(trect.height() - st::mediaInBubbleSkip);
|
||||
|
@ -636,7 +641,6 @@ void Message::draw(Painter &p, const PaintContext &context) const {
|
|||
if (entry) {
|
||||
trect.setHeight(trect.height() - entry->height());
|
||||
}
|
||||
const auto needDrawInfo = needInfoDisplay();
|
||||
if (needDrawInfo) {
|
||||
trect.setHeight(trect.height() - (_bottomInfo.size().height() - st::msgDateFont->height));
|
||||
}
|
||||
|
@ -680,10 +684,10 @@ void Message::draw(Painter &p, const PaintContext &context) const {
|
|||
inner.top() + inner.height(),
|
||||
2 * inner.left() + inner.width(),
|
||||
InfoDisplayType::Default);
|
||||
if (g != inner) {
|
||||
if (_comments) {
|
||||
const auto o = p.opacity();
|
||||
p.setOpacity(0.3);
|
||||
p.fillRect(inner.left(), inner.top() + inner.height() - st::lineWidth, inner.width(), st::lineWidth, stm->msgDateFg);
|
||||
p.fillRect(g.left(), g.top() + g.height() - st::historyCommentsButtonHeight - st::lineWidth, g.width(), st::lineWidth, stm->msgDateFg);
|
||||
p.setOpacity(o);
|
||||
}
|
||||
}
|
||||
|
@ -1213,12 +1217,21 @@ TextState Message::textState(
|
|||
if (getStateCommentsButton(point, bubble, &result)) {
|
||||
return result;
|
||||
}
|
||||
if (_viewButton
|
||||
&& _viewButton->getState(
|
||||
point,
|
||||
_viewButton->countRect(bubble),
|
||||
&result)) {
|
||||
return result;
|
||||
if (_viewButton) {
|
||||
const auto belowInfo = _viewButton->belowMessageInfo();
|
||||
const auto infoHeight = _bottomInfo.size().height();
|
||||
const auto heightMargins = QMargins(0, 0, 0, infoHeight);
|
||||
if (_viewButton->getState(
|
||||
point,
|
||||
_viewButton->countRect(belowInfo
|
||||
? bubble
|
||||
: bubble - heightMargins),
|
||||
&result)) {
|
||||
return result;
|
||||
}
|
||||
if (belowInfo) {
|
||||
bubble -= heightMargins;
|
||||
}
|
||||
}
|
||||
|
||||
auto trect = bubble.marginsRemoved(st::msgPadding);
|
||||
|
@ -2625,16 +2638,6 @@ TimeId Message::displayedEditDate() const {
|
|||
return TimeId(0);
|
||||
}
|
||||
|
||||
const HistoryMessageSponsored *Message::displayedSponsorBadge() const {
|
||||
// Ignore media while sponsored messages are text only.
|
||||
// if (const auto media = this->media()) {
|
||||
// if (media->overrideEditedDate()) {
|
||||
// return media->displayedEditBadge();
|
||||
// }
|
||||
// }
|
||||
return message()->Get<HistoryMessageSponsored>();
|
||||
}
|
||||
|
||||
HistoryMessageEdited *Message::displayedEditBadge() {
|
||||
if (const auto media = this->media()) {
|
||||
if (media->overrideEditedDate()) {
|
||||
|
|
|
@ -14,7 +14,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
|
||||
class HistoryMessage;
|
||||
struct HistoryMessageEdited;
|
||||
struct HistoryMessageSponsored;
|
||||
struct HistoryMessageForwarded;
|
||||
|
||||
namespace HistoryView {
|
||||
|
@ -54,8 +53,8 @@ public:
|
|||
|
||||
not_null<HistoryMessage*> message() const;
|
||||
|
||||
const HistoryMessageEdited *displayedEditBadge() const;
|
||||
HistoryMessageEdited *displayedEditBadge();
|
||||
[[nodiscard]] const HistoryMessageEdited *displayedEditBadge() const;
|
||||
[[nodiscard]] HistoryMessageEdited *displayedEditBadge();
|
||||
|
||||
int marginTop() const override;
|
||||
int marginBottom() const override;
|
||||
|
@ -210,8 +209,6 @@ private:
|
|||
[[nodiscard]] bool displayFastShare() const;
|
||||
[[nodiscard]] bool displayGoToOriginal() const;
|
||||
[[nodiscard]] ClickHandlerPtr fastReplyLink() const;
|
||||
[[nodiscard]] auto displayedSponsorBadge() const
|
||||
-> const HistoryMessageSponsored*;
|
||||
[[nodiscard]] bool displayPinIcon() const;
|
||||
|
||||
void initTime() const;
|
||||
|
|
|
@ -82,7 +82,7 @@ struct ViewButton::Inner {
|
|||
const style::margins &margins;
|
||||
const ClickHandlerPtr link;
|
||||
const Fn<void()> updateCallback;
|
||||
bool underDate = true;
|
||||
bool belowInfo = true;
|
||||
int lastWidth = 0;
|
||||
QPoint lastPoint;
|
||||
std::unique_ptr<Ui::RippleAnimation> ripple;
|
||||
|
@ -143,7 +143,7 @@ ViewButton::Inner::Inner(
|
|||
}
|
||||
}))
|
||||
, updateCallback(std::move(updateCallback))
|
||||
, underDate(false)
|
||||
, belowInfo(false)
|
||||
, text(st::historyViewButtonTextStyle, WebPageToPhrase(media->webpage())) {
|
||||
}
|
||||
|
||||
|
@ -187,6 +187,10 @@ int ViewButton::height() const {
|
|||
return st::historyViewButtonHeight;
|
||||
}
|
||||
|
||||
bool ViewButton::belowMessageInfo() const {
|
||||
return _inner->belowInfo;
|
||||
}
|
||||
|
||||
void ViewButton::draw(
|
||||
Painter &p,
|
||||
const QRect &r,
|
||||
|
@ -252,10 +256,9 @@ bool ViewButton::getState(
|
|||
}
|
||||
|
||||
QRect ViewButton::countRect(const QRect &r) const {
|
||||
const auto dateHeight = (_inner->underDate ? 0 : st::msgDateFont->height);
|
||||
return QRect(
|
||||
r.left(),
|
||||
r.top() + r.height() - height() - dateHeight,
|
||||
r.top() + r.height() - height(),
|
||||
r.width(),
|
||||
height()) - _inner->margins;
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ public:
|
|||
not_null<WebPageData*> webpage);
|
||||
|
||||
[[nodiscard]] int height() const;
|
||||
[[nodiscard]] bool belowMessageInfo() const;
|
||||
|
||||
void draw(
|
||||
Painter &p,
|
||||
|
|
Loading…
Add table
Reference in a new issue