From faaa055d3eb1e609588c91a8182beef20e7c312b Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Thu, 26 Oct 2023 11:54:01 +0200 Subject: [PATCH] use app events to force refresh of specific post --- .../initializers/enable-user-notes.js | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/assets/javascripts/discourse/initializers/enable-user-notes.js b/assets/javascripts/discourse/initializers/enable-user-notes.js index 20563fc..0ebb1fb 100644 --- a/assets/javascripts/discourse/initializers/enable-user-notes.js +++ b/assets/javascripts/discourse/initializers/enable-user-notes.js @@ -11,6 +11,7 @@ export default { initialize(container) { const siteSettings = container.lookup("site-settings:main"); const currentUser = container.lookup("current-user:main"); + const appEvents = container.lookup("service:app-events"); if ( !siteSettings.user_notes_enabled || @@ -100,20 +101,21 @@ export default { return { icon: "pencil-alt", label: "user_notes.attach", - action: async (post) => { - await new Promise((resolve) => { - showUserNotes( - store, - attrs.user_id, - (count) => { - const ucf = post.user_custom_fields || {}; - ucf.user_notes_count = count; - post.set("user_custom_fields", ucf); - resolve(); - }, - { postId: attrs.id } - ); - }); + action: (post) => { + showUserNotes( + store, + attrs.user_id, + (count) => { + const ucf = post.user_custom_fields || {}; + ucf.user_notes_count = count; + post.set("user_custom_fields", ucf); + + appEvents.trigger("post-stream:refresh", { + id: post.id, + }); + }, + { postId: attrs.id } + ); }, secondaryAction: "closeAdminMenu", className: "add-user-note",