diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index cea6bc17d..f4a2efc60 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -2708,39 +2708,6 @@ void ApiWrap::resolveWebPages() { } } -void ApiWrap::requestAttachedStickerSets(not_null photo) { - request(_attachedStickerSetsRequestId).cancel(); - _attachedStickerSetsRequestId = request(MTPmessages_GetAttachedStickers( - MTP_inputStickeredMediaPhoto(photo->mtpInput()) - )).done([=](const MTPVector &result) { - if (result.v.isEmpty()) { - Ui::show(Box(tr::lng_stickers_not_found(tr::now))); - return; - } else if (result.v.size() > 1) { - Ui::show(Box(_session, result)); - return; - } - // Single attached sticker pack. - const auto setData = result.v.front().match([&](const auto &data) { - return data.vset().match([&](const MTPDstickerSet &data) { - return &data; - }); - }); - - const auto setId = (setData->vid().v && setData->vaccess_hash().v) - ? MTP_inputStickerSetID(setData->vid(), setData->vaccess_hash()) - : MTP_inputStickerSetShortName(setData->vshort_name()); - const auto &windows = _session->windows(); - if (!windows.empty()) { - Ui::show( - Box(windows.front(), setId), - Ui::LayerOption::KeepOther); - } - }).fail([=](const RPCError &error) { - Ui::show(Box(tr::lng_stickers_not_found(tr::now))); - }).send(); -} - void ApiWrap::requestParticipantsCountDelayed( not_null channel) { _participantsCountRequestTimer.call( diff --git a/Telegram/SourceFiles/apiwrap.h b/Telegram/SourceFiles/apiwrap.h index f502f7f8d..f88e2ac3b 100644 --- a/Telegram/SourceFiles/apiwrap.h +++ b/Telegram/SourceFiles/apiwrap.h @@ -262,7 +262,6 @@ public: void clearWebPageRequest(WebPageData *page); void clearWebPageRequests(); - void requestAttachedStickerSets(not_null photo); void scheduleStickerSetRequest(uint64 setId, uint64 access); void requestStickerSets(); void saveStickerSets( @@ -847,8 +846,6 @@ private: std::optional _contactSignupSilent; rpl::event_stream _contactSignupSilentChanges; - mtpRequestId _attachedStickerSetsRequestId = 0; - base::flat_map _unlikelyMessageLinks; }; diff --git a/Telegram/SourceFiles/boxes/background_preview_box.cpp b/Telegram/SourceFiles/boxes/background_preview_box.cpp index 2aaeb3f6c..8de1d447a 100644 --- a/Telegram/SourceFiles/boxes/background_preview_box.cpp +++ b/Telegram/SourceFiles/boxes/background_preview_box.cpp @@ -399,7 +399,8 @@ BackgroundPreviewBox::BackgroundPreviewBox( QWidget*, not_null controller, const Data::WallPaper &paper) -: _controller(controller) +: SimpleElementDelegate(controller) +, _controller(controller) , _text1(GenerateTextItem( delegate(), _controller->session().data().history( diff --git a/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp b/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp index cd904bc05..1ad6c8241 100644 --- a/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp @@ -244,7 +244,7 @@ void AddParticipantsBoxController::Start( box->boxClosing() | rpl::start_with_next([=] { auto params = Window::SectionShow(); params.activation = anim::activation::background; - App::wnd()->sessionController()->showPeerHistory( + navigation->parentController()->showPeerHistory( channel, params, ShowAtTheEndMsgId); diff --git a/Telegram/SourceFiles/boxes/peers/edit_contact_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_contact_box.cpp index c7138e4af..f46fd99af 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_contact_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_contact_box.cpp @@ -83,7 +83,7 @@ class Controller { public: Controller( not_null box, - not_null window, + not_null window, not_null user); void prepare(); @@ -100,7 +100,7 @@ private: bool inverted); not_null _box; - not_null _window; + not_null _window; not_null _user; Ui::Checkbox *_sharePhone = nullptr; QString _phone; @@ -111,7 +111,7 @@ private: Controller::Controller( not_null box, - not_null window, + not_null window, not_null user) : _box(box) , _window(window) @@ -143,7 +143,7 @@ void Controller::setupCover() { object_ptr( _box, _user, - _window->sessionController(), + _window, (_phone.isEmpty() ? tr::lng_contact_mobile_hidden() : rpl::single(App::formatPhone(_phone)))), @@ -266,7 +266,7 @@ void Controller::setupSharePhoneNumber() { void EditContactBox( not_null box, - not_null window, + not_null window, not_null user) { box->lifetime().make_state(box, window, user)->prepare(); } diff --git a/Telegram/SourceFiles/boxes/peers/edit_contact_box.h b/Telegram/SourceFiles/boxes/peers/edit_contact_box.h index 3f3e2c776..3dc7d81f8 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_contact_box.h +++ b/Telegram/SourceFiles/boxes/peers/edit_contact_box.h @@ -12,10 +12,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL class UserData; namespace Window { -class Controller; +class SessionController; } // namespace Window void EditContactBox( not_null box, - not_null window, + not_null window, not_null user); diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp index 2d107db94..0b0801f48 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp @@ -193,9 +193,11 @@ void SaveSlowmodeSeconds( api->registerModifyRequest(key, requestId); } -void ShowEditPermissions(not_null peer) { +void ShowEditPermissions( + not_null navigation, + not_null peer) { const auto box = Ui::show( - Box(peer), + Box(navigation, peer), Ui::LayerOption::KeepOther); const auto saving = box->lifetime().make_state(0); const auto save = [=]( @@ -562,7 +564,9 @@ object_ptr Controller::createStickersEdit() { tr::lng_group_stickers_add(tr::now), st::editPeerInviteLinkButton) )->addClickHandler([=] { - Ui::show(Box(channel), Ui::LayerOption::KeepOther); + Ui::show( + Box(_navigation->parentController(), channel), + Ui::LayerOption::KeepOther); }); return result; @@ -831,8 +835,6 @@ void Controller::fillHistoryVisibilityButton() { void Controller::fillManageSection() { Expects(_controls.buttonsLayout != nullptr); - const auto navigation = App::wnd()->sessionController(); - const auto chat = _peer->asChat(); const auto channel = _peer->asChannel(); const auto isChannel = (!chat); @@ -944,7 +946,7 @@ void Controller::fillManageSection() { Info::Profile::RestrictionsCountValue ) | rpl::flatten_latest( ) | ToPositiveNumberStringRestrictions(), - [=] { ShowEditPermissions(_peer); }, + [=] { ShowEditPermissions(_navigation, _peer); }, st::infoIconPermissions); } if (canViewAdmins) { @@ -959,7 +961,7 @@ void Controller::fillManageSection() { ) | ToPositiveNumberString(), [=] { ParticipantsBoxController::Start( - navigation, + _navigation, _peer, ParticipantsBoxController::Role::Admins); }, @@ -977,7 +979,7 @@ void Controller::fillManageSection() { ) | ToPositiveNumberString(), [=] { ParticipantsBoxController::Start( - navigation, + _navigation, _peer, ParticipantsBoxController::Role::Members); }, @@ -991,7 +993,7 @@ void Controller::fillManageSection() { | ToPositiveNumberString(), [=] { ParticipantsBoxController::Start( - navigation, + _navigation, _peer, ParticipantsBoxController::Role::Kicked); }, @@ -1003,7 +1005,7 @@ void Controller::fillManageSection() { tr::lng_manage_peer_recent_actions(), rpl::single(QString()), //Empty count. [=] { - navigation->showSection(AdminLog::SectionMemento(channel)); + _navigation->showSection(AdminLog::SectionMemento(channel)); }, st::infoIconRecentActions); } diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp index c518e56f3..91c7431b6 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp @@ -307,8 +307,10 @@ ChatAdminRights FullAdminRights(bool isGroup) { EditPeerPermissionsBox::EditPeerPermissionsBox( QWidget*, + not_null navigation, not_null peer) -: _peer(peer->migrateToOrMe()) { +: _navigation(navigation) +, _peer(peer->migrateToOrMe()) { } auto EditPeerPermissionsBox::saveEvents() const -> rpl::producer { @@ -522,8 +524,6 @@ void EditPeerPermissionsBox::addBannedButtons( } } const auto channel = _peer->asChannel(); - - const auto navigation = App::wnd()->sessionController(); container->add(EditPeerInfoBox::CreateButton( container, tr::lng_manage_peer_exceptions(), @@ -532,7 +532,7 @@ void EditPeerPermissionsBox::addBannedButtons( : rpl::single(0)) | ToPositiveNumberString(), [=] { ParticipantsBoxController::Start( - navigation, + _navigation, _peer, ParticipantsBoxController::Role::Restricted); }, @@ -545,7 +545,7 @@ void EditPeerPermissionsBox::addBannedButtons( | ToPositiveNumberString(), [=] { ParticipantsBoxController::Start( - navigation, + _navigation, _peer, ParticipantsBoxController::Role::Kicked); }, diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.h b/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.h index 4faf5e468..53f16ea38 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.h +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.h @@ -15,9 +15,16 @@ class RoundButton; class VerticalLayout; } // namespace Ui +namespace Window { +class SessionNavigation; +} // namespace Window + class EditPeerPermissionsBox : public Ui::BoxContent { public: - EditPeerPermissionsBox(QWidget*, not_null peer); + EditPeerPermissionsBox( + QWidget*, + not_null navigation, + not_null peer); struct Result { MTPDchatBannedRights::Flags rights; @@ -34,7 +41,8 @@ private: void addSlowmodeLabels(not_null container); void addBannedButtons(not_null container); - not_null _peer; + const not_null _navigation; + const not_null _peer; Ui::RoundButton *_save = nullptr; Fn _value; diff --git a/Telegram/SourceFiles/boxes/stickers_box.cpp b/Telegram/SourceFiles/boxes/stickers_box.cpp index d533c5aaf..4654798e7 100644 --- a/Telegram/SourceFiles/boxes/stickers_box.cpp +++ b/Telegram/SourceFiles/boxes/stickers_box.cpp @@ -67,7 +67,6 @@ private: }; - // This class is hold in header because it requires Qt preprocessing. class StickersBox::Inner : public Ui::RpWidget @@ -77,9 +76,14 @@ public: Inner( QWidget *parent, - not_null session, + not_null controller, Section section); - Inner(QWidget *parent, not_null megagroup); + Inner( + QWidget *parent, + not_null controller, + not_null megagroup); + + [[nodiscard]] Main::Session &session() const; base::Observable scrollToY; void setInnerFocus(); @@ -232,7 +236,7 @@ private: int countMaxNameWidth() const; - const not_null _session; + const not_null _controller; MTP::Sender _api; Section _section; @@ -359,26 +363,29 @@ void StickersBox::Tab::saveScrollTop() { StickersBox::StickersBox( QWidget*, - not_null session, + not_null controller, Section section) -: _session(session) -, _api(&session->mtp()) +: _controller(controller) +, _api(&controller->session().mtp()) , _tabs(this, st::stickersTabs) , _unreadBadge( this, - _session->data().stickers().featuredSetsUnreadCountValue()) + controller->session().data().stickers().featuredSetsUnreadCountValue()) , _section(section) -, _installed(0, this, session, Section::Installed) -, _featured(1, this, session, Section::Featured) -, _archived(2, this, session, Section::Archived) { +, _installed(0, this, controller, Section::Installed) +, _featured(1, this, controller, Section::Featured) +, _archived(2, this, controller, Section::Archived) { _tabs->setRippleTopRoundRadius(st::boxRadius); } -StickersBox::StickersBox(QWidget*, not_null megagroup) -: _session(&megagroup->session()) -, _api(&_session->mtp()) +StickersBox::StickersBox( + QWidget*, + not_null controller, + not_null megagroup) +: _controller(controller) +, _api(&controller->session().mtp()) , _section(Section::Installed) -, _installed(0, this, megagroup) +, _installed(0, this, controller, megagroup) , _megagroupSet(megagroup) { subscribe(_installed.widget()->scrollToY, [=](int y) { onScrollToY(y); @@ -387,15 +394,19 @@ StickersBox::StickersBox(QWidget*, not_null megagroup) StickersBox::StickersBox( QWidget*, - not_null session, + not_null controller, const MTPVector &attachedSets) -: _session(session) -, _api(&session->mtp()) +: _controller(controller) +, _api(&controller->session().mtp()) , _section(Section::Attached) -, _attached(0, this, session, Section::Attached) +, _attached(0, this, controller, Section::Attached) , _attachedSets(attachedSets) { } +Main::Session &StickersBox::session() const { + return _controller->session(); +} + void StickersBox::showAttachedStickers() { auto addedSet = false; for (const auto &stickerSet : _attachedSets.v) { @@ -405,11 +416,11 @@ void StickersBox::showAttachedStickers() { }); }); - if (const auto set = _session->data().stickers().feedSet(*setData)) { + if (const auto set = session().data().stickers().feedSet(*setData)) { if (_attached.widget()->appendSet(set)) { addedSet = true; if (set->stickers.isEmpty() || (set->flags & MTPDstickerSet_ClientFlag::f_not_loaded)) { - _session->api().scheduleStickerSetRequest(set->id, set->access); + session().api().scheduleStickerSetRequest(set->id, set->access); } } } @@ -419,7 +430,7 @@ void StickersBox::showAttachedStickers() { } if (_section == Section::Attached && addedSet) { - _session->api().requestStickerSets(); + session().api().requestStickerSets(); } } @@ -433,7 +444,7 @@ void StickersBox::getArchivedDone( } auto &stickers = result.c_messages_archivedStickers(); - auto &archived = _session->data().stickers().archivedSetsOrderRef(); + auto &archived = session().data().stickers().archivedSetsOrderRef(); if (offsetId) { auto index = archived.indexOf(offsetId); if (index >= 0) { @@ -463,7 +474,7 @@ void StickersBox::getArchivedDone( } if (!setData) continue; - if (const auto set = _session->data().stickers().feedSet(*setData)) { + if (const auto set = session().data().stickers().feedSet(*setData)) { const auto index = archived.indexOf(set->id); if (archived.isEmpty() || index != archived.size() - 1) { changedSets = true; @@ -475,7 +486,7 @@ void StickersBox::getArchivedDone( if (_archived.widget()->appendSet(set)) { addedSet = true; if (set->stickers.isEmpty() || (set->flags & MTPDstickerSet_ClientFlag::f_not_loaded)) { - _session->api().scheduleStickerSetRequest(set->id, set->access); + session().api().scheduleStickerSetRequest(set->id, set->access); } } } @@ -493,14 +504,14 @@ void StickersBox::getArchivedDone( refreshTabs(); _someArchivedLoaded = true; if (_section == Section::Archived && addedSet) { - _session->api().requestStickerSets(); + session().api().requestStickerSets(); } } void StickersBox::prepare() { if (_section == Section::Installed) { if (_tabs) { - _session->local().readArchivedStickers(); + session().local().readArchivedStickers(); } else { setTitle(tr::lng_stickers_group_set()); } @@ -510,7 +521,7 @@ void StickersBox::prepare() { setTitle(tr::lng_stickers_attached_sets()); } if (_tabs) { - if (_session->data().stickers().archivedSetsOrder().isEmpty()) { + if (session().data().stickers().archivedSetsOrder().isEmpty()) { preloadArchivedSets(); } setNoContentMargin(true); @@ -561,11 +572,11 @@ void StickersBox::prepare() { setInnerWidget(_tab->takeWidget(), getTopSkip()); setDimensions(st::boxWideWidth, st::boxMaxListHeight); - _session->data().stickers().updated( + session().data().stickers().updated( ) | rpl::start_with_next( [this] { handleStickersUpdated(); }, lifetime()); - _session->api().updateStickers(); + session().api().updateStickers(); if (_installed.widget()) { _installed.widget()->draggingScrollDelta( @@ -593,11 +604,11 @@ void StickersBox::refreshTabs() { auto sections = QStringList(); sections.push_back(tr::lng_stickers_installed_tab(tr::now).toUpper()); _tabIndices.push_back(Section::Installed); - if (!_session->data().stickers().featuredSetsOrder().isEmpty()) { + if (!session().data().stickers().featuredSetsOrder().isEmpty()) { sections.push_back(tr::lng_stickers_featured_tab(tr::now).toUpper()); _tabIndices.push_back(Section::Featured); } - if (!_session->data().stickers().archivedSetsOrder().isEmpty()) { + if (!session().data().stickers().archivedSetsOrder().isEmpty()) { sections.push_back(tr::lng_stickers_archived_tab(tr::now).toUpper()); _tabIndices.push_back(Section::Archived); } @@ -621,8 +632,8 @@ void StickersBox::loadMoreArchived() { } uint64 lastId = 0; - const auto &order = _session->data().stickers().archivedSetsOrder(); - const auto &sets = _session->data().stickers().sets(); + const auto &order = session().data().stickers().archivedSetsOrder(); + const auto &sets = session().data().stickers().sets(); for (auto setIt = order.cend(), e = order.cbegin(); setIt != e;) { --setIt; auto it = sets.find(*setIt); @@ -745,7 +756,7 @@ QPixmap StickersBox::grabContentCache() { } void StickersBox::installSet(uint64 setId) { - const auto &sets = _session->data().stickers().sets(); + const auto &sets = session().data().stickers().sets(); const auto it = sets.find(setId); if (it == sets.cend()) { rebuildList(); @@ -771,24 +782,24 @@ void StickersBox::installSet(uint64 setId) { installFail(error, setId); }).send(); - _session->data().stickers().installLocally(setId); + session().data().stickers().installLocally(setId); } } void StickersBox::installDone(const MTPmessages_StickerSetInstallResult &result) { if (result.type() == mtpc_messages_stickerSetInstallResultArchive) { - _session->data().stickers().applyArchivedResult( + session().data().stickers().applyArchivedResult( result.c_messages_stickerSetInstallResultArchive()); } } void StickersBox::installFail(const RPCError &error, uint64 setId) { - const auto &sets = _session->data().stickers().sets(); + const auto &sets = session().data().stickers().sets(); const auto it = sets.find(setId); if (it == sets.cend()) { rebuildList(); } else { - _session->data().stickers().undoInstallLocally(setId); + session().data().stickers().undoInstallLocally(setId); } } @@ -813,18 +824,18 @@ void StickersBox::requestArchivedSets() { preloadArchivedSets(); } - const auto &sets = _session->data().stickers().sets(); - const auto &order = _session->data().stickers().archivedSetsOrder(); + const auto &sets = session().data().stickers().sets(); + const auto &order = session().data().stickers().archivedSetsOrder(); for (const auto setId : order) { auto it = sets.find(setId); if (it != sets.cend()) { const auto set = it->second.get(); if (set->stickers.isEmpty() && (set->flags & MTPDstickerSet_ClientFlag::f_not_loaded)) { - _session->api().scheduleStickerSetRequest(setId, set->access); + session().api().scheduleStickerSetRequest(setId, set->access); } } } - _session->api().requestStickerSets(); + session().api().requestStickerSets(); } void StickersBox::resizeEvent(QResizeEvent *e) { @@ -848,7 +859,7 @@ void StickersBox::handleStickersUpdated() { } else { _tab->widget()->updateRows(); } - if (_session->data().stickers().archivedSetsOrder().isEmpty()) { + if (session().data().stickers().archivedSetsOrder().isEmpty()) { preloadArchivedSets(); } else { refreshTabs(); @@ -875,9 +886,9 @@ void StickersBox::saveChanges() { rebuildList(&_installed); if (_someArchivedLoaded) { - _session->local().writeArchivedStickers(); + session().local().writeArchivedStickers(); } - _session->api().saveStickerSets(_installed.widget()->getOrder(), _installed.widget()->getRemovedSets()); + session().api().saveStickerSets(_installed.widget()->getOrder(), _installed.widget()->getRemovedSets()); } void StickersBox::setInnerFocus() { @@ -923,11 +934,11 @@ bool StickersBox::Inner::Row::isRecentSet() const { StickersBox::Inner::Inner( QWidget *parent, - not_null session, + not_null controller, StickersBox::Section section) : RpWidget(parent) -, _session(session) -, _api(&_session->mtp()) +, _controller(controller) +, _api(&_controller->session().mtp()) , _section(section) , _rowHeight(st::contactsPadding.top() + st::contactsPhotoSize + st::contactsPadding.bottom()) , _shiftingAnimation([=](crl::time now) { @@ -941,10 +952,13 @@ StickersBox::Inner::Inner( setup(); } -StickersBox::Inner::Inner(QWidget *parent, not_null megagroup) +StickersBox::Inner::Inner( + QWidget *parent, + not_null controller, + not_null megagroup) : RpWidget(parent) -, _session(&megagroup->session()) -, _api(&_session->mtp()) +, _controller(controller) +, _api(&_controller->session().mtp()) , _section(StickersBox::Section::Installed) , _rowHeight(st::contactsPadding.top() + st::contactsPhotoSize + st::contactsPadding.bottom()) , _shiftingAnimation([=](crl::time now) { @@ -958,11 +972,11 @@ StickersBox::Inner::Inner(QWidget *parent, not_null megagroup) st::groupStickersField, rpl::single(qsl("stickerset")), QString(), - _session->createInternalLink(QString())) + _controller->session().createInternalLink(QString())) , _megagroupDivider(this) , _megagroupSubTitle(this, tr::lng_stickers_group_from_your(tr::now), st::boxTitle) { _megagroupSetField->setLinkPlaceholder( - _session->createInternalLink(qsl("addstickers/"))); + _controller->session().createInternalLink(qsl("addstickers/"))); _megagroupSetField->setPlaceholderHidden(false); _megagroupSetAddressChangedTimer.setCallback([this] { handleMegagroupSetAddressChange(); }); connect( @@ -983,8 +997,12 @@ StickersBox::Inner::Inner(QWidget *parent, not_null megagroup) setup(); } +Main::Session &StickersBox::Inner::session() const { + return _controller->session(); +} + void StickersBox::Inner::setup() { - subscribe(_session->downloaderTaskFinished(), [this] { + subscribe(session().downloaderTaskFinished(), [this] { update(); readVisibleSets(); }); @@ -1211,8 +1229,7 @@ void StickersBox::Inner::paintRowThumbnail( size.width(), size.height()), frame); - const auto controller = App::wnd()->sessionController(); - const auto paused = controller->isGifPausedAtLeastFor( + const auto paused = _controller->isGifPausedAtLeastFor( Window::GifPauseReason::Layer); if (!paused) { row->lottie->markFrameShown(); @@ -1571,9 +1588,7 @@ void StickersBox::Inner::mouseReleaseEvent(QMouseEvent *e) { const auto showSetByRow = [&](const Row &row) { setSelected(SelectedRow()); Ui::show( - Box( - App::wnd()->sessionController(), - row.set->mtpInput()), + Box(_controller, row.set->mtpInput()), Ui::LayerOption::KeepOther); }; if (selectedIndex >= 0 && !_inDragArea) { @@ -1602,8 +1617,8 @@ void StickersBox::Inner::saveGroupSet() { ? _megagroupSetInput.c_inputStickerSetID().vid().v : 0; if (newId != oldId) { - _session->api().setGroupStickerSet(_megagroupSet, _megagroupSetInput); - _session->api().stickerSetInstalled(Data::Stickers::MegagroupSetId); + session().api().setGroupStickerSet(_megagroupSet, _megagroupSetInput); + session().api().stickerSetInstalled(Data::Stickers::MegagroupSetId); } } @@ -1733,7 +1748,7 @@ void StickersBox::Inner::handleMegagroupSetAddressChange() { auto text = _megagroupSetField->getLastText().trimmed(); if (text.isEmpty()) { if (_megagroupSelectedSet) { - const auto &sets = _session->data().stickers().sets(); + const auto &sets = session().data().stickers().sets(); const auto it = sets.find(_megagroupSelectedSet->set->id); if (it != sets.cend() && !it->second->shortName.isEmpty()) { setMegagroupSelectedSet(MTP_inputStickerSetEmpty()); @@ -1744,7 +1759,7 @@ void StickersBox::Inner::handleMegagroupSetAddressChange() { MTP_inputStickerSetShortName(MTP_string(text)) )).done([=](const MTPmessages_StickerSet &result) { _megagroupSetRequestId = 0; - auto set = _session->data().stickers().feedSetFull(result); + auto set = session().data().stickers().feedSetFull(result); setMegagroupSelectedSet(MTP_inputStickerSetID( MTP_long(set->id), MTP_long(set->access))); @@ -1771,11 +1786,11 @@ void StickersBox::Inner::rebuildMegagroupSet() { } auto &inputId = _megagroupSetInput.c_inputStickerSetID(); auto setId = inputId.vid().v; - const auto &sets = _session->data().stickers().sets(); + const auto &sets = session().data().stickers().sets(); auto it = sets.find(setId); if (it == sets.cend() || (it->second->flags & MTPDstickerSet_ClientFlag::f_not_loaded)) { - _session->api().scheduleStickerSetRequest( + session().api().scheduleStickerSetRequest( inputId.vid().v, inputId.vaccess_hash().v); return; @@ -1834,22 +1849,22 @@ void StickersBox::Inner::rebuild() { clear(); const auto &order = ([&]() -> const StickersSetsOrder & { if (_section == Section::Installed) { - auto &result = _session->data().stickers().setsOrder(); + auto &result = session().data().stickers().setsOrder(); if (_megagroupSet && result.empty()) { - return _session->data().stickers().featuredSetsOrder(); + return session().data().stickers().featuredSetsOrder(); } return result; } else if (_section == Section::Featured) { - return _session->data().stickers().featuredSetsOrder(); + return session().data().stickers().featuredSetsOrder(); } - return _session->data().stickers().archivedSetsOrder(); + return session().data().stickers().archivedSetsOrder(); })(); _rows.reserve(order.size() + 1); _shiftingStartTimes.reserve(order.size() + 1); - const auto &sets = _session->data().stickers().sets(); + const auto &sets = session().data().stickers().sets(); if (_megagroupSet) { - auto usingFeatured = _session->data().stickers().setsOrder().empty(); + auto usingFeatured = session().data().stickers().setsOrder().empty(); _megagroupSubTitle->setText(usingFeatured ? tr::lng_stickers_group_from_featured(tr::now) : tr::lng_stickers_group_from_your(tr::now)); @@ -1871,10 +1886,10 @@ void StickersBox::Inner::rebuild() { if (set->stickers.isEmpty() || (set->flags & MTPDstickerSet_ClientFlag::f_not_loaded)) { - _session->api().scheduleStickerSetRequest(set->id, set->access); + session().api().scheduleStickerSetRequest(set->id, set->access); } } - _session->api().requestStickerSets(); + session().api().requestStickerSets(); updateSize(); } @@ -1899,7 +1914,7 @@ void StickersBox::Inner::updateSize(int newWidth) { void StickersBox::Inner::updateRows() { int maxNameWidth = countMaxNameWidth(); - const auto &sets = _session->data().stickers().sets(); + const auto &sets = session().data().stickers().sets(); for (const auto &row : _rows) { const auto it = sets.find(row->set->id); if (it == sets.cend()) { @@ -2046,18 +2061,18 @@ int StickersBox::Inner::fillSetCount(not_null set) const { : set->stickers.size(); auto added = 0; if (set->id == Data::Stickers::CloudRecentSetId) { - const auto &sets = _session->data().stickers().sets(); + const auto &sets = session().data().stickers().sets(); auto customIt = sets.find(Data::Stickers::CustomSetId); if (customIt != sets.cend()) { added = customIt->second->stickers.size(); - const auto &recent = _session->data().stickers().getRecentPack(); + const auto &recent = session().data().stickers().getRecentPack(); for (const auto &sticker : recent) { if (customIt->second->stickers.indexOf(sticker.first) < 0) { ++added; } } } else { - added = _session->data().stickers().getRecentPack().size(); + added = session().data().stickers().getRecentPack().size(); } } return result + added; @@ -2204,7 +2219,7 @@ void StickersBox::Inner::readVisibleSets() { ? (row->stickerMedia && row->stickerMedia->loaded()) : true; if (!thumbnailLoading || thumbnailLoaded) { - _session->api().readFeaturedSetDelayed(row->set->id); + session().api().readFeaturedSetDelayed(row->set->id); } } } diff --git a/Telegram/SourceFiles/boxes/stickers_box.h b/Telegram/SourceFiles/boxes/stickers_box.h index 46977553e..e2050940c 100644 --- a/Telegram/SourceFiles/boxes/stickers_box.h +++ b/Telegram/SourceFiles/boxes/stickers_box.h @@ -29,6 +29,10 @@ class CrossButton; class BoxContentDivider; } // namespace Ui +namespace Window { +class SessionController; +} // namespace Window + namespace Main { class Session; } // namespace Main @@ -56,15 +60,20 @@ public: StickersBox( QWidget*, - not_null session, + not_null controller, Section section); - StickersBox(QWidget*, not_null megagroup); StickersBox( QWidget*, - not_null session, + not_null controller, + not_null megagroup); + StickersBox( + QWidget*, + not_null controller, const MTPVector &attachedSets); ~StickersBox(); + [[nodiscard]] Main::Session &session() const; + void setInnerFocus() override; protected: @@ -123,7 +132,7 @@ private: uint64 offsetId); void showAttachedStickers(); - const not_null _session; + const not_null _controller; MTP::Sender _api; object_ptr _tabs = { nullptr }; diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp index 303d8f52e..85f9b2e75 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp @@ -529,7 +529,7 @@ void StickersListWidget::Footer::mousePressEvent(QMouseEvent *e) { if (_iconOver == SpecialOver::Settings) { Ui::show(Box( - &_pan->session(), + _pan->controller(), (hasOnlyFeaturedSets() ? StickersBox::Section::Featured : StickersBox::Section::Installed))); @@ -886,9 +886,8 @@ StickersListWidget::StickersListWidget( setAttribute(Qt::WA_OpaquePaintEvent); _settings->addClickHandler([=] { - Ui::show(Box( - &controller->session(), - StickersBox::Section::Installed)); + Ui::show( + Box(controller, StickersBox::Section::Installed)); }); subscribe(session().downloaderTaskFinished(), [=] { @@ -2107,7 +2106,7 @@ void StickersListWidget::mouseReleaseEvent(QMouseEvent *e) { removeSet(sets[button->section].id); } } else if (base::get_if(&pressed)) { - Ui::show(Box(_megagroupSet)); + Ui::show(Box(controller(), _megagroupSet)); } } } @@ -2921,7 +2920,7 @@ void StickersListWidget::displaySet(uint64 setId) { if (_megagroupSet->canEditStickers()) { _displayingSet = true; checkHideWithBox(Ui::show( - Box(_megagroupSet), + Box(controller(), _megagroupSet), Ui::LayerOption::KeepOther).data()); return; } else if (_megagroupSet->mgInfo->stickerSet.type() == mtpc_inputStickerSetID) { diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp index 35906e55e..72f47e020 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp @@ -587,6 +587,10 @@ void InnerWidget::elementShowTooltip( Fn hiddenCallback) { } +bool InnerWidget::elementIsGifPaused() { + return _controller->isGifPausedAtLeastFor(Window::GifPauseReason::Any); +} + void InnerWidget::saveState(not_null memento) { memento->setFilter(std::move(_filter)); memento->setAdmins(std::move(_admins)); diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h index 177396075..f3c90b493 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h @@ -111,6 +111,7 @@ public: void elementShowTooltip( const TextWithEntities &text, Fn hiddenCallback) override; + bool elementIsGifPaused() override; ~InnerWidget(); diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index 33403d634..7e941ae86 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -1545,6 +1545,7 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { _menu = base::make_unique_q(this); const auto session = &this->session(); + const auto controller = _controller; const auto addItemActions = [&](HistoryItem *item) { if (!item @@ -1584,7 +1585,7 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { }); if (photo->hasSticker) { _menu->addAction(tr::lng_context_attached_stickers(tr::now), [=] { - session->api().requestAttachedStickerSets(photo); + controller->requestAttachedStickerSets(photo); }); } }; @@ -2524,6 +2525,10 @@ void HistoryInner::elementShowTooltip( _widget->showInfoTooltip(text, std::move(hiddenCallback)); } +bool HistoryInner::elementIsGifPaused() { + return _controller->isGifPausedAtLeastFor(Window::GifPauseReason::Any); +} + auto HistoryInner::getSelectionState() const -> HistoryView::TopBarWidget::SelectedState { auto result = HistoryView::TopBarWidget::SelectedState {}; @@ -3386,6 +3391,9 @@ not_null HistoryInner::ElementDelegate() { Instance->elementShowTooltip(text, hiddenCallback); } } + bool elementIsGifPaused() override { + return Instance ? Instance->elementIsGifPaused() : false; + } }; diff --git a/Telegram/SourceFiles/history/history_inner_widget.h b/Telegram/SourceFiles/history/history_inner_widget.h index 9c369638e..a97a38d1c 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.h +++ b/Telegram/SourceFiles/history/history_inner_widget.h @@ -91,6 +91,7 @@ public: void elementShowTooltip( const TextWithEntities &text, Fn hiddenCallback); + bool elementIsGifPaused(); void updateBotInfo(bool recount = true); diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index ecccead6e..925d08a9c 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -855,6 +855,7 @@ void HistoryWidget::supportShareContact(Support::Contact contact) { action); }; const auto box = Ui::show(Box( + controller(), _history, contact, crl::guard(this, submit))); @@ -1868,7 +1869,7 @@ void HistoryWidget::showHistory( _channel = peerToChannel(_peer->id); _canSendMessages = _peer->canWrite(); _contactStatus = std::make_unique( - &controller()->window(), + controller(), this, _peer); _contactStatus->heightValue() | rpl::start_with_next([=] { diff --git a/Telegram/SourceFiles/history/view/history_view_contact_status.cpp b/Telegram/SourceFiles/history/view/history_view_contact_status.cpp index 0c8d3340a..a1179a9f9 100644 --- a/Telegram/SourceFiles/history/view/history_view_contact_status.cpp +++ b/Telegram/SourceFiles/history/view/history_view_contact_status.cpp @@ -178,10 +178,10 @@ void ContactStatus::Bar::updateButtonsGeometry() { } ContactStatus::ContactStatus( - not_null window, + not_null window, not_null parent, not_null peer) -: _window(window) +: _controller(window) , _bar(parent, object_ptr(parent, peer->shortName())) , _shadow(parent) { setupWidgets(parent); @@ -294,15 +294,15 @@ void ContactStatus::setupHandlers(not_null peer) { void ContactStatus::setupAddHandler(not_null user) { _bar.entity()->addClicks( ) | rpl::start_with_next([=] { - _window->show(Box(EditContactBox, _window, user)); + _controller->window().show(Box(EditContactBox, _controller, user)); }, _bar.lifetime()); } void ContactStatus::setupBlockHandler(not_null user) { _bar.entity()->blockClicks( ) | rpl::start_with_next([=] { - _window->show( - Box(Window::PeerMenuBlockUserBox, _window, user, true)); + _controller->window().show( + Box(Window::PeerMenuBlockUserBox, &_controller->window(), user, true)); }, _bar.lifetime()); } @@ -326,7 +326,7 @@ void ContactStatus::setupShareHandler(not_null user) { (*box)->closeBox(); } }; - *box = _window->show(Box( + *box = _controller->window().show(Box( tr::lng_new_contact_share_sure( tr::now, lt_phone, @@ -365,7 +365,7 @@ void ContactStatus::setupReportHandler(not_null peer) { Ui::Toast::Show(tr::lng_report_spam_done(tr::now)); // Destroys _bar. - _window->sessionController()->showBackFromStack(); + _controller->showBackFromStack(); }); if (const auto user = peer->asUser()) { peer->session().api().blockUser(user); @@ -373,7 +373,7 @@ void ContactStatus::setupReportHandler(not_null peer) { const auto text = ((peer->isChat() || peer->isMegagroup()) ? tr::lng_report_spam_sure_group : tr::lng_report_spam_sure_channel)(tr::now); - _window->show(Box( + _controller->window().show(Box( text, tr::lng_report_spam_ok(tr::now), st::attentionBoxButton, diff --git a/Telegram/SourceFiles/history/view/history_view_contact_status.h b/Telegram/SourceFiles/history/view/history_view_contact_status.h index e75198d8d..4279ecdc9 100644 --- a/Telegram/SourceFiles/history/view/history_view_contact_status.h +++ b/Telegram/SourceFiles/history/view/history_view_contact_status.h @@ -12,7 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/shadow.h" namespace Window { -class Controller; +class SessionController; } // namespace Window namespace Ui { @@ -25,7 +25,7 @@ namespace HistoryView { class ContactStatus final { public: ContactStatus( - not_null window, + not_null controller, not_null parent, not_null peer); @@ -87,7 +87,7 @@ private: static rpl::producer PeerState(not_null peer); - not_null _window; + const not_null _controller; State _state = State::None; Ui::SlideWrap _bar; Ui::PlainShadow _shadow; diff --git a/Telegram/SourceFiles/history/view/history_view_element.cpp b/Telegram/SourceFiles/history/view/history_view_element.cpp index 1e9f793c0..7963dcfaa 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.cpp +++ b/Telegram/SourceFiles/history/view/history_view_element.cpp @@ -20,6 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/core_settings.h" #include "main/main_session.h" #include "chat_helpers/stickers_emoji_pack.h" +#include "window/window_session_controller.h" #include "data/data_session.h" #include "data/data_groups.h" #include "data/data_media_types.h" @@ -55,6 +56,10 @@ bool IsAttachedToPreviousInSavedMessages( } // namespace +SimpleElementDelegate::SimpleElementDelegate( + not_null controller) +: _controller(controller) { +} std::unique_ptr SimpleElementDelegate::elementCreate( not_null message, @@ -103,6 +108,10 @@ void SimpleElementDelegate::elementShowTooltip( Fn hiddenCallback) { } +bool SimpleElementDelegate::elementIsGifPaused() { + return _controller->isGifPausedAtLeastFor(Window::GifPauseReason::Any); +} + TextSelection UnshiftItemSelection( TextSelection selection, uint16 byLength) { diff --git a/Telegram/SourceFiles/history/view/history_view_element.h b/Telegram/SourceFiles/history/view/history_view_element.h index 264fbb898..99f0f98b5 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.h +++ b/Telegram/SourceFiles/history/view/history_view_element.h @@ -17,6 +17,10 @@ class HistoryItem; class HistoryMessage; class HistoryService; +namespace Window { +class SessionController; +} // namespace Window + namespace HistoryView { enum class PointState : char; @@ -57,11 +61,15 @@ public: virtual void elementShowTooltip( const TextWithEntities &text, Fn hiddenCallback) = 0; + virtual bool elementIsGifPaused() = 0; }; class SimpleElementDelegate : public ElementDelegate { public: + explicit SimpleElementDelegate( + not_null controller); + std::unique_ptr elementCreate( not_null message, Element *replacing = nullptr) override; @@ -83,6 +91,10 @@ public: void elementShowTooltip( const TextWithEntities &text, Fn hiddenCallback) override; + bool elementIsGifPaused() override; + +private: + const not_null _controller; }; diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index 4c915162e..ee3ff1e2b 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -1165,6 +1165,10 @@ void ListWidget::elementShowTooltip( Fn hiddenCallback) { } +bool ListWidget::elementIsGifPaused() { + return _controller->isGifPausedAtLeastFor(Window::GifPauseReason::Any); +} + void ListWidget::saveState(not_null memento) { memento->setAroundPosition(_aroundPosition); auto state = countScrollState(); diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.h b/Telegram/SourceFiles/history/view/history_view_list_widget.h index a36122faa..3912f7ee1 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.h +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.h @@ -204,6 +204,7 @@ public: void elementShowTooltip( const TextWithEntities &text, Fn hiddenCallback) override; + bool elementIsGifPaused() override; ~ListWidget(); diff --git a/Telegram/SourceFiles/history/view/media/history_view_gif.cpp b/Telegram/SourceFiles/history/view/media/history_view_gif.cpp index 15dbe6c97..c73ac810c 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_gif.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_gif.cpp @@ -282,7 +282,7 @@ void Gif::draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms const auto loaded = dataLoaded(); const auto displayLoading = item->isSending() || _data->displayLoading(); const auto selected = (selection == FullSelection); - const auto autoPaused = App::wnd()->sessionController()->isGifPausedAtLeastFor(Window::GifPauseReason::Any); + const auto autoPaused = _parent->delegate()->elementIsGifPaused(); const auto cornerDownload = downloadInCorner(); const auto canBePlayed = _dataMedia->canBePlayed(); const auto autoplay = autoplayEnabled() @@ -902,7 +902,7 @@ void Gif::drawGrouped( const auto loaded = dataLoaded(); const auto displayLoading = (item->id < 0) || _data->displayLoading(); const auto selected = (selection == FullSelection); - const auto autoPaused = App::wnd()->sessionController()->isGifPausedAtLeastFor(Window::GifPauseReason::Any); + const auto autoPaused = _parent->delegate()->elementIsGifPaused(); const auto fullFeatured = fullFeaturedGrouped(sides); const auto cornerDownload = fullFeatured && downloadInCorner(); const auto canBePlayed = _dataMedia->canBePlayed(); @@ -1465,8 +1465,7 @@ void Gif::repaintStreamedContent() { if (own && !own->frozenFrame.isNull()) { return; } - if (App::wnd()->sessionController()->isGifPausedAtLeastFor(Window::GifPauseReason::Any) - && !activeRoundStreamed()) { + if (_parent->delegate()->elementIsGifPaused() && !activeRoundStreamed()) { return; } history()->owner().requestViewRepaint(_parent); diff --git a/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp b/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp index 946cd76e1..bf4e856e9 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp @@ -185,7 +185,7 @@ void Sticker::paintLottie(Painter &p, const QRect &r, bool selected) { return; } - const auto paused = App::wnd()->sessionController()->isGifPausedAtLeastFor(Window::GifPauseReason::Any); + const auto paused = _parent->delegate()->elementIsGifPaused(); const auto playOnce = (_diceIndex > 0) ? true : (_diceIndex == 0) diff --git a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp index ad7d70d30..63bd1209b 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp @@ -277,12 +277,12 @@ object_ptr DetailsFiller::setupInfo() { UsernameValue(user), tr::lng_context_copy_mention(tr::now)); - const auto window = &_controller->parentController()->window(); + const auto controller = _controller->parentController(); AddMainButton( result, tr::lng_info_add_as_contact(), CanAddContactValue(user), - [=] { window->show(Box(EditContactBox, window, user)); }, + [=] { controller->window().show(Box(EditContactBox, controller, user)); }, tracker); } else { auto linkText = LinkValue( @@ -507,12 +507,12 @@ void ActionsFiller::addShareContactAction(not_null user) { } void ActionsFiller::addEditContactAction(not_null user) { - const auto window = &_controller->parentController()->window(); + const auto controller = _controller->parentController(); AddActionButton( _wrap, tr::lng_info_edit_contact(), IsContactValue(user), - [=] { window->show(Box(EditContactBox, window, user)); }); + [=] { controller->window().show(Box(EditContactBox, controller, user)); }); } void ActionsFiller::addDeleteContactAction( diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp index c9ff58589..ce928368c 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp @@ -1523,8 +1523,12 @@ void OverlayWidget::onAttachedStickers() { if (!session) { return; } + const auto &active = _session->windows(); + if (active.empty()) { + return; + } close(); - session->api().requestAttachedStickerSets(_photo); + active.front()->requestAttachedStickerSets(_photo); } auto OverlayWidget::sharedMediaType() const diff --git a/Telegram/SourceFiles/settings/settings_chat.cpp b/Telegram/SourceFiles/settings/settings_chat.cpp index a8f9b9353..1fa2a6049 100644 --- a/Telegram/SourceFiles/settings/settings_chat.cpp +++ b/Telegram/SourceFiles/settings/settings_chat.cpp @@ -722,7 +722,8 @@ void SetupStickersEmoji( &st::settingsIconStickers, st::settingsChatIconLeft )->addClickHandler([=] { - Ui::show(Box(session, StickersBox::Section::Installed)); + Ui::show( + Box(controller, StickersBox::Section::Installed)); }); AddButton( diff --git a/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp b/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp index ab08a5789..2963d98a8 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp +++ b/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp @@ -689,7 +689,8 @@ rpl::producer CallsPeer2PeerPrivacyController::exceptionsDescription() ForwardsPrivacyController::ForwardsPrivacyController( not_null controller) -: _controller(controller) { +: SimpleElementDelegate(controller) +, _controller(controller) { } ApiWrap::Privacy::Key ForwardsPrivacyController::key() { diff --git a/Telegram/SourceFiles/support/support_autocomplete.cpp b/Telegram/SourceFiles/support/support_autocomplete.cpp index 5fddeea3d..19fd00770 100644 --- a/Telegram/SourceFiles/support/support_autocomplete.cpp +++ b/Telegram/SourceFiles/support/support_autocomplete.cpp @@ -504,10 +504,12 @@ void Autocomplete::submitValue(const QString &value) { ConfirmContactBox::ConfirmContactBox( QWidget*, + not_null controller, not_null history, const Contact &data, Fn submit) -: _comment(GenerateCommentItem(this, history, data)) +: SimpleElementDelegate(controller) +, _comment(GenerateCommentItem(this, history, data)) , _contact(GenerateContactItem(this, history, data)) , _submit(submit) { } diff --git a/Telegram/SourceFiles/support/support_autocomplete.h b/Telegram/SourceFiles/support/support_autocomplete.h index 903c46083..bcc961a98 100644 --- a/Telegram/SourceFiles/support/support_autocomplete.h +++ b/Telegram/SourceFiles/support/support_autocomplete.h @@ -17,6 +17,10 @@ namespace Main { class Session; } // namespace Main +namespace Window { +class SessionController; +} // namespace Window + namespace Ui { class ScrollArea; class InputField; @@ -65,6 +69,7 @@ class ConfirmContactBox public: ConfirmContactBox( QWidget*, + not_null controller, not_null history, const Contact &data, Fn submit); diff --git a/Telegram/SourceFiles/window/window_main_menu.cpp b/Telegram/SourceFiles/window/window_main_menu.cpp index d194c7fa9..1ad785daf 100644 --- a/Telegram/SourceFiles/window/window_main_menu.cpp +++ b/Telegram/SourceFiles/window/window_main_menu.cpp @@ -827,12 +827,12 @@ void MainMenu::refreshMenu() { }, &st::mainMenuContacts, &st::mainMenuContactsOver); if (_controller->session().serverConfig().phoneCallsEnabled.current()) { _menu->addAction(tr::lng_menu_calls(tr::now), [=] { - Ui::show(Box(std::make_unique(controller), [](not_null box) { + Ui::show(Box(std::make_unique(controller), [=](not_null box) { box->addButton(tr::lng_close(), [=] { box->closeBox(); }); box->addTopButton(st::callSettingsButton, [=] { - App::wnd()->sessionController()->showSettings( + controller->showSettings( Settings::Type::Calls, Window::SectionShow(anim::type::instant)); }); diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index d33d5e05a..855b01aa4 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -462,7 +462,7 @@ void Filler::addUserActions(not_null user) { if (!user->isContact() && !user->isSelf() && !user->isBot()) { _addAction( tr::lng_info_add_as_contact(tr::now), - [=] { window->show(Box(EditContactBox, window, user)); }); + [=] { window->show(Box(EditContactBox, controller, user)); }); } if (user->canShareThisContact()) { _addAction( @@ -472,7 +472,7 @@ void Filler::addUserActions(not_null user) { if (user->isContact() && !user->isSelf()) { _addAction( tr::lng_info_edit_contact(tr::now), - [=] { window->show(Box(EditContactBox, window, user)); }); + [=] { window->show(Box(EditContactBox, controller, user)); }); _addAction( tr::lng_info_delete_contact(tr::now), [=] { PeerMenuDeleteContact(user); }); diff --git a/Telegram/SourceFiles/window/window_session_controller.cpp b/Telegram/SourceFiles/window/window_session_controller.cpp index 04a9d1e39..f32dd939c 100644 --- a/Telegram/SourceFiles/window/window_session_controller.cpp +++ b/Telegram/SourceFiles/window/window_session_controller.cpp @@ -23,11 +23,16 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_channel.h" #include "data/data_chat.h" #include "data/data_chat_filters.h" +#include "data/data_photo.h" // requestAttachedStickerSets. #include "passport/passport_form_controller.h" #include "chat_helpers/tabbed_selector.h" #include "core/shortcuts.h" #include "base/unixtime.h" #include "boxes/calendar_box.h" +#include "boxes/sticker_set_box.h" // requestAttachedStickerSets. +#include "boxes/confirm_box.h" // requestAttachedStickerSets. +#include "boxes/stickers_box.h" // requestAttachedStickerSets. +#include "lang/lang_keys.h" // requestAttachedStickerSets. #include "mainwidget.h" #include "mainwindow.h" #include "main/main_session.h" @@ -223,6 +228,36 @@ rpl::producer<> SessionController::filtersMenuChanged() const { return _filtersMenuChanged.events(); } +void SessionController::requestAttachedStickerSets( + not_null photo) { + session().api().request(_attachedStickerSetsRequestId).cancel(); + _attachedStickerSetsRequestId = session().api().request( + MTPmessages_GetAttachedStickers( + MTP_inputStickeredMediaPhoto(photo->mtpInput()) + )).done([=](const MTPVector &result) { + if (result.v.isEmpty()) { + Ui::show(Box(tr::lng_stickers_not_found(tr::now))); + return; + } else if (result.v.size() > 1) { + Ui::show(Box(this, result)); + return; + } + // Single attached sticker pack. + const auto setData = result.v.front().match([&](const auto &data) { + return data.vset().match([&](const MTPDstickerSet &data) { + return &data; + }); + }); + + const auto setId = (setData->vid().v && setData->vaccess_hash().v) + ? MTP_inputStickerSetID(setData->vid(), setData->vaccess_hash()) + : MTP_inputStickerSetShortName(setData->vshort_name()); + Ui::show(Box(this, setId), Ui::LayerOption::KeepOther); + }).fail([=](const RPCError &error) { + Ui::show(Box(tr::lng_stickers_not_found(tr::now))); + }).send(); +} + void SessionController::checkOpenedFilter() { if (const auto filterId = activeChatsFilterCurrent()) { const auto &list = session().data().chatsFilters().list(); @@ -800,6 +835,8 @@ void SessionController::setActiveChatsFilter(FilterId id) { } } -SessionController::~SessionController() = default; +SessionController::~SessionController() { + session().api().request(_attachedStickerSetsRequestId).cancel(); +} } // namespace Window diff --git a/Telegram/SourceFiles/window/window_session_controller.h b/Telegram/SourceFiles/window/window_session_controller.h index 8ef98ff05..bd2544027 100644 --- a/Telegram/SourceFiles/window/window_session_controller.h +++ b/Telegram/SourceFiles/window/window_session_controller.h @@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "dialogs/dialogs_key.h" #include "ui/effects/animation_value.h" +class PhotoData; class MainWidget; class MainWindow; class HistoryMessage; @@ -304,6 +305,8 @@ public: void toggleFiltersMenu(bool enabled); [[nodiscard]] rpl::producer<> filtersMenuChanged() const; + void requestAttachedStickerSets(not_null photo); + rpl::lifetime &lifetime() { return _lifetime; } @@ -361,6 +364,8 @@ private: rpl::event_stream<> _filtersMenuChanged; + mtpRequestId _attachedStickerSetsRequestId = 0; + rpl::lifetime _lifetime; };