mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-15 21:57:10 +02:00
Attempt to fix a couple of crashes.
This commit is contained in:
parent
493f1d69e2
commit
f675a8dcf7
6 changed files with 51 additions and 42 deletions
|
@ -1527,14 +1527,14 @@ void Application::closeChatFromWindows(not_null<PeerData*> peer) {
|
|||
}
|
||||
}
|
||||
if (const auto window = windowFor(&peer->account())) {
|
||||
const auto primary = window->sessionController();
|
||||
if ((primary->activeChatCurrent().peer() == peer)
|
||||
&& (&primary->session() == &peer->session())) {
|
||||
primary->clearSectionStack();
|
||||
}
|
||||
if (const auto forum = primary->shownForum().current()) {
|
||||
if (peer->forum() == forum) {
|
||||
primary->closeForum();
|
||||
if (const auto primary = window->sessionController()) {
|
||||
if (primary->activeChatCurrent().peer() == peer) {
|
||||
primary->clearSectionStack();
|
||||
}
|
||||
if (const auto forum = primary->shownForum().current()) {
|
||||
if (peer->forum() == forum) {
|
||||
primary->closeForum();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -810,7 +810,7 @@ HistoryWidget::HistoryWidget(
|
|||
const auto account = &_peer->account();
|
||||
closeCurrent();
|
||||
if (const auto primary = Core::App().windowFor(account)) {
|
||||
controller->showToast(unavailable);
|
||||
primary->showToast(unavailable);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -3316,7 +3316,7 @@ void HistoryWidget::messagesFailed(const MTP::Error &error, int requestId) {
|
|||
auto was = _peer;
|
||||
closeCurrent();
|
||||
if (const auto primary = Core::App().windowFor(&was->account())) {
|
||||
controller()->showToast((was && was->isMegagroup())
|
||||
primary->showToast((was && was->isMegagroup())
|
||||
? tr::lng_group_not_accessible(tr::now)
|
||||
: tr::lng_channel_not_accessible(tr::now));
|
||||
}
|
||||
|
|
|
@ -980,20 +980,16 @@ void Instance::processOpenChannel(const QString &context) {
|
|||
} else if (const auto channelId = ChannelId(context.toLongLong())) {
|
||||
const auto channel = _shownSession->data().channel(channelId);
|
||||
if (channel->isLoaded()) {
|
||||
if (const auto window = Core::App().windowFor(channel)) {
|
||||
if (const auto controller = window->sessionController()) {
|
||||
controller->showPeerHistory(channel);
|
||||
_shown = nullptr;
|
||||
}
|
||||
if (const auto controller = _shownSession->tryResolveWindow(channel)) {
|
||||
controller->showPeerHistory(channel);
|
||||
_shown = nullptr;
|
||||
}
|
||||
} else if (!channel->username().isEmpty()) {
|
||||
if (const auto window = Core::App().windowFor(channel)) {
|
||||
if (const auto controller = window->sessionController()) {
|
||||
controller->showPeerByLink({
|
||||
.usernameOrId = channel->username(),
|
||||
});
|
||||
_shown = nullptr;
|
||||
}
|
||||
if (const auto controller = _shownSession->tryResolveWindow(channel)) {
|
||||
controller->showPeerByLink({
|
||||
.usernameOrId = channel->username(),
|
||||
});
|
||||
_shown = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1008,13 +1004,11 @@ void Instance::processJoinChannel(const QString &context) {
|
|||
if (channel->isLoaded()) {
|
||||
_shownSession->api().joinChannel(channel);
|
||||
} else if (!channel->username().isEmpty()) {
|
||||
if (const auto window = Core::App().windowFor(channel)) {
|
||||
if (const auto controller = window->sessionController()) {
|
||||
controller->showPeerByLink({
|
||||
.usernameOrId = channel->username(),
|
||||
.joinChannel = true,
|
||||
});
|
||||
}
|
||||
if (const auto controller = _shownSession->tryResolveWindow(channel)) {
|
||||
controller->showPeerByLink({
|
||||
.usernameOrId = channel->username(),
|
||||
.joinChannel = true,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -434,6 +434,10 @@ void Session::uploadsStopWithConfirmation(Fn<void()> done) {
|
|||
const auto window = message
|
||||
? Core::App().windowFor(message->history()->peer)
|
||||
: Core::App().activePrimaryWindow();
|
||||
if (!window) {
|
||||
done();
|
||||
return;
|
||||
}
|
||||
auto box = Box([=](not_null<Ui::GenericBox*> box) {
|
||||
box->addRow(
|
||||
object_ptr<Ui::FlatLabel>(
|
||||
|
@ -476,8 +480,22 @@ auto Session::windows() const
|
|||
return _windows;
|
||||
}
|
||||
|
||||
Window::SessionController *Session::tryResolveWindow() const {
|
||||
if (_windows.empty()) {
|
||||
Window::SessionController *Session::tryResolveWindow(
|
||||
PeerData *forPeer) const {
|
||||
if (forPeer) {
|
||||
auto primary = (Window::SessionController*)nullptr;
|
||||
for (const auto &window : _windows) {
|
||||
if (window->singlePeer() == forPeer) {
|
||||
return window;
|
||||
} else if (window->isPrimary()) {
|
||||
primary = window;
|
||||
}
|
||||
}
|
||||
if (primary) {
|
||||
return primary;
|
||||
}
|
||||
}
|
||||
if (_windows.empty() || forPeer) {
|
||||
domain().activate(_account);
|
||||
if (_windows.empty()) {
|
||||
return nullptr;
|
||||
|
|
|
@ -164,7 +164,8 @@ public:
|
|||
void addWindow(not_null<Window::SessionController*> controller);
|
||||
[[nodiscard]] auto windows() const
|
||||
-> const base::flat_set<not_null<Window::SessionController*>> &;
|
||||
[[nodiscard]] Window::SessionController *tryResolveWindow() const;
|
||||
[[nodiscard]] Window::SessionController *tryResolveWindow(
|
||||
PeerData *forPeer = nullptr) const;
|
||||
|
||||
// Shortcuts.
|
||||
void notifyDownloaderTaskFinished();
|
||||
|
|
|
@ -1891,16 +1891,12 @@ ClickHandlerPtr MakeChannelPostHandler(
|
|||
FullMsgId item) {
|
||||
return std::make_shared<LambdaClickHandler>(crl::guard(session, [=] {
|
||||
const auto peer = session->data().peer(item.peer);
|
||||
if (const auto window = Core::App().windowFor(peer)) {
|
||||
if (const auto controller = window->sessionController()) {
|
||||
if (&controller->session() == &peer->session()) {
|
||||
Core::App().hideMediaView();
|
||||
controller->showPeerHistory(
|
||||
item.peer,
|
||||
Window::SectionShow::Way::ClearStack,
|
||||
item.msg);
|
||||
}
|
||||
}
|
||||
if (const auto controller = session->tryResolveWindow(peer)) {
|
||||
Core::App().hideMediaView();
|
||||
controller->showPeerHistory(
|
||||
peer,
|
||||
Window::SectionShow::Way::ClearStack,
|
||||
item.msg);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue