Improved management of online status from non-primary windows.

– The online status of the user should be checked and updated only
when the previous active window and the current active window both have
different sessions.
– Removed MainWindow::activeChangedHook since windows should not
change online status on their own on activating.
– Renamed Application::maybeActiveSession
to Application::maybePrimarySession.
– Added updating of online status on changing of the current account
since this seems to have been missed.
This commit is contained in:
23rd 2022-06-12 02:24:50 +03:00
parent 1d475ee727
commit fe7cffc509
8 changed files with 31 additions and 21 deletions

View file

@ -781,7 +781,7 @@ void Application::checkLocalTime() {
base::ConcurrentTimerEnvironment::Adjust(); base::ConcurrentTimerEnvironment::Adjust();
base::unixtime::http_invalidate(); base::unixtime::http_invalidate();
} }
if (const auto session = maybeActiveSession()) { if (const auto session = maybePrimarySession()) {
session->updates().checkLastUpdate(adjusted); session->updates().checkLastUpdate(adjusted);
} }
} }
@ -797,6 +797,14 @@ void Application::handleAppDeactivated() {
if (_primaryWindow) { if (_primaryWindow) {
_primaryWindow->updateIsActiveBlur(); _primaryWindow->updateIsActiveBlur();
} }
if (_domain->started()) {
const auto session = _lastActiveWindow
? _lastActiveWindow->account().maybeSession()
: nullptr;
if (session) {
session->updates().updateOnline();
}
}
Ui::Tooltip::Hide(); Ui::Tooltip::Hide();
} }
@ -854,7 +862,7 @@ Main::Account &Application::activeAccount() const {
return _domain->active(); return _domain->active();
} }
Main::Session *Application::maybeActiveSession() const { Main::Session *Application::maybePrimarySession() const {
return _domain->started() ? activeAccount().maybeSession() : nullptr; return _domain->started() ? activeAccount().maybeSession() : nullptr;
} }
@ -1050,7 +1058,7 @@ bool Application::passcodeLocked() const {
void Application::updateNonIdle() { void Application::updateNonIdle() {
_lastNonIdleTime = crl::now(); _lastNonIdleTime = crl::now();
if (const auto session = maybeActiveSession()) { if (const auto session = maybePrimarySession()) {
session->updates().checkIdleFinish(_lastNonIdleTime); session->updates().checkIdleFinish(_lastNonIdleTime);
} }
} }
@ -1124,11 +1132,9 @@ bool Application::hasActiveWindow(not_null<Main::Session*> session) const {
return false; return false;
} else if (_calls->hasActivePanel(session)) { } else if (_calls->hasActivePanel(session)) {
return true; return true;
} else if (const auto controller = _primaryWindow->sessionController()) { } else if (const auto window = _lastActiveWindow) {
if (&controller->session() == session return (window->account().maybeSession() == session)
&& _primaryWindow->widget()->isActive()) { && window->widget()->isActive();
return true;
}
} }
return false; return false;
} }
@ -1225,7 +1231,20 @@ void Application::closeChatFromWindows(not_null<PeerData*> peer) {
} }
void Application::windowActivated(not_null<Window::Controller*> window) { void Application::windowActivated(not_null<Window::Controller*> window) {
const auto was = _lastActiveWindow;
const auto now = window;
_lastActiveWindow = window; _lastActiveWindow = window;
const auto wasSession = was ? was->account().maybeSession() : nullptr;
const auto nowSession = now->account().maybeSession();
if (wasSession != nowSession) {
if (wasSession) {
wasSession->updates().updateOnline();
}
if (nowSession) {
nowSession->updates().updateOnline();
}
}
if (_mediaView && !_mediaView->isHidden()) { if (_mediaView && !_mediaView->isHidden()) {
_mediaView->activate(); _mediaView->activate();
} }

View file

@ -207,7 +207,7 @@ public:
[[nodiscard]] bool exportPreventsQuit(); [[nodiscard]] bool exportPreventsQuit();
// Main::Session component. // Main::Session component.
Main::Session *maybeActiveSession() const; Main::Session *maybePrimarySession() const;
[[nodiscard]] int unreadBadge() const; [[nodiscard]] int unreadBadge() const;
[[nodiscard]] bool unreadBadgeMuted() const; [[nodiscard]] bool unreadBadgeMuted() const;
[[nodiscard]] rpl::producer<> unreadBadgeChanges() const; [[nodiscard]] rpl::producer<> unreadBadgeChanges() const;

View file

@ -718,12 +718,6 @@ void MainWindow::sendPaths() {
} }
} }
void MainWindow::activeChangedHook() {
if (const auto controller = sessionController()) {
controller->session().updates().updateOnline();
}
}
MainWindow::~MainWindow() = default; MainWindow::~MainWindow() = default;
namespace App { namespace App {

View file

@ -114,7 +114,6 @@ protected:
void closeEvent(QCloseEvent *e) override; void closeEvent(QCloseEvent *e) override;
void initHook() override; void initHook() override;
void activeChangedHook() override;
void clearWidgetsHook() override; void clearWidgetsHook() override;
private: private:

View file

@ -282,7 +282,7 @@ SystemMediaControlsManager::SystemMediaControlsManager(
Core::App().passcodeLockValue( Core::App().passcodeLockValue(
) | rpl::filter([=](bool locked) { ) | rpl::filter([=](bool locked) {
return locked && Core::App().maybeActiveSession(); return locked && Core::App().maybePrimarySession();
}) | rpl::start_with_next([=] { }) | rpl::start_with_next([=] {
_controls->setEnabled(false); _controls->setEnabled(false);
}, _lifetime); }, _lifetime);

View file

@ -402,7 +402,6 @@ void MainWindow::updateIsActive() {
const auto isActive = computeIsActive(); const auto isActive = computeIsActive();
if (_isActive != isActive) { if (_isActive != isActive) {
_isActive = isActive; _isActive = isActive;
activeChangedHook();
} }
} }

View file

@ -149,9 +149,6 @@ protected:
virtual void initHook() { virtual void initHook() {
} }
virtual void activeChangedHook() {
}
virtual void handleVisibleChangedHook(bool visible) { virtual void handleVisibleChangedHook(bool visible) {
} }

View file

@ -123,6 +123,8 @@ void Controller::showAccount(
}, _sessionController->lifetime()); }, _sessionController->lifetime());
widget()->setInnerFocus(); widget()->setInnerFocus();
session->updates().updateOnline(crl::now());
} else { } else {
setupIntro(); setupIntro();
_widget.updateGlobalMenu(); _widget.updateGlobalMenu();