mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-02-24 09:16:57 +00:00
Added badge for sponsored messages.
This commit is contained in:
parent
eda5cd47ad
commit
b3f73bb6a9
@ -1335,6 +1335,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
"lng_forwarded_imported" = "This message was imported from another app. It may not be real.";
|
||||
"lng_signed_author" = "Author: {user}";
|
||||
"lng_in_reply_to" = "In reply to";
|
||||
"lng_sponsored" = "sponsored";
|
||||
"lng_edited" = "edited";
|
||||
"lng_edited_date" = "Edited: {date}";
|
||||
"lng_sent_date" = "Sent: {date}";
|
||||
|
@ -116,6 +116,17 @@ int HistoryMessageEdited::maxWidth() const {
|
||||
return text.maxWidth();
|
||||
}
|
||||
|
||||
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))
|
||||
|
@ -77,6 +77,15 @@ struct HistoryMessageEdited : public RuntimeComponent<HistoryMessageEdited, Hist
|
||||
Ui::Text::String text;
|
||||
};
|
||||
|
||||
struct HistoryMessageSponsored : public RuntimeComponent<
|
||||
HistoryMessageSponsored,
|
||||
HistoryItem> {
|
||||
HistoryMessageSponsored();
|
||||
int maxWidth() const;
|
||||
|
||||
Ui::Text::String text;
|
||||
};
|
||||
|
||||
struct HiddenSenderInfo {
|
||||
HiddenSenderInfo(const QString &name, bool external);
|
||||
|
||||
|
@ -423,6 +423,7 @@ struct HistoryMessage::CreateConfig {
|
||||
TimeId editDate = 0;
|
||||
bool imported = false;
|
||||
HistoryMessageMarkupData markup;
|
||||
bool sponsored = false;
|
||||
|
||||
// For messages created from MTP structs.
|
||||
const MTPMessageReplies *mtpReplies = nullptr;
|
||||
@ -772,6 +773,9 @@ 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));
|
||||
}
|
||||
@ -1076,6 +1080,9 @@ 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();
|
||||
}
|
||||
|
@ -1731,6 +1731,8 @@ void Message::drawInfo(
|
||||
if (const auto msgsigned = item->Get<HistoryMessageSigned>()
|
||||
; msgsigned && !msgsigned->isAnonymousRank) {
|
||||
msgsigned->signature.drawElided(p, dateX, dateY, item->_timeWidth);
|
||||
} else if (const auto sponsored = displayedSponsorBadge()) {
|
||||
sponsored->text.drawElided(p, dateX, dateY, item->_timeWidth);
|
||||
} else if (const auto edited = displayedEditBadge()) {
|
||||
edited->text.drawElided(p, dateX, dateY, item->_timeWidth);
|
||||
} else {
|
||||
@ -2639,11 +2641,13 @@ void Message::refreshEditedBadge() {
|
||||
initTime();
|
||||
}
|
||||
|
||||
void Message::initTime() {
|
||||
void Message::initTime() const {
|
||||
const auto item = message();
|
||||
if (const auto msgsigned = item->Get<HistoryMessageSigned>()
|
||||
; msgsigned && !msgsigned->isAnonymousRank) {
|
||||
item->_timeWidth = msgsigned->maxWidth();
|
||||
} else if (const auto sponsored = displayedSponsorBadge()) {
|
||||
item->_timeWidth = sponsored->maxWidth();
|
||||
} else if (const auto edited = displayedEditBadge()) {
|
||||
item->_timeWidth = edited->maxWidth();
|
||||
} else {
|
||||
@ -2680,6 +2684,16 @@ 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()) {
|
||||
|
@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
|
||||
class HistoryMessage;
|
||||
struct HistoryMessageEdited;
|
||||
struct HistoryMessageSponsored;
|
||||
struct HistoryMessageForwarded;
|
||||
|
||||
namespace HistoryView {
|
||||
@ -202,9 +203,11 @@ private:
|
||||
[[nodiscard]] ClickHandlerPtr fastReplyLink() const;
|
||||
[[nodiscard]] const HistoryMessageEdited *displayedEditBadge() const;
|
||||
[[nodiscard]] HistoryMessageEdited *displayedEditBadge();
|
||||
[[nodiscard]] auto displayedSponsorBadge() const
|
||||
-> const HistoryMessageSponsored*;
|
||||
[[nodiscard]] bool displayPinIcon() const;
|
||||
|
||||
void initTime();
|
||||
void initTime() const;
|
||||
[[nodiscard]] int timeLeft() const;
|
||||
[[nodiscard]] int plainMaxWidth() const;
|
||||
[[nodiscard]] int monospaceMaxWidth() const;
|
||||
|
Loading…
Reference in New Issue
Block a user