Disable social media sharing on private categories, unlisted topics (#10349)

Disable social media sharing on private categories, unlisted topics (#10349)

  • Do not show social media sharing on private categories, unlisted topics

  • Disable quote sharing entirely in private categories and unlisted topics

diff --git a/app/assets/javascripts/discourse/app/components/quote-button.js b/app/assets/javascripts/discourse/app/components/quote-button.js
index 1672857..c8bd985 100644
--- a/app/assets/javascripts/discourse/app/components/quote-button.js
+++ b/app/assets/javascripts/discourse/app/components/quote-button.js
@@ -12,6 +12,7 @@ import { INPUT_DELAY } from "discourse-common/config/environment";
 import { action } from "@ember/object";
 import discourseComputed from "discourse-common/utils/decorators";
 import Sharing from "discourse/lib/sharing";
+import { alias } from "@ember/object/computed";
 
 function getQuoteTitle(element) {
   const titleEl = element.querySelector(".title");
@@ -23,6 +24,7 @@ export default Component.extend({
   classNames: ["quote-button"],
   classNameBindings: ["visible"],
   visible: false,
+  privateCategory: alias("topic.category.read_restricted"),
 
   _isMouseDown: false,
   _reselected: false,
@@ -209,14 +211,16 @@ export default Component.extend({
       .off("selectionchange.quote-button");
   },
 
-  @discourseComputed
-  quoteSharingEnabled() {
+  @discourseComputed("topic.{isPrivateMessage,invisible,category}")
+  quoteSharingEnabled(topic) {
     if (
       this.site.mobileView ||
       this.siteSettings.share_quote_visibility === "none" ||
-      this.quoteSharingSources.length === 0 ||
       (this.currentUser &&
-        this.siteSettings.share_quote_visibility === "anonymous")
+        this.siteSettings.share_quote_visibility === "anonymous") ||
+      this.quoteSharingSources.length === 0 ||
+      this.privateCategory ||
+      (this.currentUser && topic.invisible)
     ) {
       return false;
     }
@@ -232,7 +236,7 @@ export default Component.extend({
     );
   },
 
-  @discourseComputed
+  @discourseComputed("topic.{isPrivateMessage,invisible,category}")
   quoteSharingShowLabel() {
     return this.quoteSharingSources.length > 1;
   },
diff --git a/app/assets/javascripts/discourse/app/components/share-panel.js b/app/assets/javascripts/discourse/app/components/share-panel.js
index 74608db..abfad8a 100644
--- a/app/assets/javascripts/discourse/app/components/share-panel.js
+++ b/app/assets/javascripts/discourse/app/components/share-panel.js
@@ -9,14 +9,17 @@ import { later } from "@ember/runloop";
 
 export default Component.extend({
   tagName: null,
-
   type: alias("panel.model.type"),
-
   topic: alias("panel.model.topic"),
+  privateCategory: alias("panel.model.topic.category.read_restricted"),
 
-  @discourseComputed("topic.isPrivateMessage")
-  sources(isPM) {
-    const privateContext = this.siteSettings.login_required || isPM;
+  @discourseComputed("topic.{isPrivateMessage,invisible,category}")
+  sources(topic) {
+    const privateContext =
+      this.siteSettings.login_required ||
+      topic.isPrivateMessage ||
+      topic.invisible ||
+      this.privateCategory;
     return Sharing.activeSources(this.siteSettings.share_links, privateContext);
   },
 
diff --git a/app/assets/javascripts/discourse/app/components/share-popup.js b/app/assets/javascripts/discourse/app/components/share-popup.js
index 9564c29..5c213f0 100644
--- a/app/assets/javascripts/discourse/app/components/share-popup.js
+++ b/app/assets/javascripts/discourse/app/components/share-popup.js
@@ -7,16 +7,23 @@ import { longDateNoYear } from "discourse/lib/formatter";
 import discourseComputed, { on } from "discourse-common/utils/decorators";
 import Sharing from "discourse/lib/sharing";
 import { nativeShare } from "discourse/lib/pwa-utils";
+import { alias } from "@ember/object/computed";
 
 export default Component.extend({
   elementId: "share-link",
   classNameBindings: ["visible"],
   link: null,
   visible: null,
+  privateCategory: alias("topic.category.read_restricted"),
+
+  @discourseComputed("topic.{isPrivateMessage,invisible,category}")
+  sources(topic) {
+    const privateContext =
+      this.siteSettings.login_required ||
+      topic.isPrivateMessage ||
+      topic.invisible ||
+      this.privateCategory;
 
-  @discourseComputed("topic.isPrivateMessage")
-  sources(isPM) {
-    const privateContext = this.siteSettings.login_required || isPM;
     return Sharing.activeSources(this.siteSettings.share_links, privateContext);
   },
 

GitHub sha: ac76bfb4

1 Like

This commit appears in #10349 which was approved by eviltrout. It was merged by SamSaffron.