Check some more App::main()s.

This commit is contained in:
John Preston 2020-06-11 20:33:15 +04:00
parent 0ad7dcaef9
commit b0f9ad71dd
15 changed files with 91 additions and 57 deletions

View file

@ -193,8 +193,8 @@ void SendExistingDocument(
if (document->sticker()) { if (document->sticker()) {
if (const auto main = App::main()) { if (const auto main = App::main()) {
main->incrementSticker(document); main->incrementSticker(document);
document->owner().stickers().notifyRecentUpdated();
} }
document->owner().stickers().notifyRecentUpdated();
} }
} }

View file

@ -461,8 +461,8 @@ void StickerSetBox::Inner::mouseReleaseEvent(QMouseEvent *e) {
const auto index = stickerFromGlobalPos(e->globalPos()); const auto index = stickerFromGlobalPos(e->globalPos());
if (index >= 0 && index < _pack.size() && !isMasksSet()) { if (index >= 0 && index < _pack.size() && !isMasksSet()) {
const auto sticker = _pack[index]; const auto sticker = _pack[index];
Ui::PostponeCall(crl::guard(App::main(), [=] { Ui::PostponeCall(crl::guard(_controller, [=] {
if (App::main()->onSendSticker(sticker)) { if (_controller->content()->sendExistingDocument(sticker)) {
Ui::hideSettingsAndLayer(); Ui::hideSettingsAndLayer();
} }
})); }));

View file

@ -302,10 +302,14 @@ void BoxController::refreshAbout() {
} }
void BoxController::rowClicked(not_null<PeerListRow*> row) { void BoxController::rowClicked(not_null<PeerListRow*> row) {
auto itemsRow = static_cast<Row*>(row.get()); const auto itemsRow = static_cast<Row*>(row.get());
auto itemId = itemsRow->maxItemId(); const auto itemId = itemsRow->maxItemId();
InvokeQueued(App::main(), [peerId = row->peer()->id, itemId] { const auto window = _window;
Ui::showPeerHistory(peerId, itemId); crl::on_main(window, [=, peer = row->peer()] {
window->showPeerHistory(
peer,
Window::SectionShow::Way::ClearStack,
itemId);
}); });
} }

View file

@ -904,16 +904,18 @@ ClickHandlerPtr goToMessageClickHandler(
MsgId msgId, MsgId msgId,
FullMsgId returnToId) { FullMsgId returnToId) {
return std::make_shared<LambdaClickHandler>([=] { return std::make_shared<LambdaClickHandler>([=] {
if (const auto main = App::main()) { if (const auto main = App::main()) { // multi good
if (const auto returnTo = peer->owner().message(returnToId)) { if (&main->session() == &peer->session()) {
if (returnTo->history()->peer == peer) { if (const auto returnTo = peer->owner().message(returnToId)) {
main->pushReplyReturn(returnTo); if (returnTo->history()->peer == peer) {
main->pushReplyReturn(returnTo);
}
} }
main->controller()->showPeerHistory(
peer,
Window::SectionShow::Way::Forward,
msgId);
} }
App::wnd()->sessionController()->showPeerHistory(
peer,
Window::SectionShow::Way::Forward,
msgId);
} }
}); });
} }

View file

@ -506,8 +506,9 @@ bool AddDeleteMessageAction(
} }
} }
} }
const auto controller = list->controller();
const auto itemId = item->fullId(); const auto itemId = item->fullId();
menu->addAction(tr::lng_context_delete_msg(tr::now), [=] { const auto callback = crl::guard(controller, [=] {
if (const auto item = owner->message(itemId)) { if (const auto item = owner->message(itemId)) {
if (asGroup) { if (asGroup) {
if (const auto group = owner->groups().find(item)) { if (const auto group = owner->groups().find(item)) {
@ -519,7 +520,7 @@ bool AddDeleteMessageAction(
} }
if (const auto message = item->toHistoryMessage()) { if (const auto message = item->toHistoryMessage()) {
if (message->uploading()) { if (message->uploading()) {
App::main()->cancelUploadLayer(item); controller->content()->cancelUploadLayer(item);
return; return;
} }
} }
@ -527,6 +528,7 @@ bool AddDeleteMessageAction(
Ui::show(Box<DeleteMessagesBox>(item, suggestModerateActions)); Ui::show(Box<DeleteMessagesBox>(item, suggestModerateActions));
} }
}); });
menu->addAction(tr::lng_context_delete_msg(tr::now), callback);
return true; return true;
} }

View file

@ -305,6 +305,10 @@ Main::Session &ListWidget::session() const {
return _controller->session(); return _controller->session();
} }
not_null<Window::SessionController*> ListWidget::controller() const {
return _controller;
}
not_null<ListDelegate*> ListWidget::delegate() const { not_null<ListDelegate*> ListWidget::delegate() const {
return _delegate; return _delegate;
} }

View file

@ -137,9 +137,9 @@ public:
not_null<Window::SessionController*> controller, not_null<Window::SessionController*> controller,
not_null<ListDelegate*> delegate); not_null<ListDelegate*> delegate);
Main::Session &session() const; [[nodiscard]] Main::Session &session() const;
[[nodiscard]] not_null<Window::SessionController*> controller() const;
not_null<ListDelegate*> delegate() const; [[nodiscard]] not_null<ListDelegate*> delegate() const;
// Set the correct scroll position after being resized. // Set the correct scroll position after being resized.
void restoreScrollPosition(); void restoreScrollPosition();
@ -437,8 +437,8 @@ private:
static constexpr auto kMinimalIdsLimit = 24; static constexpr auto kMinimalIdsLimit = 24;
not_null<ListDelegate*> _delegate; const not_null<ListDelegate*> _delegate;
not_null<Window::SessionController*> _controller; const not_null<Window::SessionController*> _controller;
Data::MessagePosition _aroundPosition; Data::MessagePosition _aroundPosition;
Data::MessagePosition _shownAtPosition; Data::MessagePosition _shownAtPosition;
Context _context; Context _context;

