2018-06-16 00:42:20 +08:00
|
|
|
import { withPluginApi } from "discourse/lib/plugin-api";
|
2022-12-12 23:32:25 +08:00
|
|
|
import { bind } from "discourse-common/utils/decorators";
|
2017-05-24 13:50:20 +08:00
|
|
|
|
|
|
|
export default {
|
2022-09-12 20:05:21 +08:00
|
|
|
name: "new-user-narrative",
|
2017-05-24 13:50:20 +08:00
|
|
|
|
|
|
|
initialize(container) {
|
2022-08-01 16:43:33 +08:00
|
|
|
const siteSettings = container.lookup("service:site-settings");
|
2022-12-12 23:32:25 +08:00
|
|
|
|
|
|
|
if (!siteSettings.discourse_narrative_bot_enabled) {
|
|
|
|
return;
|
2020-09-22 22:28:28 +08:00
|
|
|
}
|
2022-12-12 23:32:25 +08:00
|
|
|
|
|
|
|
this.messageBus = container.lookup("service:message-bus");
|
|
|
|
this.appEvents = container.lookup("service:app-events");
|
|
|
|
|
|
|
|
withPluginApi("0.8.7", (api) => {
|
2023-01-30 19:48:09 +08:00
|
|
|
this.currentUser = api.getCurrentUser();
|
2022-12-12 23:32:25 +08:00
|
|
|
|
2023-01-30 19:48:09 +08:00
|
|
|
if (!this.currentUser) {
|
2022-12-12 23:32:25 +08:00
|
|
|
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(
|
2023-01-30 19:48:09 +08:00
|
|
|
`/new_user_narrative/tutorial_search/${this.currentUser.id}`,
|
2022-12-12 23:32:25 +08:00
|
|
|
this.onMessage
|
|
|
|
);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
teardown() {
|
2023-01-30 19:48:09 +08:00
|
|
|
if (this.currentUser) {
|
|
|
|
this.messageBus?.unsubscribe(
|
|
|
|
`/new_user_narrative/tutorial_search/${this.currentUser.id}`,
|
|
|
|
this.onMessage
|
|
|
|
);
|
|
|
|
}
|
2022-12-12 23:32:25 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
@bind
|
|
|
|
onMessage() {
|
|
|
|
this.appEvents.trigger("header:search-context-trigger");
|
2017-05-24 13:50:20 +08:00
|
|
|
},
|
|
|
|
};
|