Moved out click handler for sponsored messages to separate module.
This commit is contained in:
parent
c1d20d16fd
commit
a8de145e01
|
@ -792,6 +792,8 @@ PRIVATE
|
||||||
history/view/history_view_service_message.h
|
history/view/history_view_service_message.h
|
||||||
history/view/history_view_spoiler_click_handler.cpp
|
history/view/history_view_spoiler_click_handler.cpp
|
||||||
history/view/history_view_spoiler_click_handler.h
|
history/view/history_view_spoiler_click_handler.h
|
||||||
|
history/view/history_view_sponsored_click_handler.cpp
|
||||||
|
history/view/history_view_sponsored_click_handler.h
|
||||||
history/view/history_view_sticker_toast.cpp
|
history/view/history_view_sticker_toast.cpp
|
||||||
history/view/history_view_sticker_toast.h
|
history/view/history_view_sticker_toast.h
|
||||||
history/view/history_view_transcribe_button.cpp
|
history/view/history_view_transcribe_button.cpp
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
/*
|
||||||
|
This file is part of Telegram Desktop,
|
||||||
|
the official desktop application for the Telegram messaging service.
|
||||||
|
|
||||||
|
For license and copyright information please follow this link:
|
||||||
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
*/
|
||||||
|
#include "history/view/history_view_sponsored_click_handler.h"
|
||||||
|
|
||||||
|
#include "api/api_chat_invite.h"
|
||||||
|
#include "core/click_handler_types.h"
|
||||||
|
#include "core/file_utilities.h"
|
||||||
|
#include "data/data_session.h"
|
||||||
|
#include "data/data_sponsored_messages.h"
|
||||||
|
#include "main/main_session.h"
|
||||||
|
#include "window/window_session_controller.h"
|
||||||
|
|
||||||
|
namespace HistoryView {
|
||||||
|
|
||||||
|
ClickHandlerPtr SponsoredLink(const QString &externalLink) {
|
||||||
|
if (!externalLink.isEmpty()) {
|
||||||
|
class ClickHandler : public UrlClickHandler {
|
||||||
|
public:
|
||||||
|
using UrlClickHandler::UrlClickHandler;
|
||||||
|
|
||||||
|
QString copyToClipboardContextItemText() const override {
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
return std::make_shared<ClickHandler>(externalLink, false);
|
||||||
|
} else {
|
||||||
|
return std::make_shared<LambdaClickHandler>([](ClickContext context) {
|
||||||
|
const auto my = context.other.value<ClickHandlerContext>();
|
||||||
|
const auto controller = my.sessionWindow.get();
|
||||||
|
if (!controller) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const auto &data = controller->session().data();
|
||||||
|
const auto details = data.sponsoredMessages().lookupDetails(
|
||||||
|
my.itemId);
|
||||||
|
if (!details.externalLink.isEmpty()) {
|
||||||
|
File::OpenUrl(details.externalLink);
|
||||||
|
} else if (details.hash) {
|
||||||
|
Api::CheckChatInvite(controller, *details.hash);
|
||||||
|
} else if (details.peer) {
|
||||||
|
controller->showPeerHistory(
|
||||||
|
details.peer,
|
||||||
|
Window::SectionShow::Way::Forward,
|
||||||
|
details.msgId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace HistoryView
|
|
@ -0,0 +1,17 @@
|
||||||
|
/*
|
||||||
|
This file is part of Telegram Desktop,
|
||||||
|
the official desktop application for the Telegram messaging service.
|
||||||
|
|
||||||
|
For license and copyright information please follow this link:
|
||||||
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
class ClickHandler;
|
||||||
|
|
||||||
|
namespace HistoryView {
|
||||||
|
|
||||||
|
[[nodiscard]] std::shared_ptr<ClickHandler> SponsoredLink(
|
||||||
|
const QString &externalLink);
|
||||||
|
|
||||||
|
} // namespace HistoryView
|
|
@ -7,29 +7,17 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
*/
|
*/
|
||||||
#include "history/view/history_view_view_button.h"
|
#include "history/view/history_view_view_button.h"
|
||||||
|
|
||||||
#include "api/api_chat_invite.h"
|
|
||||||
#include "core/application.h"
|
|
||||||
#include "core/click_handler_types.h"
|
#include "core/click_handler_types.h"
|
||||||
#include "core/file_utilities.h"
|
|
||||||
#include "data/data_cloud_themes.h"
|
|
||||||
#include "data/data_session.h"
|
|
||||||
#include "data/data_sponsored_messages.h"
|
|
||||||
#include "data/data_user.h"
|
|
||||||
#include "data/data_web_page.h"
|
|
||||||
#include "history/view/history_view_cursor_state.h"
|
|
||||||
#include "history/history_item_components.h"
|
|
||||||
#include "history/history.h"
|
#include "history/history.h"
|
||||||
|
#include "history/history_item_components.h"
|
||||||
|
#include "history/view/history_view_cursor_state.h"
|
||||||
|
#include "history/view/history_view_sponsored_click_handler.h"
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
#include "main/main_session.h"
|
|
||||||
#include "ui/click_handler.h"
|
|
||||||
#include "ui/effects/ripple_animation.h"
|
#include "ui/effects/ripple_animation.h"
|
||||||
#include "ui/painter.h"
|
#include "ui/painter.h"
|
||||||
#include "ui/round_rect.h"
|
|
||||||
#include "ui/text/text_utilities.h" // Ui::Text::ToUpper
|
#include "ui/text/text_utilities.h" // Ui::Text::ToUpper
|
||||||
#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_widgets.h"
|
|
||||||
#include "styles/style_window.h"
|
|
||||||
|
|
||||||
namespace HistoryView {
|
namespace HistoryView {
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -79,46 +67,6 @@ inline auto SponsoredPhrase(SponsoredType type) {
|
||||||
return Ui::Text::Upper(tr::lng_prizes_how_works(tr::now));
|
return Ui::Text::Upper(tr::lng_prizes_how_works(tr::now));
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] ClickHandlerPtr SponsoredLink(
|
|
||||||
not_null<HistoryMessageSponsored*> sponsored) {
|
|
||||||
if (!sponsored->externalLink.isEmpty()) {
|
|
||||||
class ClickHandler : public UrlClickHandler {
|
|
||||||
public:
|
|
||||||
using UrlClickHandler::UrlClickHandler;
|
|
||||||
|
|
||||||
QString copyToClipboardContextItemText() const override {
|
|
||||||
return QString();
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
return std::make_shared<ClickHandler>(
|
|
||||||
sponsored->externalLink,
|
|
||||||
false);
|
|
||||||
} else {
|
|
||||||
return std::make_shared<LambdaClickHandler>([](ClickContext context) {
|
|
||||||
const auto my = context.other.value<ClickHandlerContext>();
|
|
||||||
const auto controller = my.sessionWindow.get();
|
|
||||||
if (!controller) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const auto &data = controller->session().data();
|
|
||||||
const auto details = data.sponsoredMessages().lookupDetails(
|
|
||||||
my.itemId);
|
|
||||||
if (!details.externalLink.isEmpty()) {
|
|
||||||
File::OpenUrl(details.externalLink);
|
|
||||||
} else if (details.hash) {
|
|
||||||
Api::CheckChatInvite(controller, *details.hash);
|
|
||||||
} else if (details.peer) {
|
|
||||||
controller->showPeerHistory(
|
|
||||||
details.peer,
|
|
||||||
Window::SectionShow::Way::Forward,
|
|
||||||
details.msgId);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
struct ViewButton::Inner {
|
struct ViewButton::Inner {
|
||||||
|
@ -155,7 +103,7 @@ ViewButton::Inner::Inner(
|
||||||
uint8 colorIndex,
|
uint8 colorIndex,
|
||||||
Fn<void()> updateCallback)
|
Fn<void()> updateCallback)
|
||||||
: margins(st::historyViewButtonMargins)
|
: margins(st::historyViewButtonMargins)
|
||||||
, link(SponsoredLink(sponsored))
|
, link(SponsoredLink(sponsored->externalLink))
|
||||||
, updateCallback(std::move(updateCallback))
|
, updateCallback(std::move(updateCallback))
|
||||||
, colorIndex(colorIndex)
|
, colorIndex(colorIndex)
|
||||||
, externalLink((sponsored->type == SponsoredType::ExternalLink) ? 1 : 0)
|
, externalLink((sponsored->type == SponsoredType::ExternalLink) ? 1 : 0)
|
||||||
|
|
Loading…
Reference in New Issue