Skip to content

Commit

Permalink
qownnotes/web-companion#70 add: flag to not send bookmarks and links …
Browse files Browse the repository at this point in the history
…from current note

Signed-off-by: Patrizio Bekerle <[email protected]>
  • Loading branch information
pbek committed Dec 27, 2024
1 parent 7bfbee7 commit aebae9a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
20 changes: 12 additions & 8 deletions src/services/websocketserverservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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")) {
Expand Down Expand Up @@ -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 {};
Expand All @@ -496,12 +498,14 @@ QString WebSocketServerService::getBookmarksJsonText() {
Bookmark::mergeListInList(noteBookmarks, bookmarks);
}

// extract links from the current note
QVector<Bookmark> currentNoteBookmarks =
Bookmark::parseBookmarks(mainWindow->activeNoteTextEdit()->toPlainText(), true);
if (!hideCurrent) {
// extract links from the current note
QVector<Bookmark> 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);

Expand Down
2 changes: 1 addition & 1 deletion src/services/websocketserverservice.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class WebSocketServerService : public QObject {
QList<QWebSocket *> m_clients;
quint16 m_port{};

static QString getBookmarksJsonText();
static QString getBookmarksJsonText(bool hideCurrent = false);

static QString getCommandSnippetsJsonText();

Expand Down

0 comments on commit aebae9a

Please sign in to comment.