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
This commit is contained in:
Penar Musaraj 2020-08-03 03:06:09 -04:00 committed by GitHub
parent 4dae9d458b
commit ac76bfb400
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 13 deletions

View File

@ -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;
},

View File

@ -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);
},

View File

@ -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);
},