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 @@
< 3.6.0.beta2-latest: 68e88152d28189b3c22ec0011729fd765cf5c43a
< 3.6.0.beta1-dev: 232ac13322c390ee7646007b91982e7617dccb90
< 3.5.0.beta8-dev: 76183351645aea8d0837f602d9f3ab8c89994ed6
< 3.5.0.beta5-dev: 7b5201ca936208a19e29c4a1d3b16511120c3fd3
Expand Down
18 changes: 8 additions & 10 deletions assets/javascripts/discourse/components/whos-online-avatar.gjs
Original file line number Diff line number Diff line change
@@ -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"];

<template>
const WhosOnlineAvatar = <template>
<a data-user-card={{@user.username}} href={{@user.path}}>
{{avatar
this.user
@user
avatarTemplatePath="avatar_template"
title=this.user.username
title=@user.username
imageSize="small"
}}
</template>
}
</a>
</template>;

export default WhosOnlineAvatar;
13 changes: 4 additions & 9 deletions assets/javascripts/discourse/components/whos-online.gjs
Original file line number Diff line number Diff line change
@@ -1,39 +1,34 @@
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";

export default class WhosOnline extends Component {
@service whosOnline;

@readOnly("whosOnline.count") count;

@computed("whosOnline.users.[]")
get users() {
return this.whosOnline.users?.slice(
0,
this.siteSettings.whos_online_maximum_display
);
}

@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 &&
Expand Down
27 changes: 18 additions & 9 deletions assets/javascripts/discourse/services/whos-online.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,38 @@
import { computed } from "@ember/object";
import { readOnly } from "@ember/object/computed";
import Service, { service } from "@ember/service";
import Site from "discourse/models/site";

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([]);
Expand All @@ -36,7 +46,6 @@ export default class WhosOnlineService extends Service {
}
}

@computed
get enabled() {
const anonAndLoginRequired =
!this.currentUser && this.siteSettings.login_required;
Expand All @@ -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);
}
}