2022-03-06 19:52:19 +01:00
|
|
|
import Component from "@ember/component";
|
|
|
|
|
import { alias, or } from "@ember/object/computed";
|
2024-11-19 10:18:26 +00:00
|
|
|
import { service } from "@ember/service";
|
2025-02-06 16:42:21 +00:00
|
|
|
import discourseComputed from "discourse/lib/decorators";
|
2022-07-12 16:13:18 -03:00
|
|
|
import {
|
|
|
|
|
isNthPost,
|
|
|
|
|
isNthTopicListItem,
|
|
|
|
|
} from "discourse/plugins/discourse-adplugin/discourse/helpers/slot-position";
|
2019-04-18 14:10:56 -04:00
|
|
|
|
2024-11-29 10:11:21 +00:00
|
|
|
export default class AdComponent extends Component {
|
|
|
|
|
@service router;
|
2019-06-05 15:52:52 -04:00
|
|
|
|
2024-11-29 10:11:21 +00:00
|
|
|
@or(
|
2019-06-05 15:52:52 -04:00
|
|
|
"router.currentRoute.attributes.category.id",
|
|
|
|
|
"router.currentRoute.parent.attributes.category_id"
|
2024-11-29 10:11:21 +00:00
|
|
|
)
|
|
|
|
|
currentCategoryId;
|
2019-06-05 15:52:52 -04:00
|
|
|
|
2024-11-29 10:11:21 +00:00
|
|
|
@or(
|
2019-06-05 17:00:47 -04:00
|
|
|
"router.currentRoute.attributes.category.slug",
|
|
|
|
|
"router.currentRoute.parent.attributes.category.slug"
|
2024-11-29 10:11:21 +00:00
|
|
|
)
|
|
|
|
|
currentCategorySlug;
|
2019-06-05 17:00:47 -04:00
|
|
|
|
2019-06-17 17:20:38 -04:00
|
|
|
// Server needs to compute this in case hidden tags are being used.
|
2024-11-29 10:11:21 +00:00
|
|
|
@alias("router.currentRoute.parent.attributes.tags_disable_ads")
|
|
|
|
|
topicTagsDisableAds;
|
2019-06-17 17:20:38 -04:00
|
|
|
|
2024-11-29 10:11:21 +00:00
|
|
|
@or(
|
2019-07-22 11:43:39 -04:00
|
|
|
"router.currentRoute.attributes.category.read_restricted",
|
|
|
|
|
"router.currentRoute.parent.attributes.category.read_restricted"
|
2024-11-29 10:11:21 +00:00
|
|
|
)
|
|
|
|
|
isRestrictedCategory;
|
2019-07-22 11:43:39 -04:00
|
|
|
|
2020-03-23 09:40:29 +01:00
|
|
|
@discourseComputed(
|
2019-06-14 14:44:09 -04:00
|
|
|
"router.currentRoute.attributes.__type",
|
|
|
|
|
"router.currentRoute.attributes.id"
|
|
|
|
|
)
|
2019-06-17 17:20:38 -04:00
|
|
|
topicListTag(type, tag) {
|
2019-06-15 16:01:52 +05:30
|
|
|
if (type === "tag" && tag) {
|
2019-06-17 17:20:38 -04:00
|
|
|
return tag;
|
2019-06-14 14:44:09 -04:00
|
|
|
}
|
2024-11-29 10:11:21 +00:00
|
|
|
}
|
2019-06-14 14:44:09 -04:00
|
|
|
|
2020-03-23 09:40:29 +01:00
|
|
|
@discourseComputed("router.currentRoute.parent.attributes.archetype")
|
2019-06-27 14:13:51 -04:00
|
|
|
isPersonalMessage(topicType) {
|
|
|
|
|
return topicType === "private_message";
|
2024-11-29 10:11:21 +00:00
|
|
|
}
|
2019-06-27 14:13:51 -04:00
|
|
|
|
2024-02-15 14:52:15 -07:00
|
|
|
@discourseComputed
|
|
|
|
|
showToGroups() {
|
|
|
|
|
if (!this.currentUser) {
|
2019-04-18 14:10:56 -04:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-15 14:52:15 -07:00
|
|
|
return this.currentUser.show_to_groups;
|
2024-11-29 10:11:21 +00:00
|
|
|
}
|
2019-04-18 17:52:59 -04:00
|
|
|
|
2020-03-23 09:40:29 +01:00
|
|
|
@discourseComputed(
|
2019-06-27 14:13:51 -04:00
|
|
|
"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
|
|
|
);
|
2024-11-29 10:11:21 +00:00
|
|
|
}
|
2019-06-05 15:52:52 -04:00
|
|
|
|
2019-04-18 17:52:59 -04:00
|
|
|
isNthPost(n) {
|
2022-07-12 16:13:18 -03:00
|
|
|
return isNthPost(n, this.get("postNumber"));
|
2024-11-29 10:11:21 +00:00
|
|
|
}
|
2022-07-07 17:23:29 +05:30
|
|
|
|
|
|
|
|
isNthTopicListItem(n) {
|
2022-07-12 16:13:18 -03:00
|
|
|
return isNthTopicListItem(n, this.get("indexNumber"));
|
2024-11-29 10:11:21 +00:00
|
|
|
}
|
|
|
|
|
}
|