From b38f375d99538c91b7d707d3407b865d29f7d096 Mon Sep 17 00:00:00 2001 From: noellabo Date: Sun, 12 Feb 2023 18:57:28 +0900 Subject: [PATCH] Add feature hide preview card --- .../settings/preferences_controller.rb | 3 +++ app/javascript/mastodon/components/status.js | 17 +++++++++++++++-- .../status/components/detailed_status.js | 3 ++- app/javascript/mastodon/initial_state.js | 3 +++ app/lib/user_settings_decorator.rb | 3 +++ app/models/user.rb | 1 + app/serializers/initial_state_serializer.rb | 3 +++ app/serializers/rest/status_serializer.rb | 15 +++++++++++++++ .../preferences/appearance/show.html.haml | 11 +++++++++++ config/locales/en.yml | 1 + config/locales/ja.yml | 1 + config/locales/simple_form.en.yml | 6 ++++++ config/locales/simple_form.ja.yml | 6 ++++++ config/settings.yml | 3 +++ 14 files changed, 73 insertions(+), 3 deletions(-) diff --git a/app/controllers/settings/preferences_controller.rb b/app/controllers/settings/preferences_controller.rb index 43704d3dc..69fd7fd68 100644 --- a/app/controllers/settings/preferences_controller.rb +++ b/app/controllers/settings/preferences_controller.rb @@ -119,6 +119,9 @@ class Settings::PreferencesController < Settings::BaseController :setting_hide_personal_from_timeline, :setting_hide_personal_from_account, :setting_hide_privacy_meta, + :setting_hide_link_preview, + :setting_hide_photo_preview, + :setting_hide_video_preview, setting_prohibited_visibilities: [], notification_emails: %i(follow follow_request reblog favourite emoji_reaction status_reference mention digest report pending_account trending_tag), interactions: %i(must_be_follower must_be_following must_be_following_dm must_be_dm_to_send_email must_be_following_reference) diff --git a/app/javascript/mastodon/components/status.js b/app/javascript/mastodon/components/status.js index f66e9293e..9a0d93e13 100644 --- a/app/javascript/mastodon/components/status.js +++ b/app/javascript/mastodon/components/status.js @@ -20,7 +20,7 @@ import classNames from 'classnames'; import Icon from 'mastodon/components/icon'; import EmojiReactionsBar from 'mastodon/components/emoji_reactions_bar'; import PictureInPicturePlaceholder from 'mastodon/components/picture_in_picture_placeholder'; -import { displayMedia, enableReaction, compactReaction, show_reply_tree_button, enableStatusReference, disableRelativeTime } from 'mastodon/initial_state'; +import { displayMedia, enableReaction, compactReaction, show_reply_tree_button, enableStatusReference, disableRelativeTime, hideLinkPreview, hidePhotoPreview, hideVideoPreview } from 'mastodon/initial_state'; import { List as ImmutableList } from 'immutable'; // We use the component (and not the container) since we do not want @@ -79,6 +79,19 @@ export const defaultMediaVisibility = (status) => { return (displayMedia !== 'hide_all' && !status.get('sensitive') || displayMedia === 'show_all'); }; +export const isHideCard = (type) => { + switch(type) { + case 'link': + return hideLinkPreview; + case 'photo': + return hidePhotoPreview; + case 'video': + return hideVideoPreview; + default: + return false; + } +}; + const messages = defineMessages({ public_short: { id: 'privacy.public.short', defaultMessage: 'Public' }, unlisted_short: { id: 'privacy.unlisted.short', defaultMessage: 'Unlisted' }, @@ -554,7 +567,7 @@ class Status extends ImmutablePureComponent { ); } - } else if (showCard && status.get('spoiler_text').length === 0 && status.get('card')) { + } else if (showCard && status.get('spoiler_text').length === 0 && status.get('card') && !isHideCard(status.getIn(['card', 'type']))) { media = ( ); } - } else if (status.get('spoiler_text').length === 0) { + } else if (status.get('spoiler_text').length === 0 && !isHideCard(status.getIn(['card', 'type']))) { media = ; } diff --git a/app/javascript/mastodon/initial_state.js b/app/javascript/mastodon/initial_state.js index 857894110..1af332568 100644 --- a/app/javascript/mastodon/initial_state.js +++ b/app/javascript/mastodon/initial_state.js @@ -72,6 +72,9 @@ export const hideDirectFromTimeline = getMeta('hide_direct_from_timeline'); export const hidePersonalFromTimeline = getMeta('hide_personal_from_timeline'); export const hidePersonalFromAccount = getMeta('hide_personal_from_account'); export const hidePrivacyMeta = getMeta('hide_privacy_meta'); +export const hideLinkPreview = getMeta('hide_link_preview'); +export const hidePhotoPreview = getMeta('hide_photo_preview'); +export const hideVideoPreview = getMeta('hide_video_preview'); export const maxChars = initialState?.max_toot_chars ?? 500; diff --git a/app/lib/user_settings_decorator.rb b/app/lib/user_settings_decorator.rb index 2e7ccca4c..7284b2ac4 100644 --- a/app/lib/user_settings_decorator.rb +++ b/app/lib/user_settings_decorator.rb @@ -96,6 +96,9 @@ class UserSettingsDecorator hide_personal_from_timeline hide_personal_from_account hide_privacy_meta + hide_link_preview + hide_photo_preview + hide_video_preview ).freeze STRING_KEYS = %w( diff --git a/app/models/user.rb b/app/models/user.rb index 3ca97061f..24af0d4d4 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -146,6 +146,7 @@ class User < ApplicationRecord :disable_post, :disable_reactions, :disable_follow, :disable_unfollow, :disable_block, :disable_domain_block, :disable_clear_all_notifications, :disable_account_delete, :prohibited_visibilities, :prohibited_words, :disable_relative_time, :hide_direct_from_timeline, :hide_personal_from_timeline, :hide_personal_from_account, :hide_privacy_meta, + :hide_link_preview, :hide_photo_preview, :hide_video_preview, to: :settings, prefix: :setting, allow_nil: false diff --git a/app/serializers/initial_state_serializer.rb b/app/serializers/initial_state_serializer.rb index f8acd06da..072a995a5 100644 --- a/app/serializers/initial_state_serializer.rb +++ b/app/serializers/initial_state_serializer.rb @@ -93,6 +93,9 @@ class InitialStateSerializer < ActiveModel::Serializer store[:hide_personal_from_timeline] = object.current_account.user.setting_hide_personal_from_timeline store[:hide_personal_from_account] = object.current_account.user.setting_hide_personal_from_account store[:hide_privacy_meta] = object.current_account.user.setting_hide_privacy_meta + store[:hide_link_preview] = object.current_account.user.setting_hide_link_preview + store[:hide_photo_preview] = object.current_account.user.setting_hide_photo_preview + store[:hide_video_preview] = object.current_account.user.setting_hide_video_preview else store[:auto_play_gif] = Setting.auto_play_gif store[:display_media] = Setting.display_media diff --git a/app/serializers/rest/status_serializer.rb b/app/serializers/rest/status_serializer.rb index 1f6167413..9b3f5aa2b 100644 --- a/app/serializers/rest/status_serializer.rb +++ b/app/serializers/rest/status_serializer.rb @@ -43,6 +43,21 @@ class REST::StatusSerializer < ActiveModel::Serializer delegate :quote?, to: :object + def preview_card + object.preview_card unless hide_preview_card? + end + + def hide_preview_card? + case object&.preview_card&.type + when 'link' + current_user&.setting_hide_link_preview + when 'photo' + current_user&.setting_hide_photo_preview + when 'video' + current_user&.setting_hide_video_preview + end + end + def id object.id.to_s end diff --git a/app/views/settings/preferences/appearance/show.html.haml b/app/views/settings/preferences/appearance/show.html.haml index 7d97901ca..100d78b00 100644 --- a/app/views/settings/preferences/appearance/show.html.haml +++ b/app/views/settings/preferences/appearance/show.html.haml @@ -99,5 +99,16 @@ .fields-group = f.input :setting_expand_spoilers, as: :boolean, wrapper: :with_label + %h4= t 'appearance.preview_card' + + .fields-group + = f.input :setting_hide_link_preview, as: :boolean, wrapper: :with_label, fedibird_features: true + + .fields-group + = f.input :setting_hide_photo_preview, as: :boolean, wrapper: :with_label, fedibird_features: true + + .fields-group + = f.input :setting_hide_video_preview, as: :boolean, wrapper: :with_label, fedibird_features: true + .actions = f.button :button, t('generic.save_changes'), type: :submit diff --git a/config/locales/en.yml b/config/locales/en.yml index d2ebae9d4..bff4bcb7f 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -792,6 +792,7 @@ en: body: Mastodon is translated by volunteers. guide_link: https://crowdin.com/project/mastodon guide_link_text: Everyone can contribute. + preview_card: Preview Card sensitive_content: Sensitive content themes: Themes toot_layout: Post layout diff --git a/config/locales/ja.yml b/config/locales/ja.yml index c9476416d..076800f34 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -771,6 +771,7 @@ ja: body: Mastodonは有志によって翻訳されています。 guide_link: https://ja.crowdin.com/project/mastodon guide_link_text: 誰でも参加することができます。 + preview_card: プレビューカード sensitive_content: 閲覧注意コンテンツ themes: テーマ toot_layout: 投稿のレイアウト diff --git a/config/locales/simple_form.en.yml b/config/locales/simple_form.en.yml index e22c0a730..ff148e370 100644 --- a/config/locales/simple_form.en.yml +++ b/config/locales/simple_form.en.yml @@ -96,11 +96,14 @@ en: setting_hide_direct_from_timeline: Hide direct messages from the home and list timelines setting_hide_followers_count: The number of followers will be hidden in your profile setting_hide_following_count: The number of following will be hidden in your profile + setting_hide_link_preview: Hide the content preview card linked to the post setting_hide_network: Who you follow and who follows you will be hidden on your profile setting_hide_personal_from_account: Hide personal posts from the account post lists setting_hide_personal_from_timeline: Hide personal posts from the home and list timelines + setting_hide_photo_preview: Hide the photo preview card linked to the post setting_hide_privacy_meta: Hide the description from the drop-down menu for selecting visibility, showing only the name setting_hide_statuses_count: The number of post will be hidden in your profile + setting_hide_video_preview: Hide the video preview card linked to the post setting_match_visibility_of_references: If the referenced post is private, default the visibility of the post to private behavior accordingly setting_new_features_policy: Set the acceptance policy when new features are added to Fedibird. The recommended setting will enable many new features, so set it to disabled if it is not desirable setting_noindex: Affects your public profile and post pages @@ -290,11 +293,14 @@ en: setting_hide_direct_from_timeline: Hide direct messages from the timeline setting_hide_followers_count: Hide your followers count setting_hide_following_count: Hide your following count + setting_hide_link_preview: Hide preview card (link) setting_hide_network: Hide your social graph setting_hide_personal_from_account: Hide personal posts from account posts setting_hide_personal_from_timeline: Hide personal posts from the timeline + setting_hide_photo_preview: Hide preview card (photo) setting_hide_privacy_meta: Hide visibility description setting_hide_statuses_count: Hide your post count + setting_hide_video_preview: Hide preview card (video) setting_info_font_size: Information header font size setting_match_visibility_of_references: Match the visibility of the post to the references setting_new_features_policy: Policy for new features diff --git a/config/locales/simple_form.ja.yml b/config/locales/simple_form.ja.yml index 134b7ab38..1a9e3279c 100644 --- a/config/locales/simple_form.ja.yml +++ b/config/locales/simple_form.ja.yml @@ -92,11 +92,14 @@ ja: setting_hide_direct_from_timeline: ホームとリストタイムラインからダイレクトメッセージを隠します setting_hide_followers_count: フォロワー数をプロフィールページで見られないようにします setting_hide_following_count: フォロー数をプロフィールページで見られないようにします + setting_hide_link_preview: 投稿にリンクされたコンテンツのプレビューカードを隠します setting_hide_network: フォローとフォロワーの情報がプロフィールページで見られないようにします setting_hide_personal_from_account: アカウントの投稿一覧から個人限定投稿を隠します setting_hide_personal_from_timeline: ホームとリストタイムラインから個人限定投稿を隠します + setting_hide_photo_preview: 投稿にリンクされた画像のプレビューカードを隠します setting_hide_privacy_meta: 公開範囲を選択するドロップダウンメニューから説明を隠し、名称のみ表示します setting_hide_statuses_count: 投稿数をプロフィールページで見られないようにします + setting_hide_video_preview: 投稿にリンクされた動画のプレビューカードを隠します setting_match_visibility_of_references: 参照先の投稿がフォロワー限定の場合、投稿の公開範囲をそれに合わせてフォロワー限定とする動作をデフォルトにします setting_new_features_policy: Fedibirdに新しい機能が追加された時の受け入れポリシーを設定します。推奨設定は多くの新機能を有効にするので、望ましくない場合は無効に設定してください setting_noindex: 公開プロフィールおよび各投稿ページに影響します @@ -286,11 +289,14 @@ ja: setting_hide_direct_from_timeline: ダイレクトメッセージをタイムラインから隠す setting_hide_followers_count: フォロワー数を隠す setting_hide_following_count: フォロー数を隠す + setting_hide_link_preview: プレビューカード(リンク)を隠す setting_hide_network: 繋がりを隠す setting_hide_personal_from_account: 自分限定投稿をアカウントの投稿一覧から隠す setting_hide_personal_from_timeline: 自分限定投稿をタイムラインから隠す + setting_hide_photo_preview: プレビューカード(画像)を隠す setting_hide_privacy_meta: 公開範囲の説明を隠す setting_hide_statuses_count: 投稿数を隠す + setting_hide_video_preview: プレビューカード(動画)を隠す setting_info_font_size: 情報ヘッダのフォントサイズ setting_match_visibility_of_references: 投稿の公開範囲を参照先に合わせる setting_new_features_policy: 新機能へのポリシー diff --git a/config/settings.yml b/config/settings.yml index bb906a21b..9cde602e1 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -135,6 +135,9 @@ defaults: &defaults hide_direct_from_timeline: false hide_personal_from_timeline: false hide_privacy_meta: false + hide_link_preview: false + hide_photo_preview: false + hide_video_preview: false development: <<: *defaults