mirror of
https://github.com/discourse/discourse.git
synced 2024-12-06 01:13:45 +08:00
19214aff18
1. "What Goes Up Must Come Down" – if you subscribe to message bus, make sure you also unsubscribe 2. When you unsubscribe - remove only your subscription, not **all** subscriptions on given channel Attempt #2. The first attempt tried to extend a core `@bound` method in new-user-narrative plugin which did not work. I reworked that plugin in the meantime. This new PR also cleans up message bus subscriptions in now core-merged chat plugin.
62 lines
1.4 KiB
JavaScript
62 lines
1.4 KiB
JavaScript
import { withPluginApi } from "discourse/lib/plugin-api";
|
|
import { bind } from "discourse-common/utils/decorators";
|
|
|
|
export default {
|
|
name: "new-user-narrative",
|
|
|
|
initialize(container) {
|
|
const siteSettings = container.lookup("service:site-settings");
|
|
|
|
if (!siteSettings.discourse_narrative_bot_enabled) {
|
|
return;
|
|
}
|
|
|
|
this.messageBus = container.lookup("service:message-bus");
|
|
this.appEvents = container.lookup("service:app-events");
|
|
|
|
withPluginApi("0.8.7", (api) => {
|
|
const currentUser = api.getCurrentUser();
|
|
|
|
if (!currentUser) {
|
|
return;
|
|
}
|
|
|
|
api.dispatchWidgetAppEvent(
|
|
"site-header",
|
|
"header",
|
|
"header:search-context-trigger"
|
|
);
|
|
|
|
api.attachWidgetAction(
|
|
"header",
|
|
"headerSearchContextTrigger",
|
|
function () {
|
|
if (this.site.mobileView) {
|
|
this.state.skipSearchContext = false;
|
|
} else {
|
|
this.state.contextEnabled = true;
|
|
this.state.searchContextType = "topic";
|
|
}
|
|
}
|
|
);
|
|
|
|
this.messageBus.subscribe(
|
|
"/new_user_narrative/tutorial_search",
|
|
this.onMessage
|
|
);
|
|
});
|
|
},
|
|
|
|
teardown() {
|
|
this.messageBus?.unsubscribe(
|
|
"/new_user_narrative/tutorial_search",
|
|
this.onMessage
|
|
);
|
|
},
|
|
|
|
@bind
|
|
onMessage() {
|
|
this.appEvents.trigger("header:search-context-trigger");
|
|
},
|
|
};
|