From aebae9abb64c5d7c66370f878261a61c999ddd3c Mon Sep 17 00:00:00 2001 From: Patrizio Bekerle Date: Fri, 27 Dec 2024 16:06:27 +0100 Subject: [PATCH] qownnotes/web-companion#70 add: flag to not send bookmarks and links from current note Signed-off-by: Patrizio Bekerle --- CHANGELOG.md | 14 ++++++++++++++ src/services/websocketserverservice.cpp | 20 ++++++++++++-------- src/services/websocketserverservice.h | 2 +- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 58d06d0f80..429af382ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,19 @@ # QOwnNotes Changelog +## 24.12.7 +- The [Web Companion browser extension](https://github.com/qownnotes/web-companion) + can now tell QOwnNotes to not send bookmarks and links from the current note + (for [#70](https://github.com/qownnotes/web-companion/issues/70)) +- There was a new release of the **QOwnNotes Web Companion browser extension** 2024.12.0 + - The private mode switch got moved to the drawer menu, so it doesn't take up space in the popup anymore + (for [#76](https://github.com/qownnotes/web-companion/issues/76)) + - There now is a new switch in the drawer menu to **hide bookmarks and links from the current note** + (for [#70](https://github.com/qownnotes/web-companion/issues/70)) + - Bookmarks can still contain the `Current` tag, for example if the current note is a bookmark note + - This feature needs QOwnNotes 24.12.7 or higher + - The dependencies were updated + - More translations were added + ## 24.12.6 - A possible crash when pasting HTML as Markdown or pasting as text file was fixed (for [#3184](https://github.com/pbek/QOwnNotes/issues/3184)) diff --git a/src/services/websocketserverservice.cpp b/src/services/websocketserverservice.cpp index bbe32d3b3b..16b1c7cbd8 100644 --- a/src/services/websocketserverservice.cpp +++ b/src/services/websocketserverservice.cpp @@ -204,7 +204,8 @@ void WebSocketServerService::processMessage(const QString &message) { // R"({ "type": "bookmarks", "data": [ { "name": "Test1", // "url": "https://www.qownnotes.org" } ] })"); - QString jsonText = getBookmarksJsonText(); + const bool hideCurrent = jsonObject.value(QStringLiteral("hideCurrent")).toBool(); + QString jsonText = getBookmarksJsonText(hideCurrent); if (jsonText.isEmpty()) { return; @@ -247,7 +248,8 @@ void WebSocketServerService::processMessage(const QString &message) { pSender->sendTextMessage(getNoteFolderSwitchedJsonText(switched)); - QString jsonText = getBookmarksJsonText(); + const bool hideCurrent = jsonObject.value(QStringLiteral("hideCurrent")).toBool(); + QString jsonText = getBookmarksJsonText(hideCurrent); pSender->sendTextMessage(jsonText); #endif } else if (type == QLatin1String("getNoteFolders")) { @@ -478,7 +480,7 @@ int WebSocketServerService::editBookmark(const QJsonObject &jsonObject) { return noteCount; } -QString WebSocketServerService::getBookmarksJsonText() { +QString WebSocketServerService::getBookmarksJsonText(bool hideCurrent) { MainWindow *mainWindow = MainWindow::instance(); if (mainWindow == nullptr) { return {}; @@ -496,12 +498,14 @@ QString WebSocketServerService::getBookmarksJsonText() { Bookmark::mergeListInList(noteBookmarks, bookmarks); } - // extract links from the current note - QVector currentNoteBookmarks = - Bookmark::parseBookmarks(mainWindow->activeNoteTextEdit()->toPlainText(), true); + if (!hideCurrent) { + // extract links from the current note + QVector currentNoteBookmarks = + Bookmark::parseBookmarks(mainWindow->activeNoteTextEdit()->toPlainText(), true); - // merge bookmark lists - Bookmark::mergeListInList(currentNoteBookmarks, bookmarks); + // merge bookmark lists + Bookmark::mergeListInList(currentNoteBookmarks, bookmarks); + } QString jsonText = Bookmark::bookmarksWebServiceJsonText(bookmarks); diff --git a/src/services/websocketserverservice.h b/src/services/websocketserverservice.h index 361e03051c..a360b7d8cb 100644 --- a/src/services/websocketserverservice.h +++ b/src/services/websocketserverservice.h @@ -63,7 +63,7 @@ class WebSocketServerService : public QObject { QList m_clients; quint16 m_port{}; - static QString getBookmarksJsonText(); + static QString getBookmarksJsonText(bool hideCurrent = false); static QString getCommandSnippetsJsonText();