mirror of
https://github.com/discourse/discourse-adplugin.git
synced 2025-03-09 13:19:11 +00:00
DFP category targeting param wasn't always being updated on topic list pages. Also remove dependency on a category param being passed in to the component from a template so that we can now place dfp ads in places that don't have access to the current category and targeting will still work.
56 lines
1.4 KiB
JavaScript
56 lines
1.4 KiB
JavaScript
import computed from "ember-addons/ember-computed-decorators";
|
|
|
|
export default Ember.Component.extend({
|
|
router: Ember.inject.service(),
|
|
|
|
currentCategoryId: Ember.computed.or(
|
|
"router.currentRoute.attributes.category.id",
|
|
"router.currentRoute.parent.attributes.category_id"
|
|
),
|
|
|
|
currentCategorySlug: Ember.computed.or(
|
|
"router.currentRoute.attributes.category.slug",
|
|
"router.currentRoute.parent.attributes.category.slug"
|
|
),
|
|
|
|
@computed("currentUser.groups")
|
|
showToGroups(groups) {
|
|
const currentUser = Discourse.User.current();
|
|
|
|
if (
|
|
!currentUser ||
|
|
!groups ||
|
|
!this.siteSettings.no_ads_for_groups ||
|
|
this.siteSettings.no_ads_for_groups.length === 0
|
|
) {
|
|
return true;
|
|
}
|
|
|
|
const groupNames = groups.map(g => g.name.toLowerCase());
|
|
const noAdsGroupNames = this.siteSettings.no_ads_for_groups
|
|
.split("|")
|
|
.map(g => g.toLowerCase());
|
|
|
|
return !groupNames.any(g => noAdsGroupNames.includes(g));
|
|
},
|
|
|
|
@computed("currentCategoryId")
|
|
showOnCurrentPage(categoryId) {
|
|
return (
|
|
!categoryId ||
|
|
!this.siteSettings.no_ads_for_categories ||
|
|
!this.siteSettings.no_ads_for_categories
|
|
.split("|")
|
|
.includes(categoryId.toString())
|
|
);
|
|
},
|
|
|
|
isNthPost(n) {
|
|
if (n && n > 0) {
|
|
return this.get("postNumber") % n === 0;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
});
|