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_forwarded_imported" = "This message was imported from another app. It may not be real.";
|
||||||
"lng_signed_author" = "Author: {user}";
|
"lng_signed_author" = "Author: {user}";
|
||||||
"lng_in_reply_to" = "In reply to";
|
"lng_in_reply_to" = "In reply to";
|
||||||
|
"lng_sponsored" = "sponsored";
|
||||||
"lng_edited" = "edited";
|
"lng_edited" = "edited";
|
||||||
"lng_edited_date" = "Edited: {date}";
|
"lng_edited_date" = "Edited: {date}";
|
||||||
"lng_sent_date" = "Sent: {date}";
|
"lng_sent_date" = "Sent: {date}";
|
||||||
|
|
|
@ -116,6 +116,17 @@ int HistoryMessageEdited::maxWidth() const {
|
||||||
return text.maxWidth();
|
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)
|
HiddenSenderInfo::HiddenSenderInfo(const QString &name, bool external)
|
||||||
: name(name)
|
: name(name)
|
||||||
, colorPeerId(Data::FakePeerIdForJustName(name))
|
, colorPeerId(Data::FakePeerIdForJustName(name))
|
||||||
|
|
|
@ -77,6 +77,15 @@ struct HistoryMessageEdited : public RuntimeComponent<HistoryMessageEdited, Hist
|
||||||
Ui::Text::String text;
|
Ui::Text::String text;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
|
|
@ -423,6 +423,7 @@ struct HistoryMessage::CreateConfig {
|
||||||
TimeId editDate = 0;
|
TimeId editDate = 0;
|
||||||
bool imported = false;
|
bool imported = false;
|
||||||
HistoryMessageMarkupData markup;
|
HistoryMessageMarkupData markup;
|
||||||
|
bool sponsored = false;
|
||||||
|
|
||||||
// For messages created from MTP structs.
|
// For messages created from MTP structs.
|
||||||
const MTPMessageReplies *mtpReplies = nullptr;
|
const MTPMessageReplies *mtpReplies = nullptr;
|
||||||
|
@ -772,6 +773,9 @@ 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));
|
||||||
}
|
}
|
||||||
|
@ -1076,6 +1080,9 @@ 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();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1731,6 +1731,8 @@ void Message::drawInfo(
|
||||||
if (const auto msgsigned = item->Get<HistoryMessageSigned>()
|
if (const auto msgsigned = item->Get<HistoryMessageSigned>()
|
||||||
; msgsigned && !msgsigned->isAnonymousRank) {
|
; msgsigned && !msgsigned->isAnonymousRank) {
|
||||||
msgsigned->signature.drawElided(p, dateX, dateY, item->_timeWidth);
|
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()) {
|
} else if (const auto edited = displayedEditBadge()) {
|
||||||
edited->text.drawElided(p, dateX, dateY, item->_timeWidth);
|
edited->text.drawElided(p, dateX, dateY, item->_timeWidth);
|
||||||
} else {
|
} else {
|
||||||
|
@ -2639,11 +2641,13 @@ void Message::refreshEditedBadge() {
|
||||||
initTime();
|
initTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Message::initTime() {
|
void Message::initTime() const {
|
||||||
const auto item = message();
|
const auto item = message();
|
||||||
if (const auto msgsigned = item->Get<HistoryMessageSigned>()
|
if (const auto msgsigned = item->Get<HistoryMessageSigned>()
|
||||||
; msgsigned && !msgsigned->isAnonymousRank) {
|
; msgsigned && !msgsigned->isAnonymousRank) {
|
||||||
item->_timeWidth = msgsigned->maxWidth();
|
item->_timeWidth = msgsigned->maxWidth();
|
||||||
|
} else if (const auto sponsored = displayedSponsorBadge()) {
|
||||||
|
item->_timeWidth = sponsored->maxWidth();
|
||||||
} else if (const auto edited = displayedEditBadge()) {
|
} else if (const auto edited = displayedEditBadge()) {
|
||||||
item->_timeWidth = edited->maxWidth();
|
item->_timeWidth = edited->maxWidth();
|
||||||
} else {
|
} else {
|
||||||
|
@ -2680,6 +2684,16 @@ 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()) {
|
||||||
|
|
|
@ -13,6 +13,7 @@ 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 {
|
||||||
|
@ -202,9 +203,11 @@ private:
|
||||||
[[nodiscard]] ClickHandlerPtr fastReplyLink() const;
|
[[nodiscard]] ClickHandlerPtr fastReplyLink() const;
|
||||||
[[nodiscard]] const HistoryMessageEdited *displayedEditBadge() const;
|
[[nodiscard]] const HistoryMessageEdited *displayedEditBadge() const;
|
||||||
[[nodiscard]] HistoryMessageEdited *displayedEditBadge();
|
[[nodiscard]] HistoryMessageEdited *displayedEditBadge();
|
||||||
|
[[nodiscard]] auto displayedSponsorBadge() const
|
||||||
|
-> const HistoryMessageSponsored*;
|
||||||
[[nodiscard]] bool displayPinIcon() const;
|
[[nodiscard]] bool displayPinIcon() const;
|
||||||
|
|
||||||
void initTime();
|
void initTime() const;
|
||||||
[[nodiscard]] int timeLeft() const;
|
[[nodiscard]] int timeLeft() const;
|
||||||
[[nodiscard]] int plainMaxWidth() const;
|
[[nodiscard]] int plainMaxWidth() const;
|
||||||
[[nodiscard]] int monospaceMaxWidth() const;
|
[[nodiscard]] int monospaceMaxWidth() const;
|
||||||
|
|
Loading…
Reference in New Issue