From 7119132e4b5069146f0a6b1a9f920cfd2b7d059a Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Wed, 7 Jan 2026 15:48:33 -0500 Subject: [PATCH] Add a way to add private notes for users on their profile This is a common feature in other chat applications (like Discord) as a way to keep track of important information. While there isn't a standard API for this, we can use account data to store notes. --- src/app/qml/UserDetailDialog.qml | 29 ++++++++++++++++++++++++++++ src/libneochat/neochatconnection.cpp | 17 ++++++++++++++++ src/libneochat/neochatconnection.h | 10 ++++++++++ 3 files changed, 56 insertions(+) diff --git a/src/app/qml/UserDetailDialog.qml b/src/app/qml/UserDetailDialog.qml index 3a7424581..e03bb1eeb 100644 --- a/src/app/qml/UserDetailDialog.qml +++ b/src/app/qml/UserDetailDialog.qml @@ -401,5 +401,34 @@ Kirigami.Dialog { color: Kirigami.Theme.disabledTextColor } } + + Kirigami.Heading { + text: i18nc("@title Private note for this user", "Private Note") + level: 4 + + Layout.topMargin: Kirigami.Units.largeSpacing + } + + QQC2.TextArea { + id: noteText + + text: root.connection.noteForUser(root.user.id) + textFormat: TextEdit.PlainText + wrapMode: TextEdit.Wrap + placeholderText: i18nc("@info:placeholder", "Only visible to you") + + onTextEdited: editTimer.restart() + + Layout.fillWidth: true + Layout.topMargin: Kirigami.Units.smallSpacing + + // Prevent unnecessary edits by waiting 1 second + Timer { + id: editTimer + + interval: 1000 + onTriggered: root.connection.setNoteForUser(root.user.id, noteText.text) + } + } } } diff --git a/src/libneochat/neochatconnection.cpp b/src/libneochat/neochatconnection.cpp index d69c08636..81d9b3f2b 100644 --- a/src/libneochat/neochatconnection.cpp +++ b/src/libneochat/neochatconnection.cpp @@ -619,4 +619,21 @@ bool NeoChatConnection::supportsMatrixSpecVersion(const QString &version) return supportedMatrixSpecVersions().contains(version); } +QString NeoChatConnection::noteForUser(const QString &userId) +{ + const auto object = accountDataJson(QStringLiteral("org.kde.neochat.user_note")); + return object[userId].toString(); +} + +void NeoChatConnection::setNoteForUser(const QString &userId, const QString ¬e) +{ + auto object = accountDataJson(QStringLiteral("org.kde.neochat.user_note")); + if (note.isEmpty()) { + object.remove(userId); + } else { + object[userId] = note; + } + setAccountData(QStringLiteral("org.kde.neochat.user_note"), object); +} + #include "moc_neochatconnection.cpp" diff --git a/src/libneochat/neochatconnection.h b/src/libneochat/neochatconnection.h index 7270aafb6..547f96a39 100644 --- a/src/libneochat/neochatconnection.h +++ b/src/libneochat/neochatconnection.h @@ -234,6 +234,16 @@ public: */ Q_INVOKABLE bool supportsMatrixSpecVersion(const QString &version); + /** + * @return The private note for this user, if set. + */ + Q_INVOKABLE QString noteForUser(const QString &userId); + + /** + * @brief Sets the private note for this user. + */ + Q_INVOKABLE void setNoteForUser(const QString &userId, const QString ¬e); + Q_SIGNALS: void globalUrlPreviewEnabledChanged(); void labelChanged();