Replaced menu in media viewer with menu for sponsored messages.

This commit is contained in:
23rd 2024-08-14 14:46:26 +03:00 committed by John Preston
parent e51b2c0c91
commit 074dbf41e0
6 changed files with 36 additions and 26 deletions

View file

@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "api/api_peer_photo.h"
#include "base/qt/qt_common_adapters.h"
#include "lang/lang_keys.h"
#include "menu/menu_sponsored.h"
#include "boxes/premium_preview_box.h"
#include "core/application.h"
#include "core/click_handler_types.h"
@ -21,6 +22,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "core/crash_reports.h"
#include "core/sandbox.h"
#include "core/shortcuts.h"
#include "ui/widgets/menu/menu_add_action_callback.h"
#include "ui/widgets/menu/menu_add_action_callback_factory.h"
#include "ui/widgets/dropdown_menu.h"
#include "ui/widgets/popup_menu.h"
#include "ui/widgets/buttons.h"
@ -1484,7 +1487,15 @@ void OverlayWidget::refreshCaptionGeometry() {
captionHeight);
}
void OverlayWidget::fillContextMenuActions(const MenuCallback &addAction) {
void OverlayWidget::fillContextMenuActions(
const Ui::Menu::MenuCallback &addAction) {
if (_message && _message->isSponsored()) {
if (const auto window = findWindow()) {
const auto show = window->uiShow();
Menu::FillSponsored(_body, addAction, show, _message, true);
}
return;
}
const auto story = _stories ? _stories->story() : nullptr;
if (!story && _document && _document->loading()) {
addAction(
@ -5944,12 +5955,7 @@ bool OverlayWidget::handleContextMenu(std::optional<QPoint> position) {
_menu = base::make_unique_q<Ui::PopupMenu>(
_window,
st::mediaviewPopupMenu);
fillContextMenuActions([&](
const QString &text,
Fn<void()> handler,
const style::icon *icon) {
_menu->addAction(text, std::move(handler), icon);
});
fillContextMenuActions(Ui::Menu::CreateAddActionCallback(_menu));
if (_menu->empty()) {
_menu = nullptr;
@ -6233,12 +6239,7 @@ void OverlayWidget::receiveMouse() {
void OverlayWidget::showDropdown() {
_dropdown->clearActions();
fillContextMenuActions([&](
const QString &text,
Fn<void()> handler,
const style::icon *icon) {
_dropdown->addAction(text, std::move(handler), icon);
});
fillContextMenuActions(Ui::Menu::CreateAddActionCallback(_dropdown));
_dropdown->moveToRight(0, height() - _dropdown->height());
_dropdown->showAnimated(Ui::PanelAnimation::Origin::BottomRight);
_dropdown->setFocus();

View file

@ -47,6 +47,10 @@ struct ChosenRenderer;
enum class Backend;
} // namespace Ui::GL
namespace Ui::Menu {
class MenuCallback;
} // namespace Ui::Menu
namespace Platform {
class OverlayWidgetHelper;
} // namespace Platform
@ -364,11 +368,7 @@ private:
void updateControlsGeometry();
void updateNavigationControlsGeometry();
using MenuCallback = Fn<void(
const QString &,
Fn<void()>,
const style::icon *)>;
void fillContextMenuActions(const MenuCallback &addAction);
void fillContextMenuActions(const Ui::Menu::MenuCallback &addAction);
void resizeCenteredControls();
void resizeContentByScreenSize();

View file

@ -30,6 +30,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "styles/style_channel_earn.h"
#include "styles/style_chat.h"
#include "styles/style_layers.h"
#include "styles/style_media_view.h"
#include "styles/style_menu_icons.h"
#include "styles/style_premium.h"
#include "styles/style_settings.h"
@ -339,21 +340,24 @@ void FillSponsored(
not_null<Ui::RpWidget*> parent,
const Ui::Menu::MenuCallback &addAction,
std::shared_ptr<ChatHelpers::Show> show,
not_null<HistoryItem*> item) {
not_null<HistoryItem*> item,
bool mediaViewer) {
Expects(item->isSponsored());
const auto session = &item->history()->session();
addAction(tr::lng_sponsored_menu_revenued_about(tr::now), [=] {
show->show(Box(AboutBox, show));
}, &st::menuIconInfo);
}, (mediaViewer ? &st::mediaMenuIconInfo : &st::menuIconInfo));
addAction(tr::lng_sponsored_menu_revenued_report(tr::now), [=] {
ShowReportSponsoredBox(show, item);
}, &st::menuIconBlock);
}, (mediaViewer ? &st::mediaMenuIconBlock : &st::menuIconBlock));
addAction({
.separatorSt = &st::expandedMenuSeparator,
.separatorSt = (mediaViewer
? &st::mediaviewMenuSeparator
: &st::expandedMenuSeparator),
.isSeparator = true,
});
@ -365,7 +369,7 @@ void FillSponsored(
} else {
ShowPremiumPreviewBox(show, PremiumFeature::NoAds);
}
}, &st::menuIconCancel);
}, (mediaViewer ? &st::mediaMenuIconCancel : &st::menuIconCancel));
}
void ShowSponsored(
@ -382,7 +386,8 @@ void ShowSponsored(
parent,
Ui::Menu::CreateAddActionCallback(menu),
show,
item);
item,
false);
menu->popup(QCursor::pos());
}

View file

@ -26,7 +26,8 @@ void FillSponsored(
not_null<Ui::RpWidget*> parent,
const Ui::Menu::MenuCallback &addAction,
std::shared_ptr<ChatHelpers::Show> show,
not_null<HistoryItem*> item);
not_null<HistoryItem*> item,
bool mediaViewer);
void ShowSponsored(
not_null<Ui::RpWidget*> parent,

View file

@ -193,6 +193,9 @@ mediaMenuIconStealthLocked: icon {{ "menu/stealth_locked", mediaviewMenuFg }};
mediaMenuIconStealth: icon {{ "menu/stealth", mediaviewMenuFg }};
mediaMenuIconStats: icon {{ "menu/stats", mediaviewMenuFg }};
mediaMenuIconInfo: icon {{ "menu/info", mediaviewMenuFg }};
mediaMenuIconBlock: icon {{ "menu/block", mediaviewMenuFg }};
menuIconDeleteAttention: icon {{ "menu/delete", menuIconAttentionColor }};
menuIconLeaveAttention: icon {{ "menu/leave", menuIconAttentionColor }};
menuIconDisableAttention: icon {{ "menu/disable", menuIconAttentionColor }};

@ -1 +1 @@
Subproject commit c48bbd9b910480bc4a179df7b96d84b7dfe44671
Subproject commit e5c685c47aa21856a591b77ca6853a5aa2d0624b