2023-11-07 17:39:27 +00:00
|
|
|
import { hbs } from "ember-cli-htmlbars";
|
2018-10-22 19:49:32 +01:00
|
|
|
import { withPluginApi } from "discourse/lib/plugin-api";
|
2021-09-21 11:27:10 -07:00
|
|
|
import Site from "discourse/models/site";
|
2023-11-07 17:39:27 +00:00
|
|
|
import { registerWidgetShim } from "discourse/widgets/render-glimmer";
|
2015-08-04 11:25:00 +10:00
|
|
|
|
|
|
|
export default {
|
2018-10-22 19:49:32 +01:00
|
|
|
name: "initialize-ad-plugin",
|
2016-02-19 15:06:13 -05:00
|
|
|
initialize(container) {
|
2023-11-07 17:39:27 +00:00
|
|
|
registerWidgetShim(
|
|
|
|
"after-post-ad",
|
|
|
|
"div.widget-connector",
|
|
|
|
hbs`<PostBottomAd @model={{@data}} />`
|
|
|
|
);
|
|
|
|
|
2020-09-04 13:24:14 +02:00
|
|
|
withPluginApi("0.1", (api) => {
|
2023-11-07 17:39:27 +00:00
|
|
|
api.decorateWidget("post:after", (helper) => {
|
2024-02-14 13:59:36 +00:00
|
|
|
return helper.attach("after-post-ad", helper.widget.model);
|
2016-02-22 12:11:29 -05:00
|
|
|
});
|
|
|
|
});
|
2019-04-18 17:52:59 -04:00
|
|
|
|
2023-11-07 17:39:27 +00:00
|
|
|
const messageBus = container.lookup("service:message-bus");
|
2023-04-07 17:56:22 +03:00
|
|
|
const currentUser = container.lookup("service:current-user");
|
2023-11-07 17:39:27 +00:00
|
|
|
|
|
|
|
const channel = currentUser
|
|
|
|
? "/site/house-creatives/logged-in"
|
|
|
|
: "/site/house-creatives/anonymous";
|
|
|
|
|
2023-04-07 17:56:22 +03:00
|
|
|
messageBus.subscribe(channel, function (houseAdsSettings) {
|
2021-09-21 11:27:10 -07:00
|
|
|
Site.currentProp("house_creatives", houseAdsSettings);
|
2019-04-18 17:52:59 -04:00
|
|
|
});
|
2020-09-04 13:24:14 +02:00
|
|
|
},
|
2015-08-04 11:25:00 +10:00
|
|
|
};
|