mirror of https://github.com/procxx/kepka.git
				
				
				
			Use Controller::account in MainWindow.
This commit is contained in:
		
							parent
							
								
									1e861f79f0
								
							
						
					
					
						commit
						0868a9f7b9
					
				|  | @ -306,7 +306,7 @@ Panel::Panel(not_null<Call*> call) | |||
| 	_cancel->setDuration(st::callPanelDuration); | ||||
| 
 | ||||
| 	setMouseTracking(true); | ||||
| 	setWindowIcon(Window::CreateIcon()); | ||||
| 	setWindowIcon(Window::CreateIcon(&_user->account())); | ||||
| 	initControls(); | ||||
| 	initLayout(); | ||||
| 	showAndActivate(); | ||||
|  |  | |||
|  | @ -232,11 +232,12 @@ bool Application::hideMediaView() { | |||
| } | ||||
| 
 | ||||
| void Application::showPhoto(not_null<const PhotoOpenClickHandler*> link) { | ||||
| 	const auto item = Auth().data().message(link->context()); | ||||
| 	const auto photo = link->photo(); | ||||
| 	const auto peer = link->peer(); | ||||
| 	const auto item = photo->owner().message(link->context()); | ||||
| 	return (!item && peer) | ||||
| 		? showPhoto(link->photo(), peer) | ||||
| 		: showPhoto(link->photo(), item); | ||||
| 		? showPhoto(photo, peer) | ||||
| 		: showPhoto(photo, item); | ||||
| } | ||||
| 
 | ||||
