From fe2acbc4c41f9f8b11e559f82a49d9c0f9740414 Mon Sep 17 00:00:00 2001 From: Dean Bassett Date: Thu, 29 Dec 2022 19:48:06 -0800 Subject: [PATCH 1/5] Split 'show boosts/replies in public timelines' glitch admin settings into local and federated (#8) * Showing all federated boosts is noisy while local boosts may be acceptable (especially once #4 is addressed) --- .../api/v1/timelines/public_controller.rb | 4 ++-- app/models/form/admin_settings.rb | 12 ++++++++---- app/services/fan_out_on_write_service.rb | 19 ++++++++++++------- app/views/admin/settings/other/show.html.haml | 10 ++++++++-- config/locales-glitch/en.yml | 18 ++++++++++++------ 5 files changed, 42 insertions(+), 21 deletions(-) diff --git a/app/controllers/api/v1/timelines/public_controller.rb b/app/controllers/api/v1/timelines/public_controller.rb index 493fe4776a5c19..220b31b36a4ef8 100644 --- a/app/controllers/api/v1/timelines/public_controller.rb +++ b/app/controllers/api/v1/timelines/public_controller.rb @@ -39,8 +39,8 @@ def public_feed remote: truthy_param?(:remote), only_media: truthy_param?(:only_media), allow_local_only: truthy_param?(:allow_local_only), - with_replies: Setting.show_replies_in_public_timelines, - with_reblogs: Setting.show_reblogs_in_public_timelines, + with_replies: truthy_param?(:local) ? Setting.show_replies_in_local_timelines : Setting.show_replies_in_federated_timelines, + with_reblogs: truthy_param?(:local) ? Setting.show_reblogs_in_local_timelines : Setting.show_reblogs_in_federated_timelines, ) end diff --git a/app/models/form/admin_settings.rb b/app/models/form/admin_settings.rb index b53a82db22b818..cdded82a061f76 100644 --- a/app/models/form/admin_settings.rb +++ b/app/models/form/admin_settings.rb @@ -25,8 +25,10 @@ class Form::AdminSettings flavour_and_skin thumbnail mascot - show_reblogs_in_public_timelines - show_replies_in_public_timelines + show_reblogs_in_local_timelines + show_replies_in_local_timelines + show_reblogs_in_federated_timelines + show_replies_in_federated_timelines trends trendable_by_default trending_status_cw @@ -54,8 +56,10 @@ class Form::AdminSettings preview_sensitive_media profile_directory hide_followers_count - show_reblogs_in_public_timelines - show_replies_in_public_timelines + show_reblogs_in_local_timelines + show_replies_in_local_timelines + show_reblogs_in_federated_timelines + show_replies_in_federated_timelines trends trendable_by_default trending_status_cw diff --git a/app/services/fan_out_on_write_service.rb b/app/services/fan_out_on_write_service.rb index 8e74e152ed7d36..c7efbe05daaa51 100644 --- a/app/services/fan_out_on_write_service.rb +++ b/app/services/fan_out_on_write_service.rb @@ -129,14 +129,19 @@ def broadcast_to_hashtag_streams! end def broadcast_to_public_streams! - return if @status.reply? && @status.in_reply_to_account_id != @account.id && !Setting.show_replies_in_public_timelines - - redis.publish('timeline:public', anonymous_payload) - redis.publish(@status.local? ? 'timeline:public:local' : 'timeline:public:remote', anonymous_payload) + broadcast_to = ->(channel) { + redis.publish(channel, anonymous_payload) + if @status.with_media? + redis.publish("#{channel}:media") + end + } + is_reply = @status.reply? && @status.in_reply_to_account_id != @account.id - if @status.with_media? - redis.publish('timeline:public:media', anonymous_payload) - redis.publish(@status.local? ? 'timeline:public:local:media' : 'timeline:public:remote:media', anonymous_payload) + broadcast_to.call('timeline:public') if !is_reply || Setting.show_replies_in_federated_timelines + if @status.local + broadcast_to.call('timeline:public:local') if !is_reply || Setting.show_replies_in_local_timelines + else + broadcast_to.call('timeline:public:remote') if !is_reply || Setting.show_replies_in_federated_timelines end end diff --git a/app/views/admin/settings/other/show.html.haml b/app/views/admin/settings/other/show.html.haml index 1a7a4e46e54b16..ba201cbdac9233 100644 --- a/app/views/admin/settings/other/show.html.haml +++ b/app/views/admin/settings/other/show.html.haml @@ -14,10 +14,16 @@ = f.input :hide_followers_count, as: :boolean, wrapper: :with_label, label: t('admin.settings.hide_followers_count.title'), hint: t('admin.settings.hide_followers_count.desc_html'), glitch_only: true .fields-group - = f.input :show_reblogs_in_public_timelines, as: :boolean, wrapper: :with_label, label: t('admin.settings.show_reblogs_in_public_timelines.title'), hint: t('admin.settings.show_reblogs_in_public_timelines.desc_html'), glitch_only: true + = f.input :show_reblogs_in_local_timelines, as: :boolean, wrapper: :with_label, label: t('admin.settings.show_reblogs_in_local_timelines.title'), hint: t('admin.settings.show_reblogs_in_local_timelines.desc_html'), glitch_only: true .fields-group - = f.input :show_replies_in_public_timelines, as: :boolean, wrapper: :with_label, label: t('admin.settings.show_replies_in_public_timelines.title'), hint: t('admin.settings.show_replies_in_public_timelines.desc_html'), glitch_only: true + = f.input :show_replies_in_local_timelines, as: :boolean, wrapper: :with_label, label: t('admin.settings.show_replies_in_local_timelines.title'), hint: t('admin.settings.show_replies_in_local_timelines.desc_html'), glitch_only: true + + .fields-group + = f.input :show_reblogs_in_federated_timelines, as: :boolean, wrapper: :with_label, label: t('admin.settings.show_reblogs_in_federated_timelines.title'), hint: t('admin.settings.show_reblogs_in_federated_timelines.desc_html'), glitch_only: true + + .fields-group + = f.input :show_replies_in_federated_timelines, as: :boolean, wrapper: :with_label, label: t('admin.settings.show_replies_in_federated_timelines.title'), hint: t('admin.settings.show_replies_in_federated_timelines.desc_html'), glitch_only: true .fields-group = f.input :outgoing_spoilers, wrapper: :with_label, label: t('admin.settings.outgoing_spoilers.title'), hint: t('admin.settings.outgoing_spoilers.desc_html'), glitch_only: true diff --git a/config/locales-glitch/en.yml b/config/locales-glitch/en.yml index e60a89e1898b78..a5b6083f0060a4 100644 --- a/config/locales-glitch/en.yml +++ b/config/locales-glitch/en.yml @@ -19,12 +19,18 @@ en: outgoing_spoilers: desc_html: When federating toots, add this content warning to toots that do not have one. It is useful if your server is specialized in content other servers might want to have under a Content Warning. Media will also be marked as sensitive. title: Content warning for outgoing toots - show_reblogs_in_public_timelines: - desc_html: Show public boosts of public toots in local and public timelines. - title: Show boosts in public timelines - show_replies_in_public_timelines: - desc_html: In addition to public self-replies (threads), show public replies in local and public timelines. - title: Show replies in public timelines + show_reblogs_in_federated_timelines: + desc_html: Show public boosts of public toots in the federated timeline. + title: Show boosts in the federated timeline + show_reblogs_in_local_timelines: + desc_html: Show public boosts in the instance's local timeline. + title: Show boosts in the local timeline + show_replies_in_federated_timelines: + desc_html: In addition to public self-replies (threads), show public replies in the federated timeline. + title: Show replies in the federated timeline + show_replies_in_local_timelines: + desc_html: In addition to public self-replies (threads), show public replies in the instance's local timeline. + title: Show replies in the local timeline trending_status_cw: desc_html: When trending posts are enabled, allow posts with Content Warnings to be eligible. Changes to this setting are not retroactive. title: Allow posts with Content Warnings to trend From a6b4f5217cf74c40182d4e76555f7fb5741e1492 Mon Sep 17 00:00:00 2001 From: neatchee Date: Tue, 3 Jan 2023 10:55:59 -0800 Subject: [PATCH 2/5] Fix missing argument in 4dc140c72199287d0838b4a7723d5e3b215d4526 (#29) Fixes #25 --- app/services/fan_out_on_write_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/fan_out_on_write_service.rb b/app/services/fan_out_on_write_service.rb index c7efbe05daaa51..ecbeda3bf74db8 100644 --- a/app/services/fan_out_on_write_service.rb +++ b/app/services/fan_out_on_write_service.rb @@ -132,7 +132,7 @@ def broadcast_to_public_streams! broadcast_to = ->(channel) { redis.publish(channel, anonymous_payload) if @status.with_media? - redis.publish("#{channel}:media") + redis.publish("#{channel}:media", anonymous_payload) end } is_reply = @status.reply? && @status.in_reply_to_account_id != @account.id From 4794789f3d944a29cc462a81e1c7b5dbfb984652 Mon Sep 17 00:00:00 2001 From: neatchee Date: Wed, 4 Jan 2023 06:51:11 -0800 Subject: [PATCH 3/5] Code style improvements Co-authored-by: Claire --- app/services/fan_out_on_write_service.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/services/fan_out_on_write_service.rb b/app/services/fan_out_on_write_service.rb index ecbeda3bf74db8..d59087277ded84 100644 --- a/app/services/fan_out_on_write_service.rb +++ b/app/services/fan_out_on_write_service.rb @@ -131,9 +131,7 @@ def broadcast_to_hashtag_streams! def broadcast_to_public_streams! broadcast_to = ->(channel) { redis.publish(channel, anonymous_payload) - if @status.with_media? - redis.publish("#{channel}:media", anonymous_payload) - end + redis.publish("#{channel}:media", anonymous_payload) if @status.with_media? } is_reply = @status.reply? && @status.in_reply_to_account_id != @account.id From 80cc050e02b927251df540c13e8b70f33080c3f6 Mon Sep 17 00:00:00 2001 From: neatchee Date: Wed, 4 Jan 2023 13:46:15 -0800 Subject: [PATCH 4/5] Add missing config/settings.yml default values for show boosts/replies in local/federated timelines --- config/settings.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/config/settings.yml b/config/settings.yml index 1f44fd308d81b4..aada09c90751c9 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -73,8 +73,10 @@ defaults: &defaults bootstrap_timeline_accounts: '' activity_api_enabled: true peers_api_enabled: true - show_reblogs_in_public_timelines: false - show_replies_in_public_timelines: false + show_reblogs_in_local_timelines: false + show_reblogs_in_federated_timelines: false + show_replies_in_local_timelines: false + show_replies_in_federated_timelines: false default_content_type: 'text/plain' show_domain_blocks: 'disabled' show_domain_blocks_rationale: 'disabled' From 109ccf9f60ab7e44ad32edcb5fdf6720ca93f183 Mon Sep 17 00:00:00 2001 From: neatchee Date: Wed, 4 Jan 2023 14:48:19 -0800 Subject: [PATCH 5/5] db migration for show public reblogs/replies in public timelines setting split --- ...ogs_replies_in_public_timelines_setting.rb | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 db/migrate/20230104140536_migrate_show_reblogs_replies_in_public_timelines_setting.rb diff --git a/db/migrate/20230104140536_migrate_show_reblogs_replies_in_public_timelines_setting.rb b/db/migrate/20230104140536_migrate_show_reblogs_replies_in_public_timelines_setting.rb new file mode 100644 index 00000000000000..226d6e75231344 --- /dev/null +++ b/db/migrate/20230104140536_migrate_show_reblogs_replies_in_public_timelines_setting.rb @@ -0,0 +1,34 @@ +class MigrateShowReblogsRepliesInPublicTimelinesSetting < ActiveRecord::Migration[6.1] + def up + show_reblogs_in_public_timelines = Setting.find_by(var: 'show_reblogs_in_public_timelines') + if show_reblogs_in_public_timelines.nil? || show_reblogs_in_public_timelines.value + setting_local = Setting.where(var: 'show_reblogs_in_local_timelines').first_or_initialize(var: 'show_reblogs_in_local_timelines') + setting_federated = Setting.where(var: 'show_reblogs_in_federated_timelines').first_or_initialize(var: 'show_reblogs_in_federated_timelines') + setting_local.update(value: true) + setting_federated.update(value: true) + end + + show_replies_in_public_timelines = Setting.find_by(var: 'show_replies_in_public_timelines') + if show_replies_in_public_timelines.nil? || show_replies_in_public_timelines.value + setting_local = Setting.where(var: 'show_replies_in_local_timelines').first_or_initialize(var: 'show_replies_in_local_timelines') + setting_federated = Setting.where(var: 'show_replies_in_federated_timelines').first_or_initialize(var: 'show_replies_in_federated_timelines') + setting_local.update(value: true) + setting_federated.update(value: true) + end + end + + def down + show_reblogs_in_local_timelines = Setting.find_by(var: 'show_reblogs_in_local_timelines') + show_reblogs_in_federate_timelines = Setting.find_by(var: 'show_reblogs_in_federated_timelines') + if show_reblogs_in_local_timelines.nil? || show_reblogs_in_local_timelines.value || show_reblogs_in_federated_timelines.nil? || show_reblogs_in_federated_timelines.value + setting = Setting.where(var: 'show_reblogs_in_public_timelines').first_or_initialize(var: 'show_reblogs_in_public_timelines') + setting.update(value: true) + end + + show_replies_in_public_timelines = Setting.find_by(var: 'show_replies_in_public_timelines') + if show_replies_in_local_timelines.nil? || show_replies_in_local_timelines.value || show_replies_in_federated_timelines.nil? || show_replies_in_federated_timelines.value + setting = Setting.where(var: 'show_replies_in_public_timelines').first_or_initialize(var: 'show_replies_in_public_timelines') + setting.update(value: true) + end + end +end