From e6662e280be3540c6ea92f2de56e1839c74d4032 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Saquetim?= Date: Mon, 13 Oct 2025 23:13:39 -0300 Subject: [PATCH 1/2] DEV: Refactor `whos-online` plugin to remove legacy Ember decorators Replaced the use of deprecated Ember decorators like `@readOnly` and `@computed` with native getter methods to modernize the codebase. Updated the `#channel` property to utilize native class field syntax for improved clarity and maintainability. This change prepares the plugin for future updates and aligns it with best practices in modern Ember.js development. Existing functionality remains unaffected. --- .../components/whos-online-avatar.gjs | 18 ++++++------- .../discourse/components/whos-online.gjs | 13 +++------ .../discourse/services/whos-online.js | 27 ++++++++++++------- 3 files changed, 30 insertions(+), 28 deletions(-) diff --git a/assets/javascripts/discourse/components/whos-online-avatar.gjs b/assets/javascripts/discourse/components/whos-online-avatar.gjs index 9a160f3..f0ebf51 100644 --- a/assets/javascripts/discourse/components/whos-online-avatar.gjs +++ b/assets/javascripts/discourse/components/whos-online-avatar.gjs @@ -1,16 +1,14 @@ -import Component from "@ember/component"; import avatar from "discourse/helpers/avatar"; -export default class WhosOnlineAvatar extends Component { - tagName = "a"; - attributeBindings = ["user.username:data-user-card", "user.path:href"]; - - ; + +export default WhosOnlineAvatar; diff --git a/assets/javascripts/discourse/components/whos-online.gjs b/assets/javascripts/discourse/components/whos-online.gjs index b2b0e84..bd5f747 100644 --- a/assets/javascripts/discourse/components/whos-online.gjs +++ b/assets/javascripts/discourse/components/whos-online.gjs @@ -1,6 +1,4 @@ import Component from "@ember/component"; -import { computed } from "@ember/object"; -import { readOnly } from "@ember/object/computed"; import { service } from "@ember/service"; import { i18n } from "discourse-i18n"; import WhosOnlineAvatar from "./whos-online-avatar"; @@ -8,9 +6,6 @@ import WhosOnlineAvatar from "./whos-online-avatar"; export default class WhosOnline extends Component { @service whosOnline; - @readOnly("whosOnline.count") count; - - @computed("whosOnline.users.[]") get users() { return this.whosOnline.users?.slice( 0, @@ -18,22 +13,22 @@ export default class WhosOnline extends Component { ); } - @computed("users", "users.length") get hasUsers() { return this.users?.length >= this.siteSettings.whos_online_minimum_display; } - @computed("count") + get count() { + return this.whosOnline.count; + } + get hasCount() { return this.count >= this.siteSettings.whos_online_minimum_display; } - @computed("count") get isLong() { return this.count >= this.siteSettings.whos_online_collapse_threshold; } - @computed("count") get shouldDisplay() { if ( this.count < this.siteSettings.whos_online_minimum_display && diff --git a/assets/javascripts/discourse/services/whos-online.js b/assets/javascripts/discourse/services/whos-online.js index 432fc6a..de0400f 100755 --- a/assets/javascripts/discourse/services/whos-online.js +++ b/assets/javascripts/discourse/services/whos-online.js @@ -1,5 +1,3 @@ -import { computed } from "@ember/object"; -import { readOnly } from "@ember/object/computed"; import Service, { service } from "@ember/service"; import Site from "discourse/models/site"; @@ -7,22 +5,34 @@ export default class WhosOnlineService extends Service { @service presence; @service appEvents; - @readOnly("channel.users") users; - @readOnly("channel.count") count; - @readOnly("channel.countOnly") countOnly; + #channel; init() { super.init(...arguments); - this.set("channel", this.presence.getChannel("/whos-online/online")); + this.#channel = this.presence.getChannel("/whos-online/online"); if (this.enabled) { - this.channel.subscribe(Site.currentProp("whos_online_state")); + this.#channel.subscribe(Site.currentProp("whos_online_state")); } + // TODO (glimmer-post-stream): remove this observer when removing the legacy widget code this.addObserver("users.[]", this, this._usersChanged); } + get users() { + return this.#channel?.users; + } + + get count() { + return this.#channel?.count || 0; + } + + get countOnly() { + return this.#channel?.countOnly || 0; + } + + // TODO (glimmer-post-stream): remove this function when removing the legacy widget code _usersChanged() { const currentUserIds = new Set(this.users?.map((u) => u.id) || []); const prevUserIds = this._prevUserIds || new Set([]); @@ -36,7 +46,6 @@ export default class WhosOnlineService extends Service { } } - @computed get enabled() { const anonAndLoginRequired = !this.currentUser && this.siteSettings.login_required; @@ -52,6 +61,6 @@ export default class WhosOnlineService extends Service { } isUserOnline(id) { - return !!this.channel?.users?.find((user) => user.id === id); + return !!this.#channel?.users?.find((user) => user.id === id); } } From b03eaaea6ce0a940c6ebd932f0cda5571165b46a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Saquetim?= Date: Tue, 14 Oct 2025 15:33:16 -0300 Subject: [PATCH 2/2] DEV: Update `.discourse-compatibility` for latest beta version Added compatibility entry for `< 3.6.0.beta2-latest` in the `whos-online` plugin to reflect changes in supported Discourse versions. This ensures accurate version checks and maintains plugin stability across updates. --- .discourse-compatibility | 1 + 1 file changed, 1 insertion(+) diff --git a/.discourse-compatibility b/.discourse-compatibility index 0fd246b..0867765 100644 --- a/.discourse-compatibility +++ b/.discourse-compatibility @@ -1,3 +1,4 @@ +< 3.6.0.beta2-latest: 68e88152d28189b3c22ec0011729fd765cf5c43a < 3.6.0.beta1-dev: 232ac13322c390ee7646007b91982e7617dccb90 < 3.5.0.beta8-dev: 76183351645aea8d0837f602d9f3ab8c89994ed6 < 3.5.0.beta5-dev: 7b5201ca936208a19e29c4a1d3b16511120c3fd3