Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .discourse-compatibility
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
< 2025.12.0-latest: 3fe319b82c9146b15743537d38fdff753c35dfdb
< 3.6.0.beta2-latest: 68e88152d28189b3c22ec0011729fd765cf5c43a
< 3.6.0.beta1-dev: 232ac13322c390ee7646007b91982e7617dccb90
< 3.5.0.beta8-dev: 76183351645aea8d0837f602d9f3ab8c89994ed6
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import bodyClass from "discourse/helpers/body-class";
import { apiInitializer } from "discourse/lib/api";
import { withSilencedDeprecations } from "discourse/lib/deprecated";

const PLUGIN_ID = "whos-online";

export default apiInitializer((api) => {
const siteSettings = api.container.lookup("service:site-settings");
Expand Down Expand Up @@ -93,61 +90,4 @@ function customizePost(api) {
return value;
}
);

withSilencedDeprecations("discourse.post-stream-widget-overrides", () =>
customizeWidgetPost(api)
);
}

function customizeWidgetPost(api) {
api.modifyClass("component:scrolling-post-stream", {
pluginId: PLUGIN_ID,

didInsertElement() {
this._super();
this.appEvents.on("whosonline:changed", this, this._whosOnlineCallback);
},

willDestroyElement() {
this.appEvents.off("whosonline:changed", this, this._whosOnlineCallback);
},

_whosOnlineCallback(changedUserIds) {
changedUserIds.forEach((id) => {
let postIds = this.attrs.posts.value
.filter(({ user_id }) => {
return user_id === id;
})
.map((post) => post.id);
postIds.forEach((postId) => {
this.dirtyKeys.keyDirty(`post-${postId}`);
this.dirtyKeys.keyDirty(`post-${postId}-avatar-${id}`, {
onRefresh: "updateOnline",
});
});
});
this.queueRerender();
},
});

api.reopenWidget("post-avatar", {
buildKey: (attrs) => `post-${attrs.id}-avatar-${attrs.user_id}`,
isUserOnline(userId) {
return this.register.lookup("service:whos-online").isUserOnline(userId);
},
defaultState(attrs) {
return {
online: this.isUserOnline(attrs.user_id),
};
},
updateOnline() {
this.state.online = this.isUserOnline(this.attrs.user_id);
},
buildClasses(attrs, state) {
if (state.online) {
return "user-online";
}
return [];
},
});
}
18 changes: 0 additions & 18 deletions assets/javascripts/discourse/services/whos-online.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import Site from "discourse/models/site";

export default class WhosOnlineService extends Service {
@service presence;
@service appEvents;

#channel;

Expand All @@ -15,9 +14,6 @@ export default class WhosOnlineService extends Service {
if (this.enabled) {
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() {
Expand All @@ -32,20 +28,6 @@ export default class WhosOnlineService extends Service {
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([]);

const enteredUsers = [...currentUserIds].filter((x) => !prevUserIds.has(x));
const leftUsers = [...prevUserIds].filter((x) => !currentUserIds.has(x));
const changedUsers = [...enteredUsers, ...leftUsers];

if (changedUsers.length > 0) {
this.appEvents.trigger("whosonline:changed", changedUsers);
}
}

get enabled() {
const anonAndLoginRequired =
!this.currentUser && this.siteSettings.login_required;
Expand Down