From bef078a87a6d94087ab631d7020461e00b038e8b Mon Sep 17 00:00:00 2001 From: KMY Date: Tue, 14 Mar 2023 22:02:43 +0900 Subject: [PATCH] Remove group following limitations --- .../settings/profiles_controller.rb | 2 +- app/models/account.rb | 1 - app/models/account_stat.rb | 21 ++++++++++++------- app/models/concerns/account_counters.rb | 2 ++ app/services/group_reblog_service.rb | 17 ++++++++------- app/views/settings/profiles/show.html.haml | 3 --- config/locales/simple_form.en.yml | 2 -- config/locales/simple_form.ja.yml | 2 -- ...roup_message_following_only_to_accounts.rb | 2 ++ ...group_allow_private_message_to_accounts.rb | 2 ++ ...roup_activitypub_count_to_account_stats.rb | 7 +++++++ ...up_message_following_only_from_accounts.rb | 9 ++++++++ db/schema.rb | 4 ++-- 13 files changed, 48 insertions(+), 26 deletions(-) create mode 100644 db/migrate/20230314121142_add_group_activitypub_count_to_account_stats.rb create mode 100644 db/post_migrate/20230314120530_remove_group_message_following_only_from_accounts.rb diff --git a/app/controllers/settings/profiles_controller.rb b/app/controllers/settings/profiles_controller.rb index 5bdfdd14c9..34b7c81131 100644 --- a/app/controllers/settings/profiles_controller.rb +++ b/app/controllers/settings/profiles_controller.rb @@ -20,7 +20,7 @@ class Settings::ProfilesController < Settings::BaseController private def account_params - params.require(:account).permit(:display_name, :note, :avatar, :header, :locked, :my_actor_type, :group_message_following_only, :group_allow_private_message, :discoverable, :hide_collections, fields_attributes: [:name, :value]) + params.require(:account).permit(:display_name, :note, :avatar, :header, :locked, :my_actor_type, :group_allow_private_message, :discoverable, :hide_collections, fields_attributes: [:name, :value]) end def set_account diff --git a/app/models/account.rb b/app/models/account.rb index c14931e02f..ef9aa29b4a 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -50,7 +50,6 @@ # trendable :boolean # reviewed_at :datetime # requested_review_at :datetime -# group_message_following_only :boolean # group_allow_private_message :boolean # diff --git a/app/models/account_stat.rb b/app/models/account_stat.rb index 834f8ba4c2..c09bb58c8d 100644 --- a/app/models/account_stat.rb +++ b/app/models/account_stat.rb @@ -4,14 +4,15 @@ # # Table name: account_stats # -# id :bigint(8) not null, primary key -# account_id :bigint(8) not null -# statuses_count :bigint(8) default(0), not null -# following_count :bigint(8) default(0), not null -# followers_count :bigint(8) default(0), not null -# created_at :datetime not null -# updated_at :datetime not null -# last_status_at :datetime +# id :bigint(8) not null, primary key +# account_id :bigint(8) not null +# statuses_count :bigint(8) default(0), not null +# following_count :bigint(8) default(0), not null +# followers_count :bigint(8) default(0), not null +# created_at :datetime not null +# updated_at :datetime not null +# last_status_at :datetime +# group_activitypub_count :integer # class AccountStat < ApplicationRecord @@ -33,4 +34,8 @@ class AccountStat < ApplicationRecord def statuses_count [attributes['statuses_count'], 0].max end + + def group_activitypub_count + [attributes['group_activitypub_count'], 0].max + end end diff --git a/app/models/concerns/account_counters.rb b/app/models/concerns/account_counters.rb index 3fabb52054..9e2b9245b5 100644 --- a/app/models/concerns/account_counters.rb +++ b/app/models/concerns/account_counters.rb @@ -16,6 +16,8 @@ module AccountCounters :following_count=, :followers_count, :followers_count=, + :group_activitypub_count, + :group_activitypub_count=, :last_status_at, to: :account_stat diff --git a/app/services/group_reblog_service.rb b/app/services/group_reblog_service.rb index ddff566173..f7a7e69903 100644 --- a/app/services/group_reblog_service.rb +++ b/app/services/group_reblog_service.rb @@ -3,8 +3,7 @@ class GroupReblogService < BaseService include RoutingHelper - CHECK_POSTS_DOMAIN_SIZE = 30 - REQUESTED_LOCAL_POSTS = 5 + ACTIVITYPUB_CONTINUOUS_SIZE = 30 def call(status) visibility = status.visibility.to_sym @@ -15,16 +14,20 @@ class GroupReblogService < BaseService accounts.each do |account| next unless account.local? - next if account.group_message_following_only && !account.following?(status.account) next unless status.account.following?(account) next unless account.group? next if account.id == status.account_id next if transcription && !account.group_allow_private_message - if status.account.activitypub? - domains = account.statuses.order(created_at: 'DESC').where('reblog_of_id > 0').map(&:reblog).map(&:account).map(&:domain).take(CHECK_POSTS_DOMAIN_SIZE).to_a - local_count = domains.where { |domain| !domain }.size - next if local_count < REQUESTED_LOCAL_POSTS + if status.account.activitypub? && ACTIVITYPUB_CONTINUOUS_SIZE > 0 + next if account.group_activitypub_count >= ACTIVITYPUB_CONTINUOUS_SIZE + account.group_activitypub_count = account.group_activitypub_count + 1 + account.save! + else + if account.group_activitypub_count > 0 + account.group_activitypub_count = 0 + account.save! + end end ReblogService.new.call(account, status, { visibility: status.visibility }) if !transcription diff --git a/app/views/settings/profiles/show.html.haml b/app/views/settings/profiles/show.html.haml index 5aeb479b89..31c09007ba 100644 --- a/app/views/settings/profiles/show.html.haml +++ b/app/views/settings/profiles/show.html.haml @@ -29,9 +29,6 @@ .fields-group = f.input :my_actor_type, collection: ['person', 'bot', 'group'],label_method: lambda { |item| safe_join([t("simple_form.labels.defaults.#{item}"), content_tag(:span, I18n.t("simple_form.hints.defaults.#{item}"), class: 'hint')]) }, as: :radio_buttons, collection_wrapper_tag: 'ul', item_wrapper_tag: 'li', wrapper: :with_floating_label - .fields-group - = f.input :group_message_following_only, as: :boolean, wrapper: :with_label, hint: t('simple_form.hints.defaults.group_message_following_only') - .fields-group = f.input :group_allow_private_message, as: :boolean, wrapper: :with_label, hint: t('simple_form.hints.defaults.group_allow_private_message') diff --git a/config/locales/simple_form.en.yml b/config/locales/simple_form.en.yml index d19a3f61ce..96978578bb 100644 --- a/config/locales/simple_form.en.yml +++ b/config/locales/simple_form.en.yml @@ -42,7 +42,6 @@ en: fields: You can have up to 4 items displayed as a table on your profile group: Reps sent to this account will be automatically BT'd and distributed to all accounts you follow! group_allow_private_message: Posts are duplicated and cannot be edited or deleted by the post - group_message_following_only: Effective as an anti-troll/spam measure, but requires the effort to follow up with subscribers header: PNG, GIF or JPG. At most %{size}. Will be downscaled to %{dimensions}px inbox_url: Copy the URL from the frontpage of the relay you want to use irreversible: Filtered posts will disappear irreversibly, even if filter is later removed @@ -185,7 +184,6 @@ en: fields: Profile metadata group: This is a group account group_allow_private_message: For group accounts, duplicate private or direct message - group_message_following_only: For group accounts, BT only mentions from people you are following header: Header honeypot: "%{label} (do not fill in)" inbox_url: URL of the relay inbox diff --git a/config/locales/simple_form.ja.yml b/config/locales/simple_form.ja.yml index 05943fcaa9..8fc8dd265e 100644 --- a/config/locales/simple_form.ja.yml +++ b/config/locales/simple_form.ja.yml @@ -42,7 +42,6 @@ ja: fields: プロフィールに表として4つまでの項目を表示することができます group: このアカウントに送られたメンションは自動でBTされ、フォローしている全てのアカウントに配信されます group_allow_private_message: 投稿は複製されるため、投稿者が編集・削除することはできません - group_message_following_only: 荒らし・スパム対策として有効ですが、加入者をフォローする手間が発生します header: "%{size}までのPNG、GIF、JPGが利用可能です。 %{dimensions}pxまで縮小されます" inbox_url: 使用したいリレーサーバーのトップページからURLをコピーします irreversible: フィルターが後で削除されても、除外された投稿は元に戻せなくなります @@ -185,7 +184,6 @@ ja: fields: プロフィール補足情報 group: これはグループアカウントです group_allow_private_message: グループアカウントの場合、フォロワーのみ・ダイレクトのメンションを複製する - group_message_following_only: グループアカウントの場合、自分がフォローしている相手からのメンションのみをBTする header: ヘッダー honeypot: "%{label} (入力しない)" inbox_url: リレーサーバーの inbox URL diff --git a/db/migrate/20230314021909_add_group_message_following_only_to_accounts.rb b/db/migrate/20230314021909_add_group_message_following_only_to_accounts.rb index 40f843afd8..4712e9dd3e 100644 --- a/db/migrate/20230314021909_add_group_message_following_only_to_accounts.rb +++ b/db/migrate/20230314021909_add_group_message_following_only_to_accounts.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddGroupMessageFollowingOnlyToAccounts < ActiveRecord::Migration[6.1] def change add_column :accounts, :group_message_following_only, :boolean diff --git a/db/migrate/20230314081013_add_group_allow_private_message_to_accounts.rb b/db/migrate/20230314081013_add_group_allow_private_message_to_accounts.rb index c315c14088..367e1c1d0a 100644 --- a/db/migrate/20230314081013_add_group_allow_private_message_to_accounts.rb +++ b/db/migrate/20230314081013_add_group_allow_private_message_to_accounts.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddGroupAllowPrivateMessageToAccounts < ActiveRecord::Migration[6.1] def change add_column :accounts, :group_allow_private_message, :boolean diff --git a/db/migrate/20230314121142_add_group_activitypub_count_to_account_stats.rb b/db/migrate/20230314121142_add_group_activitypub_count_to_account_stats.rb new file mode 100644 index 0000000000..d4f06bae19 --- /dev/null +++ b/db/migrate/20230314121142_add_group_activitypub_count_to_account_stats.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddGroupActivityPubCountToAccountStats < ActiveRecord::Migration[6.1] + def change + add_column :account_stats, :group_activitypub_count, :integer + end +end diff --git a/db/post_migrate/20230314120530_remove_group_message_following_only_from_accounts.rb b/db/post_migrate/20230314120530_remove_group_message_following_only_from_accounts.rb new file mode 100644 index 0000000000..2c140d9a16 --- /dev/null +++ b/db/post_migrate/20230314120530_remove_group_message_following_only_from_accounts.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class RemoveGroupMessageFollowingOnlyFromAccounts < ActiveRecord::Migration[6.1] + disable_ddl_transaction! + + def change + safety_assured { remove_column :accounts, :group_message_following_only, :boolean } + end +end diff --git a/db/schema.rb b/db/schema.rb index 284dc41863..df73b75825 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2023_03_14_081013) do +ActiveRecord::Schema.define(version: 2023_03_14_121142) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -99,6 +99,7 @@ ActiveRecord::Schema.define(version: 2023_03_14_081013) do t.datetime "created_at", null: false t.datetime "updated_at", null: false t.datetime "last_status_at" + t.integer "group_activitypub_count" t.index ["account_id"], name: "index_account_stats_on_account_id", unique: true end @@ -186,7 +187,6 @@ ActiveRecord::Schema.define(version: 2023_03_14_081013) do t.boolean "trendable" t.datetime "reviewed_at" t.datetime "requested_review_at" - t.boolean "group_message_following_only" t.boolean "group_allow_private_message" t.index "(((setweight(to_tsvector('simple'::regconfig, (display_name)::text), 'A'::\"char\") || setweight(to_tsvector('simple'::regconfig, (username)::text), 'B'::\"char\")) || setweight(to_tsvector('simple'::regconfig, (COALESCE(domain, ''::character varying))::text), 'C'::\"char\")))", name: "search_index", using: :gin t.index "lower((username)::text), COALESCE(lower((domain)::text), ''::text)", name: "index_accounts_on_username_and_domain_lower", unique: true