From d08a36174d2a14298f31a8191bd7bdf67ec8c2c2 Mon Sep 17 00:00:00 2001 From: zadam Date: Sat, 1 Jun 2019 12:14:09 +0200 Subject: [PATCH] attribute sync should trigger note reload, fixes #551 --- src/public/javascripts/services/note_detail.js | 16 ++++++++++++---- src/services/messaging.js | 7 +++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/public/javascripts/services/note_detail.js b/src/public/javascripts/services/note_detail.js index a20275a87..3c0d91dcc 100644 --- a/src/public/javascripts/services/note_detail.js +++ b/src/public/javascripts/services/note_detail.js @@ -337,10 +337,18 @@ function fireDetailLoaded() { } messagingService.subscribeToSyncMessages(syncData => { - for (const sync of syncData) { - if (sync.entityName === 'notes') { - refreshTabs(null, sync.entityId); - } + const noteIdsToRefresh = new Set(); + + syncData + .filter(sync => sync.entityName === 'notes') + .forEach(sync => noteIdsToRefresh.add(sync.entityId)); + + syncData + .filter(sync => sync.entityName === 'attributes') + .forEach(sync => noteIdsToRefresh.add(sync.noteId)); + + for (const noteId of noteIdsToRefresh) { + refreshTabs(null, noteId); } }); diff --git a/src/services/messaging.js b/src/services/messaging.js index f19c0b054..bae58ac0c 100644 --- a/src/services/messaging.js +++ b/src/services/messaging.js @@ -65,6 +65,13 @@ async function sendMessageToAllClients(message) { async function sendPing(client, lastSentSyncId) { const syncData = await sql.getRows("SELECT * FROM sync WHERE id > ?", [lastSentSyncId]); + + for (const sync of syncData) { + if (sync.entityName === 'attributes') { + sync.noteId = await sql.getValue(`SELECT noteId FROM attributes WHERE attributeId = ?`, [sync.entityId]); + } + } + const stats = require('./sync').stats; await sendMessage(client, {