diff --git a/.discourse-compatibility b/.discourse-compatibility index 0c72b2c..618cc30 100644 --- a/.discourse-compatibility +++ b/.discourse-compatibility @@ -1,2 +1,3 @@ +< 3.2.0.beta2-dev: 134fcba29baf2ca92ec555dab1707c096712af14 3.1.999: 20f8f68d127a923942cca11a586caf4ea14019eb 2.9.0.beta12: 7137499c69065928c0fdd8795a3fb8d175e1ff3d diff --git a/assets/javascripts/discourse/initializers/enable-user-notes.js b/assets/javascripts/discourse/initializers/enable-user-notes.js index 703f89a..4d6a21d 100644 --- a/assets/javascripts/discourse/initializers/enable-user-notes.js +++ b/assets/javascripts/discourse/initializers/enable-user-notes.js @@ -10,6 +10,8 @@ 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 || !currentUser || @@ -68,8 +70,13 @@ export default { return; } - const cfs = dec.attrs.userCustomFields || {}; - if (cfs.user_notes_count > 0) { + const post = dec.getModel(); + if (!post) { + return; + } + + const ucf = post.user_custom_fields || {}; + if (ucf.user_notes_count > 0) { return dec.attach("user-notes-icon"); } }); @@ -79,23 +86,39 @@ export default { return; } - const cfs = dec.attrs.userCustomFields || {}; - if (cfs.user_notes_count > 0) { + const post = dec.getModel(); + if (!post) { + return; + } + + const ucf = post.user_custom_fields || {}; + if (ucf.user_notes_count > 0) { return dec.attach("user-notes-icon"); } }); + api.addPostAdminMenuButton((attrs) => { + return { + icon: "pencil-alt", + label: "user_notes.attach", + 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); - api.decorateWidget("post-admin-menu:after", (dec) => { - return dec.h( - "ul", - dec.attach("post-admin-menu-button", { - icon: "pencil-alt", - label: "user_notes.attach", - action: "showUserNotes", - secondaryAction: "closeAdminMenu", - className: "add-user-note", - }) - ); + appEvents.trigger("post-stream:refresh", { + id: post.id, + }); + }, + { postId: attrs.id } + ); + }, + secondaryAction: "closeAdminMenu", + className: "add-user-note", + }; }); api.attachWidgetAction("post", "showUserNotes", widgetshowUserNotes);