mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Provided session controller to AddBotToGroupBoxController.
This commit is contained in:
parent
d034410a3f
commit
bfe873e91c
6 changed files with 36 additions and 14 deletions
|
@ -24,6 +24,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "base/random.h"
|
#include "base/random.h"
|
||||||
#include "base/weak_ptr.h"
|
#include "base/weak_ptr.h"
|
||||||
#include "api/api_chat_participants.h"
|
#include "api/api_chat_participants.h"
|
||||||
|
#include "window/window_session_controller.h"
|
||||||
#include "apiwrap.h"
|
#include "apiwrap.h"
|
||||||
#include "facades.h"
|
#include "facades.h"
|
||||||
#include "styles/style_boxes.h"
|
#include "styles/style_boxes.h"
|
||||||
|
@ -91,8 +92,6 @@ void ShareBotGame(
|
||||||
).send();
|
).send();
|
||||||
return history->sendRequestId;
|
return history->sendRequestId;
|
||||||
});
|
});
|
||||||
Ui::hideLayer();
|
|
||||||
Ui::showPeerHistory(chat, ShowAtUnreadMsgId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Controller::Controller(
|
Controller::Controller(
|
||||||
|
@ -144,6 +143,7 @@ void Controller::addRow(not_null<PeerData*> peer) {
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
void AddBotToGroupBoxController::Start(
|
void AddBotToGroupBoxController::Start(
|
||||||
|
not_null<Window::SessionController*> controller,
|
||||||
not_null<UserData*> bot,
|
not_null<UserData*> bot,
|
||||||
Scope scope,
|
Scope scope,
|
||||||
const QString &token,
|
const QString &token,
|
||||||
|
@ -151,8 +151,9 @@ void AddBotToGroupBoxController::Start(
|
||||||
auto initBox = [=](not_null<PeerListBox*> box) {
|
auto initBox = [=](not_null<PeerListBox*> box) {
|
||||||
box->addButton(tr::lng_cancel(), [box] { box->closeBox(); });
|
box->addButton(tr::lng_cancel(), [box] { box->closeBox(); });
|
||||||
};
|
};
|
||||||
Ui::show(Box<PeerListBox>(
|
controller->show(Box<PeerListBox>(
|
||||||
std::make_unique<AddBotToGroupBoxController>(
|
std::make_unique<AddBotToGroupBoxController>(
|
||||||
|
controller,
|
||||||
bot,
|
bot,
|
||||||
scope,
|
scope,
|
||||||
token,
|
token,
|
||||||
|
@ -161,6 +162,7 @@ void AddBotToGroupBoxController::Start(
|
||||||
}
|
}
|
||||||
|
|
||||||
AddBotToGroupBoxController::AddBotToGroupBoxController(
|
AddBotToGroupBoxController::AddBotToGroupBoxController(
|
||||||
|
not_null<Window::SessionController*> controller,
|
||||||
not_null<UserData*> bot,
|
not_null<UserData*> bot,
|
||||||
Scope scope,
|
Scope scope,
|
||||||
const QString &token,
|
const QString &token,
|
||||||
|
@ -168,6 +170,7 @@ AddBotToGroupBoxController::AddBotToGroupBoxController(
|
||||||
: ChatsListBoxController((scope == Scope::ShareGame)
|
: ChatsListBoxController((scope == Scope::ShareGame)
|
||||||
? std::make_unique<PeerListGlobalSearchController>(&bot->session())
|
? std::make_unique<PeerListGlobalSearchController>(&bot->session())
|
||||||
: nullptr)
|
: nullptr)
|
||||||
|
, _controller(controller)
|
||||||
, _bot(bot)
|
, _bot(bot)
|
||||||
, _scope(scope)
|
, _scope(scope)
|
||||||
, _token(token)
|
, _token(token)
|
||||||
|
@ -192,8 +195,15 @@ void AddBotToGroupBoxController::rowClicked(not_null<PeerListRow*> row) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddBotToGroupBoxController::shareBotGame(not_null<PeerData*> chat) {
|
void AddBotToGroupBoxController::shareBotGame(not_null<PeerData*> chat) {
|
||||||
auto send = crl::guard(this, [bot = _bot, chat, token = _token] {
|
auto send = crl::guard(this, [
|
||||||
|
bot = _bot,
|
||||||
|
controller = _controller,
|
||||||
|
chat,
|
||||||
|
token = _token] {
|
||||||
ShareBotGame(bot, chat, token);
|
ShareBotGame(bot, chat, token);
|
||||||
|
using Way = Window::SectionShow::Way;
|
||||||
|
controller->hideLayer();
|
||||||
|
controller->showPeerHistory(chat, Way::ClearStack, ShowAtUnreadMsgId);
|
||||||
});
|
});
|
||||||
auto confirmText = [chat] {
|
auto confirmText = [chat] {
|
||||||
if (chat->isUser()) {
|
if (chat->isUser()) {
|
||||||
|
@ -201,7 +211,7 @@ void AddBotToGroupBoxController::shareBotGame(not_null<PeerData*> chat) {
|
||||||
}
|
}
|
||||||
return tr::lng_bot_sure_share_game_group(tr::now, lt_group, chat->name);
|
return tr::lng_bot_sure_share_game_group(tr::now, lt_group, chat->name);
|
||||||
}();
|
}();
|
||||||
Ui::show(
|
_controller->show(
|
||||||
Ui::MakeConfirmBox({
|
Ui::MakeConfirmBox({
|
||||||
.text = confirmText,
|
.text = confirmText,
|
||||||
.confirmed = std::move(send),
|
.confirmed = std::move(send),
|
||||||
|
@ -240,7 +250,7 @@ void AddBotToGroupBoxController::requestExistingRights(
|
||||||
void AddBotToGroupBoxController::addBotToGroup(not_null<PeerData*> chat) {
|
void AddBotToGroupBoxController::addBotToGroup(not_null<PeerData*> chat) {
|
||||||
if (const auto megagroup = chat->asMegagroup()) {
|
if (const auto megagroup = chat->asMegagroup()) {
|
||||||
if (!megagroup->canAddMembers()) {
|
if (!megagroup->canAddMembers()) {
|
||||||
Ui::show(
|
_controller->show(
|
||||||
Ui::MakeInformBox(tr::lng_error_cant_add_member()),
|
Ui::MakeInformBox(tr::lng_error_cant_add_member()),
|
||||||
Ui::LayerOption::KeepOther);
|
Ui::LayerOption::KeepOther);
|
||||||
return;
|
return;
|
||||||
|
@ -261,9 +271,11 @@ void AddBotToGroupBoxController::addBotToGroup(not_null<PeerData*> chat) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto bot = _bot;
|
const auto bot = _bot;
|
||||||
|
const auto controller = _controller;
|
||||||
const auto close = [=](auto&&...) {
|
const auto close = [=](auto&&...) {
|
||||||
Ui::hideLayer();
|
using Way = Window::SectionShow::Way;
|
||||||
Ui::showPeerHistory(chat, ShowAtUnreadMsgId);
|
controller->hideLayer();
|
||||||
|
controller->showPeerHistory(chat, Way::ClearStack, ShowAtUnreadMsgId);
|
||||||
};
|
};
|
||||||
const auto rights = requestedAddAdmin
|
const auto rights = requestedAddAdmin
|
||||||
? _requestedRights
|
? _requestedRights
|
||||||
|
@ -300,12 +312,16 @@ void AddBotToGroupBoxController::addBotToGroup(not_null<PeerData*> chat) {
|
||||||
_token,
|
_token,
|
||||||
_existingRights.value_or(ChatAdminRights()) });
|
_existingRights.value_or(ChatAdminRights()) });
|
||||||
box->setSaveCallback(saveCallback);
|
box->setSaveCallback(saveCallback);
|
||||||
Ui::show(std::move(box), Ui::LayerOption::KeepOther);
|
controller->show(std::move(box), Ui::LayerOption::KeepOther);
|
||||||
} else {
|
} else {
|
||||||
Ui::show(
|
auto callback = crl::guard(this, [=] {
|
||||||
|
AddBotToGroup(bot, chat, _token);
|
||||||
|
controller->hideLayer();
|
||||||
|
});
|
||||||
|
controller->show(
|
||||||
Ui::MakeConfirmBox({
|
Ui::MakeConfirmBox({
|
||||||
tr::lng_bot_sure_invite(tr::now, lt_group, chat->name),
|
tr::lng_bot_sure_invite(tr::now, lt_group, chat->name),
|
||||||
crl::guard(this, [=] { AddBotToGroup(bot, chat, _token); }),
|
std::move(callback),
|
||||||
}),
|
}),
|
||||||
Ui::LayerOption::KeepOther);
|
Ui::LayerOption::KeepOther);
|
||||||
}
|
}
|
||||||
|
@ -469,6 +485,5 @@ void AddBotToGroup(
|
||||||
} else {
|
} else {
|
||||||
chat->session().api().chatParticipants().add(chat, { 1, bot });
|
chat->session().api().chatParticipants().add(chat, { 1, bot });
|
||||||
}
|
}
|
||||||
Ui::hideLayer();
|
|
||||||
Ui::showPeerHistory(chat, ShowAtUnreadMsgId);
|
Ui::showPeerHistory(chat, ShowAtUnreadMsgId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,12 +22,14 @@ public:
|
||||||
All,
|
All,
|
||||||
};
|
};
|
||||||
static void Start(
|
static void Start(
|
||||||
|
not_null<Window::SessionController*> controller,
|
||||||
not_null<UserData*> bot,
|
not_null<UserData*> bot,
|
||||||
Scope scope = Scope::All,
|
Scope scope = Scope::All,
|
||||||
const QString &token = QString(),
|
const QString &token = QString(),
|
||||||
ChatAdminRights requestedRights = {});
|
ChatAdminRights requestedRights = {});
|
||||||
|
|
||||||
AddBotToGroupBoxController(
|
AddBotToGroupBoxController(
|
||||||
|
not_null<Window::SessionController*> controller,
|
||||||
not_null<UserData*> bot,
|
not_null<UserData*> bot,
|
||||||
Scope scope,
|
Scope scope,
|
||||||
const QString &token,
|
const QString &token,
|
||||||
|
@ -56,6 +58,7 @@ private:
|
||||||
void addBotToGroup(not_null<PeerData*> chat);
|
void addBotToGroup(not_null<PeerData*> chat);
|
||||||
void requestExistingRights(not_null<ChannelData*> channel);
|
void requestExistingRights(not_null<ChannelData*> channel);
|
||||||
|
|
||||||
|
const not_null<Window::SessionController*> _controller;
|
||||||
const not_null<UserData*> _bot;
|
const not_null<UserData*> _bot;
|
||||||
const Scope _scope = Scope::None;
|
const Scope _scope = Scope::None;
|
||||||
const QString _token;
|
const QString _token;
|
||||||
|
|
|
@ -384,6 +384,7 @@ void EditAdminBox::prepare() {
|
||||||
return;
|
return;
|
||||||
} else if (_addAsAdmin && !_addAsAdmin->checked()) {
|
} else if (_addAsAdmin && !_addAsAdmin->checked()) {
|
||||||
AddBotToGroup(user(), peer(), _addingBot->token);
|
AddBotToGroup(user(), peer(), _addingBot->token);
|
||||||
|
getDelegate()->hideLayer();
|
||||||
return;
|
return;
|
||||||
} else if (_addingBot && !_addingBot->existing) {
|
} else if (_addingBot && !_addingBot->existing) {
|
||||||
const auto phrase = peer()->isBroadcast()
|
const auto phrase = peer()->isBroadcast()
|
||||||
|
|
|
@ -554,11 +554,12 @@ void ActionsFiller::addInviteToGroupAction(
|
||||||
const auto notEmpty = [](const QString &value) {
|
const auto notEmpty = [](const QString &value) {
|
||||||
return !value.isEmpty();
|
return !value.isEmpty();
|
||||||
};
|
};
|
||||||
|
const auto controller = _controller->parentController();
|
||||||
AddActionButton(
|
AddActionButton(
|
||||||
_wrap,
|
_wrap,
|
||||||
InviteToChatButton(user) | rpl::filter(notEmpty),
|
InviteToChatButton(user) | rpl::filter(notEmpty),
|
||||||
InviteToChatButton(user) | rpl::map(notEmpty),
|
InviteToChatButton(user) | rpl::map(notEmpty),
|
||||||
[=] { AddBotToGroupBoxController::Start(user); },
|
[=] { AddBotToGroupBoxController::Start(controller, user); },
|
||||||
&st::infoIconAddMember);
|
&st::infoIconAddMember);
|
||||||
const auto about = _wrap->add(
|
const auto about = _wrap->add(
|
||||||
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
||||||
|
|
|
@ -684,9 +684,10 @@ void Filler::addBotToGroup() {
|
||||||
user
|
user
|
||||||
) | rpl::take(1) | rpl::start_with_next([=](QString label) {
|
) | rpl::take(1) | rpl::start_with_next([=](QString label) {
|
||||||
if (!label.isEmpty()) {
|
if (!label.isEmpty()) {
|
||||||
|
const auto controller = _controller;
|
||||||
_addAction(
|
_addAction(
|
||||||
label,
|
label,
|
||||||
[=] { AddBotToGroupBoxController::Start(user); },
|
[=] { AddBotToGroupBoxController::Start(controller, user); },
|
||||||
&st::menuIconInvite);
|
&st::menuIconInvite);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -335,6 +335,7 @@ void SessionNavigation::showPeerByLinkResolved(
|
||||||
Assert(scope != Scope::None);
|
Assert(scope != Scope::None);
|
||||||
|
|
||||||
AddBotToGroupBoxController::Start(
|
AddBotToGroupBoxController::Start(
|
||||||
|
parentController(),
|
||||||
bot,
|
bot,
|
||||||
scope,
|
scope,
|
||||||
info.startToken,
|
info.startToken,
|
||||||
|
|
Loading…
Add table
Reference in a new issue