diff --git a/src/public/javascripts/services/messaging.js b/src/public/javascripts/services/messaging.js index 09c7556ac..977342058 100644 --- a/src/public/javascripts/services/messaging.js +++ b/src/public/javascripts/services/messaging.js @@ -3,7 +3,8 @@ import infoService from "./info.js"; const $outstandingSyncsCount = $("#outstanding-syncs-count"); -const syncMessageHandlers = []; +const allSyncMessageHandlers = []; +const outsideSyncMessageHandlers = []; const messageHandlers = []; let ws; @@ -26,8 +27,12 @@ function subscribeToMessages(messageHandler) { messageHandlers.push(messageHandler); } -function subscribeToSyncMessages(messageHandler) { - syncMessageHandlers.push(messageHandler); +function subscribeToOutsideSyncMessages(messageHandler) { + outsideSyncMessageHandlers.push(messageHandler); +} + +function subscribeToAllSyncMessages(messageHandler) { + allSyncMessageHandlers.push(messageHandler); } function handleMessage(event) { @@ -46,9 +51,13 @@ function handleMessage(event) { lastSyncId = message.data[message.data.length - 1].id; } + for (const syncMessageHandler of allSyncMessageHandlers) { + syncMessageHandler(message.data); + } + const syncData = message.data.filter(sync => sync.sourceId !== glob.sourceId); - for (const syncMessageHandler of syncMessageHandlers) { + for (const syncMessageHandler of outsideSyncMessageHandlers) { syncMessageHandler(syncData); } @@ -102,5 +111,6 @@ setTimeout(() => { export default { logError, subscribeToMessages, - subscribeToSyncMessages + subscribeToAllSyncMessages, + subscribeToOutsideSyncMessages }; \ No newline at end of file diff --git a/src/public/javascripts/services/note_detail.js b/src/public/javascripts/services/note_detail.js index 4196cbb78..c791bcfb8 100644 --- a/src/public/javascripts/services/note_detail.js +++ b/src/public/javascripts/services/note_detail.js @@ -357,13 +357,14 @@ function fireDetailLoaded() { detailLoadedListeners = []; } -messagingService.subscribeToSyncMessages(syncData => { +messagingService.subscribeToOutsideSyncMessages(syncData => { const noteIdsToRefresh = new Set(); syncData .filter(sync => sync.entityName === 'notes') .forEach(sync => noteIdsToRefresh.add(sync.entityId)); + // we need to reload because of promoted attributes syncData .filter(sync => sync.entityName === 'attributes') .forEach(sync => noteIdsToRefresh.add(sync.noteId)); @@ -373,6 +374,12 @@ messagingService.subscribeToSyncMessages(syncData => { } }); +messagingService.subscribeToAllSyncMessages(syncData => { + for (const tc of tabContexts) { + tc.syncDataReceived(syncData); + } +}); + $tabContentsContainer.on("dragover", e => e.preventDefault()); $tabContentsContainer.on("dragleave", e => e.preventDefault()); diff --git a/src/public/javascripts/services/sidebar.js b/src/public/javascripts/services/sidebar.js index 115870d9c..612558181 100644 --- a/src/public/javascripts/services/sidebar.js +++ b/src/public/javascripts/services/sidebar.js @@ -27,6 +27,7 @@ class Sidebar { */ constructor(ctx) { this.ctx = ctx; + this.widgets = []; this.$sidebar = ctx.$tabContent.find(".note-detail-sidebar"); this.$widgets = this.$sidebar.find(".note-detail-widgets"); this.$showSideBarButton = this.ctx.$tabContent.find(".show-sidebar-button"); @@ -46,6 +47,7 @@ class Sidebar { } async noteLoaded() { + this.widgets = []; this.$widgets.empty(); const widgetClasses = [AttributesWidget, LinkMapWidget, NoteRevisionsWidget, NoteInfoWidget]; @@ -54,6 +56,8 @@ class Sidebar { const $widget = this.createWidgetElement(); const attributesWidget = new widgetClass(this.ctx, $widget); + this.widgets.push(attributesWidget); + attributesWidget.renderBody(); // let it run in parallel this.$widgets.append($widget); @@ -69,6 +73,14 @@ class Sidebar { return $widget; } + + syncDataReceived(syncData) { + for (const widget of this.widgets) { + if (widget.syncDataReceived) { + widget.syncDataReceived(syncData); + } + } + } } export default Sidebar; \ No newline at end of file diff --git a/src/public/javascripts/services/tab_context.js b/src/public/javascripts/services/tab_context.js index 5751a54f8..7e80f67bb 100644 --- a/src/public/javascripts/services/tab_context.js +++ b/src/public/javascripts/services/tab_context.js @@ -244,7 +244,10 @@ class TabContext { treeService.setNoteTitle(this.note.noteId, this.note.title); - await server.put('notes/' + this.note.noteId, this.note.dto); + const resp = await server.put('notes/' + this.note.noteId, this.note.dto); + + this.note.dateModified = resp.dateModified; + this.note.utcDateModified = resp.utcDateModified; if (this.note.isProtected) { protectedSessionHolder.touchProtectedSession(); @@ -352,6 +355,12 @@ class TabContext { this.$tabContent.find('.aa-input').autocomplete('close'); } } + + syncDataReceived(syncData) { + if (this.sidebar) { + this.sidebar.syncDataReceived(syncData); + } + } } export default TabContext; \ No newline at end of file diff --git a/src/public/javascripts/services/tree.js b/src/public/javascripts/services/tree.js index 1cc5093dc..4a6d6850d 100644 --- a/src/public/javascripts/services/tree.js +++ b/src/public/javascripts/services/tree.js @@ -759,7 +759,7 @@ messagingService.subscribeToMessages(message => { } }); -messagingService.subscribeToSyncMessages(syncData => { +messagingService.subscribeToOutsideSyncMessages(syncData => { if (syncData.some(sync => sync.entityName === 'branches') || syncData.some(sync => sync.entityName === 'notes')) { diff --git a/src/public/javascripts/widgets/note_info.js b/src/public/javascripts/widgets/note_info.js index d412a3ca2..12113a809 100644 --- a/src/public/javascripts/widgets/note_info.js +++ b/src/public/javascripts/widgets/note_info.js @@ -54,6 +54,14 @@ class NoteInfoWidget { $type.text(note.type); $mime.text(note.mime); } + + syncDataReceived(syncData) { + if (syncData.find(sd => sd.entityName === 'notes' && sd.entityId === this.ctx.note.noteId)) { + console.log("Re-rendering note info"); + + this.renderBody(); + } + } } export default NoteInfoWidget; \ No newline at end of file diff --git a/src/routes/api/notes.js b/src/routes/api/notes.js index 64b658e92..72b8654db 100644 --- a/src/routes/api/notes.js +++ b/src/routes/api/notes.js @@ -68,7 +68,7 @@ async function updateNote(req) { const note = req.body; const noteId = req.params.noteId; - await noteService.updateNote(noteId, note); + return await noteService.updateNote(noteId, note); } async function deleteNote(req) { diff --git a/src/services/notes.js b/src/services/notes.js index 02b8ed77c..25bbf7e28 100644 --- a/src/services/notes.js +++ b/src/services/notes.js @@ -371,6 +371,11 @@ async function updateNote(noteId, noteUpdates) { } await protectNoteRevisions(note); + + return { + dateModified: note.dateModified, + utcDateModified: note.utcDateModified + }; } /** @return {boolean} - true if note has been deleted, false otherwise */