DEV: Add compatibility with the Glimmer Post Stream (#247)
This commit updates the ad plugin to support the Glimmer Post Stream and refactors ad rendering logic for improved compatibility and maintainability. Key changes: - Introduce glimmer_post_stream_mode compatibility across all ad types and test suites. - Replace .widget-connector with .ad-connector for ad placement after posts. - Migrate initialize-ad-plugin.js to initialize-ad-plugin.gjs to leverage Glimmer and API improvements. - Use withSilencedDeprecations to handle widget overrides for post ads. - Update compatibility constraints in .discourse-compatibility. - Refactor and expand acceptance tests for AdSense, DFP, and House Ads to run with both Glimmer and legacy post stream modes.
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import { hbs } from "ember-cli-htmlbars";
|
||||
import { withSilencedDeprecations } from "discourse/lib/deprecated";
|
||||
import { withPluginApi } from "discourse/lib/plugin-api";
|
||||
import Site from "discourse/models/site";
|
||||
import { registerWidgetShim } from "discourse/widgets/render-glimmer";
|
||||
import PostBottomAd from "../components/post-bottom-ad";
|
||||
|
||||
export default {
|
||||
name: "initialize-ad-plugin",
|
||||
initialize(container) {
|
||||
withPluginApi((api) => {
|
||||
customizePost(api);
|
||||
});
|
||||
|
||||
const messageBus = container.lookup("service:message-bus");
|
||||
const currentUser = container.lookup("service:current-user");
|
||||
|
||||
const channel = currentUser
|
||||
? "/site/house-creatives/logged-in"
|
||||
: "/site/house-creatives/anonymous";
|
||||
|
||||
messageBus.subscribe(channel, function (houseAdsSettings) {
|
||||
Site.currentProp("house_creatives", houseAdsSettings);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
function customizePost(api) {
|
||||
api.renderAfterWrapperOutlet(
|
||||
"post-article",
|
||||
<template>
|
||||
<div class="ad-connector">
|
||||
<PostBottomAd @model={{@post}} />
|
||||
</div>
|
||||
</template>
|
||||
);
|
||||
|
||||
withSilencedDeprecations("discourse.post-stream-widget-overrides", () =>
|
||||
customizeWidgetPost(api)
|
||||
);
|
||||
}
|
||||
|
||||
function customizeWidgetPost(api) {
|
||||
registerWidgetShim(
|
||||
"after-post-ad",
|
||||
"div.ad-connector",
|
||||
hbs`<PostBottomAd @model={{@data}} />`
|
||||
);
|
||||
|
||||
api.decorateWidget("post:after", (helper) => {
|
||||
return helper.attach("after-post-ad", helper.widget.model);
|
||||
});
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
import { hbs } from "ember-cli-htmlbars";
|
||||
import { withPluginApi } from "discourse/lib/plugin-api";
|
||||
import Site from "discourse/models/site";
|
||||
import { registerWidgetShim } from "discourse/widgets/render-glimmer";
|
||||
|
||||
export default {
|
||||
name: "initialize-ad-plugin",
|
||||
initialize(container) {
|
||||
registerWidgetShim(
|
||||
"after-post-ad",
|
||||
"div.widget-connector",
|
||||
hbs`<PostBottomAd @model={{@data}} />`
|
||||
);
|
||||
|
||||
withPluginApi("0.1", (api) => {
|
||||
api.decorateWidget("post:after", (helper) => {
|
||||
return helper.attach("after-post-ad", helper.widget.model);
|
||||
});
|
||||
});
|
||||
|
||||
const messageBus = container.lookup("service:message-bus");
|
||||
const currentUser = container.lookup("service:current-user");
|
||||
|
||||
const channel = currentUser
|
||||
? "/site/house-creatives/logged-in"
|
||||
: "/site/house-creatives/anonymous";
|
||||
|
||||
messageBus.subscribe(channel, function (houseAdsSettings) {
|
||||
Site.currentProp("house_creatives", houseAdsSettings);
|
||||
});
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user