mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-11-04 15:11:31 +08:00 
			
		
		
		
	similar notes is getting updated automatically after the title change
This commit is contained in:
		
							parent
							
								
									9404e27cba
								
							
						
					
					
						commit
						2e05cb1764
					
				@ -267,11 +267,13 @@ class Attributes {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    syncDataReceived(syncData) {
 | 
					    eventReceived(name, data) {
 | 
				
			||||||
        if (syncData.find(sd => sd.entityName === 'attributes' && sd.noteId === this.ctx.note.noteId)) {
 | 
					        if (name === 'syncData') {
 | 
				
			||||||
 | 
					            if (data.find(sd => sd.entityName === 'attributes' && sd.noteId === this.ctx.note.noteId)) {
 | 
				
			||||||
                this.reloadAttributes();
 | 
					                this.reloadAttributes();
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default Attributes;
 | 
					export default Attributes;
 | 
				
			||||||
@ -374,7 +374,7 @@ ws.subscribeToOutsideSyncMessages(syncData => {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
ws.subscribeToAllSyncMessages(syncData => {
 | 
					ws.subscribeToAllSyncMessages(syncData => {
 | 
				
			||||||
    for (const tc of tabContexts) {
 | 
					    for (const tc of tabContexts) {
 | 
				
			||||||
        tc.syncDataReceived(syncData);
 | 
					        tc.eventReceived('syncData', syncData);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -106,10 +106,10 @@ class Sidebar {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    syncDataReceived(syncData) {
 | 
					    eventReceived(name, data) {
 | 
				
			||||||
        for (const widget of this.widgets) {
 | 
					        for (const widget of this.widgets) {
 | 
				
			||||||
            if (widget.syncDataReceived) {
 | 
					            if (widget.eventReceived) {
 | 
				
			||||||
                widget.syncDataReceived(syncData);
 | 
					                widget.eventReceived(name, data);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -267,6 +267,8 @@ class TabContext {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        // run async
 | 
					        // run async
 | 
				
			||||||
        bundleService.executeRelationBundles(this.note, 'runOnNoteChange', this);
 | 
					        bundleService.executeRelationBundles(this.note, 'runOnNoteChange', this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        this.eventReceived('noteSaved');
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async saveNoteIfChanged() {
 | 
					    async saveNoteIfChanged() {
 | 
				
			||||||
@ -366,11 +368,11 @@ class TabContext {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    syncDataReceived(syncData) {
 | 
					    eventReceived(name, data) {
 | 
				
			||||||
        this.attributes.syncDataReceived(syncData);
 | 
					        this.attributes.eventReceived(name, data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (this.sidebar) {
 | 
					        if (this.sidebar) {
 | 
				
			||||||
            this.sidebar.syncDataReceived(syncData);
 | 
					            this.sidebar.eventReceived(name, data);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -81,13 +81,15 @@ class AttributesWidget extends StandardWidget {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    syncDataReceived(syncData) {
 | 
					    eventReceived(name, data) {
 | 
				
			||||||
        if (syncData.find(sd => sd.entityName === 'attributes' && sd.noteId === this.ctx.note.noteId)) {
 | 
					        if (name === 'syncData') {
 | 
				
			||||||
 | 
					            if (data.find(sd => sd.entityName === 'attributes' && sd.noteId === this.ctx.note.noteId)) {
 | 
				
			||||||
                // no need to invalidate attributes since the Attribute class listens to this as well
 | 
					                // no need to invalidate attributes since the Attribute class listens to this as well
 | 
				
			||||||
                // (and is guaranteed to run first)
 | 
					                // (and is guaranteed to run first)
 | 
				
			||||||
                this.doRenderBody();
 | 
					                this.doRenderBody();
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default AttributesWidget;
 | 
					export default AttributesWidget;
 | 
				
			||||||
@ -44,8 +44,9 @@ class LinkMapWidget extends StandardWidget {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    syncDataReceived(syncData) {
 | 
					    eventReceived(name, data) {
 | 
				
			||||||
        if (syncData.find(sd => sd.entityName === 'attributes' && sd.noteId === this.ctx.note.noteId)) {
 | 
					        if (name === 'syncData') {
 | 
				
			||||||
 | 
					            if (data.find(sd => sd.entityName === 'attributes' && sd.noteId === this.ctx.note.noteId)) {
 | 
				
			||||||
                // no need to invalidate attributes since the Attribute class listens to this as well
 | 
					                // no need to invalidate attributes since the Attribute class listens to this as well
 | 
				
			||||||
                // (and is guaranteed to run first)
 | 
					                // (and is guaranteed to run first)
 | 
				
			||||||
                if (this.linkMapService) {
 | 
					                if (this.linkMapService) {
 | 
				
			||||||
@ -54,5 +55,6 @@ class LinkMapWidget extends StandardWidget {
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default LinkMapWidget;
 | 
					export default LinkMapWidget;
 | 
				
			||||||
@ -45,11 +45,13 @@ class NoteInfoWidget extends StandardWidget {
 | 
				
			|||||||
        $mime.text(note.mime);
 | 
					        $mime.text(note.mime);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    syncDataReceived(syncData) {
 | 
					    eventReceived(name, data) {
 | 
				
			||||||
        if (syncData.find(sd => sd.entityName === 'notes' && sd.entityId === this.ctx.note.noteId)) {
 | 
					        if (name === 'syncData') {
 | 
				
			||||||
 | 
					            if (data.find(sd => sd.entityName === 'notes' && sd.entityId === this.ctx.note.noteId)) {
 | 
				
			||||||
                this.doRenderBody();
 | 
					                this.doRenderBody();
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default NoteInfoWidget;
 | 
					export default NoteInfoWidget;
 | 
				
			||||||
@ -41,11 +41,13 @@ class NoteRevisionsWidget extends StandardWidget {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    syncDataReceived(syncData) {
 | 
					    eventReceived(name, data) {
 | 
				
			||||||
        if (syncData.find(sd => sd.entityName === 'note_revisions' && sd.noteId === this.ctx.note.noteId)) {
 | 
					        if (name === 'syncData') {
 | 
				
			||||||
 | 
					            if (data.find(sd => sd.entityName === 'note_revisions' && sd.noteId === this.ctx.note.noteId)) {
 | 
				
			||||||
                this.doRenderBody();
 | 
					                this.doRenderBody();
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default NoteRevisionsWidget;
 | 
					export default NoteRevisionsWidget;
 | 
				
			||||||
@ -2,8 +2,6 @@ import StandardWidget from "./standard_widget.js";
 | 
				
			|||||||
import linkService from "../services/link.js";
 | 
					import linkService from "../services/link.js";
 | 
				
			||||||
import server from "../services/server.js";
 | 
					import server from "../services/server.js";
 | 
				
			||||||
import treeCache from "../services/tree_cache.js";
 | 
					import treeCache from "../services/tree_cache.js";
 | 
				
			||||||
import treeUtils from "../services/tree_utils.js";
 | 
					 | 
				
			||||||
import treeService from "../services/tree.js";
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
class SimilarNotesWidget extends StandardWidget {
 | 
					class SimilarNotesWidget extends StandardWidget {
 | 
				
			||||||
    getWidgetTitle() { return "Similar notes"; }
 | 
					    getWidgetTitle() { return "Similar notes"; }
 | 
				
			||||||
@ -11,6 +9,9 @@ class SimilarNotesWidget extends StandardWidget {
 | 
				
			|||||||
    getMaxHeight() { return "200px"; }
 | 
					    getMaxHeight() { return "200px"; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async doRenderBody() {
 | 
					    async doRenderBody() {
 | 
				
			||||||
 | 
					        // remember which title was when we found the similar notes
 | 
				
			||||||
 | 
					        this.title = this.ctx.note.title;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const similarNotes = await server.get('similar_notes/' + this.ctx.note.noteId);
 | 
					        const similarNotes = await server.get('similar_notes/' + this.ctx.note.noteId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (similarNotes.length === 0) {
 | 
					        if (similarNotes.length === 0) {
 | 
				
			||||||
@ -39,6 +40,16 @@ class SimilarNotesWidget extends StandardWidget {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        this.$body.empty().append($list);
 | 
					        this.$body.empty().append($list);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    eventReceived(name, data) {
 | 
				
			||||||
 | 
					        if (name === 'noteSaved') {
 | 
				
			||||||
 | 
					            if (this.title !== this.ctx.note.title) {
 | 
				
			||||||
 | 
					                this.rendered = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                this.renderBody();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default SimilarNotesWidget;
 | 
					export default SimilarNotesWidget;
 | 
				
			||||||
@ -112,7 +112,7 @@ class StandardWidget {
 | 
				
			|||||||
        };
 | 
					        };
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    syncDataReceived(syncData) {}
 | 
					    eventReceived(name, data) {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    cleanup() {}
 | 
					    cleanup() {}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user