Added hide button to bar for sponsored messages without photo.

This commit is contained in:
23rd 2024-10-29 14:54:03 +03:00
parent b2d340cbfb
commit 1dc30caee9

View file

@ -31,6 +31,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "window/window_session_controller.h" #include "window/window_session_controller.h"
#include "styles/style_chat.h" #include "styles/style_chat.h"
#include "styles/style_chat_helpers.h" #include "styles/style_chat_helpers.h"
#include "styles/style_dialogs.h"
namespace Ui { namespace Ui {
namespace { namespace {
@ -180,6 +181,19 @@ void FillSponsoredMessageBar(
.session = session, .session = session,
.customEmojiRepaint = [=] { widget->update(); }, .customEmojiRepaint = [=] { widget->update(); },
}); });
const auto hostedClick = [=](ClickHandlerPtr handler) {
return [=] {
if (const auto controller = FindSessionController(widget)) {
ActivateClickHandler(widget, handler, {
.other = QVariant::fromValue(ClickHandlerContext{
.itemId = fullId,
.sessionWindow = base::make_weak(controller),
.show = controller->uiShow(),
})
});
}
};
};
const auto kLinesForPhoto = 3; const auto kLinesForPhoto = 3;
const auto rightPhotoSize = titleSt.font->ascent * kLinesForPhoto; const auto rightPhotoSize = titleSt.font->ascent * kLinesForPhoto;
const auto rightPhotoPlaceholder = titleSt.font->height * kLinesForPhoto; const auto rightPhotoPlaceholder = titleSt.font->height * kLinesForPhoto;
@ -197,6 +211,19 @@ void FillSponsoredMessageBar(
state->rightPhoto->subscribeToUpdates(callback); state->rightPhoto->subscribeToUpdates(callback);
callback(); callback();
} }
const auto rightHide = hasRightPhoto
? nullptr
: Ui::CreateChild<Ui::IconButton>(
container,
st::dialogsCancelSearchInPeer);
if (rightHide) {
container->sizeValue(
) | rpl::start_with_next([=](const QSize &s) {
rightHide->moveToRight(st::buttonRadius, st::lineWidth);
}, rightHide->lifetime());
rightHide->setClickedCallback(
hostedClick(HideSponsoredClickHandler()));
}
const auto badgeButton = Ui::CreateChild<BadgeButton>( const auto badgeButton = Ui::CreateChild<BadgeButton>(
widget, widget,
from.canReport from.canReport
@ -206,20 +233,10 @@ void FillSponsoredMessageBar(
widget, widget,
fullId, fullId,
from.colorIndex ? from.colorIndex : 4/*blue*/)); from.colorIndex ? from.colorIndex : 4/*blue*/));
const auto handler = from.canReport badgeButton->setClickedCallback(
? AboutSponsoredClickHandler() hostedClick(from.canReport
: HideSponsoredClickHandler(); ? AboutSponsoredClickHandler()
badgeButton->setClickedCallback([=] { : HideSponsoredClickHandler()));
if (const auto controller = FindSessionController(widget)) {
ActivateClickHandler(widget, handler, {
.other = QVariant::fromValue(ClickHandlerContext{
.itemId = fullId,
.sessionWindow = base::make_weak(controller),
.show = controller->uiShow(),
})
});
}
});
badgeButton->show(); badgeButton->show();
const auto draw = [=](QPainter &p) { const auto draw = [=](QPainter &p) {
@ -233,7 +250,8 @@ void FillSponsoredMessageBar(
- leftPadding - leftPadding
- rightPadding; - rightPadding;
const auto availableWidth = availableWidthNoPhoto const auto availableWidth = availableWidthNoPhoto
- (hasRightPhoto ? (rightPadding + rightPhotoSize) : 0); - (hasRightPhoto ? (rightPadding + rightPhotoSize) : 0)
- (rightHide ? rightHide->width() : 0);
const auto titleRight = leftPadding const auto titleRight = leftPadding
+ state->title.maxWidth() + state->title.maxWidth()
+ titleSt.font->spacew * 2; + titleSt.font->spacew * 2;
@ -258,6 +276,7 @@ void FillSponsoredMessageBar(
- (hasRightPhoto - (hasRightPhoto
? (rightPadding + rightPhotoSize) ? (rightPadding + rightPhotoSize)
: 0) : 0)
- (rightHide ? rightHide->width() : 0)
- rightPadding), - rightPadding),
topPadding topPadding
+ (titleSt.font->height - badgeButton->height()) / 2); + (titleSt.font->height - badgeButton->height()) / 2);
@ -298,16 +317,13 @@ void FillSponsoredMessageBar(
} else if (diff < 2 * lineHeight) { } else if (diff < 2 * lineHeight) {
return {}; return {};
} }
if (hasRightPhoto) { line += (hasSecondLineTitle ? 2 : 1)
line += (hasSecondLineTitle ? 2 : 1); + (hasRightPhoto ? 0 : 1);
return { return {
.width = (line > kLinesForPhoto) .width = (line > kLinesForPhoto)
? availableWidthNoPhoto ? availableWidthNoPhoto
: availableWidth, : availableWidth,
}; };
} else {
return { .width = availableWidth };
}
}; };
state->contentText.draw(p, { state->contentText.draw(p, {
.position = QPoint(left, top), .position = QPoint(left, top),