mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 22:27:20 +02:00
Fix new window crash for unavailable channels.
This commit is contained in:
parent
e2624416af
commit
d81c40f4c8
6 changed files with 32 additions and 12 deletions
|
@ -263,7 +263,7 @@ Widget::Widget(
|
|||
const auto showAtMsgId = controller->uniqueChatsInSearchResults()
|
||||
? ShowAtUnreadMsgId
|
||||
: row.message.fullId.msg;
|
||||
if (row.newWindow) {
|
||||
if (row.newWindow && controller->canShowSeparateWindow(peer)) {
|
||||
const auto active = controller->activeChatCurrent();
|
||||
if (const auto history = active.history()) {
|
||||
if (history->peer == peer) {
|
||||
|
|
|
@ -737,8 +737,10 @@ HistoryWidget::HistoryWidget(
|
|||
if (flags & PeerUpdateFlag::UnavailableReason) {
|
||||
const auto unavailable = _peer->computeUnavailableReason();
|
||||
if (!unavailable.isEmpty()) {
|
||||
controller->showBackFromStack();
|
||||
controller->show(Ui::MakeInformBox(unavailable));
|
||||
closeCurrent();
|
||||
if (const auto primary = Core::App().primaryWindow()) {
|
||||
primary->show(Ui::MakeInformBox(unavailable));
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -2932,7 +2934,7 @@ void HistoryWidget::unreadCountUpdated() {
|
|||
if (_history->chatListUnreadMark()) {
|
||||
crl::on_main(this, [=, history = _history] {
|
||||
if (history == _history) {
|
||||
controller()->showBackFromStack();
|
||||
closeCurrent();
|
||||
_cancelRequests.fire({});
|
||||
}
|
||||
});
|
||||
|
@ -2942,6 +2944,14 @@ void HistoryWidget::unreadCountUpdated() {
|
|||
}
|
||||
}
|
||||
|
||||
void HistoryWidget::closeCurrent() {
|
||||
if (controller()->isPrimary()) {
|
||||
controller()->showBackFromStack();
|
||||
} else {
|
||||
controller()->window().close();
|
||||
}
|
||||
}
|
||||
|
||||
void HistoryWidget::messagesFailed(const MTP::Error &error, int requestId) {
|
||||
if (error.type() == qstr("CHANNEL_PRIVATE")
|
||||
&& _peer->isChannel()
|
||||
|
@ -2951,13 +2961,15 @@ void HistoryWidget::messagesFailed(const MTP::Error &error, int requestId) {
|
|||
|| error.type() == qstr("CHANNEL_PUBLIC_GROUP_NA")
|
||||
|| error.type() == qstr("USER_BANNED_IN_CHANNEL")) {
|
||||
auto was = _peer;
|
||||
controller()->showBackFromStack();
|
||||
Ui::ShowMultilineToast({
|
||||
.parentOverride = Window::Show(controller()).toastParent(),
|
||||
.text = { (was && was->isMegagroup())
|
||||
? tr::lng_group_not_accessible(tr::now)
|
||||
: tr::lng_channel_not_accessible(tr::now) },
|
||||
});
|
||||
closeCurrent();
|
||||
if (const auto primary = Core::App().primaryWindow()) {
|
||||
Ui::ShowMultilineToast({
|
||||
.parentOverride = Window::Show(primary).toastParent(),
|
||||
.text = { (was && was->isMegagroup())
|
||||
? tr::lng_group_not_accessible(tr::now)
|
||||
: tr::lng_channel_not_accessible(tr::now) },
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -2972,7 +2984,7 @@ void HistoryWidget::messagesFailed(const MTP::Error &error, int requestId) {
|
|||
_preloadDownRequest = 0;
|
||||
} else if (_firstLoadRequest == requestId) {
|
||||
_firstLoadRequest = 0;
|
||||
controller()->showBackFromStack();
|
||||
closeCurrent();
|
||||
} else if (_delayedShowAtRequest == requestId) {
|
||||
_delayedShowAtRequest = 0;
|
||||
}
|
||||
|
|
|
@ -390,6 +390,7 @@ private:
|
|||
void handleHistoryChange(not_null<const History*> history);
|
||||
void showAboutTopPromotion();
|
||||
void unreadCountUpdated();
|
||||
void closeCurrent();
|
||||
|
||||
[[nodiscard]] int computeMaxFieldHeight() const;
|
||||
void toggleMuteUnmute();
|
||||
|
|
|
@ -1314,6 +1314,7 @@ void MainWidget::ui_showPeerHistory(
|
|||
}
|
||||
const auto unavailable = peer->computeUnavailableReason();
|
||||
if (!unavailable.isEmpty()) {
|
||||
Assert(isPrimary());
|
||||
if (params.activation != anim::activation::background) {
|
||||
controller()->show(Ui::MakeInformBox(unavailable));
|
||||
}
|
||||
|
|
|
@ -1220,6 +1220,11 @@ void SessionController::closeThirdSection() {
|
|||
}
|
||||
}
|
||||
|
||||
bool SessionController::canShowSeparateWindow(
|
||||
not_null<PeerData*> peer) const {
|
||||
return peer->computeUnavailableReason().isEmpty();
|
||||
}
|
||||
|
||||
void SessionController::showPeer(not_null<PeerData*> peer, MsgId msgId) {
|
||||
const auto currentPeer = activeChatCurrent().peer();
|
||||
if (peer && peer->isChannel() && currentPeer != peer) {
|
||||
|
|
|
@ -380,6 +380,7 @@ public:
|
|||
void resizeForThirdSection();
|
||||
void closeThirdSection();
|
||||
|
||||
[[nodiscard]] bool canShowSeparateWindow(not_null<PeerData*> peer) const;
|
||||
void showPeer(not_null<PeerData*> peer, MsgId msgId = ShowAtUnreadMsgId);
|
||||
|
||||
void startOrJoinGroupCall(
|
||||
|
|
Loading…
Add table
Reference in a new issue