| void Application::showPhoto(not_null<PhotoData*> photo, HistoryItem *item) { | ||||
|  | @ -664,7 +665,8 @@ void Application::startLocalStorage() { | |||
| 			if (_mtproto) { | ||||
| 				_mtproto->requestConfig(); | ||||
| 			} | ||||
| 			Platform::SetApplicationIcon(Window::CreateIcon()); | ||||
| 			Platform::SetApplicationIcon( | ||||
| 				Window::CreateIcon(&activeAccount())); | ||||
| 			Shortcuts::ToggleSupportShortcuts(support); | ||||
| 		}); | ||||
| 	}, _lifetime); | ||||
|  | @ -1114,16 +1116,18 @@ void Application::preventWindowActivation() { | |||
| 
 | ||||
| void Application::QuitAttempt() { | ||||
| 	auto prevents = false; | ||||
| 	if (AuthSession::Exists() && !Sandbox::Instance().isSavingSession()) { | ||||
| 	if (IsAppLaunched() | ||||
| 		&& App().activeAccount().sessionExists() | ||||
| 		&& !Sandbox::Instance().isSavingSession()) { | ||||
| 		if (const auto mainwidget = App::main()) { | ||||
| 			if (mainwidget->isQuitPrevent()) { | ||||
| 				prevents = true; | ||||
| 			} | ||||
| 		} | ||||
| 		if (Auth().api().isQuitPrevent()) { | ||||
| 		if (App().activeAccount().session().api().isQuitPrevent()) { | ||||
| 			prevents = true; | ||||
| 		} | ||||
| 		if (Auth().calls().isQuitPrevent()) { | ||||
| 		if (App().activeAccount().session().calls().isQuitPrevent()) { | ||||
| 			prevents = true; | ||||
| 		} | ||||
| 	} | ||||
|  |  | |||
|  | @ -111,6 +111,10 @@ AuthSession &PeerData::session() const { | |||
| 	return _owner->session(); | ||||
| } | ||||
| 
 | ||||
| Main::Account &PeerData::account() const { | ||||
| 	return session().account(); | ||||
| } | ||||
| 
 | ||||
| void PeerData::updateNameDelayed( | ||||
| 		const QString &newName, | ||||
| 		const QString &newNameOrPhone, | ||||
|  |  | |||
|  | @ -23,6 +23,10 @@ class UserData; | |||
| class ChatData; | ||||
| class ChannelData; | ||||
| 
 | ||||
| namespace Main { | ||||
| class Account; | ||||
| } // namespace Main
 | ||||
| 
 | ||||
| namespace Data { | ||||
| 
 | ||||
| class Session; | ||||
|  | @ -111,6 +115,7 @@ public: | |||
| 
 | ||||
| 	[[nodiscard]] Data::Session &owner() const; | ||||
| 	[[nodiscard]] AuthSession &session() const; | ||||
| 	[[nodiscard]] Main::Account &account() const; | ||||
| 
 | ||||
| 	[[nodiscard]] bool isUser() const { | ||||
| 		return peerIsUser(id); | ||||
|  |  | |||
|  | @ -115,7 +115,7 @@ void activateBotCommand( | |||
| 			Ui::showPeerHistory(history, ShowAtTheEndMsgId); | ||||
| 			auto options = ApiWrap::SendOptions(history); | ||||
| 			options.replyTo = msgId; | ||||
| 			Auth().api().shareContact(Auth().user(), options); | ||||
| 			history->session().api().shareContact(Auth().user(), options); | ||||
| 		})); | ||||
| 	} break; | ||||
| 
 | ||||
|  |  | |||
|  | @ -82,7 +82,7 @@ MainWindow::MainWindow(not_null<Window::Controller*> controller) | |||
| 
 | ||||
| 	setLocale(QLocale(QLocale::English, QLocale::UnitedStates)); | ||||
| 
 | ||||
| 	Core::App().activeAccount().sessionValue( | ||||
| 	account().sessionValue( | ||||
| 	) | rpl::start_with_next([=](AuthSession *session) { | ||||
| 		updateGlobalMenu(); | ||||
| 		if (!session) { | ||||
|  | @ -201,7 +201,7 @@ void MainWindow::clearPasscodeLock() { | |||
| 		Core::App().checkStartUrl(); | ||||
| 	} else { | ||||
| 		Core::App().startMtp(); | ||||
| 		if (AuthSession::Exists()) { | ||||
| 		if (account().sessionExists()) { | ||||
| 			setupMain(); | ||||
| 		} else { | ||||
| 			setupIntro(); | ||||
|  | @ -229,7 +229,7 @@ void MainWindow::setupIntro() { | |||
| } | ||||
| 
 | ||||
| void MainWindow::setupMain() { | ||||
| 	Expects(AuthSession::Exists()); | ||||
| 	Expects(account().sessionExists()); | ||||
| 
 | ||||
| 	auto animated = (_intro || _passcodeLock); | ||||
| 	auto bg = animated ? grabInner() : QPixmap(); | ||||
|  | @ -584,7 +584,7 @@ void MainWindow::updateTrayMenu(bool force) { | |||
| void MainWindow::onShowAddContact() { | ||||
| 	if (isHidden()) showFromTray(); | ||||
| 
 | ||||
| 	if (AuthSession::Exists()) { | ||||
| 	if (account().sessionExists()) { | ||||
| 		Ui::show(Box<AddContactBox>(), LayerOption::KeepOther); | ||||
| 	} | ||||
| } | ||||
|  | @ -592,7 +592,7 @@ void MainWindow::onShowAddContact() { | |||
| void MainWindow::onShowNewGroup() { | ||||
| 	if (isHidden()) showFromTray(); | ||||
| 
 | ||||
| 	if (AuthSession::Exists()) { | ||||
| 	if (account().sessionExists()) { | ||||
| 		Ui::show( | ||||
| 			Box<GroupInfoBox>(GroupInfoBox::Type::Group), | ||||
| 			LayerOption::KeepOther); | ||||
|  | @ -618,9 +618,10 @@ void MainWindow::onLogout() { | |||
| 		Core::App().logOut(); | ||||
| 	}; | ||||
| 	const auto callback = [=] { | ||||
| 		if (AuthSession::Exists() && Auth().data().exportInProgress()) { | ||||
| 		if (account().sessionExists() | ||||
| 			&& account().session().data().exportInProgress()) { | ||||
| 			Ui::hideLayer(); | ||||
| 			Auth().data().stopExportWithConfirmation(logout); | ||||
| 			account().session().data().stopExportWithConfirmation(logout); | ||||
| 		} else { | ||||
| 			logout(); | ||||
| 		} | ||||
|  | @ -708,7 +709,7 @@ void MainWindow::toggleDisplayNotifyFromTray() { | |||
| 		Ui::show(Box<InformBox>(lang(lng_passcode_need_unblock))); | ||||
| 		return; | ||||
| 	} | ||||
| 	if (!AuthSession::Exists()) { | ||||
| 	if (!account().sessionExists()) { | ||||
| 		return; | ||||
| 	} | ||||
| 
 | ||||
|  | @ -730,9 +731,11 @@ void MainWindow::toggleDisplayNotifyFromTray() { | |||
| 		} | ||||
| 	} | ||||
| 	Local::writeUserSettings(); | ||||
| 	Auth().notifications().settingsChanged().notify(Window::Notifications::ChangeType::DesktopEnabled); | ||||
| 	account().session().notifications().settingsChanged().notify( | ||||
| 		Window::Notifications::ChangeType::DesktopEnabled); | ||||
| 	if (soundNotifyChanged) { | ||||
| 		Auth().notifications().settingsChanged().notify(Window::Notifications::ChangeType::SoundEnabled); | ||||
| 		account().session().notifications().settingsChanged().notify( | ||||
| 			Window::Notifications::ChangeType::SoundEnabled); | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
|  | @ -742,7 +745,7 @@ void MainWindow::closeEvent(QCloseEvent *e) { | |||
| 		App::quit(); | ||||
| 	} else { | ||||
| 		e->ignore(); | ||||
| 		if (!AuthSession::Exists() || !hideNoQuit()) { | ||||
| 		if (!account().sessionExists() || !hideNoQuit()) { | ||||
| 			App::quit(); | ||||
| 		} | ||||
| 	} | ||||
|  | @ -904,7 +907,7 @@ QImage MainWindow::iconWithCounter(int size, int count, style::color bg, style:: | |||
| 	} | ||||
| 
 | ||||
| 	QImage img(smallIcon ? ((size == 16) ? iconbig16 : (size == 32 ? iconbig32 : iconbig64)) : ((size == 16) ? icon16 : (size == 32 ? icon32 : icon64))); | ||||
| 	if (AuthSession::Exists() && Auth().supportMode()) { | ||||
| 	if (account().sessionExists() && account().session().supportMode()) { | ||||
| 		Window::ConvertIconToBlack(img); | ||||
| 	} | ||||
| 	if (!count) return img; | ||||
|  |  | |||
|  | @ -232,7 +232,7 @@ OverlayWidget::OverlayWidget() | |||
| , _dropdownShowTimer(this) { | ||||
| 	subscribe(Lang::Current().updated(), [this] { refreshLang(); }); | ||||
| 
 | ||||
| 	setWindowIcon(Window::CreateIcon()); | ||||
| 	setWindowIcon(Window::CreateIcon(&Core::App().activeAccount())); | ||||
| 	setWindowTitle(qsl("Media viewer")); | ||||
| 
 | ||||
| 	TextCustomTagsMap custom; | ||||
|  |  | |||
|  | @ -265,7 +265,7 @@ void MainWindow::psSetupTrayIcon() { | |||
| 				QByteArray path = QFile::encodeName(iconFile.absoluteFilePath()); | ||||
| 				icon = QIcon(path.constData()); | ||||
| 			} else { | ||||
| 				icon = Window::CreateIcon(); | ||||
| 				icon = Window::CreateIcon(&account()); | ||||
| 			} | ||||
| 			trayIcon->setIcon(icon); | ||||
| 
 | ||||
|  |  | |||
|  | @ -407,7 +407,7 @@ void MainWindow::initTouchBar() { | |||
| 		return; | ||||
| 	} | ||||
| 
 | ||||
| 	Core::App().activeAccount().sessionValue( | ||||
| 	account().sessionValue( | ||||
| 	) | rpl::start_with_next([=](AuthSession *session) { | ||||
| 		if (session) { | ||||
| 			// We need only common pinned dialogs. | ||||
|  | @ -641,10 +641,13 @@ void MainWindow::createGlobalMenu() { | |||
| 
 | ||||
| 	QMenu *window = psMainMenu.addMenu(lang(lng_mac_menu_window)); | ||||
| 	psContacts = window->addAction(lang(lng_mac_menu_contacts)); | ||||
| 	connect(psContacts, &QAction::triggered, psContacts, [] { | ||||
| 		if (App::wnd() && App::wnd()->isHidden()) App::wnd()->showFromTray(); | ||||
| 
 | ||||
| 		if (!AuthSession::Exists()) return; | ||||
| 	connect(psContacts, &QAction::triggered, psContacts, crl::guard(this, [=] { | ||||
| 		if (isHidden()) { | ||||
| 			showFromTray(); | ||||
| 		} | ||||
| 		if (!account().sessionExists()) { | ||||
| 			return; | ||||
| 		} | ||||
| 		Ui::show(Box<PeerListBox>(std::make_unique<ContactsBoxController>(), [](not_null<PeerListBox*> box) { | ||||
| 			box->addButton(langFactory(lng_close), [box] { box->closeBox(); }); | ||||
| 			box->addLeftButton(langFactory(lng_profile_add_contact), [] { App::wnd()->onShowAddContact(); }); | ||||
|  | @ -734,10 +737,10 @@ void MainWindow::updateGlobalMenuHook() { | |||
| 		canDelete = list->canDeleteSelected(); | ||||
| 	} | ||||
| 	App::wnd()->updateIsActive(0); | ||||
| 	const auto logged = AuthSession::Exists(); | ||||
| 	const auto logged = account().sessionExists(); | ||||
| 	const auto locked = Core::App().locked(); | ||||
| 	const auto inactive = !logged || locked; | ||||
| 	const auto support = logged && Auth().supportMode(); | ||||
| 	const auto support = logged && account().session().supportMode(); | ||||
| 	_forceDisabled(psLogout, !logged && !locked); | ||||
| 	_forceDisabled(psUndo, !canUndo); | ||||
| 	_forceDisabled(psRedo, !canRedo); | ||||
|  |  | |||
|  | @ -93,16 +93,18 @@ void ConvertIconToBlack(QImage &image) { | |||
| 	} | ||||
| } | ||||
| 
 | ||||
| QIcon CreateOfficialIcon() { | ||||
| QIcon CreateOfficialIcon(Main::Account *account) { | ||||
| 	auto image = Core::IsAppLaunched() ? Core::App().logo() : LoadLogo(); | ||||
| 	if (AuthSession::Exists() && Auth().supportMode()) { | ||||
| 	if (account | ||||
| 		&& account->sessionExists() | ||||
| 		&& account->session().supportMode()) { | ||||
| 		ConvertIconToBlack(image); | ||||
| 	} | ||||
| 	return QIcon(App::pixmapFromImageInPlace(std::move(image))); | ||||
| } | ||||
| 
 | ||||
| QIcon CreateIcon() { | ||||
| 	auto result = CreateOfficialIcon(); | ||||
| QIcon CreateIcon(Main::Account *account) { | ||||
| 	auto result = CreateOfficialIcon(account); | ||||
| 	if (Platform::IsLinux()) { | ||||
| 		return QIcon::fromTheme("telegram", result); | ||||
| 	} | ||||
|  | @ -114,7 +116,6 @@ MainWindow::MainWindow(not_null<Controller*> controller) | |||
| , _positionUpdatedTimer([=] { savePosition(); }) | ||||
| , _outdated(CreateOutdatedBar(this)) | ||||
| , _body(this) | ||||
| , _icon(CreateIcon()) | ||||
| , _titleText(qsl("Telegram")) { | ||||
| 	subscribe(Theme::Background(), [=]( | ||||
| 			const Theme::BackgroundUpdate &data) { | ||||
|  | @ -150,13 +151,17 @@ MainWindow::MainWindow(not_null<Controller*> controller) | |||
| 	_inactivePressTimer.setCallback([this] { setInactivePress(false); }); | ||||
| } | ||||
| 
 | ||||
| Main::Account &MainWindow::account() const { | ||||
| 	return _controller->account(); | ||||
| } | ||||
| 
 | ||||
| Window::SessionController *MainWindow::sessionController() const { | ||||
| 	return _controller->sessionController(); | ||||
| } | ||||
| 
 | ||||
| void MainWindow::checkLockByTerms() { | ||||
| 	const auto data = Core::App().termsLocked(); | ||||
| 	if (!data || !AuthSession::Exists()) { | ||||
| 	if (!data || !account().sessionExists()) { | ||||
| 		if (_termsBox) { | ||||
| 			_termsBox->closeBox(); | ||||
| 		} | ||||
|  | @ -175,8 +180,8 @@ void MainWindow::checkLockByTerms() { | |||
| 	box->agreeClicks( | ||||
| 	) | rpl::start_with_next([=] { | ||||
| 		const auto mention = box ? box->lastClickedMention() : QString(); | ||||
| 		if (AuthSession::Exists()) { | ||||
| 			Auth().api().acceptTerms(id); | ||||
| 		if (account().sessionExists()) { | ||||
| 			account().session().api().acceptTerms(id); | ||||
| 			if (!mention.isEmpty()) { | ||||
| 				MentionClickHandler(mention).onClick({}); | ||||
| 			} | ||||
|  | @ -224,8 +229,8 @@ void MainWindow::showTermsDecline() { | |||
| void MainWindow::showTermsDelete() { | ||||
| 	const auto box = std::make_shared<QPointer<BoxContent>>(); | ||||
| 	const auto deleteByTerms = [=] { | ||||
| 		if (AuthSession::Exists()) { | ||||
| 			Auth().termsDeleteNow(); | ||||
| 		if (account().sessionExists()) { | ||||
| 			account().session().termsDeleteNow(); | ||||
| 		} else { | ||||
| 			Ui::hideLayer(); | ||||
| 		} | ||||
|  | @ -278,9 +283,10 @@ bool MainWindow::computeIsActive() const { | |||
| } | ||||
| 
 | ||||
| void MainWindow::updateWindowIcon() { | ||||
| 	const auto supportIcon = AuthSession::Exists() && Auth().supportMode(); | ||||
| 	if (supportIcon != _usingSupportIcon) { | ||||
| 		_icon = CreateIcon(); | ||||
| 	const auto supportIcon = account().sessionExists() | ||||
| 		&& account().session().supportMode(); | ||||
| 	if (supportIcon != _usingSupportIcon || _icon.isNull()) { | ||||
| 		_icon = CreateIcon(&account()); | ||||
| 		_usingSupportIcon = supportIcon; | ||||
| 	} | ||||
| 	setWindowIcon(_icon); | ||||
|  | @ -485,8 +491,8 @@ void MainWindow::updateControlsGeometry() { | |||
| void MainWindow::updateUnreadCounter() { | ||||
| 	if (!Global::started() || App::quitting()) return; | ||||
| 
 | ||||
| 	const auto counter = AuthSession::Exists() | ||||
| 		? Auth().data().unreadBadge() | ||||
| 	const auto counter = account().sessionExists() | ||||
| 		? account().session().data().unreadBadge() | ||||
| 		: 0; | ||||
| 	_titleText = (counter > 0) ? qsl("Telegram (%1)").arg(counter) : qsl("Telegram"); | ||||
| 
 | ||||
|  |  | |||
|  | @ -13,6 +13,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL | |||
| 
 | ||||
| class BoxContent; | ||||
| 
 | ||||
| namespace Main { | ||||
| class Account; | ||||
| } // namespace Main
 | ||||
| 
 | ||||
| namespace Window { | ||||
| 
 | ||||
| class Controller; | ||||
|  | @ -22,7 +26,7 @@ struct TermsLock; | |||
| 
 | ||||
| QImage LoadLogo(); | ||||
| QImage LoadLogoNoMargin(); | ||||
| QIcon CreateIcon(); | ||||
| QIcon CreateIcon(Main::Account *account = nullptr); | ||||
| void ConvertIconToBlack(QImage &image); | ||||
| 
 | ||||
| class MainWindow : public Ui::RpWidget, protected base::Subscriber { | ||||
|  | @ -31,9 +35,10 @@ class MainWindow : public Ui::RpWidget, protected base::Subscriber { | |||
| public: | ||||
| 	explicit MainWindow(not_null<Controller*> controller); | ||||
| 
 | ||||
| 	not_null<Window::Controller*> controller() const { | ||||
| 		return _controller; | ||||
| 	Window::Controller &controller() const { | ||||
| 		return *_controller; | ||||
| 	} | ||||
| 	Main::Account &account() const; | ||||
| 	Window::SessionController *sessionController() const; | ||||
| 	void setInactivePress(bool inactive); | ||||
| 	bool wasInactivePress() const { | ||||
|  |  | |||
|  | @ -17,7 +17,7 @@ namespace Window { | |||
| Controller::Controller(not_null<Main::Account*> account) | ||||
| : _account(account) | ||||
| , _widget(this) { | ||||
| 	Core::App().activeAccount().sessionValue( | ||||
| 	_account->sessionValue( | ||||
| 	) | rpl::start_with_next([=](AuthSession *session) { | ||||
| 		_sessionController = session | ||||
| 			? std::make_unique<SessionController>(session, &_widget) | ||||
|  |  | |||
|  | @ -23,8 +23,8 @@ public: | |||
| 	Controller(const Controller &other) = delete; | ||||
| 	Controller &operator=(const Controller &other) = delete; | ||||
| 
 | ||||
| 	not_null<Main::Account*> account() const { | ||||
| 		return _account; | ||||
| 	Main::Account &account() const { | ||||
| 		return *_account; | ||||
| 	} | ||||
| 	not_null<::MainWindow*> widget() { | ||||
| 		return &_widget; | ||||
|  |  | |||
|  | @ -103,7 +103,7 @@ SessionController::SessionController( | |||
| , _window(window) { | ||||
| 	init(); | ||||
| 
 | ||||
| 	subscribe(Auth().api().fullPeerUpdated(), [=](PeerData *peer) { | ||||
| 	subscribe(session->api().fullPeerUpdated(), [=](PeerData *peer) { | ||||
| 		if (peer == _showEditPeer) { | ||||
| 			_showEditPeer = nullptr; | ||||
| 			Ui::show(Box<EditPeerInfoBox>(peer)); | ||||
|  | @ -123,7 +123,7 @@ SessionController::SessionController( | |||
| 
 | ||||
| void SessionController::showEditPeerBox(PeerData *peer) { | ||||
| 	_showEditPeer = peer; | ||||
| 	Auth().api().requestFullPeer(peer); | ||||
| 	session().api().requestFullPeer(peer); | ||||
| } | ||||
| 
 | ||||
| void SessionController::init() { | ||||
|  | @ -190,7 +190,7 @@ bool SessionController::jumpToChatListEntry(Dialogs::RowDescriptor row) { | |||
| 		Ui::showPeerHistory(history, row.fullId.msg); | ||||
| 		return true; | ||||
| 	//} else if (const auto feed = row.key.feed()) { // #feed
 | ||||
| 	//	if (const auto item = Auth().data().message(row.fullId)) {
 | ||||
| 	//	if (const auto item = session().data().message(row.fullId)) {
 | ||||
| 	//		showSection(HistoryFeed::Memento(feed, item->position()));
 | ||||
| 	//	} else {
 | ||||
| 	//		showSection(HistoryFeed::Memento(feed));
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue