Skip to content

Commit

Permalink
DEV: Upgrade to the Glimmer topic list
Browse files Browse the repository at this point in the history
  • Loading branch information
megothss committed Jan 10, 2025
1 parent 07de7ce commit 9bd56ae
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 39 deletions.
1 change: 1 addition & 0 deletions .discourse-compatibility
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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", {
Expand Down Expand Up @@ -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", {
Expand All @@ -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", {
Expand All @@ -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() {
Expand All @@ -150,6 +135,6 @@ export default apiInitializer("0.8", (api) => {
return "user-online";
}
return [];
},
}
});
});

0 comments on commit 9bd56ae

Please sign in to comment.