From 1a8e8f02dd1105a1fcee8a23ff8d25df116779e4 Mon Sep 17 00:00:00 2001 From: KMY Date: Thu, 20 Apr 2023 17:40:25 +0900 Subject: [PATCH] Add emoji reaction option on status cleanup --- app/controllers/statuses_cleanup_controller.rb | 2 +- app/models/account_statuses_cleanup_policy.rb | 17 ++++++++++++++--- app/models/emoji_reaction.rb | 2 +- app/views/statuses_cleanup/show.html.haml | 8 ++++++++ config/locales/en.yml | 3 +++ config/locales/ja.yml | 5 +++++ ...ojis_to_account_statuses_cleanup_policies.rb | 6 ++++++ db/schema.rb | 4 +++- 8 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 db/migrate/20230420081634_add_min_emojis_to_account_statuses_cleanup_policies.rb diff --git a/app/controllers/statuses_cleanup_controller.rb b/app/controllers/statuses_cleanup_controller.rb index e912967fd7..7d2a2604aa 100644 --- a/app/controllers/statuses_cleanup_controller.rb +++ b/app/controllers/statuses_cleanup_controller.rb @@ -30,7 +30,7 @@ class StatusesCleanupController < ApplicationController end def resource_params - params.require(:account_statuses_cleanup_policy).permit(:enabled, :min_status_age, :keep_direct, :keep_pinned, :keep_polls, :keep_media, :keep_self_fav, :keep_self_bookmark, :min_favs, :min_reblogs) + params.require(:account_statuses_cleanup_policy).permit(:enabled, :min_status_age, :keep_direct, :keep_pinned, :keep_polls, :keep_media, :keep_self_fav, :keep_self_bookmark, :keep_self_emoji, :min_favs, :min_reblogs, :min_emojis) end def set_body_classes diff --git a/app/models/account_statuses_cleanup_policy.rb b/app/models/account_statuses_cleanup_policy.rb index 14ce00abbc..c09cf7677a 100644 --- a/app/models/account_statuses_cleanup_policy.rb +++ b/app/models/account_statuses_cleanup_policy.rb @@ -18,6 +18,8 @@ # min_reblogs :integer # created_at :datetime not null # updated_at :datetime not null +# min_emojis :integer +# keep_self_emoji :boolean default(TRUE), not null # class AccountStatusesCleanupPolicy < ApplicationRecord include Redisable @@ -33,8 +35,8 @@ class AccountStatusesCleanupPolicy < ApplicationRecord 2.years.seconds, ].freeze - EXCEPTION_BOOLS = %w(keep_direct keep_pinned keep_polls keep_media keep_self_fav keep_self_bookmark).freeze - EXCEPTION_THRESHOLDS = %w(min_favs min_reblogs).freeze + EXCEPTION_BOOLS = %w(keep_direct keep_pinned keep_polls keep_media keep_self_fav keep_self_bookmark keep_self_emoji).freeze + EXCEPTION_THRESHOLDS = %w(min_favs min_reblogs min_emojis).freeze # Depending on the cleanup policy, the query to discover the next # statuses to delete my get expensive if the account has a lot of old @@ -52,6 +54,7 @@ class AccountStatusesCleanupPolicy < ApplicationRecord validates :min_status_age, inclusion: { in: ALLOWED_MIN_STATUS_AGE } validates :min_favs, numericality: { greater_than_or_equal_to: 1, allow_nil: true } validates :min_reblogs, numericality: { greater_than_or_equal_to: 1, allow_nil: true } + validates :min_emojis, numericality: { greater_than_or_equal_to: 1, allow_nil: true } validate :validate_local_account before_save :update_last_inspected @@ -60,13 +63,14 @@ class AccountStatusesCleanupPolicy < ApplicationRecord scope = account.statuses scope.merge!(old_enough_scope(max_id)) scope = scope.where(Status.arel_table[:id].gteq(min_id)) if min_id.present? - scope.merge!(without_popular_scope) unless min_favs.nil? && min_reblogs.nil? + scope.merge!(without_popular_scope) unless min_favs.nil? && min_reblogs.nil? && min_emojis.nil? scope.merge!(without_direct_scope) if keep_direct? scope.merge!(without_pinned_scope) if keep_pinned? scope.merge!(without_poll_scope) if keep_polls? scope.merge!(without_media_scope) if keep_media? scope.merge!(without_self_fav_scope) if keep_self_fav? scope.merge!(without_self_bookmark_scope) if keep_self_bookmark? + scope.merge!(without_self_emoji_scope) if keep_self_emoji? scope.reorder(id: :asc).limit(limit) end @@ -107,6 +111,8 @@ class AccountStatusesCleanupPolicy < ApplicationRecord return unless keep_self_bookmark? when :unfav return unless keep_self_fav? + when :unemoji + return unless keep_self_emoji? when :unpin return unless keep_pinned? end @@ -148,6 +154,10 @@ class AccountStatusesCleanupPolicy < ApplicationRecord Status.where('NOT EXISTS (SELECT * FROM favourites fav WHERE fav.account_id = statuses.account_id AND fav.status_id = statuses.id)') end + def without_self_emoji_scope + Status.where('NOT EXISTS (SELECT * FROM emoji_reactions emj WHERE emj.account_id = statuses.account_id AND emj.status_id = statuses.id)') + end + def without_self_bookmark_scope Status.where('NOT EXISTS (SELECT * FROM bookmarks bookmark WHERE bookmark.account_id = statuses.account_id AND bookmark.status_id = statuses.id)') end @@ -168,6 +178,7 @@ class AccountStatusesCleanupPolicy < ApplicationRecord scope = Status.left_joins(:status_stat) scope = scope.where('COALESCE(status_stats.reblogs_count, 0) < ?', min_reblogs) unless min_reblogs.nil? scope = scope.where('COALESCE(status_stats.favourites_count, 0) < ?', min_favs) unless min_favs.nil? + scope = scope.where('COALESCE(status_stats.emoji_reactions_count, 0) < ?', min_emojis) unless min_emojis.nil? scope end end diff --git a/app/models/emoji_reaction.rb b/app/models/emoji_reaction.rb index 011e593bfd..01206689a9 100644 --- a/app/models/emoji_reaction.rb +++ b/app/models/emoji_reaction.rb @@ -44,7 +44,7 @@ class EmojiReaction < ApplicationRecord def invalidate_cleanup_info return unless status&.account_id == account_id && account.local? - account.statuses_cleanup_policy&.invalidate_last_inspected(status, :unfav) + account.statuses_cleanup_policy&.invalidate_last_inspected(status, :unemoji) end def paginate_by_max_id(limit, max_id = nil, since_id = nil) diff --git a/app/views/statuses_cleanup/show.html.haml b/app/views/statuses_cleanup/show.html.haml index 59de4b5aa6..d4d3282db2 100644 --- a/app/views/statuses_cleanup/show.html.haml +++ b/app/views/statuses_cleanup/show.html.haml @@ -34,6 +34,10 @@ .fields-row__column.fields-row__column-6.fields-group = f.input :keep_media, wrapper: :with_label, label: t('statuses_cleanup.keep_media'), hint: t('statuses_cleanup.keep_media_hint') + .fields-row + .fields-row__column.fields-row__column-6.fields-group + = f.input :keep_self_emoji, wrapper: :with_label, label: t('statuses_cleanup.keep_self_emoji'), hint: t('statuses_cleanup.keep_self_emoji_hint') + %h4= t('statuses_cleanup.interaction_exceptions') .fields-row @@ -42,4 +46,8 @@ .fields-row__column.fields-row__column-6.fields-group = f.input :min_reblogs, wrapper: :with_label, label: t('statuses_cleanup.min_reblogs'), hint: t('statuses_cleanup.min_reblogs_hint'), input_html: { min: 1, placeholder: t('statuses_cleanup.ignore_reblogs') } + .fields-row + .fields-row__column.fields-row__column-6.fields-group + = f.input :min_emojis, wrapper: :with_label, label: t('statuses_cleanup.min_emojis'), hint: t('statuses_cleanup.min_emojis_hint'), input_html: { min: 1, placeholder: t('statuses_cleanup.ignore_emojis') } + .flash-message= t('statuses_cleanup.interaction_exceptions_explanation') diff --git a/config/locales/en.yml b/config/locales/en.yml index c2c22e1b88..e4b6962a3c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1601,6 +1601,7 @@ en: enabled_hint: Automatically deletes your posts once they reach a specified age threshold, unless they match one of the exceptions below exceptions: Exceptions explanation: Because deleting posts is an expensive operation, this is done slowly over time when the server is not otherwise busy. For this reason, your posts may be deleted a while after they reach the age threshold. + ignore_emojis: Ignore emoji reactions ignore_favs: Ignore favourites ignore_reblogs: Ignore boosts interaction_exceptions: Exceptions based on interactions @@ -1627,6 +1628,8 @@ en: '63113904': 2 years '7889238': 3 months min_age_label: Age threshold + min_emojis: Keep posts emoji-reacted at least + min_emojis_hint: Doesn't delete any of your posts that has received at least this number of emoji reactions. Leave blank to delete posts regardless of their number of emojis min_favs: Keep posts favourited at least min_favs_hint: Doesn't delete any of your posts that has received at least this number of favourites. Leave blank to delete posts regardless of their number of favourites min_reblogs: Keep posts boosted at least diff --git a/config/locales/ja.yml b/config/locales/ja.yml index fa09ac8545..c26d47abc0 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -1562,6 +1562,7 @@ ja: enabled_hint: 設定した期間を過ぎた投稿は、以下の例外に該当しない限り、自動的に削除されます exceptions: 例外 explanation: 投稿の削除はサーバーに負荷がかかるため、サーバーが混み合っていないときに時間をかけて行われます。 + ignore_emojis: 設定しない ignore_favs: 設定しない ignore_reblogs: 設定しない interaction_exceptions: インタラクションに基づく例外 @@ -1576,6 +1577,8 @@ ja: keep_polls_hint: アンケート付きの投稿を削除せずに残します keep_self_bookmark: ブックマークした投稿を保持 keep_self_bookmark_hint: 自分自身でブックマークした投稿を削除せずに残します + keep_self_emoji: 絵文字リアクションした投稿を保持 + keep_self_emoji_hint: 自分自身で絵文字リアクションした投稿を削除せずに残します keep_self_fav: お気に入りに登録した投稿を保持 keep_self_fav_hint: 自分自身でお気に入りに登録した投稿を削除せずに残します min_age: @@ -1588,6 +1591,8 @@ ja: '63113904': 2年 '7889238': 3ヶ月 min_age_label: 投稿を保持する期間 + min_emojis: 絵文字リアクションの基準値 + min_emojis_hint: この数以上、絵文字リアクションされた投稿を削除せずに残します。空白にしておくと、数に関わらず投稿を削除します。 min_favs: お気に入りの基準値 min_favs_hint: この数以上、お気に入り登録された投稿を削除せずに残します。空白にしておくと、お気に入りの数に関わらず投稿を削除します。 min_reblogs: ブーストの基準値 diff --git a/db/migrate/20230420081634_add_min_emojis_to_account_statuses_cleanup_policies.rb b/db/migrate/20230420081634_add_min_emojis_to_account_statuses_cleanup_policies.rb new file mode 100644 index 0000000000..548b55932d --- /dev/null +++ b/db/migrate/20230420081634_add_min_emojis_to_account_statuses_cleanup_policies.rb @@ -0,0 +1,6 @@ +class AddMinEmojisToAccountStatusesCleanupPolicies < ActiveRecord::Migration[6.1] + def change + add_column :account_statuses_cleanup_policies, :min_emojis, :integer + add_column :account_statuses_cleanup_policies, :keep_self_emoji, :boolean, default: true, null: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 82581d71e5..fbc856dd5f 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_04_14_010523) do +ActiveRecord::Schema.define(version: 2023_04_20_081634) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -117,6 +117,8 @@ ActiveRecord::Schema.define(version: 2023_04_14_010523) do t.integer "min_reblogs" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false + t.integer "min_emojis" + t.boolean "keep_self_emoji", default: true, null: false t.index ["account_id"], name: "index_account_statuses_cleanup_policies_on_account_id" end