View file

@ -1668,8 +1668,10 @@ ClickHandlerPtr Message::fastReplyLink() const {
const auto itemId = data()->fullId(); const auto itemId = data()->fullId();
_fastReplyLink = std::make_shared<LambdaClickHandler>([=] { _fastReplyLink = std::make_shared<LambdaClickHandler>([=] {
if (const auto item = owner->message(itemId)) { if (const auto item = owner->message(itemId)) {
if (const auto main = App::main()) { if (const auto main = App::main()) { // multi good
main->replyToItem(item); if (&main->session() == &owner->session()) {
main->replyToItem(item);
}
} }
} }
}); });

View file

@ -1108,7 +1108,7 @@ void MainWidget::onSendFileConfirm(
_history->sendFileConfirmed(file, oldId); _history->sendFileConfirmed(file, oldId);
} }
bool MainWidget::onSendSticker(DocumentData *document) { bool MainWidget::sendExistingDocument(not_null<DocumentData*> document) {
return _history->sendExistingDocument(document); return _history->sendExistingDocument(document);
} }

View file

@ -166,7 +166,7 @@ public:
void onSendFileConfirm( void onSendFileConfirm(
const std::shared_ptr<FileLoadResult> &file, const std::shared_ptr<FileLoadResult> &file,
const std::optional<FullMsgId> &oldId); const std::optional<FullMsgId> &oldId);
bool onSendSticker(DocumentData *sticker); bool sendExistingDocument(not_null<DocumentData*> sticker);
bool isActive() const; bool isActive() const;
[[nodiscard]] bool doWeMarkAsRead() const; [[nodiscard]] bool doWeMarkAsRead() const;

View file

