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