Pass SessionNavigation to some boxes.

This commit is contained in:
John Preston 2019-07-25 20:55:11 +02:00
parent 137fa0378c
commit bacaf805b5
54 changed files with 601 additions and 233 deletions

View File

@ -21,6 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "core/file_utilities.h" #include "core/file_utilities.h"
#include "core/application.h" #include "core/application.h"
#include "chat_helpers/emoji_suggestions_widget.h" #include "chat_helpers/emoji_suggestions_widget.h"
#include "window/window_session_controller.h"
#include "ui/widgets/checkbox.h" #include "ui/widgets/checkbox.h"
#include "ui/widgets/buttons.h" #include "ui/widgets/buttons.h"
#include "ui/widgets/input_fields.h" #include "ui/widgets/input_fields.h"
@ -389,11 +390,11 @@ void AddContactBox::updateButtons() {
GroupInfoBox::GroupInfoBox( GroupInfoBox::GroupInfoBox(
QWidget*, QWidget*,
not_null<Main::Session*> session, not_null<Window::SessionNavigation*> navigation,
Type type, Type type,
const QString &title, const QString &title,
Fn<void(not_null<ChannelData*>)> channelDone) Fn<void(not_null<ChannelData*>)> channelDone)
: _session(session) : _navigation(navigation)
, _type(type) , _type(type)
, _initialTitle(title) , _initialTitle(title)
, _channelDone(std::move(channelDone)) { , _channelDone(std::move(channelDone)) {
@ -517,7 +518,7 @@ void GroupInfoBox::createGroup(
auto image = _photo->takeResultImage(); auto image = _photo->takeResultImage();
Ui::hideLayer(); Ui::hideLayer();
_session->api().applyUpdates(result); _navigation->session().api().applyUpdates(result);
auto success = base::make_optional(&result) auto success = base::make_optional(&result)
| [](auto updates) -> std::optional<const QVector<MTPChat>*> { | [](auto updates) -> std::optional<const QVector<MTPChat>*> {
@ -538,7 +539,8 @@ void GroupInfoBox::createGroup(
: std::nullopt; : std::nullopt;
} }
| [&](auto chats) { | [&](auto chats) {
return _session->data().chat(chats->front().c_chat().vid().v); return _navigation->session().data().chat(
chats->front().c_chat().vid().v);
} }
| [&](not_null<ChatData*> chat) { | [&](not_null<ChatData*> chat) {
if (!image.isNull()) { if (!image.isNull()) {
@ -609,7 +611,7 @@ void GroupInfoBox::submit() {
}; };
Ui::show( Ui::show(
Box<PeerListBox>( Box<PeerListBox>(
std::make_unique<AddParticipantsBoxController>(), std::make_unique<AddParticipantsBoxController>(_navigation),
std::move(initBox)), std::move(initBox)),
LayerOption::KeepOther); LayerOption::KeepOther);
} }
@ -626,7 +628,7 @@ void GroupInfoBox::createChannel(const QString &title, const QString &descriptio
MTPInputGeoPoint(), // geo_point MTPInputGeoPoint(), // geo_point
MTPstring() // address MTPstring() // address
)).done([=](const MTPUpdates &result) { )).done([=](const MTPUpdates &result) {
_session->api().applyUpdates(result); _navigation->session().api().applyUpdates(result);
const auto success = base::make_optional(&result) const auto success = base::make_optional(&result)
| [](auto updates) -> std::optional<const QVector<MTPChat>*> { | [](auto updates) -> std::optional<const QVector<MTPChat>*> {
@ -645,7 +647,8 @@ void GroupInfoBox::createChannel(const QString &title, const QString &descriptio
: std::nullopt; : std::nullopt;
} }
| [&](auto chats) { | [&](auto chats) {
return _session->data().channel(chats->front().c_channel().vid().v); return _navigation->session().data().channel(
chats->front().c_channel().vid().v);
} }
| [&](not_null<ChannelData*> channel) { | [&](not_null<ChannelData*> channel) {
auto image = _photo->takeResultImage(); auto image = _photo->takeResultImage();
@ -669,7 +672,9 @@ void GroupInfoBox::createChannel(const QString &title, const QString &descriptio
closeBox(); closeBox();
callback(argument); callback(argument);
} else { } else {
Ui::show(Box<SetupChannelBox>(_createdChannel)); Ui::show(Box<SetupChannelBox>(
_navigation,
_createdChannel));
} }
}).send(); }).send();
}; };
@ -711,9 +716,11 @@ void GroupInfoBox::updateMaxHeight() {
SetupChannelBox::SetupChannelBox( SetupChannelBox::SetupChannelBox(
QWidget*, QWidget*,
not_null<Window::SessionNavigation*> navigation,
not_null<ChannelData*> channel, not_null<ChannelData*> channel,
bool existing) bool existing)
: _channel(channel) : _navigation(navigation)
, _channel(channel)
, _existing(existing) , _existing(existing)
, _privacyGroup( , _privacyGroup(
std::make_shared<Ui::RadioenumGroup<Privacy>>(Privacy::Public)) std::make_shared<Ui::RadioenumGroup<Privacy>>(Privacy::Public))
@ -788,7 +795,7 @@ void SetupChannelBox::prepare() {
boxClosing() | rpl::start_with_next([=] { boxClosing() | rpl::start_with_next([=] {
if (!_existing) { if (!_existing) {
AddParticipantsBoxController::Start(_channel); AddParticipantsBoxController::Start(_navigation, _channel);
} }
}, lifetime()); }, lifetime());
@ -1092,9 +1099,10 @@ bool SetupChannelBox::onCheckFail(const RPCError &error) {
void SetupChannelBox::showRevokePublicLinkBoxForEdit() { void SetupChannelBox::showRevokePublicLinkBoxForEdit() {
const auto channel = _channel; const auto channel = _channel;
const auto existing = _existing; const auto existing = _existing;
const auto navigation = _navigation;
const auto callback = [=] { const auto callback = [=] {
Ui::show( Ui::show(
Box<SetupChannelBox>(channel, existing), Box<SetupChannelBox>(navigation, channel, existing),
LayerOption::KeepOther); LayerOption::KeepOther);
}; };
closeBox(); closeBox();

View File

@ -14,6 +14,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
class ConfirmBox; class ConfirmBox;
class PeerListBox; class PeerListBox;
namespace Window {
class SessionNavigation;
} // namespace Window
namespace Main { namespace Main {
class Session; class Session;
} // namespace Main } // namespace Main
@ -98,7 +102,7 @@ public:
}; };
GroupInfoBox( GroupInfoBox(
QWidget*, QWidget*,
not_null<Main::Session*> session, not_null<Window::SessionNavigation*> navigation,
Type type, Type type,
const QString &title = QString(), const QString &title = QString(),
Fn<void(not_null<ChannelData*>)> channelDone = nullptr); Fn<void(not_null<ChannelData*>)> channelDone = nullptr);
@ -118,7 +122,7 @@ private:
void descriptionResized(); void descriptionResized();
void updateMaxHeight(); void updateMaxHeight();
const not_null<Main::Session*> _session; const not_null<Window::SessionNavigation*> _navigation;
Type _type = Type::Group; Type _type = Type::Group;
QString _initialTitle; QString _initialTitle;
@ -138,6 +142,7 @@ class SetupChannelBox : public BoxContent, public RPCSender {
public: public:
SetupChannelBox( SetupChannelBox(
QWidget*, QWidget*,
not_null<Window::SessionNavigation*> navigation,
not_null<ChannelData*> channel, not_null<ChannelData*> channel,
bool existing = false); bool existing = false);
@ -175,6 +180,7 @@ private:
void showRevokePublicLinkBoxForEdit(); void showRevokePublicLinkBoxForEdit();
const not_null<Window::SessionNavigation*> _navigation;
const not_null<ChannelData*> _channel; const not_null<ChannelData*> _channel;
bool _existing = false; bool _existing = false;

View File

@ -34,8 +34,11 @@ namespace {
class PrivacyExceptionsBoxController : public ChatsListBoxController { class PrivacyExceptionsBoxController : public ChatsListBoxController {
public: public:
PrivacyExceptionsBoxController( PrivacyExceptionsBoxController(
not_null<Window::SessionNavigation*> navigation,
rpl::producer<QString> title, rpl::producer<QString> title,
const std::vector<not_null<PeerData*>> &selected); const std::vector<not_null<PeerData*>> &selected);
Main::Session &session() const override;
void rowClicked(not_null<PeerListRow*> row) override; void rowClicked(not_null<PeerListRow*> row) override;
std::vector<not_null<PeerData*>> getResult() const; std::vector<not_null<PeerData*>> getResult() const;
@ -45,18 +48,26 @@ protected:
std::unique_ptr<Row> createRow(not_null<History*> history) override; std::unique_ptr<Row> createRow(not_null<History*> history) override;
private: private:
not_null<Window::SessionNavigation*> _navigation;
rpl::producer<QString> _title; rpl::producer<QString> _title;
std::vector<not_null<PeerData*>> _selected; std::vector<not_null<PeerData*>> _selected;
}; };
PrivacyExceptionsBoxController::PrivacyExceptionsBoxController( PrivacyExceptionsBoxController::PrivacyExceptionsBoxController(
not_null<Window::SessionNavigation*> navigation,
rpl::producer<QString> title, rpl::producer<QString> title,
const std::vector<not_null<PeerData*>> &selected) const std::vector<not_null<PeerData*>> &selected)
: _title(std::move(title)) : ChatsListBoxController(navigation)
, _navigation(navigation)
, _title(std::move(title))
, _selected(selected) { , _selected(selected) {
} }
Main::Session &PrivacyExceptionsBoxController::session() const {
return _navigation->session();
}
void PrivacyExceptionsBoxController::prepareViewHook() { void PrivacyExceptionsBoxController::prepareViewHook() {
delegate()->peerListSetTitle(std::move(_title)); delegate()->peerListSetTitle(std::move(_title));
delegate()->peerListAddSelectedRows(_selected); delegate()->peerListAddSelectedRows(_selected);
@ -132,6 +143,7 @@ void EditPrivacyBox::editExceptions(
Exception exception, Exception exception,
Fn<void()> done) { Fn<void()> done) {
auto controller = std::make_unique<PrivacyExceptionsBoxController>( auto controller = std::make_unique<PrivacyExceptionsBoxController>(
_window,
_controller->exceptionBoxTitle(exception), _controller->exceptionBoxTitle(exception),
exceptions(exception)); exceptions(exception));
auto initBox = [=, controller = controller.get()]( auto initBox = [=, controller = controller.get()](

View File

@ -66,11 +66,15 @@ void PeerListBox::createMultiSelect() {
) | rpl::start_with_next( ) | rpl::start_with_next(
[this] { updateScrollSkips(); }, [this] { updateScrollSkips(); },
lifetime()); lifetime());
_select->entity()->setSubmittedCallback([this](Qt::KeyboardModifiers) { content()->submitted(); }); _select->entity()->setSubmittedCallback([=](Qt::KeyboardModifiers) {
_select->entity()->setQueryChangedCallback([this](const QString &query) { searchQueryChanged(query); }); content()->submitted();
_select->entity()->setItemRemovedCallback([this](uint64 itemId) { });
if (auto peer = Auth().data().peerLoaded(itemId)) { _select->entity()->setQueryChangedCallback([=](const QString &query) {
if (auto row = peerListFindRow(peer->id)) { searchQueryChanged(query);
});
_select->entity()->setItemRemovedCallback([=](uint64 itemId) {
if (const auto peer = _controller->session().data().peerLoaded(itemId)) {
if (const auto row = peerListFindRow(peer->id)) {
content()->changeCheckState(row, false, PeerListRow::SetStyle::Animated); content()->changeCheckState(row, false, PeerListRow::SetStyle::Animated);
update(); update();
} }
@ -336,7 +340,7 @@ auto PeerListBox::peerListCollectSelectedRows()
if (!items.empty()) { if (!items.empty()) {
result.reserve(items.size()); result.reserve(items.size());
for (const auto itemId : items) { for (const auto itemId : items) {
result.push_back(Auth().data().peer(itemId)); result.push_back(_controller->session().data().peer(itemId));
} }
} }
return result; return result;
@ -574,7 +578,9 @@ PeerListContent::PeerListContent(
, _st(st) , _st(st)
, _controller(controller) , _controller(controller)
, _rowHeight(_st.item.height) { , _rowHeight(_st.item.height) {
subscribe(Auth().downloaderTaskFinished(), [this] { update(); }); subscribe(_controller->session().downloaderTaskFinished(), [=] {
update();
});
using UpdateFlag = Notify::PeerUpdate::Flag; using UpdateFlag = Notify::PeerUpdate::Flag;
auto changes = UpdateFlag::NameChanged | UpdateFlag::PhotoChanged; auto changes = UpdateFlag::NameChanged | UpdateFlag::PhotoChanged;
@ -1279,7 +1285,7 @@ void PeerListContent::loadProfilePhotos() {
auto yFrom = _visibleTop; auto yFrom = _visibleTop;
auto yTo = _visibleBottom + (_visibleBottom - _visibleTop) * PreloadHeightsCount; auto yTo = _visibleBottom + (_visibleBottom - _visibleTop) * PreloadHeightsCount;
Auth().downloader().clearPriorities(); _controller->session().downloader().clearPriorities();
if (yTo < 0) return; if (yTo < 0) return;
if (yFrom < 0) yFrom = 0; if (yFrom < 0) yFrom = 0;

View File

@ -19,6 +19,10 @@ struct PeerList;
struct PeerListItem; struct PeerListItem;
} // namespace style } // namespace style
namespace Main {
class Session;
} // namespace Main
namespace Ui { namespace Ui {
class RippleAnimation; class RippleAnimation;
class RoundImageCheckbox; class RoundImageCheckbox;
@ -334,6 +338,7 @@ public:
virtual void prepare() = 0; virtual void prepare() = 0;
virtual void rowClicked(not_null<PeerListRow*> row) = 0; virtual void rowClicked(not_null<PeerListRow*> row) = 0;
virtual Main::Session &session() const = 0;
virtual void rowActionClicked(not_null<PeerListRow*> row) { virtual void rowActionClicked(not_null<PeerListRow*> row) {
} }
virtual void loadMoreRows() { virtual void loadMoreRows() {

View File

@ -21,6 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "history/history.h" #include "history/history.h"
#include "dialogs/dialogs_main_list.h" #include "dialogs/dialogs_main_list.h"
#include "window/window_session_controller.h"
#include "styles/style_boxes.h" #include "styles/style_boxes.h"
#include "styles/style_profile.h" #include "styles/style_profile.h"
@ -136,7 +137,9 @@ void PeerListRowWithLink::paintAction(
p.drawTextLeft(x, y, outerWidth, _action, _actionWidth); p.drawTextLeft(x, y, outerWidth, _action, _actionWidth);
} }
PeerListGlobalSearchController::PeerListGlobalSearchController() { PeerListGlobalSearchController::PeerListGlobalSearchController(
not_null<Window::SessionNavigation*> navigation)
: _navigation(navigation) {
_timer.setCallback([this] { searchOnServer(); }); _timer.setCallback([this] { searchOnServer(); });
} }
@ -185,8 +188,8 @@ void PeerListGlobalSearchController::searchDone(
auto &contacts = result.c_contacts_found(); auto &contacts = result.c_contacts_found();
auto query = _query; auto query = _query;
if (requestId) { if (requestId) {
Auth().data().processUsers(contacts.vusers()); _navigation->session().data().processUsers(contacts.vusers());
Auth().data().processChats(contacts.vchats()); _navigation->session().data().processChats(contacts.vchats());
auto it = _queries.find(requestId); auto it = _queries.find(requestId);
if (it != _queries.cend()) { if (it != _queries.cend()) {
query = it->second; query = it->second;
@ -196,7 +199,9 @@ void PeerListGlobalSearchController::searchDone(
} }
const auto feedList = [&](const MTPVector<MTPPeer> &list) { const auto feedList = [&](const MTPVector<MTPPeer> &list) {
for (const auto &mtpPeer : list.v) { for (const auto &mtpPeer : list.v) {
if (const auto peer = Auth().data().peerLoaded(peerFromMTP(mtpPeer))) { const auto peer = _navigation->session().data().peerLoaded(
peerFromMTP(mtpPeer));
if (peer) {
delegate()->peerListSearchAddRow(peer); delegate()->peerListSearchAddRow(peer);
} }
} }
@ -218,6 +223,12 @@ ChatsListBoxController::Row::Row(not_null<History*> history)
, _history(history) { , _history(history) {
} }
ChatsListBoxController::ChatsListBoxController(
not_null<Window::SessionNavigation*> navigation)
: ChatsListBoxController(
std::make_unique<PeerListGlobalSearchController>(navigation)) {
}
ChatsListBoxController::ChatsListBoxController( ChatsListBoxController::ChatsListBoxController(
std::unique_ptr<PeerListSearchController> searchController) std::unique_ptr<PeerListSearchController> searchController)
: PeerListController(std::move(searchController)) { : PeerListController(std::move(searchController)) {
@ -229,8 +240,8 @@ void ChatsListBoxController::prepare() {
prepareViewHook(); prepareViewHook();
if (!Auth().data().chatsListLoaded()) { if (!session().data().chatsListLoaded()) {
Auth().data().chatsListLoadedEvents( session().data().chatsListLoadedEvents(
) | rpl::filter([=](Data::Folder *folder) { ) | rpl::filter([=](Data::Folder *folder) {
return !folder; return !folder;
}) | rpl::start_with_next([=] { }) | rpl::start_with_next([=] {
@ -238,12 +249,12 @@ void ChatsListBoxController::prepare() {
}, lifetime()); }, lifetime());
} }
Auth().data().chatsListChanges( session().data().chatsListChanges(
) | rpl::start_with_next([=] { ) | rpl::start_with_next([=] {
rebuildRows(); rebuildRows();
}, lifetime()); }, lifetime());
Auth().data().contactsLoaded().value( session().data().contactsLoaded().value(
) | rpl::start_with_next([=] { ) | rpl::start_with_next([=] {
rebuildRows(); rebuildRows();
}, lifetime()); }, lifetime());
@ -264,16 +275,16 @@ void ChatsListBoxController::rebuildRows() {
}; };
auto added = 0; auto added = 0;
if (respectSavedMessagesChat()) { if (respectSavedMessagesChat()) {
if (appendRow(Auth().data().history(Auth().user()))) { if (appendRow(session().data().history(session().user()))) {
++added; ++added;
} }
} }
added += appendList(Auth().data().chatsList()->indexed()); added += appendList(session().data().chatsList()->indexed());
const auto id = Data::Folder::kId; const auto id = Data::Folder::kId;
if (const auto folder = Auth().data().folderLoaded(id)) { if (const auto folder = session().data().folderLoaded(id)) {
added += appendList(folder->chatsList()->indexed()); added += appendList(folder->chatsList()->indexed());
} }
added += appendList(Auth().data().contactsNoChatsList()); added += appendList(session().data().contactsNoChatsList());
if (!wasEmpty && added > 0) { if (!wasEmpty && added > 0) {
// Place dialogs list before contactsNoDialogs list. // Place dialogs list before contactsNoDialogs list.
delegate()->peerListPartitionRows([](const PeerListRow &a) { delegate()->peerListPartitionRows([](const PeerListRow &a) {
@ -294,8 +305,8 @@ void ChatsListBoxController::checkForEmptyRows() {
if (delegate()->peerListFullRowsCount()) { if (delegate()->peerListFullRowsCount()) {
setDescriptionText(QString()); setDescriptionText(QString());
} else { } else {
const auto loaded = Auth().data().contactsLoaded().current() const auto loaded = session().data().contactsLoaded().current()
&& Auth().data().chatsListLoaded(); && session().data().chatsListLoaded();
setDescriptionText(loaded ? emptyBoxText() : tr::lng_contacts_loading(tr::now)); setDescriptionText(loaded ? emptyBoxText() : tr::lng_contacts_loading(tr::now));
} }
} }
@ -321,8 +332,21 @@ bool ChatsListBoxController::appendRow(not_null<History*> history) {
} }
ContactsBoxController::ContactsBoxController( ContactsBoxController::ContactsBoxController(
not_null<Window::SessionNavigation*> navigation)
: PeerListController(
std::make_unique<PeerListGlobalSearchController>(navigation))
, _navigation(navigation) {
}
ContactsBoxController::ContactsBoxController(
not_null<Window::SessionNavigation*> navigation,
std::unique_ptr<PeerListSearchController> searchController) std::unique_ptr<PeerListSearchController> searchController)
: PeerListController(std::move(searchController)) { : PeerListController(std::move(searchController))
, _navigation(navigation) {
}
Main::Session &ContactsBoxController::session() const {
return _navigation->session();
} }
void ContactsBoxController::prepare() { void ContactsBoxController::prepare() {
@ -332,7 +356,7 @@ void ContactsBoxController::prepare() {
prepareViewHook(); prepareViewHook();
Auth().data().contactsLoaded().value( session().data().contactsLoaded().value(
) | rpl::start_with_next([=] { ) | rpl::start_with_next([=] {
rebuildRows(); rebuildRows();
}, lifetime()); }, lifetime());
@ -352,7 +376,7 @@ void ContactsBoxController::rebuildRows() {
} }
return count; return count;
}; };
appendList(Auth().data().contactsList()); appendList(session().data().contactsList());
checkForEmptyRows(); checkForEmptyRows();
delegate()->peerListRefreshRows(); delegate()->peerListRefreshRows();
} }
@ -360,7 +384,7 @@ void ContactsBoxController::rebuildRows() {
void ContactsBoxController::checkForEmptyRows() { void ContactsBoxController::checkForEmptyRows() {
setDescriptionText(delegate()->peerListFullRowsCount() setDescriptionText(delegate()->peerListFullRowsCount()
? QString() ? QString()
: Auth().data().contactsLoaded().current() : session().data().contactsLoaded().current()
? tr::lng_contacts_not_found(tr::now) ? tr::lng_contacts_not_found(tr::now)
: tr::lng_contacts_loading(tr::now)); : tr::lng_contacts_loading(tr::now));
} }
@ -393,20 +417,30 @@ std::unique_ptr<PeerListRow> ContactsBoxController::createRow(not_null<UserData*
return std::make_unique<PeerListRow>(user); return std::make_unique<PeerListRow>(user);
} }
void AddBotToGroupBoxController::Start(not_null<UserData*> bot) { void AddBotToGroupBoxController::Start(
not_null<Window::SessionNavigation*> navigation,
not_null<UserData*> bot) {
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>(std::make_unique<AddBotToGroupBoxController>(bot), std::move(initBox))); Ui::show(Box<PeerListBox>(
std::make_unique<AddBotToGroupBoxController>(navigation, bot),
std::move(initBox)));
} }
AddBotToGroupBoxController::AddBotToGroupBoxController(not_null<UserData*> bot) AddBotToGroupBoxController::AddBotToGroupBoxController(
not_null<Window::SessionNavigation*> navigation,
not_null<UserData*> bot)
: ChatsListBoxController(SharingBotGame(bot) : ChatsListBoxController(SharingBotGame(bot)
? std::make_unique<PeerListGlobalSearchController>() ? std::make_unique<PeerListGlobalSearchController>(navigation)
: nullptr) : nullptr)
, _bot(bot) { , _bot(bot) {
} }
Main::Session &AddBotToGroupBoxController::session() const {
return _bot->session();
}
void AddBotToGroupBoxController::rowClicked(not_null<PeerListRow*> row) { void AddBotToGroupBoxController::rowClicked(not_null<PeerListRow*> row) {
if (sharingBotGame()) { if (sharingBotGame()) {
shareBotGame(row->peer()); shareBotGame(row->peer());
@ -483,7 +517,7 @@ bool AddBotToGroupBoxController::sharingBotGame() const {
} }
QString AddBotToGroupBoxController::emptyBoxText() const { QString AddBotToGroupBoxController::emptyBoxText() const {
return !Auth().data().chatsListLoaded() return !session().data().chatsListLoaded()
? tr::lng_contacts_loading(tr::now) ? tr::lng_contacts_loading(tr::now)
: sharingBotGame() : sharingBotGame()
? tr::lng_bot_no_chats(tr::now) ? tr::lng_bot_no_chats(tr::now)
@ -491,7 +525,7 @@ QString AddBotToGroupBoxController::emptyBoxText() const {
} }
QString AddBotToGroupBoxController::noResultsText() const { QString AddBotToGroupBoxController::noResultsText() const {
return !Auth().data().chatsListLoaded() return !session().data().chatsListLoaded()
? tr::lng_contacts_loading(tr::now) ? tr::lng_contacts_loading(tr::now)
: sharingBotGame() : sharingBotGame()
? tr::lng_bot_chats_not_found(tr::now) ? tr::lng_bot_chats_not_found(tr::now)
@ -507,7 +541,7 @@ void AddBotToGroupBoxController::prepareViewHook() {
? tr::lng_bot_choose_chat() ? tr::lng_bot_choose_chat()
: tr::lng_bot_choose_group()); : tr::lng_bot_choose_group());
updateLabels(); updateLabels();
Auth().data().chatsListLoadedEvents( session().data().chatsListLoadedEvents(
) | rpl::filter([=](Data::Folder *folder) { ) | rpl::filter([=](Data::Folder *folder) {
return !folder; return !folder;
}) | rpl::start_with_next([=] { }) | rpl::start_with_next([=] {
@ -516,8 +550,15 @@ void AddBotToGroupBoxController::prepareViewHook() {
} }
ChooseRecipientBoxController::ChooseRecipientBoxController( ChooseRecipientBoxController::ChooseRecipientBoxController(
not_null<Window::SessionNavigation*> navigation,
FnMut<void(not_null<PeerData*>)> callback) FnMut<void(not_null<PeerData*>)> callback)
: _callback(std::move(callback)) { : ChatsListBoxController(navigation)
, _navigation(navigation)
, _callback(std::move(callback)) {
}
Main::Session &ChooseRecipientBoxController::session() const {
return _navigation->session();
} }
void ChooseRecipientBoxController::prepareViewHook() { void ChooseRecipientBoxController::prepareViewHook() {

View File

@ -28,6 +28,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
// //
//}; //};
namespace Window {
class SessionNavigation;
} // namespace Window
class PeerListRowWithLink : public PeerListRow { class PeerListRowWithLink : public PeerListRow {
public: public:
using PeerListRow::PeerListRow; using PeerListRow::PeerListRow;
@ -53,9 +57,12 @@ private:
}; };
class PeerListGlobalSearchController : public PeerListSearchController, private MTP::Sender { class PeerListGlobalSearchController
: public PeerListSearchController
, private MTP::Sender {
public: public:
PeerListGlobalSearchController(); PeerListGlobalSearchController(
not_null<Window::SessionNavigation*> navigation);
void searchQuery(const QString &query) override; void searchQuery(const QString &query) override;
bool isLoading() override; bool isLoading() override;
@ -68,6 +75,7 @@ private:
void searchOnServer(); void searchOnServer();
void searchDone(const MTPcontacts_Found &result, mtpRequestId requestId); void searchDone(const MTPcontacts_Found &result, mtpRequestId requestId);
const not_null<Window::SessionNavigation*> _navigation;
base::Timer _timer; base::Timer _timer;
QString _query; QString _query;
mtpRequestId _requestId = 0; mtpRequestId _requestId = 0;
@ -78,9 +86,9 @@ private:
class ChatsListBoxController : public PeerListController { class ChatsListBoxController : public PeerListController {
public: public:
ChatsListBoxController(not_null<Window::SessionNavigation*> navigation);
ChatsListBoxController( ChatsListBoxController(
std::unique_ptr<PeerListSearchController> searchController std::unique_ptr<PeerListSearchController> searchController);
= std::make_unique<PeerListGlobalSearchController>());
void prepare() override final; void prepare() override final;
std::unique_ptr<PeerListRow> createSearchRow(not_null<PeerData*> peer) override final; std::unique_ptr<PeerListRow> createSearchRow(not_null<PeerData*> peer) override final;
@ -114,9 +122,12 @@ private:
class ContactsBoxController : public PeerListController { class ContactsBoxController : public PeerListController {
public: public:
ContactsBoxController( ContactsBoxController(
std::unique_ptr<PeerListSearchController> searchController not_null<Window::SessionNavigation*> navigation);
= std::make_unique<PeerListGlobalSearchController>()); ContactsBoxController(
not_null<Window::SessionNavigation*> navigation,
std::unique_ptr<PeerListSearchController> searchController);
Main::Session &session() const override;
void prepare() override final; void prepare() override final;
std::unique_ptr<PeerListRow> createSearchRow(not_null<PeerData*> peer) override final; std::unique_ptr<PeerListRow> createSearchRow(not_null<PeerData*> peer) override final;
void rowClicked(not_null<PeerListRow*> row) override; void rowClicked(not_null<PeerListRow*> row) override;
@ -133,16 +144,23 @@ private:
void checkForEmptyRows(); void checkForEmptyRows();
bool appendRow(not_null<UserData*> user); bool appendRow(not_null<UserData*> user);
const not_null<Window::SessionNavigation*> _navigation;
}; };
class AddBotToGroupBoxController class AddBotToGroupBoxController
: public ChatsListBoxController : public ChatsListBoxController
, public base::has_weak_ptr { , public base::has_weak_ptr {
public: public:
static void Start(not_null<UserData*> bot); static void Start(
not_null<Window::SessionNavigation*> navigation,
not_null<UserData*> bot);
AddBotToGroupBoxController(not_null<UserData*> bot); AddBotToGroupBoxController(
not_null<Window::SessionNavigation*> navigation,
not_null<UserData*> bot);
Main::Session &session() const override;
void rowClicked(not_null<PeerListRow*> row) override; void rowClicked(not_null<PeerListRow*> row) override;
protected: protected:
@ -171,8 +189,10 @@ class ChooseRecipientBoxController
, public base::has_weak_ptr { , public base::has_weak_ptr {
public: public:
ChooseRecipientBoxController( ChooseRecipientBoxController(
not_null<Window::SessionNavigation*> navigation,
FnMut<void(not_null<PeerData*>)> callback); FnMut<void(not_null<PeerData*>)> callback);
Main::Session &session() const override;
void rowClicked(not_null<PeerListRow*> row) override; void rowClicked(not_null<PeerListRow*> row) override;
bool respectSavedMessagesChat() const override { bool respectSavedMessagesChat() const override {
@ -185,6 +205,7 @@ protected:
not_null<History*> history) override; not_null<History*> history) override;
private: private:
const not_null<Window::SessionNavigation*> _navigation;
FnMut<void(not_null<PeerData*>)> _callback; FnMut<void(not_null<PeerData*>)> _callback;
}; };

View File

@ -47,20 +47,29 @@ base::flat_set<not_null<UserData*>> GetAlreadyInFromPeer(PeerData *peer) {
} // namespace } // namespace
AddParticipantsBoxController::AddParticipantsBoxController() AddParticipantsBoxController::AddParticipantsBoxController(
not_null<Window::SessionNavigation*> navigation)
: ContactsBoxController( : ContactsBoxController(
std::make_unique<PeerListGlobalSearchController>()) { navigation,
std::make_unique<PeerListGlobalSearchController>(navigation)) {
} }
AddParticipantsBoxController::AddParticipantsBoxController( AddParticipantsBoxController::AddParticipantsBoxController(
not_null<Window::SessionNavigation*> navigation,
not_null<PeerData*> peer) not_null<PeerData*> peer)
: AddParticipantsBoxController(peer, GetAlreadyInFromPeer(peer)) { : AddParticipantsBoxController(
navigation,
peer,
GetAlreadyInFromPeer(peer)) {
} }
AddParticipantsBoxController::AddParticipantsBoxController( AddParticipantsBoxController::AddParticipantsBoxController(
not_null<Window::SessionNavigation*> navigation,
not_null<PeerData*> peer, not_null<PeerData*> peer,
base::flat_set<not_null<UserData*>> &&alreadyIn) base::flat_set<not_null<UserData*>> &&alreadyIn)
: ContactsBoxController(std::make_unique<PeerListGlobalSearchController>()) : ContactsBoxController(
navigation,
std::make_unique<PeerListGlobalSearchController>(navigation))
, _peer(peer) , _peer(peer)
, _alreadyIn(std::move(alreadyIn)) { , _alreadyIn(std::move(alreadyIn)) {
subscribeToMigration(); subscribeToMigration();
@ -180,8 +189,12 @@ bool AddParticipantsBoxController::inviteSelectedUsers(
return true; return true;
} }
void AddParticipantsBoxController::Start(not_null<ChatData*> chat) { void AddParticipantsBoxController::Start(
auto controller = std::make_unique<AddParticipantsBoxController>(chat); not_null<Window::SessionNavigation*> navigation,
not_null<ChatData*> chat) {
auto controller = std::make_unique<AddParticipantsBoxController>(
navigation,
chat);
const auto weak = controller.get(); const auto weak = controller.get();
auto initBox = [=](not_null<PeerListBox*> box) { auto initBox = [=](not_null<PeerListBox*> box) {
box->addButton(tr::lng_participant_invite(), [=] { box->addButton(tr::lng_participant_invite(), [=] {
@ -199,10 +212,12 @@ void AddParticipantsBoxController::Start(not_null<ChatData*> chat) {
} }
void AddParticipantsBoxController::Start( void AddParticipantsBoxController::Start(
not_null<Window::SessionNavigation*> navigation,
not_null<ChannelData*> channel, not_null<ChannelData*> channel,
base::flat_set<not_null<UserData*>> &&alreadyIn, base::flat_set<not_null<UserData*>> &&alreadyIn,
bool justCreated) { bool justCreated) {
auto controller = std::make_unique<AddParticipantsBoxController>( auto controller = std::make_unique<AddParticipantsBoxController>(
navigation,
channel, channel,
std::move(alreadyIn)); std::move(alreadyIn));
const auto weak = controller.get(); const auto weak = controller.get();
@ -238,13 +253,16 @@ void AddParticipantsBoxController::Start(
} }
void AddParticipantsBoxController::Start( void AddParticipantsBoxController::Start(
not_null<Window::SessionNavigation*> navigation,
not_null<ChannelData*> channel, not_null<ChannelData*> channel,
base::flat_set<not_null<UserData*>> &&alreadyIn) { base::flat_set<not_null<UserData*>> &&alreadyIn) {
Start(channel, std::move(alreadyIn), false); Start(navigation, channel, std::move(alreadyIn), false);
} }
void AddParticipantsBoxController::Start(not_null<ChannelData*> channel) { void AddParticipantsBoxController::Start(
Start(channel, {}, true); not_null<Window::SessionNavigation*> navigation,
not_null<ChannelData*> channel) {
Start(navigation, channel, {}, true);
} }
AddSpecialBoxController::AddSpecialBoxController( AddSpecialBoxController::AddSpecialBoxController(
@ -263,6 +281,10 @@ AddSpecialBoxController::AddSpecialBoxController(
subscribeToMigration(); subscribeToMigration();
} }
Main::Session &AddSpecialBoxController::session() const {
return _peer->session();
}
void AddSpecialBoxController::subscribeToMigration() { void AddSpecialBoxController::subscribeToMigration() {
SubscribeToMigration( SubscribeToMigration(
_peer, _peer,

View File

@ -10,17 +10,30 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "boxes/peer_list_controllers.h" #include "boxes/peer_list_controllers.h"
#include "boxes/peers/edit_participants_box.h" #include "boxes/peers/edit_participants_box.h"
namespace Window {
class SessionNavigation;
} // namespace Window
class AddParticipantsBoxController : public ContactsBoxController { class AddParticipantsBoxController : public ContactsBoxController {
public: public:
static void Start(not_null<ChatData*> chat);
static void Start(not_null<ChannelData*> channel);
static void Start( static void Start(
not_null<Window::SessionNavigation*> navigation,
not_null<ChatData*> chat);
static void Start(
not_null<Window::SessionNavigation*> navigation,
not_null<ChannelData*> channel);
static void Start(
not_null<Window::SessionNavigation*> navigation,
not_null<ChannelData*> channel, not_null<ChannelData*> channel,
base::flat_set<not_null<UserData*>> &&alreadyIn); base::flat_set<not_null<UserData*>> &&alreadyIn);
AddParticipantsBoxController(); explicit AddParticipantsBoxController(
AddParticipantsBoxController(not_null<PeerData*> peer); not_null<Window::SessionNavigation*> navigation);
AddParticipantsBoxController( AddParticipantsBoxController(
not_null<Window::SessionNavigation*> navigation,
not_null<PeerData*> peer);
AddParticipantsBoxController(
not_null<Window::SessionNavigation*> navigation,
not_null<PeerData*> peer, not_null<PeerData*> peer,
base::flat_set<not_null<UserData*>> &&alreadyIn); base::flat_set<not_null<UserData*>> &&alreadyIn);
@ -34,6 +47,7 @@ protected:
private: private:
static void Start( static void Start(
not_null<Window::SessionNavigation*> navigation,
not_null<ChannelData*> channel, not_null<ChannelData*> channel,
base::flat_set<not_null<UserData*>> &&alreadyIn, base::flat_set<not_null<UserData*>> &&alreadyIn,
bool justCreated); bool justCreated);
@ -73,6 +87,7 @@ public:
AdminDoneCallback adminDoneCallback, AdminDoneCallback adminDoneCallback,
BannedDoneCallback bannedDoneCallback); BannedDoneCallback bannedDoneCallback);
Main::Session &session() const override;
void prepare() override; void prepare() override;
void rowClicked(not_null<PeerListRow*> row) override; void rowClicked(not_null<PeerListRow*> row) override;
void loadMoreRows() override; void loadMoreRows() override;

View File

@ -34,6 +34,7 @@ public:
const std::vector<not_null<PeerData*>> &chats, const std::vector<not_null<PeerData*>> &chats,
Fn<void(ChannelData*)> callback); Fn<void(ChannelData*)> callback);
Main::Session &session() const override;
void prepare() override; void prepare() override;
void rowClicked(not_null<PeerListRow*> row) override; void rowClicked(not_null<PeerListRow*> row) override;
int contentWidth() const override; int contentWidth() const override;
@ -69,6 +70,10 @@ Controller::Controller(
}, lifetime()); }, lifetime());
} }
Main::Session &Controller::session() const {
return _channel->session();
}
int Controller::contentWidth() const { int Controller::contentWidth() const {
return st::boxWidth; return st::boxWidth;
} }
@ -232,6 +237,7 @@ object_ptr<Ui::RpWidget> SetupFooter(
object_ptr<Ui::RpWidget> SetupCreateGroup( object_ptr<Ui::RpWidget> SetupCreateGroup(
not_null<QWidget*> parent, not_null<QWidget*> parent,
not_null<Window::SessionNavigation*> navigation,
not_null<ChannelData*> channel, not_null<ChannelData*> channel,
Fn<void(ChannelData*)> callback) { Fn<void(ChannelData*)> callback) {
Expects(channel->isBroadcast()); Expects(channel->isBroadcast());
@ -245,7 +251,7 @@ object_ptr<Ui::RpWidget> SetupCreateGroup(
const auto guarded = crl::guard(parent, callback); const auto guarded = crl::guard(parent, callback);
Ui::show( Ui::show(
Box<GroupInfoBox>( Box<GroupInfoBox>(
&channel->session(), navigation,
GroupInfoBox::Type::Megagroup, GroupInfoBox::Type::Megagroup,
channel->name + " Chat", channel->name + " Chat",
guarded), guarded),
@ -271,6 +277,7 @@ object_ptr<Ui::RpWidget> SetupUnlink(
} }
object_ptr<BoxContent> EditLinkedChatBox( object_ptr<BoxContent> EditLinkedChatBox(
not_null<Window::SessionNavigation*> navigation,
not_null<ChannelData*> channel, not_null<ChannelData*> channel,
ChannelData *chat, ChannelData *chat,
std::vector<not_null<PeerData*>> &&chats, std::vector<not_null<PeerData*>> &&chats,
@ -284,7 +291,11 @@ object_ptr<BoxContent> EditLinkedChatBox(
SetupAbout(above, channel, chat), SetupAbout(above, channel, chat),
st::linkedChatAboutPadding); st::linkedChatAboutPadding);
if (!chat) { if (!chat) {
above->add(SetupCreateGroup(above, channel, callback)); above->add(SetupCreateGroup(
above,
navigation,
channel,
callback));
} }
box->peerListSetAboveWidget(std::move(above)); box->peerListSetAboveWidget(std::move(above));
@ -313,10 +324,12 @@ object_ptr<BoxContent> EditLinkedChatBox(
} // namespace } // namespace
object_ptr<BoxContent> EditLinkedChatBox( object_ptr<BoxContent> EditLinkedChatBox(
not_null<Window::SessionNavigation*> navigation,
not_null<ChannelData*> channel, not_null<ChannelData*> channel,
std::vector<not_null<PeerData*>> &&chats, std::vector<not_null<PeerData*>> &&chats,
Fn<void(ChannelData*)> callback) { Fn<void(ChannelData*)> callback) {
return EditLinkedChatBox( return EditLinkedChatBox(
navigation,
channel, channel,
nullptr, nullptr,
std::move(chats), std::move(chats),
@ -325,9 +338,16 @@ object_ptr<BoxContent> EditLinkedChatBox(
} }
object_ptr<BoxContent> EditLinkedChatBox( object_ptr<BoxContent> EditLinkedChatBox(
not_null<Window::SessionNavigation*> navigation,
not_null<ChannelData*> channel, not_null<ChannelData*> channel,
not_null<ChannelData*> chat, not_null<ChannelData*> chat,
bool canEdit, bool canEdit,
Fn<void(ChannelData*)> callback) { Fn<void(ChannelData*)> callback) {
return EditLinkedChatBox(channel, chat, {}, canEdit, callback); return EditLinkedChatBox(
navigation,
channel,
chat,
{},
canEdit,
callback);
} }

View File

@ -9,13 +9,19 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "boxes/abstract_box.h" #include "boxes/abstract_box.h"
namespace Window {
class SessionNavigation;
} // namespace Window
object_ptr<BoxContent> EditLinkedChatBox( object_ptr<BoxContent> EditLinkedChatBox(
not_null<Window::SessionNavigation*> navigation,
not_null<ChannelData*> channel, not_null<ChannelData*> channel,
not_null<ChannelData*> chat, not_null<ChannelData*> chat,
bool canEdit, bool canEdit,
Fn<void(ChannelData*)> callback); Fn<void(ChannelData*)> callback);
object_ptr<BoxContent> EditLinkedChatBox( object_ptr<BoxContent> EditLinkedChatBox(
not_null<Window::SessionNavigation*> navigation,
not_null<ChannelData*> channel, not_null<ChannelData*> channel,
std::vector<not_null<PeerData*>> &&chats, std::vector<not_null<PeerData*>> &&chats,
Fn<void(ChannelData*)> callback); Fn<void(ChannelData*)> callback);

View File

@ -754,6 +754,10 @@ ParticipantsBoxController::ParticipantsBoxController(
} }
} }
Main::Session &ParticipantsBoxController::session() const {
return _peer->session();
}
void ParticipantsBoxController::setupListChangeViewers() { void ParticipantsBoxController::setupListChangeViewers() {
const auto channel = _peer->asChannel(); const auto channel = _peer->asChannel();
if (!channel || !channel->isMegagroup()) { if (!channel || !channel->isMegagroup()) {
@ -908,7 +912,7 @@ void ParticipantsBoxController::addNewParticipants() {
const auto chat = _peer->asChat(); const auto chat = _peer->asChat();
const auto channel = _peer->asChannel(); const auto channel = _peer->asChannel();
if (chat) { if (chat) {
AddParticipantsBoxController::Start(chat); AddParticipantsBoxController::Start(_navigation, chat);
} else if (channel->isMegagroup() } else if (channel->isMegagroup()
|| channel->membersCount() < Global::ChatSizeMax()) { || channel->membersCount() < Global::ChatSizeMax()) {
const auto count = delegate()->peerListFullRowsCount(); const auto count = delegate()->peerListFullRowsCount();
@ -919,6 +923,7 @@ void ParticipantsBoxController::addNewParticipants() {
delegate()->peerListRowAt(i)->peer()->asUser()); delegate()->peerListRowAt(i)->peer()->asUser());
} }
AddParticipantsBoxController::Start( AddParticipantsBoxController::Start(
_navigation,
channel, channel,
{ already.begin(), already.end() }); { already.begin(), already.end() });
} else { } else {

View File

@ -149,6 +149,7 @@ public:
not_null<PeerData*> peer, not_null<PeerData*> peer,
Role role); Role role);
Main::Session &session() const override;
void prepare() override; void prepare() override;
void rowClicked(not_null<PeerListRow*> row) override; void rowClicked(not_null<PeerListRow*> row) override;
void rowActionClicked(not_null<PeerListRow*> row) override; void rowActionClicked(not_null<PeerListRow*> row) override;

View File

@ -243,6 +243,7 @@ class Controller
, private MTP::Sender { , private MTP::Sender {
public: public:
Controller( Controller(
not_null<Window::SessionNavigation*> navigation,
not_null<BoxContent*> box, not_null<BoxContent*> box,
not_null<PeerData*> peer); not_null<PeerData*> peer);
@ -328,9 +329,10 @@ private:
std::optional<QString> _usernameSavedValue; std::optional<QString> _usernameSavedValue;
std::optional<bool> _signaturesSavedValue; std::optional<bool> _signaturesSavedValue;
not_null<BoxContent*> _box; const not_null<Window::SessionNavigation*> _navigation;
const not_null<BoxContent*> _box;
not_null<PeerData*> _peer; not_null<PeerData*> _peer;
bool _isGroup = false; const bool _isGroup = false;
base::unique_qptr<Ui::VerticalLayout> _wrap; base::unique_qptr<Ui::VerticalLayout> _wrap;
Controls _controls; Controls _controls;
@ -348,18 +350,20 @@ private:
}; };
Controller::Controller( Controller::Controller(
not_null<Window::SessionNavigation*> navigation,
not_null<BoxContent*> box, not_null<BoxContent*> box,
not_null<PeerData*> peer) not_null<PeerData*> peer)
: _box(box) : _navigation(navigation)
, _box(box)
, _peer(peer) , _peer(peer)
, _isGroup(_peer->isChat() || _peer->isMegagroup()) { , _isGroup(_peer->isChat() || _peer->isMegagroup()) {
_box->setTitle(_isGroup _box->setTitle(_isGroup
? tr::lng_edit_group() ? tr::lng_edit_group()
: tr::lng_edit_channel_title()); : tr::lng_edit_channel_title());
_box->addButton(tr::lng_settings_save(), [this] { _box->addButton(tr::lng_settings_save(), [=] {
save(); save();
}); });
_box->addButton(tr::lng_cancel(), [this] { _box->addButton(tr::lng_cancel(), [=] {
_box->closeBox(); _box->closeBox();
}); });
subscribeToMigration(); subscribeToMigration();
@ -621,7 +625,12 @@ void Controller::showEditLinkedChatBox() {
if (const auto chat = *_linkedChatSavedValue) { if (const auto chat = *_linkedChatSavedValue) {
*box = Ui::show( *box = Ui::show(
EditLinkedChatBox(channel, chat, canEdit, callback), EditLinkedChatBox(
_navigation,
channel,
chat,
canEdit,
callback),
LayerOption::KeepOther); LayerOption::KeepOther);
return; return;
} else if (!canEdit || _linkedChatsRequestId) { } else if (!canEdit || _linkedChatsRequestId) {
@ -644,7 +653,11 @@ void Controller::showEditLinkedChatBox() {
chats.emplace_back(_peer->owner().processChat(item)); chats.emplace_back(_peer->owner().processChat(item));
} }
*box = Ui::show( *box = Ui::show(
EditLinkedChatBox(channel, std::move(chats), callback), EditLinkedChatBox(
_navigation,
channel,
std::move(chats),
callback),
LayerOption::KeepOther); LayerOption::KeepOther);
}).fail([=](const RPCError &error) { }).fail([=](const RPCError &error) {
_linkedChatsRequestId = 0; _linkedChatsRequestId = 0;
@ -1438,12 +1451,18 @@ void Controller::deleteChannel() {
EditPeerInfoBox::EditPeerInfoBox( EditPeerInfoBox::EditPeerInfoBox(
QWidget*, QWidget*,
not_null<Window::SessionNavigation*> navigation,
not_null<PeerData*> peer) not_null<PeerData*> peer)
: _peer(peer->migrateToOrMe()) { : _navigation(navigation)
, _peer(peer->migrateToOrMe()) {
} }
void EditPeerInfoBox::prepare() { void EditPeerInfoBox::prepare() {
const auto controller = Ui::CreateChild<Controller>(this, this, _peer); const auto controller = Ui::CreateChild<Controller>(
this,
_navigation,
this,
_peer);
_focusRequests.events( _focusRequests.events(
) | rpl::start_with_next( ) | rpl::start_with_next(
[=] { controller->setFocus(); }, [=] { controller->setFocus(); },

View File

@ -14,6 +14,10 @@ namespace style {
struct InfoProfileCountButton; struct InfoProfileCountButton;
} // namespace style } // namespace style
namespace Window {
class SessionNavigation;
} // namespace Window
namespace Ui { namespace Ui {
class VerticalLayout; class VerticalLayout;
} // namespace Ui } // namespace Ui
@ -26,7 +30,10 @@ class Button;
class EditPeerInfoBox : public BoxContent { class EditPeerInfoBox : public BoxContent {
public: public:
EditPeerInfoBox(QWidget*, not_null<PeerData*> peer); EditPeerInfoBox(
QWidget*,
not_null<Window::SessionNavigation*> navigation,
not_null<PeerData*> peer);
void setInnerFocus() override { void setInnerFocus() override {
_focusRequests.fire({}); _focusRequests.fire({});
@ -47,6 +54,7 @@ protected:
private: private:
rpl::event_stream<> _focusRequests; rpl::event_stream<> _focusRequests;
not_null<Window::SessionNavigation*> _navigation;
not_null<PeerData*> _peer; not_null<PeerData*> _peer;
}; };

View File

@ -25,8 +25,13 @@ constexpr auto kRateCallCommentLengthMax = 200;
} // namespace } // namespace
RateCallBox::RateCallBox(QWidget*, uint64 callId, uint64 callAccessHash) RateCallBox::RateCallBox(
: _callId(callId) QWidget*,
not_null<Main::Session*> session,
uint64 callId,
uint64 callAccessHash)
: _session(session)
, _callId(callId)
, _callAccessHash(callAccessHash) { , _callAccessHash(callAccessHash) {
} }
@ -35,7 +40,7 @@ void RateCallBox::prepare() {
addButton(tr::lng_cancel(), [this] { closeBox(); }); addButton(tr::lng_cancel(), [this] { closeBox(); });
for (auto i = 0; i < kMaxRating; ++i) { for (auto i = 0; i < kMaxRating; ++i) {
_stars.push_back(object_ptr<Ui::IconButton>(this, st::callRatingStar)); _stars.emplace_back(this, st::callRatingStar);
_stars.back()->setClickedCallback([this, value = i + 1] { ratingChanged(value); }); _stars.back()->setClickedCallback([this, value = i + 1] { ratingChanged(value); });
_stars.back()->show(); _stars.back()->show();
} }
@ -121,7 +126,7 @@ void RateCallBox::send() {
MTP_int(_rating), MTP_int(_rating),
MTP_string(comment) MTP_string(comment)
)).done([=](const MTPUpdates &updates) { )).done([=](const MTPUpdates &updates) {
Auth().api().applyUpdates(updates); _session->api().applyUpdates(updates);
closeBox(); closeBox();
}).fail([=](const RPCError &error) { closeBox(); }).send(); }).fail([=](const RPCError &error) { closeBox(); }).send();
} }

View File

@ -16,9 +16,17 @@ class FlatLabel;
class IconButton; class IconButton;
} // namespace Ui } // namespace Ui
namespace Main {
class Session;
} // namespace Main
class RateCallBox : public BoxContent, private MTP::Sender { class RateCallBox : public BoxContent, private MTP::Sender {
public: public:
RateCallBox(QWidget*, uint64 callId, uint64 callAccessHash); RateCallBox(
QWidget*,
not_null<Main::Session*> session,
uint64 callId,
uint64 callAccessHash);
protected: protected:
void prepare() override; void prepare() override;
@ -32,6 +40,8 @@ private:
void send(); void send();
void commentResized(); void commentResized();
const not_null<Main::Session*> _session;
uint64 _callId = 0; uint64 _callId = 0;
uint64 _callAccessHash = 0; uint64 _callAccessHash = 0;
int _rating = 0; int _rating = 0;

View File

@ -16,8 +16,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
SelfDestructionBox::SelfDestructionBox( SelfDestructionBox::SelfDestructionBox(
QWidget*, QWidget*,
not_null<Main::Session*> session,
rpl::producer<int> preloaded) rpl::producer<int> preloaded)
: _ttlValues{ 30, 90, 180, 365 } : _session(session)
, _ttlValues{ 30, 90, 180, 365 }
, _loading( , _loading(
this, this,
tr::lng_contacts_loading(tr::now), tr::lng_contacts_loading(tr::now),
@ -73,7 +75,7 @@ void SelfDestructionBox::showContent() {
clearButtons(); clearButtons();
addButton(tr::lng_settings_save(), [=] { addButton(tr::lng_settings_save(), [=] {
Auth().api().saveSelfDestruct(_ttlGroup->value()); _session->api().saveSelfDestruct(_ttlGroup->value());
closeBox(); closeBox();
}); });
addButton(tr::lng_cancel(), [=] { closeBox(); }); addButton(tr::lng_cancel(), [=] { closeBox(); });

View File

@ -16,9 +16,16 @@ class Radiobutton;
class FlatLabel; class FlatLabel;
} // namespace Ui } // namespace Ui
namespace Main {
class Session;
} // namespace Main
class SelfDestructionBox : public BoxContent, private MTP::Sender { class SelfDestructionBox : public BoxContent, private MTP::Sender {
public: public:
SelfDestructionBox(QWidget*, rpl::producer<int> preloaded); SelfDestructionBox(
QWidget*,
not_null<Main::Session*> session,
rpl::producer<int> preloaded);
static QString DaysLabel(int days); static QString DaysLabel(int days);
@ -29,6 +36,7 @@ private:
void gotCurrent(int days); void gotCurrent(int days);
void showContent(); void showContent();
const not_null<Main::Session*> _session;
bool _prepared = false; bool _prepared = false;
std::vector<int> _ttlValues; std::vector<int> _ttlValues;
object_ptr<Ui::FlatLabel> _description = { nullptr }; object_ptr<Ui::FlatLabel> _description = { nullptr };

View File

@ -1497,10 +1497,10 @@ void SendFilesBox::initSendWay() {
? SendFilesWay::Album ? SendFilesWay::Album
: SendFilesWay::Photos; : SendFilesWay::Photos;
} }
const auto currentWay = Auth().settings().sendFilesWay(); const auto way = _controller->session().settings().sendFilesWay();
if (currentWay == SendFilesWay::Files) { if (way == SendFilesWay::Files) {
return currentWay; return way;
} else if (currentWay == SendFilesWay::Album) { } else if (way == SendFilesWay::Album) {
return _list.albumIsPossible return _list.albumIsPossible
? SendFilesWay::Album ? SendFilesWay::Album
: SendFilesWay::Photos; : SendFilesWay::Photos;
@ -1914,7 +1914,7 @@ void SendFilesBox::send(bool ctrlShiftEnter) {
const auto way = _sendWay ? _sendWay->value() : Way::Files; const auto way = _sendWay ? _sendWay->value() : Way::Files;
if (_compressConfirm == CompressConfirm::Auto) { if (_compressConfirm == CompressConfirm::Auto) {
const auto oldWay = Auth().settings().sendFilesWay(); const auto oldWay = _controller->session().settings().sendFilesWay();
if (way != oldWay) { if (way != oldWay) {
// Check if the user _could_ use the old value, but didn't. // Check if the user _could_ use the old value, but didn't.
if ((oldWay == Way::Album && _sendAlbum) if ((oldWay == Way::Album && _sendAlbum)
@ -1922,8 +1922,8 @@ void SendFilesBox::send(bool ctrlShiftEnter) {
|| (oldWay == Way::Files && _sendFiles) || (oldWay == Way::Files && _sendFiles)
|| (way == Way::Files && (_sendAlbum || _sendPhotos))) { || (way == Way::Files && (_sendAlbum || _sendPhotos))) {
// And in that case save it to settings. // And in that case save it to settings.
Auth().settings().setSendFilesWay(way); _controller->session().settings().setSendFilesWay(way);
Auth().saveSettingsDelayed(); _controller->session().saveSettingsDelayed();
} }
} }
} }

View File

@ -75,8 +75,9 @@ private:
}; };
SessionsBox::SessionsBox(QWidget*) SessionsBox::SessionsBox(QWidget*, not_null<Main::Session*> session)
: _shortPollTimer([=] { shortPollSessions(); }) { : _session(session)
, _shortPollTimer([=] { shortPollSessions(); }) {
} }
void SessionsBox::prepare() { void SessionsBox::prepare() {
@ -99,7 +100,7 @@ void SessionsBox::prepare() {
terminateAll(); terminateAll();
}, lifetime()); }, lifetime());
Auth().data().newAuthorizationChecks( _session->data().newAuthorizationChecks(
) | rpl::start_with_next([=] { ) | rpl::start_with_next([=] {
shortPollSessions(); shortPollSessions();
}, lifetime()); }, lifetime());

View File

@ -18,9 +18,13 @@ class IconButton;
class LinkButton; class LinkButton;
} // namespace Ui } // namespace Ui
namespace Main {
class Session;
} // namespace Main
class SessionsBox : public BoxContent, private MTP::Sender { class SessionsBox : public BoxContent, private MTP::Sender {
public: public:
SessionsBox(QWidget*); SessionsBox(QWidget*, not_null<Main::Session*> session);
protected: protected:
void prepare() override; void prepare() override;
@ -55,6 +59,8 @@ private:
void terminateOne(uint64 hash); void terminateOne(uint64 hash);
void terminateAll(); void terminateAll();
const not_null<Main::Session*> _session;
bool _loading = false; bool _loading = false;
Full _data; Full _data;

View File

@ -27,6 +27,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/history.h" #include "history/history.h"
#include "history/history_message.h" #include "history/history_message.h"
#include "window/themes/window_theme.h" #include "window/themes/window_theme.h"
#include "window/window_session_controller.h"
#include "boxes/peer_list_box.h" #include "boxes/peer_list_box.h"
#include "chat_helpers/emoji_suggestions_widget.h" #include "chat_helpers/emoji_suggestions_widget.h"
#include "data/data_channel.h" #include "data/data_channel.h"
@ -43,7 +44,10 @@ class ShareBox::Inner
, public RPCSender , public RPCSender
, private base::Subscriber { , private base::Subscriber {
public: public:
Inner(QWidget *parent, ShareBox::FilterCallback &&filterCallback); Inner(
QWidget *parent,
not_null<Window::SessionNavigation*> navigation,
ShareBox::FilterCallback &&filterCallback);
void setPeerSelectedChangedCallback( void setPeerSelectedChangedCallback(
Fn<void(PeerData *peer, bool selected)> callback); Fn<void(PeerData *peer, bool selected)> callback);
@ -118,6 +122,8 @@ private:
void refresh(); void refresh();
const not_null<Window::SessionNavigation*> _navigation;
float64 _columnSkip = 0.; float64 _columnSkip = 0.;
float64 _rowWidthReal = 0.; float64 _rowWidthReal = 0.;
int _rowsLeft = 0; int _rowsLeft = 0;
@ -150,10 +156,12 @@ private:
ShareBox::ShareBox( ShareBox::ShareBox(
QWidget*, QWidget*,
not_null<Window::SessionNavigation*> navigation,
CopyCallback &&copyCallback, CopyCallback &&copyCallback,
SubmitCallback &&submitCallback, SubmitCallback &&submitCallback,
FilterCallback &&filterCallback) FilterCallback &&filterCallback)
: _copyCallback(std::move(copyCallback)) : _navigation(navigation)
, _copyCallback(std::move(copyCallback))
, _submitCallback(std::move(submitCallback)) , _submitCallback(std::move(submitCallback))
, _filterCallback(std::move(filterCallback)) , _filterCallback(std::move(filterCallback))
, _select( , _select(
@ -209,6 +217,7 @@ void ShareBox::prepare() {
_inner = setInnerWidget( _inner = setInnerWidget(
object_ptr<Inner>( object_ptr<Inner>(
this, this,
_navigation,
std::move(_filterCallback)), std::move(_filterCallback)),
getTopScrollSkip(), getTopScrollSkip(),
getBottomScrollSkip()); getBottomScrollSkip());
@ -221,7 +230,7 @@ void ShareBox::prepare() {
applyFilterUpdate(query); applyFilterUpdate(query);
}); });
_select->setItemRemovedCallback([=](uint64 itemId) { _select->setItemRemovedCallback([=](uint64 itemId) {
if (const auto peer = Auth().data().peerLoaded(itemId)) { if (const auto peer = _navigation->session().data().peerLoaded(itemId)) {
_inner->peerUnselected(peer); _inner->peerUnselected(peer);
selectedChanged(); selectedChanged();
update(); update();
@ -335,8 +344,8 @@ void ShareBox::peopleReceived(
switch (result.type()) { switch (result.type()) {
case mtpc_contacts_found: { case mtpc_contacts_found: {
auto &found = result.c_contacts_found(); auto &found = result.c_contacts_found();
Auth().data().processUsers(found.vusers()); _navigation->session().data().processUsers(found.vusers());
Auth().data().processChats(found.vchats()); _navigation->session().data().processChats(found.vchats());
_inner->peopleReceived( _inner->peopleReceived(
query, query,
found.vmy_results().v, found.vmy_results().v,
@ -479,8 +488,10 @@ void ShareBox::scrollAnimationCallback() {
ShareBox::Inner::Inner( ShareBox::Inner::Inner(
QWidget *parent, QWidget *parent,
not_null<Window::SessionNavigation*> navigation,
ShareBox::FilterCallback &&filterCallback) ShareBox::FilterCallback &&filterCallback)
: RpWidget(parent) : RpWidget(parent)
, _navigation(navigation)
, _filterCallback(std::move(filterCallback)) , _filterCallback(std::move(filterCallback))
, _chatsIndexed( , _chatsIndexed(
std::make_unique<Dialogs::IndexedList>( std::make_unique<Dialogs::IndexedList>(
@ -489,7 +500,7 @@ ShareBox::Inner::Inner(
_rowHeight = st::shareRowHeight; _rowHeight = st::shareRowHeight;
setAttribute(Qt::WA_OpaquePaintEvent); setAttribute(Qt::WA_OpaquePaintEvent);
const auto self = Auth().user(); const auto self = _navigation->session().user();
if (_filterCallback(self)) { if (_filterCallback(self)) {
_chatsIndexed->addToEnd(self->owner().history(self)); _chatsIndexed->addToEnd(self->owner().history(self));
} }
@ -503,12 +514,12 @@ ShareBox::Inner::Inner(
} }
} }
}; };
addList(Auth().data().chatsList()->indexed()); addList(_navigation->session().data().chatsList()->indexed());
const auto id = Data::Folder::kId; const auto id = Data::Folder::kId;
if (const auto folder = Auth().data().folderLoaded(id)) { if (const auto folder = _navigation->session().data().folderLoaded(id)) {
addList(folder->chatsList()->indexed()); addList(folder->chatsList()->indexed());
} }
addList(Auth().data().contactsNoChatsList()); addList(_navigation->session().data().contactsNoChatsList());
_filter = qsl("a"); _filter = qsl("a");
updateFilter(); updateFilter();
@ -518,7 +529,9 @@ ShareBox::Inner::Inner(
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(observeEvents, [this](const Notify::PeerUpdate &update) { subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(observeEvents, [this](const Notify::PeerUpdate &update) {
notifyPeerUpdated(update); notifyPeerUpdated(update);
})); }));
subscribe(Auth().downloaderTaskFinished(), [this] { update(); }); subscribe(_navigation->session().downloaderTaskFinished(), [=] {
update();
});
subscribe(Window::Theme::Background(), [this](const Window::Theme::BackgroundUpdate &update) { subscribe(Window::Theme::Background(), [this](const Window::Theme::BackgroundUpdate &update) {
if (update.paletteChanged()) { if (update.paletteChanged()) {
@ -675,7 +688,7 @@ void ShareBox::Inner::loadProfilePhotos(int yFrom) {
yFrom *= _columnCount; yFrom *= _columnCount;
yTo *= _columnCount; yTo *= _columnCount;
Auth().downloader().clearPriorities(); _navigation->session().downloader().clearPriorities();
if (_filter.isEmpty()) { if (_filter.isEmpty()) {
if (!_chatsIndexed->empty()) { if (!_chatsIndexed->empty()) {
auto i = _chatsIndexed->cfind(yFrom, _rowHeight); auto i = _chatsIndexed->cfind(yFrom, _rowHeight);
@ -984,8 +997,8 @@ void ShareBox::Inner::peopleReceived(
d_byUsernameFiltered.reserve(already + my.size() + people.size()); d_byUsernameFiltered.reserve(already + my.size() + people.size());
const auto feedList = [&](const QVector<MTPPeer> &list) { const auto feedList = [&](const QVector<MTPPeer> &list) {
for (const auto &data : list) { for (const auto &data : list) {
if (const auto peer = Auth().data().peerLoaded(peerFromMTP(data))) { if (const auto peer = _navigation->session().data().peerLoaded(peerFromMTP(data))) {
const auto history = Auth().data().historyLoaded(peer); const auto history = _navigation->session().data().historyLoaded(peer);
if (!_filterCallback(peer)) { if (!_filterCallback(peer)) {
continue; continue;
} else if (history && _chatsIndexed->getRow(history)) { } else if (history && _chatsIndexed->getRow(history)) {
@ -1030,15 +1043,18 @@ QVector<PeerData*> ShareBox::Inner::selected() const {
return result; return result;
} }
QString AppendShareGameScoreUrl(const QString &url, const FullMsgId &fullId) { QString AppendShareGameScoreUrl(
not_null<Main::Session*> session,
const QString &url,
const FullMsgId &fullId) {
auto shareHashData = QByteArray(0x10, Qt::Uninitialized); auto shareHashData = QByteArray(0x10, Qt::Uninitialized);
auto shareHashDataInts = reinterpret_cast<int32*>(shareHashData.data()); auto shareHashDataInts = reinterpret_cast<int32*>(shareHashData.data());
auto channel = fullId.channel auto channel = fullId.channel
? Auth().data().channelLoaded(fullId.channel) ? session->data().channelLoaded(fullId.channel)
: static_cast<ChannelData*>(nullptr); : static_cast<ChannelData*>(nullptr);
auto channelAccessHash = channel ? channel->access : 0ULL; auto channelAccessHash = channel ? channel->access : 0ULL;
auto channelAccessHashInts = reinterpret_cast<int32*>(&channelAccessHash); auto channelAccessHashInts = reinterpret_cast<int32*>(&channelAccessHash);
shareHashDataInts[0] = Auth().userId(); shareHashDataInts[0] = session->userId();
shareHashDataInts[1] = fullId.channel; shareHashDataInts[1] = fullId.channel;
shareHashDataInts[2] = fullId.msg; shareHashDataInts[2] = fullId.msg;
shareHashDataInts[3] = channelAccessHashInts[0]; shareHashDataInts[3] = channelAccessHashInts[0];
@ -1075,7 +1091,9 @@ QString AppendShareGameScoreUrl(const QString &url, const FullMsgId &fullId) {
return url + shareComponent; return url + shareComponent;
} }
void ShareGameScoreByHash(const QString &hash) { void ShareGameScoreByHash(
not_null<Main::Session*> session,
const QString &hash) {
auto key128Size = 0x10; auto key128Size = 0x10;
auto hashEncrypted = QByteArray::fromBase64(hash.toLatin1(), QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals); auto hashEncrypted = QByteArray::fromBase64(hash.toLatin1(), QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals);
@ -1105,7 +1123,7 @@ void ShareGameScoreByHash(const QString &hash) {
} }
auto hashDataInts = reinterpret_cast<int32*>(hashData.data()); auto hashDataInts = reinterpret_cast<int32*>(hashData.data());
if (!Main::Session::Exists() || hashDataInts[0] != Auth().userId()) { if (hashDataInts[0] != session->userId()) {
Ui::show(Box<InformBox>(tr::lng_share_wrong_user(tr::now))); Ui::show(Box<InformBox>(tr::lng_share_wrong_user(tr::now)));
return; return;
} }
@ -1125,14 +1143,14 @@ void ShareGameScoreByHash(const QString &hash) {
return; return;
} }
if (const auto item = Auth().data().message(channelId, msgId)) { if (const auto item = session->data().message(channelId, msgId)) {
FastShareMessage(item); FastShareMessage(item);
} else { } else {
auto resolveMessageAndShareScore = [=](ChannelData *channel) { auto resolveMessageAndShareScore = [=](ChannelData *channel) {
Auth().api().requestMessageData(channel, msgId, []( session->api().requestMessageData(channel, msgId, [=](
ChannelData *channel, ChannelData *channel,
MsgId msgId) { MsgId msgId) {
if (const auto item = Auth().data().message(channel, msgId)) { if (const auto item = session->data().message(channel, msgId)) {
FastShareMessage(item); FastShareMessage(item);
} else { } else {
Ui::show(Box<InformBox>(tr::lng_edit_deleted(tr::now))); Ui::show(Box<InformBox>(tr::lng_edit_deleted(tr::now)));
@ -1141,21 +1159,25 @@ void ShareGameScoreByHash(const QString &hash) {
}; };
const auto channel = channelId const auto channel = channelId
? Auth().data().channelLoaded(channelId) ? session->data().channelLoaded(channelId)
: nullptr; : nullptr;
if (channel || !channelId) { if (channel || !channelId) {
resolveMessageAndShareScore(channel); resolveMessageAndShareScore(channel);
} else { } else {
auto requestChannelIds = MTP_vector<MTPInputChannel>(1, MTP_inputChannel(MTP_int(channelId), MTP_long(channelAccessHash))); session->api().request(MTPchannels_GetChannels(
auto requestChannel = MTPchannels_GetChannels(requestChannelIds); MTP_vector<MTPInputChannel>(
MTP::send(requestChannel, rpcDone([=](const MTPmessages_Chats &result) { 1,
result.match([](const auto &data) { MTP_inputChannel(
Auth().data().processChats(data.vchats()); MTP_int(channelId),
MTP_long(channelAccessHash)))
)).done([=](const MTPmessages_Chats &result) {
result.match([&](const auto &data) {
session->data().processChats(data.vchats());
}); });
if (const auto channel = Auth().data().channelLoaded(channelId)) { if (const auto channel = session->data().channelLoaded(channelId)) {
resolveMessageAndShareScore(channel); resolveMessageAndShareScore(channel);
} }
})); }).send();
} }
} }
} }

View File

@ -13,6 +13,14 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/effects/animations.h" #include "ui/effects/animations.h"
#include "ui/effects/round_checkbox.h" #include "ui/effects/round_checkbox.h"
namespace Window {
class SessionNavigation;
} // namespace Window
namespace Main {
class Session;
} // namespace Main
namespace Dialogs { namespace Dialogs {
class Row; class Row;
class IndexedList; class IndexedList;
@ -30,16 +38,23 @@ template <typename Widget>
class SlideWrap; class SlideWrap;
} // namespace Ui } // namespace Ui
QString AppendShareGameScoreUrl(const QString &url, const FullMsgId &fullId); QString AppendShareGameScoreUrl(
void ShareGameScoreByHash(const QString &hash); not_null<Main::Session*> session,
const QString &url,
const FullMsgId &fullId);
void ShareGameScoreByHash(
not_null<Main::Session*> session,
const QString &hash);
class ShareBox : public BoxContent, public RPCSender { class ShareBox : public BoxContent, public RPCSender {
public: public:
using CopyCallback = Fn<void()>; using CopyCallback = Fn<void()>;
using SubmitCallback = Fn<void(QVector<PeerData*>&&, TextWithTags&&)>; using SubmitCallback = Fn<void(QVector<PeerData*>&&, TextWithTags&&)>;
using FilterCallback = Fn<bool(PeerData*)>; using FilterCallback = Fn<bool(PeerData*)>;
ShareBox( ShareBox(
QWidget*, QWidget*,
not_null<Window::SessionNavigation*> navigation,
CopyCallback &&copyCallback, CopyCallback &&copyCallback,
SubmitCallback &&submitCallback, SubmitCallback &&submitCallback,
FilterCallback &&filterCallback); FilterCallback &&filterCallback);
@ -77,6 +92,8 @@ private:
mtpRequestId requestId); mtpRequestId requestId);
bool peopleFailed(const RPCError &error, mtpRequestId requestId); bool peopleFailed(const RPCError &error, mtpRequestId requestId);
const not_null<Window::SessionNavigation*> _navigation;
CopyCallback _copyCallback; CopyCallback _copyCallback;
SubmitCallback _submitCallback; SubmitCallback _submitCallback;
FilterCallback _filterCallback; FilterCallback _filterCallback;

View File

@ -150,7 +150,7 @@ void StickerSetBox::prepare() {
_inner = setInnerWidget( _inner = setInnerWidget(
object_ptr<Inner>(this, _controller, _set), object_ptr<Inner>(this, _controller, _set),
st::stickersScroll); st::stickersScroll);
Auth().data().stickersUpdated( _controller->session().data().stickersUpdated(
) | rpl::start_with_next([=] { ) | rpl::start_with_next([=] {
updateButtons(); updateButtons();
}, lifetime()); }, lifetime());
@ -166,7 +166,7 @@ void StickerSetBox::prepare() {
_inner->setInstalled( _inner->setInstalled(
) | rpl::start_with_next([=](uint64 setId) { ) | rpl::start_with_next([=](uint64 setId) {
Auth().api().stickerSetInstalled(setId); _controller->session().api().stickerSetInstalled(setId);
closeBox(); closeBox();
}, lifetime()); }, lifetime());
} }
@ -234,9 +234,9 @@ StickerSetBox::Inner::Inner(
Ui::show(Box<InformBox>(tr::lng_stickers_not_found(tr::now))); Ui::show(Box<InformBox>(tr::lng_stickers_not_found(tr::now)));
}).send(); }).send();
Auth().api().updateStickers(); _controller->session().api().updateStickers();
subscribe(Auth().downloaderTaskFinished(), [this] { update(); }); subscribe(_controller->session().downloaderTaskFinished(), [this] { update(); });
setMouseTracking(true); setMouseTracking(true);
} }
@ -252,7 +252,7 @@ void StickerSetBox::Inner::gotSet(const MTPmessages_StickerSet &set) {
_pack.reserve(v.size()); _pack.reserve(v.size());
_elements.reserve(v.size()); _elements.reserve(v.size());
for (const auto &item : v) { for (const auto &item : v) {
const auto document = Auth().data().processDocument(item); const auto document = _controller->session().data().processDocument(item);
const auto sticker = document->sticker(); const auto sticker = document->sticker();
if (!sticker) { if (!sticker) {
continue; continue;
@ -269,7 +269,7 @@ void StickerSetBox::Inner::gotSet(const MTPmessages_StickerSet &set) {
auto p = Stickers::Pack(); auto p = Stickers::Pack();
p.reserve(stickers.size()); p.reserve(stickers.size());
for (auto j = 0, c = stickers.size(); j != c; ++j) { for (auto j = 0, c = stickers.size(); j != c; ++j) {
auto doc = Auth().data().document(stickers[j].v); auto doc = _controller->session().data().document(stickers[j].v);
if (!doc || !doc->sticker()) continue; if (!doc || !doc->sticker()) continue;
p.push_back(doc); p.push_back(doc);
@ -292,7 +292,7 @@ void StickerSetBox::Inner::gotSet(const MTPmessages_StickerSet &set) {
} else { } else {
_setThumbnail = ImagePtr(); _setThumbnail = ImagePtr();
} }
auto &sets = Auth().data().stickerSetsRef(); auto &sets = _controller->session().data().stickerSetsRef();
const auto it = sets.find(_setId); const auto it = sets.find(_setId);
if (it != sets.cend()) { if (it != sets.cend()) {
using ClientFlag = MTPDstickerSet_ClientFlag; using ClientFlag = MTPDstickerSet_ClientFlag;
@ -334,13 +334,13 @@ rpl::producer<> StickerSetBox::Inner::updateControls() const {
void StickerSetBox::Inner::installDone( void StickerSetBox::Inner::installDone(
const MTPmessages_StickerSetInstallResult &result) { const MTPmessages_StickerSetInstallResult &result) {
auto &sets = Auth().data().stickerSetsRef(); auto &sets = _controller->session().data().stickerSetsRef();
bool wasArchived = (_setFlags & MTPDstickerSet::Flag::f_archived); bool wasArchived = (_setFlags & MTPDstickerSet::Flag::f_archived);
if (wasArchived) { if (wasArchived) {
auto index = Auth().data().archivedStickerSetsOrderRef().indexOf(_setId); auto index = _controller->session().data().archivedStickerSetsOrderRef().indexOf(_setId);
if (index >= 0) { if (index >= 0) {
Auth().data().archivedStickerSetsOrderRef().removeAt(index); _controller->session().data().archivedStickerSetsOrderRef().removeAt(index);
} }
} }
_setInstallDate = base::unixtime::now(); _setInstallDate = base::unixtime::now();
@ -367,7 +367,7 @@ void StickerSetBox::Inner::installDone(
it->stickers = _pack; it->stickers = _pack;
it->emoji = _emoji; it->emoji = _emoji;
auto &order = Auth().data().stickerSetsOrderRef(); auto &order = _controller->session().data().stickerSetsOrderRef();
int insertAtIndex = 0, currentIndex = order.indexOf(_setId); int insertAtIndex = 0, currentIndex = order.indexOf(_setId);
if (currentIndex != insertAtIndex) { if (currentIndex != insertAtIndex) {
if (currentIndex > 0) { if (currentIndex > 0) {
@ -394,7 +394,7 @@ void StickerSetBox::Inner::installDone(
Local::writeArchivedStickers(); Local::writeArchivedStickers();
} }
Local::writeInstalledStickers(); Local::writeInstalledStickers();
Auth().data().notifyStickersUpdated(); _controller->session().data().notifyStickersUpdated();
} }
_setInstalled.fire_copy(_setId); _setInstalled.fire_copy(_setId);
} }
@ -657,8 +657,8 @@ bool StickerSetBox::Inner::notInstalled() const {
if (!_loaded) { if (!_loaded) {
return false; return false;
} }
const auto it = Auth().data().stickerSets().constFind(_setId); const auto it = _controller->session().data().stickerSets().constFind(_setId);
if ((it == Auth().data().stickerSets().cend()) if ((it == _controller->session().data().stickerSets().cend())
|| !(it->flags & MTPDstickerSet::Flag::f_installed_date) || !(it->flags & MTPDstickerSet::Flag::f_installed_date)
|| (it->flags & MTPDstickerSet::Flag::f_archived)) { || (it->flags & MTPDstickerSet::Flag::f_archived)) {
return !_pack.empty(); return !_pack.empty();

View File

@ -16,6 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/history.h" #include "history/history.h"
#include "history/history_item.h" #include "history/history_item.h"
#include "mainwidget.h" #include "mainwidget.h"
#include "window/window_session_controller.h"
#include "main/main_session.h" #include "main/main_session.h"
#include "data/data_session.h" #include "data/data_session.h"
#include "data/data_media_types.h" #include "data/data_media_types.h"
@ -211,8 +212,16 @@ void BoxController::Row::stopLastActionRipple() {
} }
} }
BoxController::BoxController(not_null<Window::SessionController*> window)
: _window(window) {
}
Main::Session &BoxController::session() const {
return _window->session();
}
void BoxController::prepare() { void BoxController::prepare() {
Auth().data().itemRemoved( session().data().itemRemoved(
) | rpl::start_with_next([=](not_null<const HistoryItem*> item) { ) | rpl::start_with_next([=](not_null<const HistoryItem*> item) {
if (const auto row = rowForItem(item)) { if (const auto row = rowForItem(item)) {
row->itemRemoved(item); row->itemRemoved(item);
@ -226,7 +235,7 @@ void BoxController::prepare() {
} }
}, lifetime()); }, lifetime());
subscribe(Current().newServiceMessage(), [=](FullMsgId msgId) { subscribe(Current().newServiceMessage(), [=](FullMsgId msgId) {
if (const auto item = Auth().data().message(msgId)) { if (const auto item = session().data().message(msgId)) {
insertRow(item, InsertWay::Prepend); insertRow(item, InsertWay::Prepend);
} }
}); });
@ -261,8 +270,8 @@ void BoxController::loadMoreRows() {
_loadRequestId = 0; _loadRequestId = 0;
auto handleResult = [&](auto &data) { auto handleResult = [&](auto &data) {
Auth().data().processUsers(data.vusers()); session().data().processUsers(data.vusers());
Auth().data().processChats(data.vchats()); session().data().processChats(data.vchats());
receivedCalls(data.vmessages().v); receivedCalls(data.vmessages().v);
}; };
@ -310,8 +319,8 @@ void BoxController::receivedCalls(const QVector<MTPMessage> &result) {
for (const auto &message : result) { for (const auto &message : result) {
const auto msgId = IdFromMessage(message); const auto msgId = IdFromMessage(message);
const auto peerId = PeerFromMessage(message); const auto peerId = PeerFromMessage(message);
if (const auto peer = Auth().data().peerLoaded(peerId)) { if (const auto peer = session().data().peerLoaded(peerId)) {
const auto item = Auth().data().addNewMessage( const auto item = session().data().addNewMessage(
message, message,
NewMessageType::Existing); NewMessageType::Existing);
insertRow(item, InsertWay::Append); insertRow(item, InsertWay::Append);

View File

@ -9,6 +9,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "boxes/peer_list_box.h" #include "boxes/peer_list_box.h"
namespace Window {
class SessionController;
} // namespace Window
namespace Calls { namespace Calls {
class BoxController class BoxController
@ -16,6 +20,9 @@ class BoxController
, private base::Subscriber , private base::Subscriber
, private MTP::Sender { , private MTP::Sender {
public: public:
explicit BoxController(not_null<Window::SessionController*> window);
Main::Session &session() const override;
void prepare() override; void prepare() override;
void rowClicked(not_null<PeerListRow*> row) override; void rowClicked(not_null<PeerListRow*> row) override;
void rowActionClicked(not_null<PeerListRow*> row) override; void rowActionClicked(not_null<PeerListRow*> row) override;
@ -36,6 +43,8 @@ private:
std::unique_ptr<PeerListRow> createRow( std::unique_ptr<PeerListRow> createRow(
not_null<HistoryItem*> item) const; not_null<HistoryItem*> item) const;
const not_null<Window::SessionController*> _window;
MsgId _offsetId = 0; MsgId _offsetId = 0;
mtpRequestId _loadRequestId = 0; mtpRequestId _loadRequestId = 0;
bool _allLoaded = false; bool _allLoaded = false;

View File

@ -446,7 +446,7 @@ bool Call::handleUpdate(const MTPPhoneCall &call) {
} }
} }
if (data.is_need_rating() && _id && _accessHash) { if (data.is_need_rating() && _id && _accessHash) {
Ui::show(Box<RateCallBox>(_id, _accessHash)); Ui::show(Box<RateCallBox>(&Auth(), _id, _accessHash));
} }
const auto reason = data.vreason(); const auto reason = data.vreason();
if (reason && reason->type() == mtpc_phoneCallDiscardReasonDisconnect) { if (reason && reason->type() == mtpc_phoneCallDiscardReasonDisconnect) {

View File

@ -139,13 +139,15 @@ GifsListWidget::GifsListWidget(
this, this,
[=] { sendInlineRequest(); }); [=] { sendInlineRequest(); });
Auth().data().savedGifsUpdated( controller->session().data().savedGifsUpdated(
) | rpl::start_with_next([this] { ) | rpl::start_with_next([this] {
refreshSavedGifs(); refreshSavedGifs();
}, lifetime()); }, lifetime());
subscribe(Auth().downloaderTaskFinished(), [this] {
subscribe(controller->session().downloaderTaskFinished(), [this] {
update(); update();
}); });
subscribe(controller->gifPauseLevelChanged(), [=] { subscribe(controller->gifPauseLevelChanged(), [=] {
if (!controller->isGifPausedAtLeastFor( if (!controller->isGifPausedAtLeastFor(
Window::GifPauseReason::SavedGifs)) { Window::GifPauseReason::SavedGifs)) {
@ -228,7 +230,7 @@ void GifsListWidget::inlineResultsDone(const MTPmessages_BotResults &result) {
auto adding = (it != _inlineCache.cend()); auto adding = (it != _inlineCache.cend());
if (result.type() == mtpc_messages_botResults) { if (result.type() == mtpc_messages_botResults) {
auto &d = result.c_messages_botResults(); auto &d = result.c_messages_botResults();
Auth().data().processUsers(d.vusers()); controller()->session().data().processUsers(d.vusers());
auto &v = d.vresults().v; auto &v = d.vresults().v;
auto queryId = d.vquery_id().v; auto queryId = d.vquery_id().v;
@ -492,7 +494,7 @@ void GifsListWidget::refreshSavedGifs() {
if (_section == Section::Gifs) { if (_section == Section::Gifs) {
clearInlineRows(false); clearInlineRows(false);
auto &saved = Auth().data().savedGifs(); auto &saved = controller()->session().data().savedGifs();
if (!saved.isEmpty()) { if (!saved.isEmpty()) {
_rows.reserve(saved.size()); _rows.reserve(saved.size());
auto row = Row(); auto row = Row();
@ -855,12 +857,12 @@ void GifsListWidget::searchForGifs(const QString &query) {
Expects(result.type() == mtpc_contacts_resolvedPeer); Expects(result.type() == mtpc_contacts_resolvedPeer);
auto &data = result.c_contacts_resolvedPeer(); auto &data = result.c_contacts_resolvedPeer();
Auth().data().processUsers(data.vusers()); controller()->session().data().processUsers(data.vusers());
Auth().data().processChats(data.vchats()); controller()->session().data().processChats(data.vchats());
if (auto peer = Auth().data().peerLoaded(peerFromMTP(data.vpeer()))) { const auto peer = controller()->session().data().peerLoaded(
if (auto user = peer->asUser()) { peerFromMTP(data.vpeer()));
_searchBot = user; if (const auto user = peer ? peer->asUser() : nullptr) {
} _searchBot = user;
} }
}).send(); }).send();
} }

View File

@ -134,7 +134,7 @@ bool ShareGameScore(
const auto params = url_parse_params( const auto params = url_parse_params(
match->captured(1), match->captured(1),
qthelp::UrlParamNameTransform::ToLower); qthelp::UrlParamNameTransform::ToLower);
ShareGameScoreByHash(params.value(qsl("hash"))); ShareGameScoreByHash(session, params.value(qsl("hash")));
return true; return true;
} }

View File

@ -2974,12 +2974,14 @@ void HistoryInner::changeSelectionAsGroup(
} }
void HistoryInner::forwardItem(FullMsgId itemId) { void HistoryInner::forwardItem(FullMsgId itemId) {
Window::ShowForwardMessagesBox({ 1, itemId }); Window::ShowForwardMessagesBox(_controller, { 1, itemId });
} }
void HistoryInner::forwardAsGroup(FullMsgId itemId) { void HistoryInner::forwardAsGroup(FullMsgId itemId) {
if (const auto item = session().data().message(itemId)) { if (const auto item = session().data().message(itemId)) {
Window::ShowForwardMessagesBox(session().data().itemOrItsGroup(item)); Window::ShowForwardMessagesBox(
_controller,
session().data().itemOrItsGroup(item));
} }
} }

View File

@ -314,6 +314,7 @@ void FastShareMessage(not_null<HistoryItem*> item) {
? Fn<void()>(std::move(copyCallback)) ? Fn<void()>(std::move(copyCallback))
: Fn<void()>(); : Fn<void()>();
Ui::show(Box<ShareBox>( Ui::show(Box<ShareBox>(
App::wnd()->sessionController(),
std::move(copyLinkCallback), std::move(copyLinkCallback),
std::move(submitCallback), std::move(submitCallback),
std::move(filterCallback))); std::move(filterCallback)));

View File

@ -3345,7 +3345,7 @@ void HistoryWidget::botCallbackDone(
} else if (const auto url = data.vurl()) { } else if (const auto url = data.vurl()) {
auto link = qs(*url); auto link = qs(*url);
if (info.game) { if (info.game) {
link = AppendShareGameScoreUrl(link, info.msgId); link = AppendShareGameScoreUrl(&session(), link, info.msgId);
BotGameUrlClickHandler(info.bot, link).onClick({}); BotGameUrlClickHandler(info.bot, link).onClick({});
if (item) { if (item) {
updateSendAction(item->history(), SendAction::Type::PlayGame); updateSendAction(item->history(), SendAction::Type::PlayGame);
@ -5200,11 +5200,12 @@ void HistoryWidget::mousePressEvent(QMouseEvent *e) {
if (readyToForward()) { if (readyToForward()) {
const auto items = std::move(_toForward); const auto items = std::move(_toForward);
App::main()->cancelForwarding(_history); App::main()->cancelForwarding(_history);
Window::ShowForwardMessagesBox(ranges::view::all( auto list = ranges::view::all(
items items
) | ranges::view::transform([](not_null<HistoryItem*> item) { ) | ranges::view::transform(
return item->fullId(); &HistoryItem::fullId
}) | ranges::to_vector); ) | ranges::to_vector;
Window::ShowForwardMessagesBox(controller(), std::move(list));
} else { } else {
Ui::showPeerHistory(_peer, _editMsgId ? _editMsgId : replyToId()); Ui::showPeerHistory(_peer, _editMsgId ? _editMsgId : replyToId());
} }
@ -6116,7 +6117,7 @@ void HistoryWidget::forwardSelected() {
return; return;
} }
const auto weak = make_weak(this); const auto weak = make_weak(this);
Window::ShowForwardMessagesBox(getSelectedItems(), [=] { Window::ShowForwardMessagesBox(controller(), getSelectedItems(), [=] {
if (const auto strong = weak.data()) { if (const auto strong = weak.data()) {
strong->clearSelected(); strong->clearSelected();
} }

View File

@ -30,6 +30,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "core/file_utilities.h" #include "core/file_utilities.h"
#include "platform/platform_info.h" #include "platform/platform_info.h"
#include "window/window_peer_menu.h" #include "window/window_peer_menu.h"
#include "window/window_session_controller.h"
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "core/application.h" #include "core/application.h"
#include "mainwidget.h" #include "mainwidget.h"
@ -235,12 +236,15 @@ bool AddForwardSelectedAction(
menu->addAction(tr::lng_context_forward_selected(tr::now), [=] { menu->addAction(tr::lng_context_forward_selected(tr::now), [=] {
const auto weak = make_weak(list); const auto weak = make_weak(list);
auto items = ExtractIdsList(request.selectedItems); const auto callback = [=] {
Window::ShowForwardMessagesBox(std::move(items), [=] {
if (const auto strong = weak.data()) { if (const auto strong = weak.data()) {
strong->cancelSelection(); strong->cancelSelection();
} }
}); };
Window::ShowForwardMessagesBox(
request.navigation,
ExtractIdsList(request.selectedItems),
callback);
}); });
return true; return true;
} }
@ -269,9 +273,11 @@ bool AddForwardMessageAction(
const auto itemId = item->fullId(); const auto itemId = item->fullId();
menu->addAction(tr::lng_context_forward_msg(tr::now), [=] { menu->addAction(tr::lng_context_forward_msg(tr::now), [=] {
if (const auto item = owner->message(itemId)) { if (const auto item = owner->message(itemId)) {
Window::ShowForwardMessagesBox(asGroup Window::ShowForwardMessagesBox(
? owner->itemOrItsGroup(item) request.navigation,
: MessageIdsList{ 1, itemId }); (asGroup
? owner->itemOrItsGroup(item)
: MessageIdsList{ 1, itemId }));
} }
}); });
return true; return true;
@ -298,12 +304,11 @@ bool AddDeleteSelectedAction(
return false; return false;
} }
const auto session = request.session;
menu->addAction(tr::lng_context_delete_selected(tr::now), [=] { menu->addAction(tr::lng_context_delete_selected(tr::now), [=] {
const auto weak = make_weak(list); const auto weak = make_weak(list);
auto items = ExtractIdsList(request.selectedItems); auto items = ExtractIdsList(request.selectedItems);
const auto box = Ui::show(Box<DeleteMessagesBox>( const auto box = Ui::show(Box<DeleteMessagesBox>(
session, &request.navigation->session(),
std::move(items))); std::move(items)));
box->setDeleteConfirmedCallback([=] { box->setDeleteConfirmedCallback([=] {
if (const auto strong = weak.data()) { if (const auto strong = weak.data()) {
@ -443,8 +448,9 @@ void AddCopyLinkAction(
} // namespace } // namespace
ContextMenuRequest::ContextMenuRequest(not_null<Main::Session*> session) ContextMenuRequest::ContextMenuRequest(
: session(session) { not_null<Window::SessionNavigation*> navigation)
: navigation(navigation) {
} }
base::unique_qptr<Ui::PopupMenu> FillContextMenu( base::unique_qptr<Ui::PopupMenu> FillContextMenu(

View File

@ -13,8 +13,8 @@ namespace Ui {
class PopupMenu; class PopupMenu;
} // namespace Ui } // namespace Ui
namespace Main { namespace Window {
class Session; class SessionNavigation;
} // namespace Main } // namespace Main
namespace HistoryView { namespace HistoryView {
@ -26,9 +26,10 @@ struct SelectedItem;
using SelectedItems = std::vector<SelectedItem>; using SelectedItems = std::vector<SelectedItem>;
struct ContextMenuRequest { struct ContextMenuRequest {
explicit ContextMenuRequest(not_null<Main::Session*> session); explicit ContextMenuRequest(
not_null<Window::SessionNavigation*> navigation);
const not_null<Main::Session*> session; const not_null<Window::SessionNavigation*> navigation;
ClickHandlerPtr link; ClickHandlerPtr link;
Element *view = nullptr; Element *view = nullptr;
HistoryItem *item = nullptr; HistoryItem *item = nullptr;

View File

@ -1611,7 +1611,7 @@ void ListWidget::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
mouseActionUpdate(e->globalPos()); mouseActionUpdate(e->globalPos());
} }
auto request = ContextMenuRequest(&_controller->session()); auto request = ContextMenuRequest(_controller);
request.link = ClickHandler::getActive(); request.link = ClickHandler::getActive();
request.view = _overElement; request.view = _overElement;

View File

@ -36,6 +36,7 @@ public:
not_null<Controller*> controller, not_null<Controller*> controller,
not_null<UserData*> user); not_null<UserData*> user);
Main::Session &session() const override;
void prepare() override; void prepare() override;
void rowClicked(not_null<PeerListRow*> row) override; void rowClicked(not_null<PeerListRow*> row) override;
void loadMoreRows() override; void loadMoreRows() override;
@ -73,6 +74,10 @@ ListController::ListController(
_controller->setSearchEnabledByContent(false); _controller->setSearchEnabledByContent(false);
} }
Main::Session &ListController::session() const {
return _user->session();
}
std::unique_ptr<PeerListRow> ListController::createRow( std::unique_ptr<PeerListRow> ListController::createRow(
not_null<PeerData*> peer) { not_null<PeerData*> peer) {
auto result = std::make_unique<PeerListRow>(peer); auto result = std::make_unique<PeerListRow>(peer);

View File

@ -35,11 +35,11 @@ namespace Info {
TopBar::TopBar( TopBar::TopBar(
QWidget *parent, QWidget *parent,
not_null<Main::Session*> session, not_null<Window::SessionNavigation*> navigation,
const style::InfoTopBar &st, const style::InfoTopBar &st,
SelectedItems &&selectedItems) SelectedItems &&selectedItems)
: RpWidget(parent) : RpWidget(parent)
, _session(session) , _navigation(navigation)
, _st(st) , _st(st)
, _selectedItems(Section::MediaType::kCount) { , _selectedItems(Section::MediaType::kCount) {
setAttribute(Qt::WA_OpaquePaintEvent); setAttribute(Qt::WA_OpaquePaintEvent);
@ -519,7 +519,7 @@ MessageIdsList TopBar::collectItems() const {
) | ranges::view::transform([](auto &&item) { ) | ranges::view::transform([](auto &&item) {
return item.msgId; return item.msgId;
}) | ranges::view::filter([&](FullMsgId msgId) { }) | ranges::view::filter([&](FullMsgId msgId) {
return _session->data().message(msgId) != nullptr; return _navigation->session().data().message(msgId) != nullptr;
}) | ranges::to_vector; }) | ranges::to_vector;
} }
@ -530,6 +530,7 @@ void TopBar::performForward() {
return; return;
} }
Window::ShowForwardMessagesBox( Window::ShowForwardMessagesBox(
_navigation,
std::move(items), std::move(items),
[weak = make_weak(this)] { [weak = make_weak(this)] {
if (weak) { if (weak) {
@ -544,7 +545,7 @@ void TopBar::performDelete() {
_cancelSelectionClicks.fire({}); _cancelSelectionClicks.fire({});
} else { } else {
const auto box = Ui::show(Box<DeleteMessagesBox>( const auto box = Ui::show(Box<DeleteMessagesBox>(
_session, &_navigation->session(),
std::move(items))); std::move(items)));
box->setDeleteConfirmedCallback([weak = make_weak(this)] { box->setDeleteConfirmedCallback([weak = make_weak(this)] {
if (weak) { if (weak) {

View File

@ -17,6 +17,10 @@ namespace style {
struct InfoTopBar; struct InfoTopBar;
} // namespace style } // namespace style
namespace Window {
class SessionNavigation;
} // namespace Window
namespace Ui { namespace Ui {
class IconButton; class IconButton;
class FlatLabel; class FlatLabel;
@ -39,7 +43,7 @@ class TopBar : public Ui::RpWidget {
public: public:
TopBar( TopBar(
QWidget *parent, QWidget *parent,
not_null<Main::Session*> session, not_null<Window::SessionNavigation*> navigation,
const style::InfoTopBar &st, const style::InfoTopBar &st,
SelectedItems &&items); SelectedItems &&items);
@ -131,7 +135,7 @@ private:
template <typename Widget, typename IsVisible> template <typename Widget, typename IsVisible>
void registerToggleControlCallback(Widget *widget, IsVisible &&callback); void registerToggleControlCallback(Widget *widget, IsVisible &&callback);
const not_null<Main::Session*> _session; const not_null<Window::SessionNavigation*> _navigation;
const style::InfoTopBar &_st; const style::InfoTopBar &_st;
Ui::Animations::Simple _a_highlight; Ui::Animations::Simple _a_highlight;

View File

@ -355,7 +355,7 @@ void WrapWidget::createTopBar() {
: SelectedItems(Section::MediaType::kCount); : SelectedItems(Section::MediaType::kCount);
_topBar.create( _topBar.create(
this, this,
&session(), _controller.get(),
TopBarStyle(wrapValue), TopBarStyle(wrapValue),
std::move(selectedItems)); std::move(selectedItems));
_topBar->cancelSelectionRequests( _topBar->cancelSelectionRequests(

View File

@ -1398,6 +1398,7 @@ void ListWidget::forwardItems(MessageIdsList &&items) {
} }
}; };
setActionBoxWeak(Window::ShowForwardMessagesBox( setActionBoxWeak(Window::ShowForwardMessagesBox(
_controller,
std::move(items), std::move(items),
std::move(callback))); std::move(callback)));
} }

View File

@ -483,19 +483,21 @@ ActionsFiller::ActionsFiller(
void ActionsFiller::addInviteToGroupAction( void ActionsFiller::addInviteToGroupAction(
not_null<UserData*> user) { not_null<UserData*> user) {
const auto controller = _controller;
AddActionButton( AddActionButton(
_wrap, _wrap,
tr::lng_profile_invite_to_group(), tr::lng_profile_invite_to_group(),
CanInviteBotToGroupValue(user), CanInviteBotToGroupValue(user),
[user] { AddBotToGroupBoxController::Start(user); }); [=] { AddBotToGroupBoxController::Start(controller, user); });
} }
void ActionsFiller::addShareContactAction(not_null<UserData*> user) { void ActionsFiller::addShareContactAction(not_null<UserData*> user) {
const auto controller = _controller;
AddActionButton( AddActionButton(
_wrap, _wrap,
tr::lng_info_share_contact(), tr::lng_info_share_contact(),
CanShareContactValue(user), CanShareContactValue(user),
[user] { Window::PeerMenuShareContactBox(user); }); [=] { Window::PeerMenuShareContactBox(controller, user); });
} }
void ActionsFiller::addEditContactAction(not_null<UserData*> user) { void ActionsFiller::addEditContactAction(not_null<UserData*> user) {
@ -790,14 +792,15 @@ object_ptr<Ui::RpWidget> SetupActions(
} }
void SetupAddChannelMember( void SetupAddChannelMember(
not_null<Window::SessionNavigation*> navigation,
not_null<Ui::RpWidget*> parent, not_null<Ui::RpWidget*> parent,
not_null<ChannelData*> channel) { not_null<ChannelData*> channel) {
auto add = Ui::CreateChild<Ui::IconButton>( auto add = Ui::CreateChild<Ui::IconButton>(
parent.get(), parent.get(),
st::infoMembersAddMember); st::infoMembersAddMember);
add->showOn(CanAddMemberValue(channel)); add->showOn(CanAddMemberValue(channel));
add->addClickHandler([channel] { add->addClickHandler([=] {
Window::PeerMenuAddChannelMembers(channel); Window::PeerMenuAddChannelMembers(navigation, channel);
}); });
parent->widthValue( parent->widthValue(
) | rpl::start_with_next([add](int newWidth) { ) | rpl::start_with_next([add](int newWidth) {
@ -854,7 +857,7 @@ object_ptr<Ui::RpWidget> SetupChannelMembers(
rpl::single(true), rpl::single(true),
std::move(membersCallback))->entity(); std::move(membersCallback))->entity();
SetupAddChannelMember(button, channel); SetupAddChannelMember(controller, button, channel);
object_ptr<FloatingIcon>( object_ptr<FloatingIcon>(
members, members,

View File

@ -324,7 +324,7 @@ void Members::updateHeaderControlsGeometry(int newWidth) {
void Members::addMember() { void Members::addMember() {
if (const auto chat = _peer->asChat()) { if (const auto chat = _peer->asChat()) {
AddParticipantsBoxController::Start(chat); AddParticipantsBoxController::Start(_controller, chat);
} else if (const auto channel = _peer->asChannel()) { } else if (const auto channel = _peer->asChannel()) {
const auto state = _listController->saveState(); const auto state = _listController->saveState();
const auto users = ranges::view::all( const auto users = ranges::view::all(
@ -333,6 +333,7 @@ void Members::addMember() {
return peer->asUser(); return peer->asUser();
}) | ranges::to_vector; }) | ranges::to_vector;
AddParticipantsBoxController::Start( AddParticipantsBoxController::Start(
_controller,
channel, channel,
{ users.begin(), users.end() }); { users.begin(), users.end() });
} }

View File

@ -3244,7 +3244,9 @@ void MainWidget::openPeerByName(
if (msgId == ShowAtGameShareMsgId) { if (msgId == ShowAtGameShareMsgId) {
if (peer->isUser() && peer->asUser()->isBot() && !startToken.isEmpty()) { if (peer->isUser() && peer->asUser()->isBot() && !startToken.isEmpty()) {
peer->asUser()->botInfo->shareGameShortName = startToken; peer->asUser()->botInfo->shareGameShortName = startToken;
AddBotToGroupBoxController::Start(peer->asUser()); AddBotToGroupBoxController::Start(
_controller,
peer->asUser());
} else { } else {
InvokeQueued(this, [this, peer] { InvokeQueued(this, [this, peer] {
_controller->showPeerHistory( _controller->showPeerHistory(
@ -3255,7 +3257,9 @@ void MainWidget::openPeerByName(
} else if (msgId == ShowAtProfileMsgId && !peer->isChannel()) { } else if (msgId == ShowAtProfileMsgId && !peer->isChannel()) {
if (peer->isUser() && peer->asUser()->isBot() && !peer->asUser()->botInfo->cantJoinGroups && !startToken.isEmpty()) { if (peer->isUser() && peer->asUser()->isBot() && !peer->asUser()->botInfo->cantJoinGroups && !startToken.isEmpty()) {
peer->asUser()->botInfo->startGroupToken = startToken; peer->asUser()->botInfo->startGroupToken = startToken;
AddBotToGroupBoxController::Start(peer->asUser()); AddBotToGroupBoxController::Start(
_controller,
peer->asUser());
} else if (peer->isUser() && peer->asUser()->isBot()) { } else if (peer->isUser() && peer->asUser()->isBot()) {
// Always open bot chats, even from mention links. // Always open bot chats, even from mention links.
InvokeQueued(this, [this, peer] { InvokeQueued(this, [this, peer] {
@ -3317,7 +3321,9 @@ void MainWidget::usernameResolveDone(QPair<MsgId, QString> msgIdAndStartToken, c
if (msgId == ShowAtProfileMsgId && !peer->isChannel()) { if (msgId == ShowAtProfileMsgId && !peer->isChannel()) {
if (peer->isUser() && peer->asUser()->isBot() && !peer->asUser()->botInfo->cantJoinGroups && !startToken.isEmpty()) { if (peer->isUser() && peer->asUser()->isBot() && !peer->asUser()->botInfo->cantJoinGroups && !startToken.isEmpty()) {
peer->asUser()->botInfo->startGroupToken = startToken; peer->asUser()->botInfo->startGroupToken = startToken;
AddBotToGroupBoxController::Start(peer->asUser()); AddBotToGroupBoxController::Start(
_controller,
peer->asUser());
} else if (peer->isUser() && peer->asUser()->isBot()) { } else if (peer->isUser() && peer->asUser()->isBot()) {
// Always open bot chats, even from mention links. // Always open bot chats, even from mention links.
InvokeQueued(this, [this, peer] { InvokeQueued(this, [this, peer] {

View File

@ -602,7 +602,7 @@ void MainWindow::onShowNewGroup() {
if (account().sessionExists()) { if (account().sessionExists()) {
Ui::show( Ui::show(
Box<GroupInfoBox>( Box<GroupInfoBox>(
&account().session(), sessionController(),
GroupInfoBox::Type::Group), GroupInfoBox::Type::Group),
LayerOption::KeepOther); LayerOption::KeepOther);
} }
@ -611,10 +611,10 @@ void MainWindow::onShowNewGroup() {
void MainWindow::onShowNewChannel() { void MainWindow::onShowNewChannel() {
if (isHidden()) showFromTray(); if (isHidden()) showFromTray();
if (_main) { if (account().sessionExists()) {
Ui::show( Ui::show(
Box<GroupInfoBox>( Box<GroupInfoBox>(
&account().session(), sessionController(),
GroupInfoBox::Type::Channel), GroupInfoBox::Type::Channel),
LayerOption::KeepOther); LayerOption::KeepOther);
} }

View File

@ -36,6 +36,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_user.h" #include "data/data_user.h"
#include "window/themes/window_theme_preview.h" #include "window/themes/window_theme_preview.h"
#include "window/window_peer_menu.h" #include "window/window_peer_menu.h"
#include "window/window_session_controller.h"
#include "window/window_controller.h" #include "window/window_controller.h"
#include "main/main_account.h" // Account::sessionValue. #include "main/main_account.h" // Account::sessionValue.
#include "base/unixtime.h" #include "base/unixtime.h"
@ -1260,7 +1261,9 @@ void OverlayWidget::onForward() {
} }
close(); close();
Window::ShowForwardMessagesBox({ 1, item->fullId() }); Window::ShowForwardMessagesBox(
App::wnd()->sessionController(),
{ 1, item->fullId() });
} }
void OverlayWidget::onDelete() { void OverlayWidget::onDelete() {

View File

@ -673,7 +673,7 @@ void MainWindow::createGlobalMenu() {
if (!account().sessionExists()) { if (!account().sessionExists()) {
return; return;
} }
Ui::show(Box<PeerListBox>(std::make_unique<ContactsBoxController>(), [](not_null<PeerListBox*> box) { Ui::show(Box<PeerListBox>(std::make_unique<ContactsBoxController>(sessionController()), [](not_null<PeerListBox*> box) {
box->addButton(tr::lng_close(), [box] { box->closeBox(); }); box->addButton(tr::lng_close(), [box] { box->closeBox(); });
box->addLeftButton(tr::lng_profile_add_contact(), [] { App::wnd()->onShowAddContact(); }); box->addLeftButton(tr::lng_profile_add_contact(), [] { App::wnd()->onShowAddContact(); });
})); }));

View File

@ -46,6 +46,10 @@ class BlockUserBoxController
: public ChatsListBoxController : public ChatsListBoxController
, private base::Subscriber { , private base::Subscriber {
public: public:
explicit BlockUserBoxController(
not_null<Window::SessionNavigation*> navigation);
Main::Session &session() const override;
void rowClicked(not_null<PeerListRow*> row) override; void rowClicked(not_null<PeerListRow*> row) override;
void setBlockUserCallback(Fn<void(not_null<UserData*> user)> callback) { void setBlockUserCallback(Fn<void(not_null<UserData*> user)> callback) {
@ -63,10 +67,21 @@ protected:
private: private:
void updateIsBlocked(not_null<PeerListRow*> row, UserData *user) const; void updateIsBlocked(not_null<PeerListRow*> row, UserData *user) const;
const not_null<Window::SessionNavigation*> _navigation;
Fn<void(not_null<UserData*> user)> _blockUserCallback; Fn<void(not_null<UserData*> user)> _blockUserCallback;
}; };
BlockUserBoxController::BlockUserBoxController(
not_null<Window::SessionNavigation*> navigation)
: ChatsListBoxController(navigation)
, _navigation(navigation) {
}
Main::Session &BlockUserBoxController::session() const {
return _navigation->session();
}
void BlockUserBoxController::prepareViewHook() { void BlockUserBoxController::prepareViewHook() {
delegate()->peerListSetTitle(tr::lng_blocked_list_add_title()); delegate()->peerListSetTitle(tr::lng_blocked_list_add_title());
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(Notify::PeerUpdate::Flag::UserIsBlocked, [this](const Notify::PeerUpdate &update) { subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(Notify::PeerUpdate::Flag::UserIsBlocked, [this](const Notify::PeerUpdate &update) {
@ -160,6 +175,10 @@ BlockedBoxController::BlockedBoxController(
: _window(window) { : _window(window) {
} }
Main::Session &BlockedBoxController::session() const {
return _window->session();
}
void BlockedBoxController::prepare() { void BlockedBoxController::prepare() {
delegate()->peerListSetTitle(tr::lng_blocked_list_title()); delegate()->peerListSetTitle(tr::lng_blocked_list_title());
setDescriptionText(tr::lng_contacts_loading(tr::now)); setDescriptionText(tr::lng_contacts_loading(tr::now));
@ -262,7 +281,7 @@ void BlockedBoxController::handleBlockedEvent(not_null<UserData*> user) {
void BlockedBoxController::BlockNewUser( void BlockedBoxController::BlockNewUser(
not_null<Window::SessionController*> window) { not_null<Window::SessionController*> window) {
auto controller = std::make_unique<BlockUserBoxController>(); auto controller = std::make_unique<BlockUserBoxController>(window);
auto initBox = [=, controller = controller.get()]( auto initBox = [=, controller = controller.get()](
not_null<PeerListBox*> box) { not_null<PeerListBox*> box) {
controller->setBlockUserCallback([=](not_null<UserData*> user) { controller->setBlockUserCallback([=](not_null<UserData*> user) {

View File

@ -14,11 +14,15 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace Settings { namespace Settings {
class BlockedBoxController : public PeerListController, private base::Subscriber, private MTP::Sender { class BlockedBoxController
: public PeerListController
, private base::Subscriber
, private MTP::Sender {
public: public:
explicit BlockedBoxController( explicit BlockedBoxController(
not_null<Window::SessionController*> window); not_null<Window::SessionController*> window);
Main::Session &session() const override;
void prepare() override; void prepare() override;
void rowClicked(not_null<PeerListRow*> row) override; void rowClicked(not_null<PeerListRow*> row) override;
void rowActionClicked(not_null<PeerListRow*> row) override; void rowActionClicked(not_null<PeerListRow*> row) override;

View File

@ -448,7 +448,9 @@ void SetupSelfDestruction(
label(), label(),
st::settingsButton st::settingsButton
)->addClickHandler([=] { )->addClickHandler([=] {
Ui::show(Box<SelfDestructionBox>(session->api().selfDestructValue())); Ui::show(Box<SelfDestructionBox>(
session,
session->api().selfDestructValue()));
}); });
AddSkip(container); AddSkip(container);
@ -464,8 +466,8 @@ void SetupSessionsList(
container, container,
tr::lng_settings_show_sessions(), tr::lng_settings_show_sessions(),
st::settingsButton st::settingsButton
)->addClickHandler([] { )->addClickHandler([=] {
Ui::show(Box<SessionsBox>()); Ui::show(Box<SessionsBox>(&controller->session()));
}); });
AddSkip(container, st::settingsPrivacySecurityPadding); AddSkip(container, st::settingsPrivacySecurityPadding);
AddDividerText(container, tr::lng_settings_sessions_about()); AddDividerText(container, tr::lng_settings_sessions_about());

View File

@ -235,21 +235,22 @@ MainMenu::MainMenu(
void MainMenu::refreshMenu() { void MainMenu::refreshMenu() {
_menu->clearActions(); _menu->clearActions();
if (!_controller->session().supportMode()) { if (!_controller->session().supportMode()) {
const auto controller = _controller;
_menu->addAction(tr::lng_create_group_title(tr::now), [] { _menu->addAction(tr::lng_create_group_title(tr::now), [] {
App::wnd()->onShowNewGroup(); App::wnd()->onShowNewGroup();
}, &st::mainMenuNewGroup, &st::mainMenuNewGroupOver); }, &st::mainMenuNewGroup, &st::mainMenuNewGroupOver);
_menu->addAction(tr::lng_create_channel_title(tr::now), [] { _menu->addAction(tr::lng_create_channel_title(tr::now), [] {
App::wnd()->onShowNewChannel(); App::wnd()->onShowNewChannel();
}, &st::mainMenuNewChannel, &st::mainMenuNewChannelOver); }, &st::mainMenuNewChannel, &st::mainMenuNewChannelOver);
_menu->addAction(tr::lng_menu_contacts(tr::now), [] { _menu->addAction(tr::lng_menu_contacts(tr::now), [=] {
Ui::show(Box<PeerListBox>(std::make_unique<ContactsBoxController>(), [](not_null<PeerListBox*> box) { Ui::show(Box<PeerListBox>(std::make_unique<ContactsBoxController>(controller), [](not_null<PeerListBox*> box) {
box->addButton(tr::lng_close(), [box] { box->closeBox(); }); box->addButton(tr::lng_close(), [box] { box->closeBox(); });
box->addLeftButton(tr::lng_profile_add_contact(), [] { App::wnd()->onShowAddContact(); }); box->addLeftButton(tr::lng_profile_add_contact(), [] { App::wnd()->onShowAddContact(); });
})); }));
}, &st::mainMenuContacts, &st::mainMenuContactsOver); }, &st::mainMenuContacts, &st::mainMenuContactsOver);
if (Global::PhoneCallsEnabled()) { if (Global::PhoneCallsEnabled()) {
_menu->addAction(tr::lng_menu_calls(tr::now), [] { _menu->addAction(tr::lng_menu_calls(tr::now), [=] {
Ui::show(Box<PeerListBox>(std::make_unique<Calls::BoxController>(), [](not_null<PeerListBox*> box) { Ui::show(Box<PeerListBox>(std::make_unique<Calls::BoxController>(controller), [](not_null<PeerListBox*> box) {
box->addButton(tr::lng_close(), [=] { box->addButton(tr::lng_close(), [=] {
box->closeBox(); box->closeBox();
}); });

View File

@ -119,8 +119,10 @@ History *FindWastedPin(not_null<Data::Session*> data, Data::Folder *folder) {
return nullptr; return nullptr;
} }
void AddChatMembers(not_null<ChatData*> chat) { void AddChatMembers(
AddParticipantsBoxController::Start(chat); not_null<Window::SessionNavigation*> navigation,
not_null<ChatData*> chat) {
AddParticipantsBoxController::Start(navigation, chat);
} }
bool PinnedLimitReached(Dialogs::Key key) { bool PinnedLimitReached(Dialogs::Key key) {
@ -371,6 +373,7 @@ void Filler::addBlockUser(not_null<UserData*> user) {
} }
void Filler::addUserActions(not_null<UserData*> user) { void Filler::addUserActions(not_null<UserData*> user) {
const auto controller = _controller;
const auto window = &_controller->window()->controller(); const auto window = &_controller->window()->controller();
if (_source != PeerMenuSource::ChatsList) { if (_source != PeerMenuSource::ChatsList) {
if (user->session().supportMode()) { if (user->session().supportMode()) {
@ -386,7 +389,7 @@ void Filler::addUserActions(not_null<UserData*> user) {
if (user->canShareThisContact()) { if (user->canShareThisContact()) {
_addAction( _addAction(
tr::lng_info_share_contact(tr::now), tr::lng_info_share_contact(tr::now),
[=] { PeerMenuShareContactBox(user); }); [=] { PeerMenuShareContactBox(controller, user); });
} }
if (user->isContact() && !user->isSelf()) { if (user->isContact() && !user->isSelf()) {
_addAction( _addAction(
@ -397,9 +400,10 @@ void Filler::addUserActions(not_null<UserData*> user) {
[=] { PeerMenuDeleteContact(user); }); [=] { PeerMenuDeleteContact(user); });
} }
if (user->isBot() && !user->botInfo->cantJoinGroups) { if (user->isBot() && !user->botInfo->cantJoinGroups) {
using AddBotToGroup = AddBotToGroupBoxController;
_addAction( _addAction(
tr::lng_profile_invite_to_group(tr::now), tr::lng_profile_invite_to_group(tr::now),
[=] { AddBotToGroupBoxController::Start(user); }); [=] { AddBotToGroup::Start(controller, user); });
} }
if (user->canExportChatHistory()) { if (user->canExportChatHistory()) {
_addAction( _addAction(
@ -432,7 +436,7 @@ void Filler::addChatActions(not_null<ChatData*> chat) {
if (chat->canAddMembers()) { if (chat->canAddMembers()) {
_addAction( _addAction(
tr::lng_profile_add_participant(tr::now), tr::lng_profile_add_participant(tr::now),
[chat] { AddChatMembers(chat); }); [=] { AddChatMembers(controller, chat); });
} }
if (chat->canSendPolls()) { if (chat->canSendPolls()) {
_addAction( _addAction(
@ -454,7 +458,8 @@ void Filler::addChatActions(not_null<ChatData*> chat) {
} }
void Filler::addChannelActions(not_null<ChannelData*> channel) { void Filler::addChannelActions(not_null<ChannelData*> channel) {
auto isGroup = channel->isMegagroup(); const auto isGroup = channel->isMegagroup();
const auto navigation = _controller;
//if (!isGroup) { // #feed //if (!isGroup) { // #feed
// const auto feed = channel->feed(); // const auto feed = channel->feed();
// const auto grouped = (feed != nullptr); // const auto grouped = (feed != nullptr);
@ -477,7 +482,7 @@ void Filler::addChannelActions(not_null<ChannelData*> channel) {
if (channel->canAddMembers()) { if (channel->canAddMembers()) {
_addAction( _addAction(
tr::lng_channel_add_members(tr::now), tr::lng_channel_add_members(tr::now),
[channel] { PeerMenuAddChannelMembers(channel); }); [=] { PeerMenuAddChannelMembers(navigation, channel); });
} }
if (channel->canSendPolls()) { if (channel->canSendPolls()) {
_addAction( _addAction(
@ -649,7 +654,9 @@ void PeerMenuDeleteContact(not_null<UserData*> user) {
deleteSure)); deleteSure));
} }
void PeerMenuShareContactBox(not_null<UserData*> user) { void PeerMenuShareContactBox(
not_null<Window::SessionNavigation*> navigation,
not_null<UserData*> user) {
const auto weak = std::make_shared<QPointer<PeerListBox>>(); const auto weak = std::make_shared<QPointer<PeerListBox>>();
auto callback = [=](not_null<PeerData*> peer) { auto callback = [=](not_null<PeerData*> peer) {
if (!peer->canWrite()) { if (!peer->canWrite()) {
@ -680,9 +687,11 @@ void PeerMenuShareContactBox(not_null<UserData*> user) {
}), LayerOption::KeepOther); }), LayerOption::KeepOther);
}; };
*weak = Ui::show(Box<PeerListBox>( *weak = Ui::show(Box<PeerListBox>(
std::make_unique<ChooseRecipientBoxController>(std::move(callback)), std::make_unique<ChooseRecipientBoxController>(
navigation,
std::move(callback)),
[](not_null<PeerListBox*> box) { [](not_null<PeerListBox*> box) {
box->addButton(tr::lng_cancel(), [box] { box->addButton(tr::lng_cancel(), [=] {
box->closeBox(); box->closeBox();
}); });
})); }));
@ -798,6 +807,7 @@ void PeerMenuUnblockUserWithBotRestart(not_null<UserData*> user) {
} }
QPointer<Ui::RpWidget> ShowForwardMessagesBox( QPointer<Ui::RpWidget> ShowForwardMessagesBox(
not_null<Window::SessionNavigation*> navigation,
MessageIdsList &&items, MessageIdsList &&items,
FnMut<void()> &&successCallback) { FnMut<void()> &&successCallback) {
const auto weak = std::make_shared<QPointer<PeerListBox>>(); const auto weak = std::make_shared<QPointer<PeerListBox>>();
@ -832,12 +842,16 @@ QPointer<Ui::RpWidget> ShowForwardMessagesBox(
}); });
}; };
*weak = Ui::show(Box<PeerListBox>( *weak = Ui::show(Box<PeerListBox>(
std::make_unique<ChooseRecipientBoxController>(std::move(callback)), std::make_unique<ChooseRecipientBoxController>(
navigation,
std::move(callback)),
std::move(initBox)), LayerOption::KeepOther); std::move(initBox)), LayerOption::KeepOther);
return weak->data(); return weak->data();
} }
void PeerMenuAddChannelMembers(not_null<ChannelData*> channel) { void PeerMenuAddChannelMembers(
not_null<Window::SessionNavigation*> navigation,
not_null<ChannelData*> channel) {
if (!channel->isMegagroup() if (!channel->isMegagroup()
&& channel->membersCount() >= Global::ChatSizeMax()) { && channel->membersCount() >= Global::ChatSizeMax()) {
Ui::show( Ui::show(
@ -864,6 +878,7 @@ void PeerMenuAddChannelMembers(not_null<ChannelData*> channel) {
}) | ranges::to_vector; }) | ranges::to_vector;
AddParticipantsBoxController::Start( AddParticipantsBoxController::Start(
navigation,
channel, channel,
{ already.begin(), already.end() }); { already.begin(), already.end() });
}); });

View File

@ -21,6 +21,7 @@ namespace Window {
class Controller; class Controller;
class SessionController; class SessionController;
class SessionNavigation;
enum class PeerMenuSource { enum class PeerMenuSource {
ChatsList, ChatsList,
@ -49,8 +50,12 @@ void PeerMenuAddMuteAction(
void PeerMenuExportChat(not_null<PeerData*> peer); void PeerMenuExportChat(not_null<PeerData*> peer);
void PeerMenuDeleteContact(not_null<UserData*> user); void PeerMenuDeleteContact(not_null<UserData*> user);
void PeerMenuShareContactBox(not_null<UserData*> user); void PeerMenuShareContactBox(
void PeerMenuAddChannelMembers(not_null<ChannelData*> channel); not_null<Window::SessionNavigation*> navigation,
not_null<UserData*> user);
void PeerMenuAddChannelMembers(
not_null<Window::SessionNavigation*> navigation,
not_null<ChannelData*> channel);
//void PeerMenuUngroupFeed(not_null<Data::Feed*> feed); // #feed //void PeerMenuUngroupFeed(not_null<Data::Feed*> feed); // #feed
void PeerMenuCreatePoll(not_null<PeerData*> peer); void PeerMenuCreatePoll(not_null<PeerData*> peer);
void PeerMenuBlockUserBox( void PeerMenuBlockUserBox(
@ -65,6 +70,7 @@ Fn<void()> ClearHistoryHandler(not_null<PeerData*> peer);
Fn<void()> DeleteAndLeaveHandler(not_null<PeerData*> peer); Fn<void()> DeleteAndLeaveHandler(not_null<PeerData*> peer);
QPointer<Ui::RpWidget> ShowForwardMessagesBox( QPointer<Ui::RpWidget> ShowForwardMessagesBox(
not_null<Window::SessionNavigation*> navigation,
MessageIdsList &&items, MessageIdsList &&items,
FnMut<void()> &&successCallback = nullptr); FnMut<void()> &&successCallback = nullptr);

View File

@ -107,7 +107,7 @@ SessionController::SessionController(
subscribe(session->api().fullPeerUpdated(), [=](PeerData *peer) { subscribe(session->api().fullPeerUpdated(), [=](PeerData *peer) {
if (peer == _showEditPeer) { if (peer == _showEditPeer) {
_showEditPeer = nullptr; _showEditPeer = nullptr;
Ui::show(Box<EditPeerInfoBox>(peer)); Ui::show(Box<EditPeerInfoBox>(this, peer));
} }
}); });