From bbfbba30b0e27dbd606fa09c0e016e94aacd4858 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Wed, 25 Oct 2023 23:22:39 +0200 Subject: [PATCH] Allow setting presence state again --- resources/qml/RoomList.qml | 34 ++++++++++++++++++++++++++++++++++ src/ChatPage.cpp | 23 ++++++++++++++++++++--- src/ChatPage.h | 5 +++-- src/MainWindow.cpp | 21 +-------------------- src/UserSettingsPage.cpp | 1 - 5 files changed, 58 insertions(+), 26 deletions(-) diff --git a/resources/qml/RoomList.qml b/resources/qml/RoomList.qml index eab6520e..0f8dc24a 100644 --- a/resources/qml/RoomList.qml +++ b/resources/qml/RoomList.qml @@ -267,6 +267,40 @@ Page { onTriggered: statusDialog.show() } + Platform.MenuSeparator { + } + + Platform.MenuItemGroup { + id: onlineStateGroup + } + Platform.MenuItem { + text: qsTr("Automatic online status") + group: onlineStateGroup + checkable: true + checked: Settings.presence == Settings.AutomaticPresence + onTriggered: if (checked) Settings.presence = Settings.AutomaticPresence + } + Platform.MenuItem { + text: qsTr("Online") + group: onlineStateGroup + checkable: true + checked: Settings.presence == Settings.Online + onTriggered: if (checked) Settings.presence = Settings.Online + } + Platform.MenuItem { + text: qsTr("Unavailable") + group: onlineStateGroup + checkable: true + checked: Settings.presence == Settings.Unavailable + onTriggered: if (checked) Settings.presence = Settings.Unavailable + } + Platform.MenuItem { + text: qsTr("Offline") + group: onlineStateGroup + checkable: true + checked: Settings.presence == Settings.Offline + onTriggered: if (checked) Settings.presence = Settings.Offline + } } TapHandler { acceptedButtons: Qt.LeftButton diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp index 90d542dd..25af8974 100644 --- a/src/ChatPage.cpp +++ b/src/ChatPage.cpp @@ -21,7 +21,6 @@ #include "encryption/DeviceVerificationFlow.h" #include "encryption/Olm.h" #include "ui/RoomSummary.h" -#include "ui/Theme.h" #include "ui/UserProfile.h" #include "voip/CallManager.h" @@ -29,8 +28,6 @@ #include "timeline/TimelineViewManager.h" -#include "blurhash.hpp" - ChatPage *ChatPage::instance_ = nullptr; static constexpr int CHECK_CONNECTIVITY_INTERVAL = 15'000; static constexpr int RETRY_TIMEOUT = 5'000; @@ -404,6 +401,19 @@ ChatPage::ChatPage(QSharedPointer userSettings, QObject *parent) [](std::function f) { f(); }, Qt::QueuedConnection); + connect(qobject_cast(QGuiApplication::instance()), + &QGuiApplication::focusWindowChanged, + this, + [this](QWindow *activeWindow) { + if (activeWindow) { + nhlog::ui()->debug("Stopping inactive timer."); + lastWindowActive = QDateTime(); + } else { + nhlog::ui()->debug("Starting inactive timer."); + lastWindowActive = QDateTime::currentDateTime(); + } + }); + connectCallMessage(); connectCallMessage(); connectCallMessage(); @@ -1107,6 +1117,13 @@ ChatPage::currentPresence() const return mtx::presence::unavailable; case UserSettings::Presence::Offline: return mtx::presence::offline; + case UserSettings::Presence::AutomaticPresence: + if (lastWindowActive.isValid() && + lastWindowActive.addSecs(60 * 5) < QDateTime::currentDateTime()) + return mtx::presence::unavailable; + else + return mtx::presence::online; + default: return mtx::presence::online; } diff --git a/src/ChatPage.h b/src/ChatPage.h index fbf4fbce..685b719b 100644 --- a/src/ChatPage.h +++ b/src/ChatPage.h @@ -21,8 +21,6 @@ #include #include -#include "CacheCryptoStructs.h" -#include "CacheStructs.h" #include "ui/RoomSummary.h" class TimelineViewManager; @@ -225,6 +223,9 @@ private: std::unique_ptr pushrules; QDateTime lastSpacesUpdate = QDateTime::currentDateTime(); + + // Stores when our windows lost focus. Invalid when our windows have focus. + QDateTime lastWindowActive; }; template diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index d06171de..1a0b1e96 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -9,42 +9,23 @@ #include #include -#include "AliasEditModel.h" #include "BlurhashProvider.h" -#include "Cache.h" #include "Cache_p.h" #include "ChatPage.h" -#include "Clipboard.h" #include "ColorImageProvider.h" -#include "CombinedImagePackModel.h" -#include "CompletionProxyModel.h" #include "Config.h" -#include "EventAccessors.h" -#include "GridImagePackModel.h" -#include "ImagePackListModel.h" -#include "InviteesModel.h" #include "JdenticonProvider.h" #include "Logging.h" #include "MainWindow.h" #include "MatrixClient.h" -#include "MemberList.h" #include "MxcImageProvider.h" -#include "PowerlevelsEditModels.h" -#include "SingleImagePackModel.h" #include "TrayIcon.h" -#include "UserDirectoryModel.h" #include "UserSettingsPage.h" #include "Utils.h" #include "dock/Dock.h" -#include "emoji/Provider.h" #include "encryption/DeviceVerificationFlow.h" -#include "encryption/SelfVerificationStatus.h" -#include "timeline/DelegateChooser.h" -#include "timeline/TimelineFilter.h" #include "timeline/TimelineViewManager.h" -#include "ui/NhekoGlobalObject.h" -#include "ui/RoomSummary.h" -#include "ui/UIA.h" +#include "ui/Theme.h" #include "voip/CallManager.h" #include "voip/WebRTCSession.h" diff --git a/src/UserSettingsPage.cpp b/src/UserSettingsPage.cpp index 4a25880c..c9c878d0 100644 --- a/src/UserSettingsPage.cpp +++ b/src/UserSettingsPage.cpp @@ -14,7 +14,6 @@ #include #include "Cache.h" -#include "Config.h" #include "JdenticonProvider.h" #include "MainWindow.h" #include "MatrixClient.h"