@ -1444,6 +1444,10 @@ void OverlayWidget::onForward() {
if (!_session) { if (!_session) {
return; return;
} }
const auto &active = _session->windows();
if (active.empty()) {
return;
}
const auto item = _session->data().message(_msgid); const auto item = _session->data().message(_msgid);
if (!item || !IsServerMsgId(item->id) || item->serviceMsg()) { if (!item || !IsServerMsgId(item->id) || item->serviceMsg()) {
return; return;
@ -1451,7 +1455,7 @@ void OverlayWidget::onForward() {
close(); close();
Window::ShowForwardMessagesBox( Window::ShowForwardMessagesBox(
App::wnd()->sessionController(), active.front(),
{ 1, item->fullId() }); { 1, item->fullId() });
} }
@ -1474,8 +1478,12 @@ void OverlayWidget::onDelete() {
return false; return false;
}; };
const auto &active = _session->windows();
if (active.empty()) {
return;
}
if (deletingPeerPhoto()) { if (deletingPeerPhoto()) {
App::main()->deletePhotoLayer(_photo); active.front()->content()->deletePhotoLayer(_photo);
} else if (const auto item = session->data().message(_msgid)) { } else if (const auto item = session->data().message(_msgid)) {
const auto suggestModerateActions = true; const auto suggestModerateActions = true;
Ui::show(Box<DeleteMessagesBox>(item, suggestModerateActions)); Ui::show(Box<DeleteMessagesBox>(item, suggestModerateActions));

View file

@ -602,18 +602,20 @@ void AppendEmojiPacks(
} }
- (void) buttonActionPin:(NSButton *)sender { - (void) buttonActionPin:(NSButton *)sender {
const auto active = Core::App().activeWindow();
const auto controller = active ? active->sessionController() : nullptr;
const auto openFolder = [=] { const auto openFolder = [=] {
if (!App::wnd()) { if (!controller) {
return; return;
} }
if (const auto folder = _session->data().folderLoaded(Data::Folder::kId)) { if (const auto folder = _session->data().folderLoaded(Data::Folder::kId)) {
App::wnd()->sessionController()->openFolder(folder); controller->openFolder(folder);
} }
}; };
Core::Sandbox::Instance().customEnterFromEventLoop([=] { Core::Sandbox::Instance().customEnterFromEventLoop([=] {
self.number == kArchiveId self.number == kArchiveId
? openFolder() ? openFolder()
: App::main()->choosePeer(self.number == kSavedMessagesId : controller->content()->choosePeer(self.number == kSavedMessagesId
? _session->userPeerId() ? _session->userPeerId()
: self.peer->id, ShowAtUnreadMsgId); : self.peer->id, ShowAtUnreadMsgId);
}); });
@ -1477,6 +1479,8 @@ void AppendEmojiPacks(
- (void) buttonAction:(NSButton *)sender { - (void) buttonAction:(NSButton *)sender {
const auto command = sender.tag; const auto command = sender.tag;
const auto active = Core::App().activeWindow();
const auto controller = active ? active->sessionController() : nullptr;
Core::Sandbox::Instance().customEnterFromEventLoop([=] { Core::Sandbox::Instance().customEnterFromEventLoop([=] {
switch (command) { switch (command) {
case kCommandPlayPause: case kCommandPlayPause:
@ -1489,7 +1493,7 @@ void AppendEmojiPacks(
Media::Player::instance()->next(kSongType); Media::Player::instance()->next(kSongType);
break; break;
case kCommandClosePlayer: case kCommandClosePlayer:
App::main()->closeBothPlayers(); controller->content()->closeBothPlayers();
break; break;
} }
}); });

View file

@ -384,6 +384,7 @@ private:
crl::time radialTimeShift() const; crl::time radialTimeShift() const;
void radialAnimationCallback(crl::time now); void radialAnimationCallback(crl::time now);
const not_null<Window::SessionController*> _controller;
QPixmap _background; QPixmap _background;
object_ptr<Ui::LinkButton> _chooseFromGallery; object_ptr<Ui::LinkButton> _chooseFromGallery;
object_ptr<Ui::LinkButton> _chooseFromFile; object_ptr<Ui::LinkButton> _chooseFromFile;
@ -400,6 +401,7 @@ BackgroundRow::BackgroundRow(
QWidget *parent, QWidget *parent,
not_null<Window::SessionController*> controller) not_null<Window::SessionController*> controller)
: RpWidget(parent) : RpWidget(parent)
, _controller(controller)
, _chooseFromGallery( , _chooseFromGallery(
this, this,
tr::lng_settings_bg_from_gallery(tr::now), tr::lng_settings_bg_from_gallery(tr::now),
@ -433,7 +435,7 @@ void BackgroundRow::paintEvent(QPaintEvent *e) {
const auto radial = _radial.animating(); const auto radial = _radial.animating();
const auto radialOpacity = radial ? _radial.opacity() : 0.; const auto radialOpacity = radial ? _radial.opacity() : 0.;
if (radial) { if (radial) {
const auto backThumb = App::main()->newBackgroundThumb(); const auto backThumb = _controller->content()->newBackgroundThumb();
if (!backThumb) { if (!backThumb) {
p.drawPixmap(0, 0, _background); p.drawPixmap(0, 0, _background);
} else { } else {
@ -494,14 +496,14 @@ int BackgroundRow::resizeGetHeight(int newWidth) {
} }
float64 BackgroundRow::radialProgress() const { float64 BackgroundRow::radialProgress() const {
return App::main()->chatBackgroundProgress(); return _controller->content()->chatBackgroundProgress();
} }
bool BackgroundRow::radialLoading() const { bool BackgroundRow::radialLoading() const {
const auto main = App::main(); const auto widget = _controller->content();
if (main->chatBackgroundLoading()) { if (widget->chatBackgroundLoading()) {
main->checkChatBackground(); widget->checkChatBackground();
if (main->chatBackgroundLoading()) { if (widget->chatBackgroundLoading()) {
return true; return true;
} else { } else {
const_cast<BackgroundRow*>(this)->updateImage(); const_cast<BackgroundRow*>(this)->updateImage();
@ -788,9 +790,7 @@ void SetupMessages(
group->setChangedCallback([=](SendByType value) { group->setChangedCallback([=](SendByType value) {
controller->session().settings().setSendSubmitWay(value); controller->session().settings().setSendSubmitWay(value);
if (App::main()) { controller->content()->ctrlEnterSubmitUpdated();
App::main()->ctrlEnterSubmitUpdated();
}
controller->session().saveSettingsDelayed(); controller->session().saveSettingsDelayed();
}); });

View file

@ -246,7 +246,8 @@ void BlockedBoxController::loadMoreRows() {
} }
void BlockedBoxController::rowClicked(not_null<PeerListRow*> row) { void BlockedBoxController::rowClicked(not_null<PeerListRow*> row) {
InvokeQueued(App::main(), [peerId = row->peer()->id] { const auto peer = row->peer();
crl::on_main(&peer->session(), [peerId = peer->id] {
Ui::showPeerHistory(peerId, ShowAtUnreadMsgId); Ui::showPeerHistory(peerId, ShowAtUnreadMsgId);
}); });
} }

View file

@ -170,7 +170,9 @@ bool PinnedLimitReached(Dialogs::Key key, FilterId filterId) {
return true; return true;
} }
void TogglePinnedDialog(Dialogs::Key key) { void TogglePinnedDialog(
not_null<Window::SessionController*> controller,
Dialogs::Key key) {
if (!key.entry()->folderKnown()) { if (!key.entry()->folderKnown()) {
return; return;
} }
@ -198,15 +200,16 @@ void TogglePinnedDialog(Dialogs::Key key) {
)).send(); )).send();
} }
if (isPinned) { if (isPinned) {
if (const auto main = App::main()) { controller->content()->dialogsToUp();
main->dialogsToUp();
}
} }
} }
void TogglePinnedDialog(Dialogs::Key key, FilterId filterId) { void TogglePinnedDialog(
not_null<Window::SessionController*> controller,
Dialogs::Key key,
FilterId filterId) {
if (!filterId) { if (!filterId) {
return TogglePinnedDialog(key); return TogglePinnedDialog(controller, key);
} }
const auto owner = &key.entry()->owner(); const auto owner = &key.entry()->owner();
@ -227,9 +230,7 @@ void TogglePinnedDialog(Dialogs::Key key, FilterId filterId) {
owner->setChatPinned(key, filterId, isPinned); owner->setChatPinned(key, filterId, isPinned);
Api::SaveNewFilterPinned(&owner->session(), filterId); Api::SaveNewFilterPinned(&owner->session(), filterId);
if (isPinned) { if (isPinned) {
if (const auto main = App::main()) { controller->content()->dialogsToUp();
main->dialogsToUp();
}
} }
} }
@ -315,7 +316,10 @@ void Filler::addTogglePin() {
: tr::lng_context_pin_to_top(tr::now); : tr::lng_context_pin_to_top(tr::now);
}; };
const auto pinToggle = [=] { const auto pinToggle = [=] {
TogglePinnedDialog(peer->owner().history(peer), filterId); TogglePinnedDialog(
_controller,
peer->owner().history(peer),
filterId);
}; };
const auto pinAction = _addAction(pinText(isPinned), pinToggle); const auto pinAction = _addAction(pinText(isPinned), pinToggle);
@ -344,8 +348,10 @@ void Filler::addInfo() {
} }
//void Filler::addSearch() { //void Filler::addSearch() {
// _addAction(tr::lng_profile_search_messages(tr::now), [peer = _peer] { // const auto controller = _controller;
// App::main()->searchInChat(peer->owner().history(peer)); // const auto peer = _peer;
// _addAction(tr::lng_profile_search_messages(tr::now), [=] {
// controller->content()->searchInChat(peer->owner().history(peer));
// }); // });
//} //}
@ -689,8 +695,8 @@ void FolderFiller::addTogglesForArchive() {
} }
// //
//void FolderFiller::addInfo() { //void FolderFiller::addInfo() {
// auto controller = _controller; // const auto controller = _controller;
// auto feed = _feed; // const auto feed = _feed;
// _addAction(tr::lng_context_view_feed_info(tr::now), [=] { // _addAction(tr::lng_context_view_feed_info(tr::now), [=] {
// controller->showSection(Info::Memento( // controller->showSection(Info::Memento(
// feed, // feed,
@ -707,8 +713,9 @@ void FolderFiller::addTogglesForArchive() {
// //
//void FolderFiller::addSearch() { //void FolderFiller::addSearch() {
// const auto feed = _feed; // const auto feed = _feed;
// const auto controller = _controller;
// _addAction(tr::lng_profile_search_messages(tr::now), [=] { // _addAction(tr::lng_profile_search_messages(tr::now), [=] {
// App::main()->searchInChat(feed); // controller->content()->searchInChat(feed);
// }); // });
//} //}
// //