From 80fadeb7665e8df86e3f6b7dc8433d5f78647d12 Mon Sep 17 00:00:00 2001 From: KMY Date: Tue, 19 Sep 2023 10:04:22 +0900 Subject: [PATCH] Add single_ref_to_quote setting and check ref sync --- app/models/concerns/has_user_settings.rb | 4 ++++ app/models/user_settings.rb | 1 + .../activitypub/note_serializer.rb | 20 +++++++++++++++++++ app/services/post_status_service.rb | 2 +- app/services/process_references_service.rb | 6 ++++++ app/services/update_status_service.rb | 2 +- .../settings/preferences/other/show.html.haml | 3 +++ config/locales/simple_form.en.yml | 1 + config/locales/simple_form.ja.yml | 1 + 9 files changed, 38 insertions(+), 2 deletions(-) diff --git a/app/models/concerns/has_user_settings.rb b/app/models/concerns/has_user_settings.rb index 430fc9c044f32b..780c6345bb3e16 100644 --- a/app/models/concerns/has_user_settings.rb +++ b/app/models/concerns/has_user_settings.rb @@ -127,6 +127,10 @@ def setting_link_preview settings['link_preview'] end + def setting_single_ref_to_quote + settings['single_ref_to_quote'] + end + def setting_dtl_force_with_tag settings['dtl_force_with_tag']&.to_sym || :none end diff --git a/app/models/user_settings.rb b/app/models/user_settings.rb index b52bf67e7f4577..93f7f4a64f2c7f 100644 --- a/app/models/user_settings.rb +++ b/app/models/user_settings.rb @@ -41,6 +41,7 @@ class KeyError < Error; end setting :dtl_force_with_tag, default: :none, in: %w(full searchability none) setting :dtl_force_subscribable, default: false setting :lock_follow_from_bot, default: false + setting :single_ref_to_quote, default: false setting_inverse_alias :indexable, :noindex diff --git a/app/serializers/activitypub/note_serializer.rb b/app/serializers/activitypub/note_serializer.rb index ec16d3b56709f7..19b22b9b0b984f 100644 --- a/app/serializers/activitypub/note_serializer.rb +++ b/app/serializers/activitypub/note_serializer.rb @@ -17,6 +17,10 @@ class ActivityPub::NoteSerializer < ActivityPub::Serializer attribute :content_map, if: :language? attribute :updated, if: :edited? + attribute :quote_uri, if: :quote? + attribute :misskey_quote, key: :_misskey_quote, if: :quote? + attribute :misskey_content, key: :_misskey_content, if: :quote? + has_many :virtual_attachments, key: :attachment has_many :virtual_tags, key: :tag @@ -160,6 +164,22 @@ def not_private_post? !object.private_visibility? && !object.direct_visibility? && !object.limited_visibility? end + def quote? + object.references.count == 1 && object.account.user&.single_ref_to_quote + end + + def quote_uri + ActivityPub::TagManager.instance.uri_for(object.references.first) + end + + def misskey_quote + quote_uri + end + + def misskey_content + object.text + end + def poll_options object.preloadable_poll.loaded_options end diff --git a/app/services/post_status_service.rb b/app/services/post_status_service.rb index e8725528d9e025..a549ab1c78a893 100644 --- a/app/services/post_status_service.rb +++ b/app/services/post_status_service.rb @@ -188,7 +188,7 @@ def postprocess_status! process_hashtags_service.call(@status) Trends.tags.register(@status) - ProcessReferencesService.perform_worker_async(@status, @reference_ids, []) + ProcessReferencesService.call_service(@status, @reference_ids, []) LinkCrawlWorker.perform_async(@status.id) DistributionWorker.perform_async(@status.id) ActivityPub::DistributionWorker.perform_async(@status.id) diff --git a/app/services/process_references_service.rb b/app/services/process_references_service.rb index c98a0434c79421..1043190473f63b 100644 --- a/app/services/process_references_service.rb +++ b/app/services/process_references_service.rb @@ -40,6 +40,12 @@ def self.perform_worker_async(status, reference_parameters, urls) ProcessReferencesWorker.perform_async(status.id, reference_parameters, urls) end + def self.call_service(status, reference_parameters, urls) + return unless need_process?(status, reference_parameters, urls) + + ProcessReferencesService.new.call(status, reference_parameters || [], urls: urls || []) + end + private def references diff --git a/app/services/update_status_service.rb b/app/services/update_status_service.rb index 8d99ebdd3ddcd3..6e63fa97421051 100644 --- a/app/services/update_status_service.rb +++ b/app/services/update_status_service.rb @@ -162,7 +162,7 @@ def reset_preview_card! def update_references! reference_ids = (@options[:status_reference_ids] || []).map(&:to_i).filter(&:positive?) - ProcessReferencesService.perform_worker_async(@status, reference_ids, []) + ProcessReferencesService.call_service(@status, reference_ids, []) end def update_metadata! diff --git a/app/views/settings/preferences/other/show.html.haml b/app/views/settings/preferences/other/show.html.haml index 353715df01a66e..149a3d56efbc8b 100644 --- a/app/views/settings/preferences/other/show.html.haml +++ b/app/views/settings/preferences/other/show.html.haml @@ -14,6 +14,9 @@ .fields-group = ff.input :lock_follow_from_bot, wrapper: :with_label, kmyblue: true, label: I18n.t('simple_form.labels.defaults.setting_lock_follow_from_bot') + .fields-group + = ff.input :single_ref_to_quote, wrapper: :with_label, kmyblue: true, label: I18n.t('simple_form.labels.defaults.setting_single_ref_to_quote') + %h4= t 'preferences.posting_defaults' .fields-row diff --git a/config/locales/simple_form.en.yml b/config/locales/simple_form.en.yml index 958f1040f51e4f..576b535f109682 100644 --- a/config/locales/simple_form.en.yml +++ b/config/locales/simple_form.en.yml @@ -272,6 +272,7 @@ en: setting_show_application: Disclose application used to send posts setting_show_emoji_reaction_on_timeline: Show all stamps on timeline setting_simple_timeline_menu: Reduce post menu on timeline + setting_single_ref_to_quote: Deliver single reference to other server as quote setting_stay_privacy: Not change privacy after post setting_stop_emoji_reaction_streaming: Disable stamp streamings setting_system_font_ui: Use system's default font diff --git a/config/locales/simple_form.ja.yml b/config/locales/simple_form.ja.yml index be5d0e9f6567b8..6283e5f431ae27 100644 --- a/config/locales/simple_form.ja.yml +++ b/config/locales/simple_form.ja.yml @@ -287,6 +287,7 @@ ja: setting_show_application: 送信したアプリを開示する setting_show_emoji_reaction_on_timeline: タイムライン上に他の人のつけたスタンプを表示する setting_simple_timeline_menu: タイムライン上でメニューの項目を減らす + setting_single_ref_to_quote: 参照が1つしかない投稿は、他のサーバーには引用として配信する setting_stay_privacy: 投稿時に公開範囲を保存する setting_stop_emoji_reaction_streaming: スタンプのストリーミングを停止する setting_system_font_ui: システムのデフォルトフォントを使う