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