mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 14:38:15 +00:00
Move some calls from App namespace.
This commit is contained in:
@@ -586,7 +586,7 @@ void MainWindow::launchDrag(std::unique_ptr<QMimeData> data) {
|
||||
|
||||
void MainWindow::checkAuthSession() {
|
||||
if (AuthSession::Exists()) {
|
||||
_controller = std::make_unique<Window::Controller>(this);
|
||||
_controller = std::make_unique<Window::Controller>(&Auth(), this);
|
||||
} else {
|
||||
_controller = nullptr;
|
||||
}
|
||||
|
@@ -396,7 +396,7 @@ Manager::DisplayOptions Manager::getNotificationOptions(HistoryItem *item) {
|
||||
void Manager::notificationActivated(PeerId peerId, MsgId msgId) {
|
||||
onBeforeNotificationActivated(peerId, msgId);
|
||||
if (auto window = App::wnd()) {
|
||||
auto history = App::history(peerId);
|
||||
auto history = Auth().data().history(peerId);
|
||||
window->showFromTray();
|
||||
window->reActivateWindow();
|
||||
if (Messenger::Instance().locked()) {
|
||||
@@ -447,7 +447,7 @@ void Manager::notificationReplied(
|
||||
const TextWithTags &reply) {
|
||||
if (!peerId) return;
|
||||
|
||||
const auto history = App::history(peerId);
|
||||
const auto history = Auth().data().history(peerId);
|
||||
|
||||
auto message = ApiWrap::MessageToSend(history);
|
||||
message.textWithTags = reply;
|
||||
|
@@ -50,10 +50,61 @@ void DateClickHandler::onClick(ClickContext context) const {
|
||||
App::wnd()->controller()->showJumpToDate(_chat, _date);
|
||||
}
|
||||
|
||||
Controller::Controller(not_null<MainWindow*> window)
|
||||
: _window(window) {
|
||||
Auth().data().animationPlayInlineRequest(
|
||||
) | rpl::start_with_next([this](auto item) {
|
||||
Navigation::Navigation(not_null<AuthSession*> session) : _session(session) {
|
||||
}
|
||||
|
||||
AuthSession &Navigation::session() const {
|
||||
return *_session;
|
||||
}
|
||||
|
||||
void Navigation::showPeerInfo(
|
||||
PeerId peerId,
|
||||
const SectionShow ¶ms) {
|
||||
//if (Adaptive::ThreeColumn()
|
||||
// && !_session->settings().thirdSectionInfoEnabled()) {
|
||||
// _session->settings().setThirdSectionInfoEnabled(true);
|
||||
// _session->saveSettingsDelayed();
|
||||
//}
|
||||
showSection(Info::Memento(peerId), params);
|
||||
}
|
||||
|
||||
void Navigation::showPeerInfo(
|
||||
not_null<PeerData*> peer,
|
||||
const SectionShow ¶ms) {
|
||||
showPeerInfo(peer->id, params);
|
||||
}
|
||||
|
||||
void Navigation::showPeerInfo(
|
||||
not_null<History*> history,
|
||||
const SectionShow ¶ms) {
|
||||
showPeerInfo(history->peer->id, params);
|
||||
}
|
||||
|
||||
void Navigation::showSettings(
|
||||
Settings::Type type,
|
||||
const SectionShow ¶ms) {
|
||||
showSection(
|
||||
Info::Memento(
|
||||
Info::Settings::Tag{ _session->user() },
|
||||
Info::Section(type)),
|
||||
params);
|
||||
}
|
||||
|
||||
void Navigation::showSettings(const SectionShow ¶ms) {
|
||||
showSettings(Settings::Type::Main, params);
|
||||
}
|
||||
|
||||
Controller::Controller(
|
||||
not_null<AuthSession*> session,
|
||||
not_null<MainWindow*> window)
|
||||
: Navigation(session)
|
||||
, _window(window) {
|
||||
init();
|
||||
}
|
||||
|
||||
void Controller::init() {
|
||||
session().data().animationPlayInlineRequest(
|
||||
) | rpl::start_with_next([=](auto item) {
|
||||
if (const auto video = roundVideo(item)) {
|
||||
video->pauseResume();
|
||||
} else {
|
||||
@@ -61,13 +112,13 @@ Controller::Controller(not_null<MainWindow*> window)
|
||||
}
|
||||
}, lifetime());
|
||||
|
||||
if (Auth().supportMode()) {
|
||||
if (session().supportMode()) {
|
||||
initSupportMode();
|
||||
}
|
||||
}
|
||||
|
||||
void Controller::initSupportMode() {
|
||||
Auth().supportHelper().registerWindow(this);
|
||||
session().supportHelper().registerWindow(this);
|
||||
|
||||
Shortcuts::Requests(
|
||||
) | rpl::start_with_next([=](not_null<Shortcuts::Request*> request) {
|
||||
@@ -84,7 +135,7 @@ void Controller::initSupportMode() {
|
||||
|
||||
void Controller::setActiveChatEntry(Dialogs::RowDescriptor row) {
|
||||
_activeChatEntry = row;
|
||||
if (Auth().supportMode()) {
|
||||
if (session().supportMode()) {
|
||||
pushToChatEntryHistory(row);
|
||||
}
|
||||
}
|
||||
@@ -229,8 +280,8 @@ Controller::ColumnLayout Controller::computeColumnLayout() const {
|
||||
if (bodyWidth < minimalThreeColumnWidth()) {
|
||||
return true;
|
||||
}
|
||||
if (!Auth().settings().tabbedSelectorSectionEnabled()
|
||||
&& !Auth().settings().thirdSectionInfoEnabled()) {
|
||||
if (!session().settings().tabbedSelectorSectionEnabled()
|
||||
&& !session().settings().thirdSectionInfoEnabled()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -260,14 +311,14 @@ Controller::ColumnLayout Controller::computeColumnLayout() const {
|
||||
}
|
||||
|
||||
int Controller::countDialogsWidthFromRatio(int bodyWidth) const {
|
||||
auto result = qRound(bodyWidth * Auth().settings().dialogsWidthRatio());
|
||||
auto result = qRound(bodyWidth * session().settings().dialogsWidthRatio());
|
||||
accumulate_max(result, st::columnMinimalWidthLeft);
|
||||
// accumulate_min(result, st::columnMaximalWidthLeft);
|
||||
return result;
|
||||
}
|
||||
|
||||
int Controller::countThirdColumnWidthFromRatio(int bodyWidth) const {
|
||||
auto result = Auth().settings().thirdColumnWidth();
|
||||
auto result = session().settings().thirdColumnWidth();
|
||||
accumulate_max(result, st::columnMinimalWidthThird);
|
||||
accumulate_min(result, st::columnMaximalWidthThird);
|
||||
return result;
|
||||
@@ -320,11 +371,11 @@ void Controller::resizeForThirdSection() {
|
||||
|
||||
auto layout = computeColumnLayout();
|
||||
auto tabbedSelectorSectionEnabled =
|
||||
Auth().settings().tabbedSelectorSectionEnabled();
|
||||
session().settings().tabbedSelectorSectionEnabled();
|
||||
auto thirdSectionInfoEnabled =
|
||||
Auth().settings().thirdSectionInfoEnabled();
|
||||
Auth().settings().setTabbedSelectorSectionEnabled(false);
|
||||
Auth().settings().setThirdSectionInfoEnabled(false);
|
||||
session().settings().thirdSectionInfoEnabled();
|
||||
session().settings().setTabbedSelectorSectionEnabled(false);
|
||||
session().settings().setThirdSectionInfoEnabled(false);
|
||||
|
||||
auto wanted = countThirdColumnWidthFromRatio(layout.bodyWidth);
|
||||
auto minimal = st::columnMinimalWidthThird;
|
||||
@@ -345,20 +396,20 @@ void Controller::resizeForThirdSection() {
|
||||
return window()->tryToExtendWidthBy(minimal);
|
||||
}();
|
||||
if (extendedBy) {
|
||||
if (extendBy != Auth().settings().thirdColumnWidth()) {
|
||||
Auth().settings().setThirdColumnWidth(extendBy);
|
||||
if (extendBy != session().settings().thirdColumnWidth()) {
|
||||
session().settings().setThirdColumnWidth(extendBy);
|
||||
}
|
||||
auto newBodyWidth = layout.bodyWidth + extendedBy;
|
||||
auto currentRatio = Auth().settings().dialogsWidthRatio();
|
||||
Auth().settings().setDialogsWidthRatio(
|
||||
auto currentRatio = session().settings().dialogsWidthRatio();
|
||||
session().settings().setDialogsWidthRatio(
|
||||
(currentRatio * layout.bodyWidth) / newBodyWidth);
|
||||
}
|
||||
auto savedValue = (extendedBy == extendBy) ? -1 : extendedBy;
|
||||
Auth().settings().setThirdSectionExtendedBy(savedValue);
|
||||
session().settings().setThirdSectionExtendedBy(savedValue);
|
||||
|
||||
Auth().settings().setTabbedSelectorSectionEnabled(
|
||||
session().settings().setTabbedSelectorSectionEnabled(
|
||||
tabbedSelectorSectionEnabled);
|
||||
Auth().settings().setThirdSectionInfoEnabled(
|
||||
session().settings().setThirdSectionInfoEnabled(
|
||||
thirdSectionInfoEnabled);
|
||||
}
|
||||
|
||||
@@ -368,23 +419,23 @@ void Controller::closeThirdSection() {
|
||||
if (layout.windowLayout == Adaptive::WindowLayout::ThreeColumn) {
|
||||
auto noResize = window()->isFullScreen()
|
||||
|| window()->isMaximized();
|
||||
auto savedValue = Auth().settings().thirdSectionExtendedBy();
|
||||
auto savedValue = session().settings().thirdSectionExtendedBy();
|
||||
auto extendedBy = (savedValue == -1)
|
||||
? layout.thirdWidth
|
||||
: savedValue;
|
||||
auto newBodyWidth = noResize
|
||||
? layout.bodyWidth
|
||||
: (layout.bodyWidth - extendedBy);
|
||||
auto currentRatio = Auth().settings().dialogsWidthRatio();
|
||||
Auth().settings().setDialogsWidthRatio(
|
||||
auto currentRatio = session().settings().dialogsWidthRatio();
|
||||
session().settings().setDialogsWidthRatio(
|
||||
(currentRatio * layout.bodyWidth) / newBodyWidth);
|
||||
newWindowSize = QSize(
|
||||
window()->width() + (newBodyWidth - layout.bodyWidth),
|
||||
window()->height());
|
||||
}
|
||||
Auth().settings().setTabbedSelectorSectionEnabled(false);
|
||||
Auth().settings().setThirdSectionInfoEnabled(false);
|
||||
Auth().saveSettingsDelayed();
|
||||
session().settings().setTabbedSelectorSectionEnabled(false);
|
||||
session().settings().setThirdSectionInfoEnabled(false);
|
||||
session().saveSettingsDelayed();
|
||||
if (window()->size() != newWindowSize) {
|
||||
window()->resize(newWindowSize);
|
||||
} else {
|
||||
@@ -400,7 +451,7 @@ void Controller::showJumpToDate(Dialogs::Key chat, QDate requestedDate) {
|
||||
} else if (history->loadedAtTop()
|
||||
&& !history->isEmpty()
|
||||
&& history->peer->migrateFrom()) {
|
||||
if (const auto migrated = App::historyLoaded(history->peer->migrateFrom())) {
|
||||
if (const auto migrated = history->owner().historyLoaded(history->peer->migrateFrom())) {
|
||||
if (migrated->scrollTopItem) {
|
||||
// We're up in the migrated history.
|
||||
// So current date is the date of first message here.
|
||||
@@ -422,7 +473,7 @@ void Controller::showJumpToDate(Dialogs::Key chat, QDate requestedDate) {
|
||||
const auto maxPeerDate = [](Dialogs::Key chat) {
|
||||
if (auto history = chat.history()) {
|
||||
if (const auto channel = history->peer->migrateTo()) {
|
||||
history = App::historyLoaded(channel);
|
||||
history = channel->owner().historyLoaded(channel);
|
||||
}
|
||||
if (history && history->chatListTimeId() != 0) {
|
||||
return ParseDateTime(history->chatListTimeId()).date();
|
||||
@@ -441,7 +492,7 @@ void Controller::showJumpToDate(Dialogs::Key chat, QDate requestedDate) {
|
||||
};
|
||||
if (const auto history = chat.history()) {
|
||||
if (const auto chat = history->peer->migrateFrom()) {
|
||||
if (const auto history = App::historyLoaded(chat)) {
|
||||
if (const auto history = chat->owner().historyLoaded(chat)) {
|
||||
if (history->loadedAtTop()) {
|
||||
if (!history->isEmpty()) {
|
||||
return history->blocks.front()->messages.front()->dateTime().date();
|
||||
@@ -467,7 +518,7 @@ void Controller::showJumpToDate(Dialogs::Key chat, QDate requestedDate) {
|
||||
: requestedDate;
|
||||
const auto month = highlighted;
|
||||
auto callback = [=](const QDate &date) {
|
||||
Auth().api().jumpToDate(chat, date);
|
||||
session().api().jumpToDate(chat, date);
|
||||
};
|
||||
auto box = Box<CalendarBox>(
|
||||
month,
|
||||
@@ -523,43 +574,6 @@ void Controller::showPeerHistory(
|
||||
msgId);
|
||||
}
|
||||
|
||||
void Navigation::showPeerInfo(
|
||||
PeerId peerId,
|
||||
const SectionShow ¶ms) {
|
||||
//if (Adaptive::ThreeColumn()
|
||||
// && !Auth().settings().thirdSectionInfoEnabled()) {
|
||||
// Auth().settings().setThirdSectionInfoEnabled(true);
|
||||
// Auth().saveSettingsDelayed();
|
||||
//}
|
||||
showSection(Info::Memento(peerId), params);
|
||||
}
|
||||
|
||||
void Navigation::showPeerInfo(
|
||||
not_null<PeerData*> peer,
|
||||
const SectionShow ¶ms) {
|
||||
showPeerInfo(peer->id, params);
|
||||
}
|
||||
|
||||
void Navigation::showPeerInfo(
|
||||
not_null<History*> history,
|
||||
const SectionShow ¶ms) {
|
||||
showPeerInfo(history->peer->id, params);
|
||||
}
|
||||
|
||||
void Navigation::showSettings(
|
||||
Settings::Type type,
|
||||
const SectionShow ¶ms) {
|
||||
showSection(
|
||||
Info::Memento(
|
||||
Info::Settings::Tag{ Auth().user() },
|
||||
Info::Section(type)),
|
||||
params);
|
||||
}
|
||||
|
||||
void Navigation::showSettings(const SectionShow ¶ms) {
|
||||
showSettings(Settings::Type::Main, params);
|
||||
}
|
||||
|
||||
void Controller::showSection(
|
||||
SectionMemento &&memento,
|
||||
const SectionShow ¶ms) {
|
||||
|
@@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "base/flags.h"
|
||||
#include "dialogs/dialogs_key.h"
|
||||
|
||||
class AuthSession;
|
||||
class MainWidget;
|
||||
class HistoryMessage;
|
||||
class HistoryService;
|
||||
@@ -103,6 +104,10 @@ class Controller;
|
||||
|
||||
class Navigation {
|
||||
public:
|
||||
explicit Navigation(not_null<AuthSession*> session);
|
||||
|
||||
AuthSession &session() const;
|
||||
|
||||
virtual void showSection(
|
||||
SectionMemento &&memento,
|
||||
const SectionShow ¶ms = SectionShow()) = 0;
|
||||
@@ -127,11 +132,16 @@ public:
|
||||
|
||||
virtual ~Navigation() = default;
|
||||
|
||||
private:
|
||||
const not_null<AuthSession*> _session;
|
||||
|
||||
};
|
||||
|
||||
class Controller : public Navigation {
|
||||
public:
|
||||
Controller(not_null<MainWindow*> window);
|
||||
Controller(
|
||||
not_null<AuthSession*> session,
|
||||
not_null<MainWindow*> window);
|
||||
|
||||
not_null<MainWindow*> window() const {
|
||||
return _window;
|
||||
@@ -260,6 +270,7 @@ public:
|
||||
~Controller();
|
||||
|
||||
private:
|
||||
void init();
|
||||
void initSupportMode();
|
||||
|
||||
int minimalThreeColumnWidth() const;
|
||||
@@ -278,7 +289,7 @@ private:
|
||||
void pushToChatEntryHistory(Dialogs::RowDescriptor row);
|
||||
bool chatEntryHistoryMove(int steps);
|
||||
|
||||
not_null<MainWindow*> _window;
|
||||
const not_null<MainWindow*> _window;
|
||||
|
||||
std::unique_ptr<Passport::FormController> _passportForm;
|
||||
|
||||
|
@@ -188,7 +188,7 @@ bool Filler::showInfo() {
|
||||
void Filler::addPinToggle() {
|
||||
auto peer = _peer;
|
||||
auto isPinned = false;
|
||||
if (auto history = App::historyLoaded(peer)) {
|
||||
if (auto history = peer->owner().historyLoaded(peer)) {
|
||||
isPinned = history->isPinnedDialog();
|
||||
}
|
||||
auto pinText = [](bool isPinned) {
|
||||
@@ -197,7 +197,7 @@ void Filler::addPinToggle() {
|
||||
: lng_context_pin_to_top);
|
||||
};
|
||||
auto pinToggle = [=] {
|
||||
TogglePinnedDialog(App::history(peer));
|
||||
TogglePinnedDialog(peer->owner().history(peer));
|
||||
};
|
||||
auto pinAction = _addAction(pinText(isPinned), pinToggle);
|
||||
|
||||
@@ -206,7 +206,7 @@ void Filler::addPinToggle() {
|
||||
peer,
|
||||
Notify::PeerUpdate::Flag::ChatPinnedChanged
|
||||
) | rpl::start_with_next([peer, pinAction, pinText] {
|
||||
auto isPinned = App::history(peer)->isPinnedDialog();
|
||||
auto isPinned = peer->owner().history(peer)->isPinnedDialog();
|
||||
pinAction->setText(pinText(isPinned));
|
||||
}, *lifetime);
|
||||
}
|
||||
@@ -226,14 +226,14 @@ void Filler::addInfo() {
|
||||
|
||||
void Filler::addSearch() {
|
||||
_addAction(lang(lng_profile_search_messages), [peer = _peer] {
|
||||
App::main()->searchInChat(App::history(peer));
|
||||
App::main()->searchInChat(peer->owner().history(peer));
|
||||
});
|
||||
}
|
||||
|
||||
void Filler::addToggleUnreadMark() {
|
||||
const auto peer = _peer;
|
||||
const auto isUnread = [](not_null<PeerData*> peer) {
|
||||
if (const auto history = App::historyLoaded(peer)) {
|
||||
if (const auto history = peer->owner().historyLoaded(peer)) {
|
||||
return (history->chatListUnreadCount() > 0)
|
||||
|| (history->chatListUnreadMark());
|
||||
}
|
||||
@@ -253,7 +253,7 @@ void Filler::addToggleUnreadMark() {
|
||||
Auth().api().changeDialogUnreadMark(history, !markAsRead);
|
||||
}
|
||||
};
|
||||
const auto history = App::history(peer);
|
||||
const auto history = peer->owner().history(peer);
|
||||
handle(history);
|
||||
if (markAsRead) {
|
||||
if (const auto migrated = history->migrateSibling()) {
|
||||
@@ -447,7 +447,7 @@ void Filler::addChannelActions(not_null<ChannelData*> channel) {
|
||||
|
||||
void Filler::fill() {
|
||||
if (_source == PeerMenuSource::ChatsList) {
|
||||
if (const auto history = App::historyLoaded(_peer)) {
|
||||
if (const auto history = _peer->owner().historyLoaded(_peer)) {
|
||||
if (!history->useProxyPromotion()) {
|
||||
addPinToggle();
|
||||
}
|
||||
@@ -598,7 +598,7 @@ void PeerMenuShareContactBox(not_null<UserData*> user) {
|
||||
LayerOption::KeepOther);
|
||||
return;
|
||||
} else if (peer->isSelf()) {
|
||||
auto options = ApiWrap::SendOptions(App::history(peer));
|
||||
auto options = ApiWrap::SendOptions(peer->owner().history(peer));
|
||||
Auth().api().shareContact(user, options);
|
||||
Ui::Toast::Show(lang(lng_share_done));
|
||||
if (auto strong = *weak) {
|
||||
@@ -613,7 +613,7 @@ void PeerMenuShareContactBox(not_null<UserData*> user) {
|
||||
lng_forward_share_contact(lt_recipient, recipient),
|
||||
lang(lng_forward_send),
|
||||
[peer, user] {
|
||||
const auto history = App::history(peer);
|
||||
const auto history = peer->owner().history(peer);
|
||||
Ui::showPeerHistory(history, ShowAtTheEndMsgId);
|
||||
auto options = ApiWrap::SendOptions(history);
|
||||
Auth().api().shareContact(user, options);
|
||||
@@ -636,7 +636,7 @@ void PeerMenuCreatePoll(not_null<PeerData*> peer) {
|
||||
if (std::exchange(*lock, true)) {
|
||||
return;
|
||||
}
|
||||
const auto options = ApiWrap::SendOptions(App::history(peer));
|
||||
const auto options = ApiWrap::SendOptions(peer->owner().history(peer));
|
||||
Auth().api().createPoll(result, options, crl::guard(box, [=] {
|
||||
box->closeBox();
|
||||
}), crl::guard(box, [=](const RPCError &error) {
|
||||
@@ -658,7 +658,7 @@ QPointer<Ui::RpWidget> ShowForwardMessagesBox(
|
||||
if (peer->isSelf()) {
|
||||
auto items = Auth().data().idsToItems(ids);
|
||||
if (!items.empty()) {
|
||||
auto options = ApiWrap::SendOptions(App::history(peer));
|
||||
auto options = ApiWrap::SendOptions(peer->owner().history(peer));
|
||||
options.generateLocal = false;
|
||||
Auth().api().forwardMessages(std::move(items), options, [] {
|
||||
Ui::Toast::Show(lang(lng_share_done));
|
||||
@@ -704,7 +704,7 @@ void PeerMenuAddChannelMembers(not_null<ChannelData*> channel) {
|
||||
return data.vuser_id.v;
|
||||
});
|
||||
}) | ranges::view::transform([](UserId userId) {
|
||||
return App::userLoaded(userId);
|
||||
return Auth().data().userLoaded(userId);
|
||||
}) | ranges::view::filter([](UserData *user) {
|
||||
return (user != nullptr);
|
||||
}) | ranges::to_vector;
|
||||
|
Reference in New Issue
Block a user