Added fast right action to sponsored messages.

This commit is contained in:
23rd 2023-11-15 18:17:49 +03:00 committed by John Preston
parent 4c5c2aadc4
commit 0da515abc5
6 changed files with 34 additions and 5 deletions

View file

@ -35,6 +35,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "apiwrap.h"
#include "base/unixtime.h"
#include "core/application.h"
#include "core/click_handler_types.h" // ClickHandlerContext.
#include "settings/settings_premium.h" // Settings::ShowPremium.
#include "ui/text/format_values.h"
#include "ui/text/text_utilities.h"
#include "ui/text/text_entity.h"
@ -330,6 +332,15 @@ ClickHandlerPtr JumpToStoryClickHandler(
});
}
ClickHandlerPtr HideSponsoredClickHandler() {
return std::make_shared<LambdaClickHandler>([=](ClickContext context) {
const auto my = context.other.value<ClickHandlerContext>();
if (const auto controller = my.sessionWindow.get()) {
Settings::ShowPremium(controller, "no_ads");
}
});
}
MessageFlags FlagsFromMTP(
MsgId id,
MTPDmessage::Flags flags,

View file

@ -136,6 +136,7 @@ struct SendingErrorRequest {
ClickHandlerPtr JumpToStoryClickHandler(
not_null<PeerData*> peer,
StoryId storyId);
[[nodiscard]] ClickHandlerPtr HideSponsoredClickHandler();
[[nodiscard]] not_null<HistoryItem*> GenerateJoinedMessage(
not_null<History*> history,

View file

@ -1191,7 +1191,9 @@ void Message::draw(Painter &p, const PaintContext &context) const {
0,
st::historyFastShareBottom);
const auto fastShareLeft = g.left() + g.width() + st::historyFastShareLeft;
const auto fastShareTop = g.top() + g.height() - fastShareSkip - size->height();
const auto fastShareTop = data()->isSponsored()
? g.top() + fastShareSkip
: g.top() + g.height() - fastShareSkip - size->height();
drawRightAction(p, context, fastShareLeft, fastShareTop, width());
}
@ -2209,7 +2211,9 @@ TextState Message::textState(
0,
st::historyFastShareBottom);
const auto fastShareLeft = g.left() + g.width() + st::historyFastShareLeft;
const auto fastShareTop = g.top() + g.height() - fastShareSkip - size->height();
const auto fastShareTop = data()->isSponsored()
? g.top() + fastShareSkip
: g.top() + g.height() - fastShareSkip - size->height();
if (QRect(
fastShareLeft,
fastShareTop,
@ -3343,7 +3347,9 @@ std::optional<QSize> Message::rightActionSize() const {
st::historyFastShareSize + st::historyFastShareBottom + st::semiboldFont->height)
: QSize(st::historyFastShareSize, st::historyFastShareSize);
}
return (displayFastShare() || displayGoToOriginal())
return data()->isSponsored()
? QSize(st::historyFastCloseSize, st::historyFastCloseSize)
: (displayFastShare() || displayGoToOriginal())
? QSize(st::historyFastShareSize, st::historyFastShareSize)
: std::optional<QSize>();
}
@ -3447,7 +3453,9 @@ void Message::drawRightAction(
views->repliesSmall.textWidth);
}
} else {
const auto &icon = (displayFastShare() && !isPinnedContext())
const auto &icon = data()->isSponsored()
? st->historyFastCloseIcon()
: (displayFastShare() && !isPinnedContext())
? st->historyFastShareIcon()
: st->historyGoToOriginalIcon();
icon.paintInCenter(p, { left, top, size->width(), size->height() });
@ -3475,7 +3483,9 @@ void Message::ensureRightAction() const {
}
ClickHandlerPtr Message::prepareRightActionLink() const {
if (isPinnedContext()) {
if (data()->isSponsored()) {
return HideSponsoredClickHandler();
} else if (isPinnedContext()) {
return JumpToMessageClickHandler(data());
} else if (displayRightActionComments()) {
return createGoToCommentsLink();

View file

@ -559,6 +559,8 @@ historyFastShareBottom: 5px;
historyFastShareIcon: icon {{ "fast_share", msgServiceFg }};
historyGoToOriginalIcon: icon {{ "fast_to_original", msgServiceFg, point(1px, 0px) }};
historyFastCommentsIcon: icon {{ "fast_comments", msgServiceFg }};
historyFastCloseSize: 30px;
historyFastCloseIcon: icon {{ "box_button_close", msgServiceFg }};
historyFastTranscribeIcon: icon {{ "chat/voice_to_text", msgServiceFg }};
historySavedFont: font(semibold 14px);

View file

@ -190,6 +190,7 @@ ChatStyle::ChatStyle(rpl::producer<ColorIndicesCompressed> colorIndices) {
make(_historyFastShareIcon, st::historyFastShareIcon);
make(_historyFastTranscribeIcon, st::historyFastTranscribeIcon);
make(_historyGoToOriginalIcon, st::historyGoToOriginalIcon);
make(_historyFastCloseIcon, st::historyFastCloseIcon);
make(_historyMapPoint, st::historyMapPoint);
make(_historyMapPointInner, st::historyMapPointInner);
make(_youtubeIcon, st::youtubeIcon);

View file

@ -388,6 +388,9 @@ public:
[[nodiscard]] const style::icon &historyGoToOriginalIcon() const {
return _historyGoToOriginalIcon;
}
[[nodiscard]] const style::icon &historyFastCloseIcon() const {
return _historyFastCloseIcon;
}
[[nodiscard]] const style::icon &historyMapPoint() const {
return _historyMapPoint;
}
@ -512,6 +515,7 @@ private:
style::icon _historyFastShareIcon = { Qt::Uninitialized };
style::icon _historyFastTranscribeIcon = { Qt::Uninitialized };
style::icon _historyGoToOriginalIcon = { Qt::Uninitialized };
style::icon _historyFastCloseIcon = { Qt::Uninitialized };
style::icon _historyMapPoint = { Qt::Uninitialized };
style::icon _historyMapPointInner = { Qt::Uninitialized };
style::icon _youtubeIcon = { Qt::Uninitialized };