mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Improved display some api errors in non-primary windows.
This commit is contained in:
parent
d1c1b687c7
commit
1b754d14ae
3 changed files with 65 additions and 27 deletions
|
@ -74,6 +74,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "boxes/sticker_set_box.h"
|
#include "boxes/sticker_set_box.h"
|
||||||
#include "boxes/premium_limits_box.h"
|
#include "boxes/premium_limits_box.h"
|
||||||
#include "window/notifications_manager.h"
|
#include "window/notifications_manager.h"
|
||||||
|
#include "window/window_controller.h"
|
||||||
#include "window/window_lock_widgets.h"
|
#include "window/window_lock_widgets.h"
|
||||||
#include "window/window_session_controller.h"
|
#include "window/window_session_controller.h"
|
||||||
#include "inline_bots/inline_bot_result.h"
|
#include "inline_bots/inline_bot_result.h"
|
||||||
|
@ -117,6 +118,26 @@ using UpdatedFileReferences = Data::UpdatedFileReferences;
|
||||||
return TimeId(msgId >> 32);
|
return TimeId(msgId >> 32);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] std::shared_ptr<Window::Show> ShowForPeer(
|
||||||
|
not_null<PeerData*> peer) {
|
||||||
|
const auto separate = Core::App().separateWindowForPeer(peer);
|
||||||
|
const auto window = separate ? separate : Core::App().primaryWindow();
|
||||||
|
return std::make_shared<Window::Show>(window);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShowChannelsLimitBox(not_null<PeerData*> peer) {
|
||||||
|
const auto primary = Core::App().primaryWindow();
|
||||||
|
if (!primary) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
primary->invokeForSessionController(
|
||||||
|
&peer->session().account(),
|
||||||
|
peer,
|
||||||
|
[&](not_null<Window::SessionController*> controller) {
|
||||||
|
controller->show(Box(ChannelsLimitBox, &peer->session()));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
ApiWrap::ApiWrap(not_null<Main::Session*> session)
|
ApiWrap::ApiWrap(not_null<Main::Session*> session)
|
||||||
|
@ -417,19 +438,25 @@ void ApiWrap::sendMessageFail(
|
||||||
not_null<PeerData*> peer,
|
not_null<PeerData*> peer,
|
||||||
uint64 randomId,
|
uint64 randomId,
|
||||||
FullMsgId itemId) {
|
FullMsgId itemId) {
|
||||||
|
const auto show = ShowForPeer(peer);
|
||||||
|
|
||||||
if (error.type() == qstr("PEER_FLOOD")) {
|
if (error.type() == qstr("PEER_FLOOD")) {
|
||||||
Ui::show(Ui::MakeInformBox(
|
show->showBox(
|
||||||
PeerFloodErrorText(&session(), PeerFloodType::Send)));
|
Ui::MakeInformBox(
|
||||||
|
PeerFloodErrorText(&session(), PeerFloodType::Send)),
|
||||||
|
Ui::LayerOption::CloseOther);
|
||||||
} else if (error.type() == qstr("USER_BANNED_IN_CHANNEL")) {
|
} else if (error.type() == qstr("USER_BANNED_IN_CHANNEL")) {
|
||||||
const auto link = Ui::Text::Link(
|
const auto link = Ui::Text::Link(
|
||||||
tr::lng_cant_more_info(tr::now),
|
tr::lng_cant_more_info(tr::now),
|
||||||
session().createInternalLinkFull(qsl("spambot")));
|
session().createInternalLinkFull(qsl("spambot")));
|
||||||
Ui::show(Ui::MakeInformBox(
|
show->showBox(
|
||||||
tr::lng_error_public_groups_denied(
|
Ui::MakeInformBox(
|
||||||
tr::now,
|
tr::lng_error_public_groups_denied(
|
||||||
lt_more_info,
|
tr::now,
|
||||||
link,
|
lt_more_info,
|
||||||
Ui::Text::WithEntities)));
|
link,
|
||||||
|
Ui::Text::WithEntities)),
|
||||||
|
Ui::LayerOption::CloseOther);
|
||||||
} else if (error.type().startsWith(qstr("SLOWMODE_WAIT_"))) {
|
} else if (error.type().startsWith(qstr("SLOWMODE_WAIT_"))) {
|
||||||
const auto chop = qstr("SLOWMODE_WAIT_").size();
|
const auto chop = qstr("SLOWMODE_WAIT_").size();
|
||||||
const auto left = base::StringViewMid(error.type(), chop).toInt();
|
const auto left = base::StringViewMid(error.type(), chop).toInt();
|
||||||
|
@ -447,13 +474,21 @@ void ApiWrap::sendMessageFail(
|
||||||
Assert(peer->isUser());
|
Assert(peer->isUser());
|
||||||
if (const auto item = scheduled.lookupItem(peer->id, itemId.msg)) {
|
if (const auto item = scheduled.lookupItem(peer->id, itemId.msg)) {
|
||||||
scheduled.removeSending(item);
|
scheduled.removeSending(item);
|
||||||
Ui::show(Ui::MakeInformBox(tr::lng_cant_do_this()));
|
show->showBox(
|
||||||
|
Ui::MakeInformBox(tr::lng_cant_do_this()),
|
||||||
|
Ui::LayerOption::CloseOther);
|
||||||
}
|
}
|
||||||
} else if (error.type() == qstr("CHAT_FORWARDS_RESTRICTED")) {
|
} else if (error.type() == qstr("CHAT_FORWARDS_RESTRICTED")) {
|
||||||
Ui::ShowMultilineToast({ .text = { peer->isBroadcast()
|
if (show->valid()) {
|
||||||
? tr::lng_error_noforwards_channel(tr::now)
|
Ui::ShowMultilineToast({
|
||||||
: tr::lng_error_noforwards_group(tr::now)
|
.parentOverride = show->toastParent(),
|
||||||
}, .duration = kJoinErrorDuration });
|
.text = { peer->isBroadcast()
|
||||||
|
? tr::lng_error_noforwards_channel(tr::now)
|
||||||
|
: tr::lng_error_noforwards_group(tr::now)
|
||||||
|
},
|
||||||
|
.duration = kJoinErrorDuration
|
||||||
|
});
|
||||||
|
}
|
||||||
} else if (error.type() == qstr("PREMIUM_ACCOUNT_REQUIRED")) {
|
} else if (error.type() == qstr("PREMIUM_ACCOUNT_REQUIRED")) {
|
||||||
Settings::ShowPremium(&session(), "premium_stickers");
|
Settings::ShowPremium(&session(), "premium_stickers");
|
||||||
}
|
}
|
||||||
|
@ -1214,7 +1249,7 @@ void ApiWrap::migrateDone(
|
||||||
|
|
||||||
void ApiWrap::migrateFail(not_null<PeerData*> peer, const QString &error) {
|
void ApiWrap::migrateFail(not_null<PeerData*> peer, const QString &error) {
|
||||||
if (error == u"CHANNELS_TOO_MUCH"_q) {
|
if (error == u"CHANNELS_TOO_MUCH"_q) {
|
||||||
Ui::show(Box(ChannelsLimitBox, _session));
|
ShowChannelsLimitBox(peer);
|
||||||
}
|
}
|
||||||
if (auto handlers = _migrateCallbacks.take(peer)) {
|
if (auto handlers = _migrateCallbacks.take(peer)) {
|
||||||
for (auto &handler : *handlers) {
|
for (auto &handler : *handlers) {
|
||||||
|
@ -1635,37 +1670,40 @@ void ApiWrap::joinChannel(not_null<ChannelData*> channel) {
|
||||||
channel,
|
channel,
|
||||||
Data::PeerUpdate::Flag::ChannelAmIn);
|
Data::PeerUpdate::Flag::ChannelAmIn);
|
||||||
} else if (!_channelAmInRequests.contains(channel)) {
|
} else if (!_channelAmInRequests.contains(channel)) {
|
||||||
auto requestId = request(MTPchannels_JoinChannel(
|
const auto requestId = request(MTPchannels_JoinChannel(
|
||||||
channel->inputChannel
|
channel->inputChannel
|
||||||
)).done([=](const MTPUpdates &result) {
|
)).done([=](const MTPUpdates &result) {
|
||||||
_channelAmInRequests.remove(channel);
|
_channelAmInRequests.remove(channel);
|
||||||
applyUpdates(result);
|
applyUpdates(result);
|
||||||
}).fail([=](const MTP::Error &error) {
|
}).fail([=](const MTP::Error &error) {
|
||||||
const auto &type = error.type();
|
const auto &type = error.type();
|
||||||
if (type == qstr("CHANNEL_PRIVATE")
|
|
||||||
|
const auto show = ShowForPeer(channel);
|
||||||
|
if (type == u"CHANNEL_PRIVATE"_q
|
||||||
&& channel->invitePeekExpires()) {
|
&& channel->invitePeekExpires()) {
|
||||||
channel->privateErrorReceived();
|
channel->privateErrorReceived();
|
||||||
} else if (type == qstr("CHANNELS_TOO_MUCH")) {
|
} else if (type == u"CHANNELS_TOO_MUCH"_q) {
|
||||||
Ui::show(Box(ChannelsLimitBox, _session));
|
ShowChannelsLimitBox(channel);
|
||||||
} else {
|
} else {
|
||||||
const auto text = [&] {
|
const auto text = [&] {
|
||||||
if (type == qstr("INVITE_REQUEST_SENT")) {
|
if (type == u"INVITE_REQUEST_SENT"_q) {
|
||||||
return channel->isMegagroup()
|
return channel->isMegagroup()
|
||||||
? tr::lng_group_request_sent(tr::now)
|
? tr::lng_group_request_sent(tr::now)
|
||||||
: tr::lng_group_request_sent_channel(tr::now);
|
: tr::lng_group_request_sent_channel(tr::now);
|
||||||
} else if (type == qstr("CHANNEL_PRIVATE")
|
} else if (type == u"CHANNEL_PRIVATE"_q
|
||||||
|| type == qstr("CHANNEL_PUBLIC_GROUP_NA")
|
|| type == u"CHANNEL_PUBLIC_GROUP_NA"_q
|
||||||
|| type == qstr("USER_BANNED_IN_CHANNEL")) {
|
|| type == u"USER_BANNED_IN_CHANNEL"_q) {
|
||||||
return channel->isMegagroup()
|
return channel->isMegagroup()
|
||||||
? tr::lng_group_not_accessible(tr::now)
|
? tr::lng_group_not_accessible(tr::now)
|
||||||
: tr::lng_channel_not_accessible(tr::now);
|
: tr::lng_channel_not_accessible(tr::now);
|
||||||
} else if (type == qstr("USERS_TOO_MUCH")) {
|
} else if (type == u"USERS_TOO_MUCH"_q) {
|
||||||
return tr::lng_group_full(tr::now);
|
return tr::lng_group_full(tr::now);
|
||||||
}
|
}
|
||||||
return QString();
|
return QString();
|
||||||
}();
|
}();
|
||||||
if (!text.isEmpty()) {
|
if (!text.isEmpty() && show->valid()) {
|
||||||
Ui::ShowMultilineToast({
|
Ui::ShowMultilineToast({
|
||||||
|
.parentOverride = show->toastParent(),
|
||||||
.text = { text },
|
.text = { text },
|
||||||
.duration = kJoinErrorDuration,
|
.duration = kJoinErrorDuration,
|
||||||
});
|
});
|
||||||
|
|
|
@ -1926,8 +1926,8 @@ Show::Show(not_null<SessionNavigation*> navigation)
|
||||||
: Show(&navigation->parentController()->window()) {
|
: Show(&navigation->parentController()->window()) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Show::Show(not_null<Controller*> window)
|
Show::Show(Controller *window)
|
||||||
: _window(base::make_weak(window.get())) {
|
: _window(base::make_weak(window)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Show::~Show() = default;
|
Show::~Show() = default;
|
||||||
|
|
|
@ -609,7 +609,7 @@ void ActivateWindow(not_null<SessionController*> controller);
|
||||||
class Show : public Ui::Show {
|
class Show : public Ui::Show {
|
||||||
public:
|
public:
|
||||||
explicit Show(not_null<SessionNavigation*> navigation);
|
explicit Show(not_null<SessionNavigation*> navigation);
|
||||||
explicit Show(not_null<Controller*> window);
|
explicit Show(Controller *window);
|
||||||
~Show();
|
~Show();
|
||||||
void showBox(
|
void showBox(
|
||||||
object_ptr<Ui::BoxContent> content,
|
object_ptr<Ui::BoxContent> content,
|
||||||
|
|
Loading…
Add table
Reference in a new issue