diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index 2e26bf4d6..ea13cd743 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -460,6 +460,8 @@ PRIVATE data/business/data_business_info.h data/business/data_shortcut_messages.cpp data/business/data_shortcut_messages.h + data/components/sponsored_messages.cpp + data/components/sponsored_messages.h data/notify/data_notify_settings.cpp data/notify/data_notify_settings.h data/notify/data_peer_notify_settings.cpp @@ -583,8 +585,6 @@ PRIVATE data/data_shared_media.h data/data_sparse_ids.cpp data/data_sparse_ids.h - data/data_sponsored_messages.cpp - data/data_sponsored_messages.h data/data_statistics.h data/data_stories.cpp data/data_stories.h diff --git a/Telegram/SourceFiles/core/ui_integration.cpp b/Telegram/SourceFiles/core/ui_integration.cpp index 6de0c7570..c1ef63e1b 100644 --- a/Telegram/SourceFiles/core/ui_integration.cpp +++ b/Telegram/SourceFiles/core/ui_integration.cpp @@ -13,9 +13,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/application.h" #include "core/sandbox.h" #include "core/click_handler_types.h" +#include "data/components/sponsored_messages.h" #include "data/stickers/data_custom_emoji.h" #include "data/data_session.h" -#include "data/data_sponsored_messages.h" #include "iv/iv_instance.h" #include "ui/text/text_custom_emoji.h" #include "ui/basic_click_handlers.h" @@ -295,7 +295,7 @@ bool UiIntegration::allowClickHandlerActivation( const ClickContext &context) { const auto my = context.other.value(); if (const auto window = my.sessionWindow.get()) { - window->session().data().sponsoredMessages().clicked(my.itemId); + window->session().sponsoredMessages().clicked(my.itemId); } return true; } diff --git a/Telegram/SourceFiles/data/data_sponsored_messages.cpp b/Telegram/SourceFiles/data/components/sponsored_messages.cpp similarity index 99% rename from Telegram/SourceFiles/data/data_sponsored_messages.cpp rename to Telegram/SourceFiles/data/components/sponsored_messages.cpp index 22cfbfeef..a60d7c3fd 100644 --- a/Telegram/SourceFiles/data/data_sponsored_messages.cpp +++ b/Telegram/SourceFiles/data/components/sponsored_messages.cpp @@ -5,7 +5,7 @@ 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 "data/data_sponsored_messages.h" +#include "data/components/sponsored_messages.h" #include "api/api_text_entities.h" #include "apiwrap.h" @@ -30,8 +30,8 @@ constexpr auto kRequestTimeLimit = 5 * 60 * crl::time(1000); } // namespace -SponsoredMessages::SponsoredMessages(not_null owner) -: _session(&owner->session()) +SponsoredMessages::SponsoredMessages(not_null session) +: _session(session) , _clearTimer([=] { clearOldRequests(); }) { } diff --git a/Telegram/SourceFiles/data/data_sponsored_messages.h b/Telegram/SourceFiles/data/components/sponsored_messages.h similarity index 98% rename from Telegram/SourceFiles/data/data_sponsored_messages.h rename to Telegram/SourceFiles/data/components/sponsored_messages.h index cad8a6134..022ccd19e 100644 --- a/Telegram/SourceFiles/data/data_sponsored_messages.h +++ b/Telegram/SourceFiles/data/components/sponsored_messages.h @@ -20,8 +20,6 @@ class Session; namespace Data { -class Session; - struct SponsoredReportResult final { using Id = QByteArray; struct Option final { @@ -89,7 +87,7 @@ public: bool canReport = false; }; using RandomId = QByteArray; - explicit SponsoredMessages(not_null owner); + explicit SponsoredMessages(not_null session); SponsoredMessages(const SponsoredMessages &other) = delete; SponsoredMessages &operator=(const SponsoredMessages &other) = delete; ~SponsoredMessages(); diff --git a/Telegram/SourceFiles/data/data_session.cpp b/Telegram/SourceFiles/data/data_session.cpp index 4614fae09..7a8e9e372 100644 --- a/Telegram/SourceFiles/data/data_session.cpp +++ b/Telegram/SourceFiles/data/data_session.cpp @@ -58,7 +58,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_chat_filters.h" #include "data/data_scheduled_messages.h" #include "data/data_send_action.h" -#include "data/data_sponsored_messages.h" #include "data/data_message_reactions.h" #include "data/data_emoji_statuses.h" #include "data/data_forum_icons.h" @@ -273,8 +272,7 @@ Session::Session(not_null session) , _chatbots(std::make_unique(this)) , _businessInfo(std::make_unique(this)) , _scheduledMessages(std::make_unique(this)) -, _shortcutMessages(std::make_unique(this)) -, _sponsoredMessages(std::make_unique(this)) { +, _shortcutMessages(std::make_unique(this)) { _cache->open(_session->local().cacheKey()); _bigFileCache->open(_session->local().cacheBigFileKey()); @@ -399,7 +397,6 @@ void Session::clear() { _histories->unloadAll(); _scheduledMessages = nullptr; _shortcutMessages = nullptr; - _sponsoredMessages = nullptr; _dependentMessages.clear(); base::take(_messages); base::take(_nonChannelMessages); diff --git a/Telegram/SourceFiles/data/data_session.h b/Telegram/SourceFiles/data/data_session.h index 0f7df77f4..9bf97e60f 100644 --- a/Telegram/SourceFiles/data/data_session.h +++ b/Telegram/SourceFiles/data/data_session.h @@ -50,7 +50,6 @@ class WallPaper; class ScheduledMessages; class ShortcutMessages; class SendActionManager; -class SponsoredMessages; class Reactions; class EmojiStatuses; class ForumIcons; @@ -128,9 +127,6 @@ public: [[nodiscard]] Stickers &stickers() const { return *_stickers; } - [[nodiscard]] SponsoredMessages &sponsoredMessages() const { - return *_sponsoredMessages; - } [[nodiscard]] Reactions &reactions() const { return *_reactions; } @@ -1086,7 +1082,6 @@ private: const std::unique_ptr _businessInfo; std::unique_ptr _scheduledMessages; std::unique_ptr _shortcutMessages; - std::unique_ptr _sponsoredMessages; MsgId _nonHistoryEntryId = ShortcutMaxMsgId; diff --git a/Telegram/SourceFiles/history/history.cpp b/Telegram/SourceFiles/history/history.cpp index 499bf7cea..b91d0fdf4 100644 --- a/Telegram/SourceFiles/history/history.cpp +++ b/Telegram/SourceFiles/history/history.cpp @@ -19,6 +19,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history_unread_things.h" #include "dialogs/ui/dialogs_layout.h" #include "data/business/data_shortcut_messages.h" +#include "data/components/sponsored_messages.h" #include "data/notify/data_notify_settings.h" #include "data/stickers/data_stickers.h" #include "data/data_drafts.h" @@ -29,7 +30,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_changes.h" #include "data/data_chat_filters.h" #include "data/data_scheduled_messages.h" -#include "data/data_sponsored_messages.h" #include "data/data_send_action.h" #include "data/data_folder.h" #include "data/data_forum.h" diff --git a/Telegram/SourceFiles/history/history.h b/Telegram/SourceFiles/history/history.h index 29620dc2e..4a4ad8ddc 100644 --- a/Telegram/SourceFiles/history/history.h +++ b/Telegram/SourceFiles/history/history.h @@ -25,10 +25,6 @@ struct HistoryMessageMarkupData; class HistoryMainElementDelegateMixin; struct LanguageId; -namespace Main { -class Session; -} // namespace Main - namespace Data { struct Draft; class Session; diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index 26ca88b58..b450b3f43 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -68,6 +68,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "api/api_who_reacted.h" #include "api/api_views.h" #include "lang/lang_keys.h" +#include "data/components/sponsored_messages.h" #include "data/data_session.h" #include "data/data_document.h" #include "data/data_channel.h" @@ -79,7 +80,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_file_click_handler.h" #include "data/data_histories.h" #include "data/data_changes.h" -#include "data/data_sponsored_messages.h" #include "dialogs/ui/dialogs_video_userpic.h" #include "styles/style_chat.h" #include "styles/style_menu_icons.h" @@ -118,7 +118,7 @@ void FillSponsoredMessagesMenu( not_null controller, FullMsgId itemId, not_null menu) { - const auto &data = controller->session().data().sponsoredMessages(); + const auto &data = controller->session().sponsoredMessages(); const auto info = data.lookupDetails(itemId).info; const auto show = controller->uiShow(); if (!info.empty()) { @@ -979,7 +979,7 @@ void HistoryInner::paintEvent(QPaintEvent *e) { : yShown(top + height / 2); if (markShown) { if (isSponsored) { - session().data().sponsoredMessages().view(item->fullId()); + session().sponsoredMessages().view(item->fullId()); } else if (isUnread) { readTill = item; } diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index dc5ad0b86..10dfc93f0 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -40,6 +40,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/timer_rpl.h" #include "api/api_text_entities.h" #include "api/api_updates.h" +#include "data/components/sponsored_messages.h" #include "data/notify/data_notify_settings.h" #include "data/data_bot_app.h" #include "data/data_saved_messages.h" @@ -57,7 +58,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_user.h" #include "data/data_group_call.h" // Data::GroupCall::id(). #include "data/data_poll.h" // PollData::publicVotes. -#include "data/data_sponsored_messages.h" #include "data/data_stories.h" #include "data/data_web_page.h" #include "chat_helpers/stickers_gift_box_pack.h" diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index a3bd3ebf8..6938bafd8 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -54,6 +54,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/unixtime.h" #include "base/call_delayed.h" #include "data/business/data_shortcut_messages.h" +#include "data/components/sponsored_messages.h" #include "data/notify/data_notify_settings.h" #include "data/data_changes.h" #include "data/data_drafts.h" @@ -69,7 +70,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_user.h" #include "data/data_chat_filters.h" #include "data/data_scheduled_messages.h" -#include "data/data_sponsored_messages.h" #include "data/data_file_origin.h" #include "data/data_histories.h" #include "data/data_group_call.h" @@ -311,7 +311,7 @@ HistoryWidget::HistoryWidget( ) | rpl::start_with_next([=] { if (_history && _history->loadedAtBottom() - && session().data().sponsoredMessages().append(_history)) { + && session().sponsoredMessages().append(_history)) { _scroll->contentAdded(); } }, lifetime()); @@ -2216,7 +2216,7 @@ void HistoryWidget::showHistory( return; } else { _sponsoredMessagesStateKnown = false; - session().data().sponsoredMessages().clearItems(_history); + session().sponsoredMessages().clearItems(_history); session().data().hideShownSpoilers(); _composeSearch = nullptr; } @@ -2466,20 +2466,18 @@ void HistoryWidget::showHistory( if (history != _history) { return; } - auto &sponsored = session().data().sponsoredMessages(); using State = Data::SponsoredMessages::State; - const auto state = sponsored.state(_history); + const auto state = session().sponsoredMessages().state( + _history); _sponsoredMessagesStateKnown = (state != State::None); if (state == State::AppendToEnd) { _scroll->setTrackingContent( - sponsored.canHaveFor(_history)); + session().sponsoredMessages().canHaveFor(_history)); } else if (state == State::InjectToMiddle) { injectSponsoredMessages(); } }); - session().data().sponsoredMessages().request( - _history, - checkState); + session().sponsoredMessages().request(_history, checkState); checkState(); } } else { @@ -2583,7 +2581,7 @@ void HistoryWidget::setupPreview() { } void HistoryWidget::injectSponsoredMessages() const { - session().data().sponsoredMessages().inject( + session().sponsoredMessages().inject( _history, _showAtMsgId, _scroll->height() * 2, @@ -3631,7 +3629,7 @@ void HistoryWidget::loadMessagesDown() { auto from = loadMigrated ? _migrated : _history; if (from->loadedAtBottom()) { if (_sponsoredMessagesStateKnown) { - session().data().sponsoredMessages().request(_history, nullptr); + session().sponsoredMessages().request(_history, nullptr); } return; } diff --git a/Telegram/SourceFiles/history/view/history_view_element.cpp b/Telegram/SourceFiles/history/view/history_view_element.cpp index ce25da4dd..1c7927701 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.cpp +++ b/Telegram/SourceFiles/history/view/history_view_element.cpp @@ -39,10 +39,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/text/text_utilities.h" #include "ui/item_text_options.h" #include "ui/painter.h" +#include "data/components/sponsored_messages.h" #include "data/data_session.h" #include "data/data_forum.h" #include "data/data_forum_topic.h" -#include "data/data_sponsored_messages.h" #include "data/data_message_reactions.h" #include "data/data_user.h" #include "lang/lang_keys.h" @@ -1108,7 +1108,7 @@ ClickHandlerPtr Element::fromLink() const { } const auto my = context.other.value(); if (const auto window = ContextOrSessionWindow(my, session)) { - auto &sponsored = session->data().sponsoredMessages(); + auto &sponsored = session->sponsoredMessages(); const auto itemId = my.itemId ? my.itemId : item->fullId(); const auto details = sponsored.lookupDetails(itemId); if (!details.externalLink.isEmpty()) { diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index dc1255e2c..e849bd943 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -56,8 +56,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/premium_preview_box.h" #include "boxes/peers/edit_participant_box.h" #include "core/crash_reports.h" +#include "data/components/sponsored_messages.h" #include "data/data_session.h" -#include "data/data_sponsored_messages.h" #include "data/data_changes.h" #include "data/data_folder.h" #include "data/data_media_types.h" @@ -2138,8 +2138,7 @@ void ListWidget::paintEvent(QPaintEvent *e) { : yShown(top + height / 2); if (markShown) { if (isSponsored) { - session->data().sponsoredMessages().view( - item->fullId()); + session->sponsoredMessages().view(item->fullId()); } else if (isUnread) { readTill = item; } diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index 3a94363e2..2a7ee708d 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -27,12 +27,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/round_rect.h" #include "ui/text/text_utilities.h" #include "ui/power_saving.h" +#include "data/components/sponsored_messages.h" #include "data/data_session.h" #include "data/data_user.h" #include "data/data_channel.h" #include "data/data_forum_topic.h" #include "data/data_message_reactions.h" -#include "data/data_sponsored_messages.h" #include "lang/lang_keys.h" #include "mainwidget.h" #include "main/main_session.h" @@ -435,8 +435,9 @@ Message::Message( } } if (data->isSponsored()) { - const auto &messages = data->history()->owner().sponsoredMessages(); - const auto details = messages.lookupDetails(data->fullId()); + const auto &session = data->history()->session(); + const auto details = session.sponsoredMessages().lookupDetails( + data->fullId()); if (details.canReport) { _rightAction = std::make_unique(); _rightAction->second = std::make_unique(); diff --git a/Telegram/SourceFiles/history/view/history_view_sponsored_click_handler.cpp b/Telegram/SourceFiles/history/view/history_view_sponsored_click_handler.cpp index 65b030476..7a6d7b685 100644 --- a/Telegram/SourceFiles/history/view/history_view_sponsored_click_handler.cpp +++ b/Telegram/SourceFiles/history/view/history_view_sponsored_click_handler.cpp @@ -10,8 +10,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "api/api_chat_invite.h" #include "core/click_handler_types.h" #include "core/file_utilities.h" +#include "data/components/sponsored_messages.h" #include "data/data_session.h" -#include "data/data_sponsored_messages.h" #include "main/main_session.h" #include "window/window_session_controller.h" @@ -37,8 +37,8 @@ ClickHandlerPtr SponsoredLink(const QString &externalLink) { if (!controller) { return; } - const auto &data = controller->session().data(); - const auto details = data.sponsoredMessages().lookupDetails( + const auto &session = controller->session(); + const auto details = session.sponsoredMessages().lookupDetails( my.itemId); if (!details.externalLink.isEmpty()) { File::OpenUrl(details.externalLink); diff --git a/Telegram/SourceFiles/history/view/media/history_view_web_page.cpp b/Telegram/SourceFiles/history/view/media/history_view_web_page.cpp index c275e3b35..3acd1c69f 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_web_page.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_web_page.cpp @@ -13,11 +13,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "iv/iv_instance.h" #include "core/click_handler_types.h" #include "core/ui_integration.h" +#include "data/components/sponsored_messages.h" #include "data/stickers/data_custom_emoji.h" #include "data/data_file_click_handler.h" #include "data/data_photo_media.h" #include "data/data_session.h" -#include "data/data_sponsored_messages.h" #include "data/data_web_page.h" #include "history/history.h" #include "history/history_item_components.h" @@ -227,8 +227,8 @@ WebPage::WebPage( if (!(flags & MediaWebPageFlag::Sponsored)) { return std::nullopt; } - const auto &data = _parent->data()->history()->owner(); - const auto details = data.sponsoredMessages().lookupDetails( + const auto &session = _parent->data()->history()->session(); + const auto details = session.sponsoredMessages().lookupDetails( _parent->data()->fullId()); auto result = std::make_optional(); result->buttonText = details.buttonText; diff --git a/Telegram/SourceFiles/main/main_session.cpp b/Telegram/SourceFiles/main/main_session.cpp index 8ec284294..95d39c141 100644 --- a/Telegram/SourceFiles/main/main_session.cpp +++ b/Telegram/SourceFiles/main/main_session.cpp @@ -28,6 +28,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "storage/file_upload.h" #include "storage/storage_account.h" #include "storage/storage_facade.h" +#include "data/components/sponsored_messages.h" #include "data/data_session.h" #include "data/data_changes.h" #include "data/data_user.h" @@ -96,6 +97,7 @@ Session::Session( , _giftBoxStickersPacks(std::make_unique(this)) , _sendAsPeers(std::make_unique(this)) , _attachWebView(std::make_unique(this)) +, _sponsoredMessages(std::make_unique(this)) , _supportHelper(Support::Helper::Create(this)) , _saveSettingsTimer([=] { saveSettings(); }) { Expects(_settings != nullptr); diff --git a/Telegram/SourceFiles/main/main_session.h b/Telegram/SourceFiles/main/main_session.h index d8c74e087..7346498d8 100644 --- a/Telegram/SourceFiles/main/main_session.h +++ b/Telegram/SourceFiles/main/main_session.h @@ -31,6 +31,7 @@ class Templates; namespace Data { class Session; class Changes; +class SponsoredMessages; } // namespace Data namespace Storage { @@ -104,6 +105,9 @@ public: [[nodiscard]] Data::Changes &changes() const { return *_changes; } + [[nodiscard]] Data::SponsoredMessages &sponsoredMessages() const { + return *_sponsoredMessages; + } [[nodiscard]] Api::Updates &updates() const { return *_updates; } @@ -224,6 +228,7 @@ private: const std::unique_ptr _giftBoxStickersPacks; const std::unique_ptr _sendAsPeers; const std::unique_ptr _attachWebView; + const std::unique_ptr _sponsoredMessages; const std::unique_ptr _supportHelper; diff --git a/Telegram/SourceFiles/menu/menu_sponsored.cpp b/Telegram/SourceFiles/menu/menu_sponsored.cpp index bfa8427f1..153bb46bd 100644 --- a/Telegram/SourceFiles/menu/menu_sponsored.cpp +++ b/Telegram/SourceFiles/menu/menu_sponsored.cpp @@ -10,9 +10,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/premium_preview_box.h" #include "chat_helpers/compose/compose_show.h" #include "core/ui_integration.h" // Core::MarkedTextContext. +#include "data/components/sponsored_messages.h" #include "data/data_premium_limits.h" #include "data/data_session.h" -#include "data/data_sponsored_messages.h" #include "data/stickers/data_custom_emoji.h" #include "history/history.h" #include "lang/lang_keys.h" @@ -217,7 +217,7 @@ void ShowReportSponsoredBox( std::shared_ptr show, not_null item) { const auto peer = item->history()->peer; - auto &sponsoredMessages = peer->session().data().sponsoredMessages(); + auto &sponsoredMessages = peer->session().sponsoredMessages(); const auto fullId = item->fullId(); const auto report = sponsoredMessages.createReportCallback(fullId); const auto guideLink = Ui::Text::Link(