This commit adds 2 new settings to house ads to control whether an ad is shown to anonymous users and logged in users. Existing ads that were created before this feature will default to true for both settings; i.e., they will remain to be visible to both anonymous and logged-in users, but it will be possible to change the settings. Turning off both settings will effectively disable the ad completely.
43 lines
1.2 KiB
JavaScript
43 lines
1.2 KiB
JavaScript
import { withPluginApi } from "discourse/lib/plugin-api";
|
|
import Site from "discourse/models/site";
|
|
|
|
export default {
|
|
name: "initialize-ad-plugin",
|
|
initialize(container) {
|
|
withPluginApi("0.1", (api) => {
|
|
api.decorateWidget("post:after", (dec) => {
|
|
if (dec.canConnectComponent) {
|
|
if (!dec.attrs.cloaked) {
|
|
return dec.connect({
|
|
component: "post-bottom-ad",
|
|
context: "model",
|
|
});
|
|
}
|
|
} else {
|
|
// Old way for backwards compatibility
|
|
return dec.connect({
|
|
templateName: "connectors/post-bottom/discourse-adplugin",
|
|
context: "model",
|
|
});
|
|
}
|
|
});
|
|
});
|
|
|
|
const messageBus = container.lookup("message-bus:main");
|
|
if (!messageBus) {
|
|
return;
|
|
}
|
|
|
|
const currentUser = container.lookup("service:current-user");
|
|
let channel;
|
|
if (currentUser) {
|
|
channel = "/site/house-creatives/logged-in";
|
|
} else {
|
|
channel = "/site/house-creatives/anonymous";
|
|
}
|
|
messageBus.subscribe(channel, function (houseAdsSettings) {
|
|
Site.currentProp("house_creatives", houseAdsSettings);
|
|
});
|
|
},
|
|
};
|