mirror of
https://github.com/discourse/discourse-adplugin.git
synced 2025-03-09 13:19:11 +00:00
If the selected group to not display ads to had its visibility set to not be visible then this setting wouldn't work correctly because that group wouldn't be available client side. The change moves that group check to be server side so that we can correctly see all the groups that should not see ads.
95 lines
2.5 KiB
JavaScript
95 lines
2.5 KiB
JavaScript
import Component from "@ember/component";
|
|
import { alias, or } from "@ember/object/computed";
|
|
import { inject as service } from "@ember/service";
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
|
import {
|
|
isNthPost,
|
|
isNthTopicListItem,
|
|
} from "discourse/plugins/discourse-adplugin/discourse/helpers/slot-position";
|
|
|
|
export default Component.extend({
|
|
router: service(),
|
|
|
|
currentCategoryId: or(
|
|
"router.currentRoute.attributes.category.id",
|
|
"router.currentRoute.parent.attributes.category_id"
|
|
),
|
|
|
|
currentCategorySlug: or(
|
|
"router.currentRoute.attributes.category.slug",
|
|
"router.currentRoute.parent.attributes.category.slug"
|
|
),
|
|
|
|
// Server needs to compute this in case hidden tags are being used.
|
|
topicTagsDisableAds: alias(
|
|
"router.currentRoute.parent.attributes.tags_disable_ads"
|
|
),
|
|
|
|
isRestrictedCategory: or(
|
|
"router.currentRoute.attributes.category.read_restricted",
|
|
"router.currentRoute.parent.attributes.category.read_restricted"
|
|
),
|
|
|
|
@discourseComputed(
|
|
"router.currentRoute.attributes.__type",
|
|
"router.currentRoute.attributes.id"
|
|
)
|
|
topicListTag(type, tag) {
|
|
if (type === "tag" && tag) {
|
|
return tag;
|
|
}
|
|
},
|
|
|
|
@discourseComputed("router.currentRoute.parent.attributes.archetype")
|
|
isPersonalMessage(topicType) {
|
|
return topicType === "private_message";
|
|
},
|
|
|
|
@discourseComputed
|
|
showToGroups() {
|
|
if (!this.currentUser) {
|
|
return true;
|
|
}
|
|
|
|
return this.currentUser.show_to_groups;
|
|
},
|
|
|
|
@discourseComputed(
|
|
"currentCategoryId",
|
|
"topicTagsDisableAds",
|
|
"topicListTag",
|
|
"isPersonalMessage",
|
|
"isRestrictedCategory"
|
|
)
|
|
showOnCurrentPage(
|
|
categoryId,
|
|
topicTagsDisableAds,
|
|
topicListTag,
|
|
isPersonalMessage,
|
|
isRestrictedCategory
|
|
) {
|
|
return (
|
|
!topicTagsDisableAds &&
|
|
(!categoryId ||
|
|
!this.siteSettings.no_ads_for_categories ||
|
|
!this.siteSettings.no_ads_for_categories
|
|
.split("|")
|
|
.includes(categoryId.toString())) &&
|
|
(!topicListTag ||
|
|
!this.siteSettings.no_ads_for_tags ||
|
|
!this.siteSettings.no_ads_for_tags.split("|").includes(topicListTag)) &&
|
|
(!isPersonalMessage || !this.siteSettings.no_ads_for_personal_messages) &&
|
|
(!isRestrictedCategory ||
|
|
!this.siteSettings.no_ads_for_restricted_categories)
|
|
);
|
|
},
|
|
|
|
isNthPost(n) {
|
|
return isNthPost(n, this.get("postNumber"));
|
|
},
|
|
|
|
isNthTopicListItem(n) {
|
|
return isNthTopicListItem(n, this.get("indexNumber"));
|
|
},
|
|
});
|