From 9bd56ae4295cd88dd7ebe51f7b1493a352f6e0bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Saquetim?= Date: Fri, 10 Jan 2025 17:29:19 -0300 Subject: [PATCH] DEV: Upgrade to the Glimmer topic list --- .discourse-compatibility | 1 + .../intitialize-whos-online-indicators.js | 63 +++++++------------ 2 files changed, 25 insertions(+), 39 deletions(-) diff --git a/.discourse-compatibility b/.discourse-compatibility index ac6f8bb..ebe992e 100644 --- a/.discourse-compatibility +++ b/.discourse-compatibility @@ -1,3 +1,4 @@ +< 3.4.0.beta4-dev: 07de7ce25081e7038e48259801930ef1a97d36c0 < 3.4.0.beta3-dev: 699113133bcdff762c42823aace5164161ac50d7 < 3.4.0.beta1-dev: be99b48d01d65ffdb1f646996e9917b96da78bdc < 3.3.0.beta1-dev: 98b5a78d48a18fedb6075bb9c4eeaf7e3ebf96cc diff --git a/assets/javascripts/discourse/api-initializers/intitialize-whos-online-indicators.js b/assets/javascripts/discourse/api-initializers/intitialize-whos-online-indicators.js index b8a03e0..2335e30 100644 --- a/assets/javascripts/discourse/api-initializers/intitialize-whos-online-indicators.js +++ b/assets/javascripts/discourse/api-initializers/intitialize-whos-online-indicators.js @@ -4,7 +4,7 @@ import discourseComputed, { observes } from "discourse-common/utils/decorators"; const PLUGIN_ID = "whos-online"; -export default apiInitializer("0.8", (api) => { +export default apiInitializer("1.39.0", (api) => { const siteSettings = api.container.lookup("service:site-settings"); const indicatorType = siteSettings.whos_online_avatar_indicator; @@ -16,7 +16,7 @@ export default apiInitializer("0.8", (api) => { !( siteSettings.whos_online_display_public || api.getCurrentUser()?.trust_level >= - siteSettings.whos_online_display_min_trust_level + siteSettings.whos_online_display_min_trust_level ) ) { return; @@ -33,7 +33,7 @@ export default apiInitializer("0.8", (api) => { @discourseComputed("user", "whosOnline.users.[]") isOnline(user) { return user && this.whosOnline.isUserOnline(user.id); - }, + } }); api.modifyClass("route:user", { @@ -65,41 +65,26 @@ export default apiInitializer("0.8", (api) => { deactivate() { this._super(); document.body.classList.remove("user-page-online"); - }, + } }); + if (siteSettings.whos_online_avatar_indicator_topic_lists) { - api.modifyClass("component:topic-list-item", { - pluginId: PLUGIN_ID, - - whosOnline: service(), - classNameBindings: ["isOnline:last-poster-online"], - - @discourseComputed( - "topic.lastPoster.id", - "topic.lastPosterUser.id", - "whosOnline.users.[]" - ) - isOnline(lastPosterId, lastPosterUserId) { - return this.whosOnline.isUserOnline(lastPosterId || lastPosterUserId); - }, - }); - - api.modifyClass("component:latest-topic-list-item", { - pluginId: PLUGIN_ID, - - whosOnline: service(), - classNameBindings: ["isOnline:last-poster-online"], - - @discourseComputed( - "topic.lastPoster.id", - "topic.lastPosterUser.id", - "whosOnline.users.[]" - ) - isOnline(lastPosterId, lastPosterUserId) { - return this.whosOnline.isUserOnline(lastPosterId || lastPosterUserId); - }, - }); + const addLastPosterOnlineClassNameTransformer = ({ value: additionalClasses, context: { topic } }) => { + const whosOnline = api.container.lookup("service:whos-online"); + + const lastPosterId = topic.lastPoster.id; + const lastPosterUserId = topic.lastPosterUser.id; + + if (whosOnline.isUserOnline(lastPosterId || lastPosterUserId)) { + additionalClasses.push("last-poster-online"); + } + + return additionalClasses; + }; + + api.registerValueTransformer("latest-topic-list-item-class", addLastPosterOnlineClassNameTransformer); + api.registerValueTransformer("topic-list-item-class", addLastPosterOnlineClassNameTransformer); } api.modifyClass("component:scrolling-post-stream", { @@ -124,12 +109,12 @@ export default apiInitializer("0.8", (api) => { postIds.forEach((postId) => { this.dirtyKeys.keyDirty(`post-${postId}`); this.dirtyKeys.keyDirty(`post-${postId}-avatar-${id}`, { - onRefresh: "updateOnline", + onRefresh: "updateOnline" }); }); }); this.queueRerender(); - }, + } }); api.reopenWidget("post-avatar", { @@ -139,7 +124,7 @@ export default apiInitializer("0.8", (api) => { }, defaultState(attrs) { return { - online: this.isUserOnline(attrs.user_id), + online: this.isUserOnline(attrs.user_id) }; }, updateOnline() { @@ -150,6 +135,6 @@ export default apiInitializer("0.8", (api) => { return "user-online"; } return []; - }, + } }); });