2018-06-16 00:42:20 +08:00
|
|
|
import { withPluginApi } from "discourse/lib/plugin-api";
|
2020-04-22 11:34:58 +08:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
2017-05-24 13:50:20 +08:00
|
|
|
|
|
|
|
function initialize(api) {
|
2018-06-16 00:42:20 +08:00
|
|
|
const messageBus = api.container.lookup("message-bus:main");
|
2017-05-24 13:50:20 +08:00
|
|
|
const currentUser = api.getCurrentUser();
|
2019-10-04 22:06:08 +08:00
|
|
|
const appEvents = api.container.lookup("service:app-events");
|
2017-05-24 13:50:20 +08:00
|
|
|
|
2018-06-16 00:42:20 +08:00
|
|
|
api.modifyClass("component:site-header", {
|
2017-05-24 13:50:20 +08:00
|
|
|
didInsertElement() {
|
2019-01-19 17:05:51 +08:00
|
|
|
this._super(...arguments);
|
2018-06-16 00:42:20 +08:00
|
|
|
this.dispatch("header:search-context-trigger", "header");
|
2017-05-24 13:50:20 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-04-22 11:34:58 +08:00
|
|
|
api.modifyClass("model:post", {
|
|
|
|
toggleBookmarkWithReminder() {
|
|
|
|
// if we are talking to discobot then any bookmarks should just
|
|
|
|
// be created without reminder options, to streamline the new user
|
|
|
|
// narrative.
|
|
|
|
const discobotUserId = -2;
|
|
|
|
if (this.user_id === discobotUserId && !this.bookmarked_with_reminder) {
|
|
|
|
return ajax("/bookmarks", {
|
|
|
|
type: "POST",
|
|
|
|
data: { post_id: this.id }
|
|
|
|
}).then(response => {
|
|
|
|
this.setProperties({
|
|
|
|
"topic.bookmarked": true,
|
|
|
|
bookmarked_with_reminder: true,
|
|
|
|
bookmark_id: response.id
|
|
|
|
});
|
|
|
|
this.appEvents.trigger("post-stream:refresh", { id: this.id });
|
|
|
|
});
|
|
|
|
}
|
|
|
|
this._super();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-06-16 00:42:20 +08:00
|
|
|
api.attachWidgetAction("header", "headerSearchContextTrigger", function() {
|
2017-05-24 13:50:20 +08:00
|
|
|
if (this.site.mobileView) {
|
|
|
|
this.state.skipSearchContext = false;
|
|
|
|
} else {
|
|
|
|
this.state.contextEnabled = true;
|
2018-06-16 00:42:20 +08:00
|
|
|
this.state.searchContextType = "topic";
|
2017-05-24 13:50:20 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (messageBus && currentUser) {
|
|
|
|
messageBus.subscribe(`/new_user_narrative/tutorial_search`, () => {
|
2018-06-16 00:42:20 +08:00
|
|
|
appEvents.trigger("header:search-context-trigger");
|
2017-05-24 13:50:20 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: "new-user-narratve",
|
|
|
|
|
|
|
|
initialize(container) {
|
2018-06-16 00:42:20 +08:00
|
|
|
const siteSettings = container.lookup("site-settings:main");
|
|
|
|
if (siteSettings.discourse_narrative_bot_enabled)
|
|
|
|
withPluginApi("0.8.7", initialize);
|
2017-05-24 13:50:20 +08:00
|
|
|
}
|
|
|
|
};
|