FEATURE: option to disable ads on personal messages

FEATURE: option to disable ads on personal messages

Use the new setting “no ads for personal messages”.

diff --git a/assets/javascripts/discourse/components/ad-component.js.es6 b/assets/javascripts/discourse/components/ad-component.js.es6
index 3fa3310..52393bb 100644
--- a/assets/javascripts/discourse/components/ad-component.js.es6
+++ b/assets/javascripts/discourse/components/ad-component.js.es6
@@ -28,6 +28,11 @@ export default Ember.Component.extend({
     }
   },
 
+  @computed("router.currentRoute.parent.attributes.archetype")
+  isPersonalMessage(topicType) {
+    return topicType === "private_message";
+  },
+
   @computed("currentUser.groups")
   showToGroups(groups) {
     const currentUser = Discourse.User.current();
@@ -49,8 +54,18 @@ export default Ember.Component.extend({
     return !groupNames.any(g => noAdsGroupNames.includes(g));
   },
 
-  @computed("currentCategoryId", "topicTagsDisableAds", "topicListTag")
-  showOnCurrentPage(categoryId, topicTagsDisableAds, topicListTag) {
+  @computed(
+    "currentCategoryId",
+    "topicTagsDisableAds",
+    "topicListTag",
+    "isPersonalMessage"
+  )
+  showOnCurrentPage(
+    categoryId,
+    topicTagsDisableAds,
+    topicListTag,
+    isPersonalMessage
+  ) {
     return (
       !topicTagsDisableAds &&
       (!categoryId ||
@@ -60,7 +75,8 @@ export default Ember.Component.extend({
           .includes(categoryId.toString())) &&
       (!topicListTag ||
         !this.siteSettings.no_ads_for_tags ||
-        !this.siteSettings.no_ads_for_tags.split("|").includes(topicListTag))
+        !this.siteSettings.no_ads_for_tags.split("|").includes(topicListTag)) &&
+      (!isPersonalMessage || !this.siteSettings.no_ads_for_personal_messages)
     );
   },
 
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index 107a890..508c2cf 100755
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -1,5 +1,6 @@
 en:
   site_settings:
+    no_ads_for_personal_messages: "Don't show ads when viewing personal messages"
     no_ads_for_groups: "Don't show ads to users in these groups."
     no_ads_for_categories: "Don't show ads on topic list and topic pages belonging to these categories."
     no_ads_for_tags: "Don't show ads on topic list and topic pages belonging to these tags."
diff --git a/config/settings.yml b/config/settings.yml
index a94fb90..44cad5f 100755
--- a/config/settings.yml
+++ b/config/settings.yml
@@ -1,4 +1,7 @@
 ad_plugin:
+  no_ads_for_personal_messages:
+    client: true
+    default: true
   no_ads_for_groups:
     client: true
     default: ""

GitHub sha: ad939a85

2 Likes