From 5557b949e1a96b0482efb713292fcd9e9694f499 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Fri, 31 Mar 2023 01:59:56 +0200 Subject: [PATCH] Allow querying your status message over dbus Contributed by a Nheko user starting with S. --- src/dbus/NhekoDBusApi.cpp | 10 ++++++++++ src/dbus/NhekoDBusApi.h | 3 +++ src/dbus/NhekoDBusBackend.cpp | 6 ++++++ src/dbus/NhekoDBusBackend.h | 2 ++ 4 files changed, 21 insertions(+) diff --git a/src/dbus/NhekoDBusApi.cpp b/src/dbus/NhekoDBusApi.cpp index a669238c..a613b610 100644 --- a/src/dbus/NhekoDBusApi.cpp +++ b/src/dbus/NhekoDBusApi.cpp @@ -152,6 +152,16 @@ directChat(const QString &userId) interface.call(QDBus::NoBlock, QStringLiteral("directChat"), userId); } +QString +statusMessage() +{ + if (QDBusInterface interface{QStringLiteral(NHEKO_DBUS_SERVICE_NAME), QStringLiteral("/")}; + interface.isValid()) + return QDBusReply{interface.call(QStringLiteral("statusMessage"))}.value(); + else + return {}; +} + void setStatusMessage(const QString &message) { diff --git a/src/dbus/NhekoDBusApi.h b/src/dbus/NhekoDBusApi.h index 78bd9fbb..5a34f0b7 100644 --- a/src/dbus/NhekoDBusApi.h +++ b/src/dbus/NhekoDBusApi.h @@ -80,6 +80,9 @@ joinRoom(const QString &alias); //! desired). void directChat(const QString &userId); +//! Get the user's status message. +QString +statusMessage(); //! Sets the user's status message (if supported by the homeserver). void setStatusMessage(const QString &message); diff --git a/src/dbus/NhekoDBusBackend.cpp b/src/dbus/NhekoDBusBackend.cpp index 46ba7ab1..9690cdfa 100644 --- a/src/dbus/NhekoDBusBackend.cpp +++ b/src/dbus/NhekoDBusBackend.cpp @@ -100,6 +100,12 @@ NhekoDBusBackend::directChat(const QString &userId) const ChatPage::instance()->startChat(userId); } +QString +NhekoDBusBackend::statusMessage() const +{ + return ChatPage::instance()->status(); +} + void NhekoDBusBackend::setStatusMessage(const QString &message) { diff --git a/src/dbus/NhekoDBusBackend.h b/src/dbus/NhekoDBusBackend.h index e07e09f0..e1b5fabb 100644 --- a/src/dbus/NhekoDBusBackend.h +++ b/src/dbus/NhekoDBusBackend.h @@ -37,6 +37,8 @@ public slots: //! Starts or activates a direct chat. It is your responsibility to ask for confirmation (if //! desired). Q_SCRIPTABLE void directChat(const QString &userId) const; + //! Gets the user's status message. + Q_SCRIPTABLE QString statusMessage() const; //! Sets the user's status message. Q_SCRIPTABLE void setStatusMessage(const QString &message);