discourse-follow/assets/javascripts/discourse/initializers/follow-initializer.js
Régis Hanol 506bd361ab
DEV: Use new addSaveableCustomFields plugin API (#166)
Follow-up to discourse/discourse commit that simplified the method
signature from `addSaveableCustomFields({ page })` to
`addSaveableCustomFields(page)`.

cf. https://github.com/discourse/discourse/pull/36757
2025-12-18 11:29:57 +01:00

58 lines
1.5 KiB
JavaScript

import { withPluginApi } from "discourse/lib/plugin-api";
import { userPath } from "discourse/lib/url";
import { i18n } from "discourse-i18n";
export default {
name: "follow-plugin-initializer",
initialize(/*container*/) {
withPluginApi((api) => {
const currentUser = api.getCurrentUser();
if (!currentUser) {
return;
}
api.replaceIcon(
"notification.following",
"discourse-follow-new-follower"
);
api.replaceIcon(
"notification.following_created_topic",
"discourse-follow-new-topic"
);
api.replaceIcon(
"notification.following_replied",
"discourse-follow-new-reply"
);
if (api.registerNotificationTypeRenderer) {
api.registerNotificationTypeRenderer(
"following",
(NotificationTypeBase) => {
return class extends NotificationTypeBase {
get linkTitle() {
return i18n("notifications.titles.following");
}
get linkHref() {
return userPath(this.notification.data.display_username);
}
get icon() {
return "discourse-follow-new-follower";
}
get label() {
return this.notification.data.display_username;
}
get description() {
return i18n("notifications.following_description", {});
}
};
}
);
}
api.addSaveableCustomFields("notifications");
});
},
};