DEV: Deprecate show_in_ui argument of the register_stat API (#28727)

We need to start printing deprecation notices when the `show_in_ui` argument is used because it works only for the old about page which will be removed soon. For the new about page, we've introduced a new API `addAboutPageActivity` which is more flexible than a true/false argument on the server side.

Internal topic: t/136551.
This commit is contained in:
Osama Sayegh
2024-09-04 19:58:14 +03:00
committed by GitHub
parent e6edd52047
commit a23773f83d
7 changed files with 63 additions and 29 deletions

View File

@ -29,11 +29,26 @@ class ChatSetupInit {
setOwner(this, owner);
this.appEvents.on("discourse:focus-changed", this, "_handleFocusChanged");
if (!this.chatService.userCanChat) {
return;
}
withPluginApi("0.12.1", (api) => {
api.addAboutPageActivity("chat_messages", (periods) => {
const count = periods["7_days"];
if (count) {
return {
icon: "comment-dots",
class: "chat-messages",
activityText: I18n.t("about.activities.chat_messages", {
count,
formatted_number: number(count),
}),
period: I18n.t("about.activities.periods.last_7_days"),
};
}
});
if (!this.chatService.userCanChat) {
return;
}
api.onPageChange((path) => {
const route = this.router.recognize(path);
if (route.name.startsWith("chat.")) {
@ -157,21 +172,6 @@ class ChatSetupInit {
category: "organisms",
id: "chat",
});
api.addAboutPageActivity("chat_messages", (periods) => {
const count = periods["7_days"];
if (count) {
return {
icon: "comment-dots",
class: "chat-messages",
activityText: I18n.t("about.activities.chat_messages", {
count,
formatted_number: number(count),
}),
period: I18n.t("about.activities.periods.last_7_days"),
};
}
});
});
}

View File

@ -500,9 +500,7 @@ after_initialize do
register_email_unsubscriber("chat_summary", EmailControllerHelper::ChatSummaryUnsubscriber)
register_stat("chat_messages", show_in_ui: true, expose_via_api: true) do
Chat::Statistics.about_messages
end
register_stat("chat_messages", expose_via_api: true) { Chat::Statistics.about_messages }
register_stat("chat_users", expose_via_api: true) { Chat::Statistics.about_users }
register_stat("chat_channels", expose_via_api: true) { Chat::Statistics.about_channels }