From 2d5f770295a983a15ece5004cef2e80e48ef5efb Mon Sep 17 00:00:00 2001 From: Jeremy Kescher Date: Sun, 3 Nov 2024 18:26:16 +0100 Subject: [PATCH] feat(preview): Allow bypassing CW/sensitive for link preview --- README.md | 2 ++ app/helpers/statuses_helper.rb | 2 +- .../flavours/glitch/components/status_action_bar.jsx | 10 ++++++++++ .../glitch/features/status/components/action_bar.jsx | 10 ++++++++++ app/javascript/flavours/glitch/locales/en.json | 1 + app/views/statuses/_og_image.html.haml | 2 +- 6 files changed, 25 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 49805c35c8..fd6bf9a0ae 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,8 @@ For production, it is suggested you run: - Allow dashes in emoji shortcodes - This is simply to allow custom emoji compat with other fedi software. - Original patch by hazycora: https://github.com/TheEssem/mastodon/commit/2dde7a25a47a23f827e2fd2d07f55438f9985181 +- Allow appending "?unrestricted_preview=true" to post links to bypass CWs and sensitive-markings of media for link + previews. ## Contributions to glitch-soc Mastodon diff --git a/app/helpers/statuses_helper.rb b/app/helpers/statuses_helper.rb index 9bbb03fd82..d6777e68eb 100644 --- a/app/helpers/statuses_helper.rb +++ b/app/helpers/statuses_helper.rb @@ -52,7 +52,7 @@ module StatusesHelper def status_description(status) components = [[media_summary(status), status_text_summary(status)].compact_blank.join(' ยท ')] - if status.spoiler_text.blank? + if status.spoiler_text.blank? || ActiveRecord::Type::Boolean.new.deserialize(params[:unrestricted_preview]) components << status.text components << poll_summary(status) end diff --git a/app/javascript/flavours/glitch/components/status_action_bar.jsx b/app/javascript/flavours/glitch/components/status_action_bar.jsx index e6b63b4310..f8e701c4b7 100644 --- a/app/javascript/flavours/glitch/components/status_action_bar.jsx +++ b/app/javascript/flavours/glitch/components/status_action_bar.jsx @@ -64,6 +64,7 @@ const messages = defineMessages({ admin_status: { id: 'status.admin_status', defaultMessage: 'Open this post in the moderation interface' }, admin_domain: { id: 'status.admin_domain', defaultMessage: 'Open moderation interface for {domain}' }, copy: { id: 'status.copy', defaultMessage: 'Copy link to post' }, + copyUnrestricted: { id: 'status.copyUnrestricted', defaultMessage: 'Copy link to post (no CW preview)' }, hide: { id: 'status.hide', defaultMessage: 'Hide post' }, edited: { id: 'status.edited', defaultMessage: 'Edited {date}' }, filter: { id: 'status.filter', defaultMessage: 'Filter this post' }, @@ -205,6 +206,11 @@ class StatusActionBar extends ImmutablePureComponent { navigator.clipboard.writeText(url); }; + handleCopyUnrestricted = () => { + const url = `${this.props.status.get('url')}?unrestricted_preview=true`; + navigator.clipboard.writeText(url); + }; + handleHideClick = () => { this.props.onFilter(); }; @@ -237,6 +243,10 @@ class StatusActionBar extends ImmutablePureComponent { menu.push({ text: intl.formatMessage(messages.copy), action: this.handleCopy }); + if (publicStatus) { + menu.push({ text: intl.formatMessage(messages.copyUnrestricted), action: this.handleCopyUnrestricted }); + } + if (publicStatus && 'share' in navigator) { menu.push({ text: intl.formatMessage(messages.share), action: this.handleShareClick }); } diff --git a/app/javascript/flavours/glitch/features/status/components/action_bar.jsx b/app/javascript/flavours/glitch/features/status/components/action_bar.jsx index 45d071b91c..a027d11e05 100644 --- a/app/javascript/flavours/glitch/features/status/components/action_bar.jsx +++ b/app/javascript/flavours/glitch/features/status/components/action_bar.jsx @@ -57,6 +57,7 @@ const messages = defineMessages({ admin_status: { id: 'status.admin_status', defaultMessage: 'Open this post in the moderation interface' }, admin_domain: { id: 'status.admin_domain', defaultMessage: 'Open moderation interface for {domain}' }, copy: { id: 'status.copy', defaultMessage: 'Copy link to post' }, + copyUnrestricted: { id: 'status.copyUnrestricted', defaultMessage: 'Copy link to post (no CW preview)' }, openOriginalPage: { id: 'account.open_original_page', defaultMessage: 'Open original page' }, }); @@ -157,6 +158,11 @@ class ActionBar extends PureComponent { navigator.clipboard.writeText(url); }; + handleCopyUnrestricted = () => { + const url = `${this.props.status.get('url')}?unrestricted_preview=true`; + navigator.clipboard.writeText(url); + }; + render () { const { status, intl } = this.props; const { signedIn, permissions } = this.props.identity; @@ -175,6 +181,10 @@ class ActionBar extends PureComponent { menu.push({ text: intl.formatMessage(messages.copy), action: this.handleCopy }); + if (publicStatus) { + menu.push({ text: intl.formatMessage(messages.copyUnrestricted), action: this.handleCopyUnrestricted }); + } + if (publicStatus && 'share' in navigator) { menu.push({ text: intl.formatMessage(messages.share), action: this.handleShare }); } diff --git a/app/javascript/flavours/glitch/locales/en.json b/app/javascript/flavours/glitch/locales/en.json index b963f8f33f..2660560231 100644 --- a/app/javascript/flavours/glitch/locales/en.json +++ b/app/javascript/flavours/glitch/locales/en.json @@ -148,6 +148,7 @@ "settings.wide_view": "Wide view (Desktop mode only)", "settings.wide_view_hint": "Stretches columns to better fill the available space.", "status.collapse": "Collapse", + "status.copyUnrestricted": "Copy link to post (no CW preview)", "status.filtered": "Filtered", "status.has_audio": "Features attached audio files", "status.has_pictures": "Features attached pictures", diff --git a/app/views/statuses/_og_image.html.haml b/app/views/statuses/_og_image.html.haml index 1ae97adff6..4669b22722 100644 --- a/app/views/statuses/_og_image.html.haml +++ b/app/views/statuses/_og_image.html.haml @@ -1,4 +1,4 @@ -- if activity.is_a?(Status) && (activity.non_sensitive_with_media? || (activity.with_media? && Setting.preview_sensitive_media)) +- if activity.is_a?(Status) && (activity.non_sensitive_with_media? || ActiveRecord::Type::Boolean.new.deserialize(params[:unrestricted_preview]) || (activity.with_media? && Setting.preview_sensitive_media)) - player_card = false - activity.ordered_media_attachments.each do |media| - if media.image?