2019-04-18 14:10:56 -04:00
|
|
|
import computed from "ember-addons/ember-computed-decorators";
|
|
|
|
|
|
|
|
export default Ember.Component.extend({
|
2019-06-05 15:52:52 -04:00
|
|
|
router: Ember.inject.service(),
|
|
|
|
|
|
|
|
currentCategoryId: Ember.computed.or(
|
|
|
|
"router.currentRoute.attributes.category.id",
|
|
|
|
"router.currentRoute.parent.attributes.category_id"
|
|
|
|
),
|
|
|
|
|
2019-06-05 17:00:47 -04:00
|
|
|
currentCategorySlug: Ember.computed.or(
|
|
|
|
"router.currentRoute.attributes.category.slug",
|
|
|
|
"router.currentRoute.parent.attributes.category.slug"
|
|
|
|
),
|
|
|
|
|
2019-06-17 17:20:38 -04:00
|
|
|
// Server needs to compute this in case hidden tags are being used.
|
|
|
|
topicTagsDisableAds: Ember.computed.alias(
|
|
|
|
"router.currentRoute.parent.attributes.tags_disable_ads"
|
|
|
|
),
|
|
|
|
|
2019-07-22 11:43:39 -04:00
|
|
|
isRestrictedCategory: Ember.computed.or(
|
|
|
|
"router.currentRoute.attributes.category.read_restricted",
|
|
|
|
"router.currentRoute.parent.attributes.category.read_restricted"
|
|
|
|
),
|
|
|
|
|
2019-06-14 14:44:09 -04:00
|
|
|
@computed(
|
|
|
|
"router.currentRoute.attributes.__type",
|
|
|
|
"router.currentRoute.attributes.id"
|
|
|
|
)
|
2019-06-17 17:20:38 -04:00
|
|
|
topicListTag(type, tag) {
|
2019-06-15 06:31:52 -04:00
|
|
|
if (type === "tag" && tag) {
|
2019-06-17 17:20:38 -04:00
|
|
|
return tag;
|
2019-06-14 14:44:09 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-06-27 14:13:51 -04:00
|
|
|
@computed("router.currentRoute.parent.attributes.archetype")
|
|
|
|
isPersonalMessage(topicType) {
|
|
|
|
return topicType === "private_message";
|
|
|
|
},
|
|
|
|
|
2019-04-18 17:52:59 -04:00
|
|
|
@computed("currentUser.groups")
|
|
|
|
showToGroups(groups) {
|
2019-04-18 14:10:56 -04:00
|
|
|
const currentUser = Discourse.User.current();
|
|
|
|
|
|
|
|
if (
|
|
|
|
!currentUser ||
|
|
|
|
!groups ||
|
|
|
|
!this.siteSettings.no_ads_for_groups ||
|
|
|
|
this.siteSettings.no_ads_for_groups.length === 0
|
|
|
|
) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-07-19 09:29:52 -04:00
|
|
|
let noAdsGroups = this.siteSettings.no_ads_for_groups.split("|");
|
2019-04-18 14:10:56 -04:00
|
|
|
|
2019-07-19 09:29:52 -04:00
|
|
|
// TODO: Remove when 2.4 becomes the new stable. This is for backwards compatibility.
|
|
|
|
const groupListUseIDs = this.site.group_list_use_ids;
|
|
|
|
|
|
|
|
let currentGroups = groups;
|
|
|
|
if (groupListUseIDs) {
|
|
|
|
currentGroups = currentGroups.map(g => g.id.toString());
|
|
|
|
} else {
|
|
|
|
currentGroups = currentGroups.map(g => g.name.toLowerCase());
|
|
|
|
noAdsGroups = noAdsGroups.map(g => g.toLowerCase());
|
|
|
|
}
|
|
|
|
|
|
|
|
return !currentGroups.any(g => noAdsGroups.includes(g));
|
2019-04-18 17:52:59 -04:00
|
|
|
},
|
|
|
|
|
2019-06-27 14:13:51 -04:00
|
|
|
@computed(
|
|
|
|
"currentCategoryId",
|
|
|
|
"topicTagsDisableAds",
|
|
|
|
"topicListTag",
|
2019-07-22 11:43:39 -04:00
|
|
|
"isPersonalMessage",
|
|
|
|
"isRestrictedCategory"
|
2019-06-27 14:13:51 -04:00
|
|
|
)
|
|
|
|
showOnCurrentPage(
|
|
|
|
categoryId,
|
|
|
|
topicTagsDisableAds,
|
|
|
|
topicListTag,
|
2019-07-22 11:43:39 -04:00
|
|
|
isPersonalMessage,
|
|
|
|
isRestrictedCategory
|
2019-06-27 14:13:51 -04:00
|
|
|
) {
|
2019-06-05 15:52:52 -04:00
|
|
|
return (
|
2019-06-17 17:20:38 -04:00
|
|
|
!topicTagsDisableAds &&
|
2019-06-14 14:44:09 -04:00
|
|
|
(!categoryId ||
|
|
|
|
!this.siteSettings.no_ads_for_categories ||
|
|
|
|
!this.siteSettings.no_ads_for_categories
|
|
|
|
.split("|")
|
|
|
|
.includes(categoryId.toString())) &&
|
2019-06-17 17:20:38 -04:00
|
|
|
(!topicListTag ||
|
2019-06-14 14:44:09 -04:00
|
|
|
!this.siteSettings.no_ads_for_tags ||
|
2019-06-27 14:13:51 -04:00
|
|
|
!this.siteSettings.no_ads_for_tags.split("|").includes(topicListTag)) &&
|
2019-07-22 11:43:39 -04:00
|
|
|
(!isPersonalMessage || !this.siteSettings.no_ads_for_personal_messages) &&
|
|
|
|
(!isRestrictedCategory ||
|
|
|
|
!this.siteSettings.no_ads_for_restricted_categories)
|
2019-06-05 15:52:52 -04:00
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2019-04-18 17:52:59 -04:00
|
|
|
isNthPost(n) {
|
|
|
|
if (n && n > 0) {
|
|
|
|
return this.get("postNumber") % n === 0;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2019-04-18 14:10:56 -04:00
|
|
|
}
|
|
|
|
});
|