From 3810837b65110cc2d847a6de920c5f91a70b2663 Mon Sep 17 00:00:00 2001 From: KMY Date: Fri, 14 Apr 2023 09:56:28 +0900 Subject: [PATCH 1/3] Add cloudflare warning when register --- app/views/auth/registrations/new.html.haml | 3 +++ config/locales/en.yml | 1 + config/locales/ja.yml | 1 + 3 files changed, 5 insertions(+) diff --git a/app/views/auth/registrations/new.html.haml b/app/views/auth/registrations/new.html.haml index 0d8fd800f9..5149ecbac1 100644 --- a/app/views/auth/registrations/new.html.haml +++ b/app/views/auth/registrations/new.html.haml @@ -37,6 +37,9 @@ .fields-group = f.input :agreement, as: :boolean, wrapper: :with_label, label: t('auth.privacy_policy_agreement_html', rules_path: about_more_path, privacy_policy_path: privacy_policy_path), required: true + %div + = t('auth.cloudflare_with_registering') + .actions = f.button :button, @invite.present? ? t('auth.register') : sign_up_message, type: :submit diff --git a/config/locales/en.yml b/config/locales/en.yml index 97cefc852b..50934a335d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -994,6 +994,7 @@ en: auth: apply_for_account: Request an account change_password: Password + cloudflare_with_registering: With cloudflare on auth confirmations: wrong_email_hint: If that e-mail address is not correct, you can change it in account settings. delete_account: Delete account diff --git a/config/locales/ja.yml b/config/locales/ja.yml index 561a38e5e6..989a5b0a09 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -970,6 +970,7 @@ ja: auth: apply_for_account: アカウントのリクエスト change_password: パスワード + cloudflare_with_registering: 登録時にCloudflareの画面が表示されます。登録できないときは tt@kmycode.net までご連絡ください confirmations: wrong_email_hint: メールアドレスが正しくない場合は、アカウント設定で変更できます。 delete_account: アカウントの削除 From 1efc51313d31c2f5a1dc33ab9e9d1f419af12adc Mon Sep 17 00:00:00 2001 From: KMY Date: Fri, 14 Apr 2023 10:06:51 +0900 Subject: [PATCH 2/3] Add emoji reaction validation per account/emoji --- app/models/emoji_reaction.rb | 7 +++++++ config/locales/en.yml | 1 + config/locales/ja.yml | 1 + 3 files changed, 9 insertions(+) diff --git a/app/models/emoji_reaction.rb b/app/models/emoji_reaction.rb index 80d92c2424..011e593bfd 100644 --- a/app/models/emoji_reaction.rb +++ b/app/models/emoji_reaction.rb @@ -28,6 +28,7 @@ class EmojiReaction < ApplicationRecord has_one :notification, as: :activity, dependent: :destroy + validate :status_same_emoji_reaction validate :status_emoji_reactions_count after_create :refresh_cache @@ -53,6 +54,12 @@ class EmojiReaction < ApplicationRecord query end + def status_same_emoji_reaction + if status && account && status.emoji_reactions.where(account: account).where(name: name).where(custom_emoji_id: custom_emoji_id).any? + raise Mastodon::ValidationError, I18n.t('reactions.errors.duplication') + end + end + def status_emoji_reactions_count if status && account && status.emoji_reactions.where(account: account).count >= EMOJI_REACTION_PER_ACCOUNT_LIMIT raise Mastodon::ValidationError, I18n.t('reactions.errors.limit_reached') diff --git a/config/locales/en.yml b/config/locales/en.yml index 50934a335d..8b41597056 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1423,6 +1423,7 @@ en: title: Privacy Policy reactions: errors: + duplication: Cannot react same things limit_reached: Limit of different reactions reached unrecognized_emoji: is not a recognized emoji relationships: diff --git a/config/locales/ja.yml b/config/locales/ja.yml index 989a5b0a09..d8ec9ed394 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -1390,6 +1390,7 @@ ja: title: プライバシーポリシー reactions: errors: + duplication: 同じリアクションを複数行おうとしました limit_reached: リアクションの種類が上限に達しました unrecognized_emoji: は絵文字として認識されていません relationships: From fed859a7d68ba3916f74a4d70231eacdb147fd04 Mon Sep 17 00:00:00 2001 From: KMY Date: Fri, 14 Apr 2023 10:20:15 +0900 Subject: [PATCH 3/3] Add emoji_reactions_count_per_account --- app/models/status.rb | 6 ++++- app/models/status_stat.rb | 25 +++++++++++-------- app/models/trends/statuses.rb | 2 +- ...tions_count_per_account_to_status_stats.rb | 5 ++++ db/schema.rb | 3 ++- 5 files changed, 28 insertions(+), 13 deletions(-) create mode 100644 db/migrate/20230414010523_add_emoji_reactions_count_per_account_to_status_stats.rb diff --git a/app/models/status.rb b/app/models/status.rb index fb5805a32f..f0529e0410 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -318,6 +318,10 @@ class Status < ApplicationRecord status_stat&.emoji_reactions_count || 0 end + def emoji_reactions_count_per_account + status_stat&.emoji_reactions_count_per_account || 0 + end + def increment_count!(key) update_status_stat!(key => public_send(key) + 1) end @@ -345,7 +349,7 @@ class Status < ApplicationRecord def refresh_emoji_reactions_grouped_by_name! generate_emoji_reactions_grouped_by_name.tap do |emoji_reactions_json| - update_status_stat!(emoji_reactions: emoji_reactions_json, emoji_reactions_count: emoji_reactions.size) + update_status_stat!(emoji_reactions: emoji_reactions_json, emoji_reactions_count: emoji_reactions.size, emoji_reactions_count_per_account: emoji_reactions.map(&:account_id).uniq.size) end end diff --git a/app/models/status_stat.rb b/app/models/status_stat.rb index 0f651959f1..cdee95855b 100644 --- a/app/models/status_stat.rb +++ b/app/models/status_stat.rb @@ -4,16 +4,17 @@ # # Table name: status_stats # -# id :bigint(8) not null, primary key -# status_id :bigint(8) not null -# replies_count :bigint(8) default(0), not null -# reblogs_count :bigint(8) default(0), not null -# favourites_count :bigint(8) default(0), not null -# created_at :datetime not null -# updated_at :datetime not null -# emoji_reactions :string -# emoji_reactions_count :integer default(0), not null -# test :integer default(0), not null +# id :bigint(8) not null, primary key +# status_id :bigint(8) not null +# replies_count :bigint(8) default(0), not null +# reblogs_count :bigint(8) default(0), not null +# favourites_count :bigint(8) default(0), not null +# created_at :datetime not null +# updated_at :datetime not null +# emoji_reactions :string +# emoji_reactions_count :integer default(0), not null +# test :integer default(0), not null +# emoji_reactions_count_per_account :integer default(0), not null # class StatusStat < ApplicationRecord @@ -41,6 +42,10 @@ class StatusStat < ApplicationRecord [attributes['emoji_reactions_count'], 0].max end + def emoji_reactions_count_per_account + [attributes['emoji_reactions_count_per_account'], 0].max + end + private def reset_parent_cache diff --git a/app/models/trends/statuses.rb b/app/models/trends/statuses.rb index 110c3da045..d808b817be 100644 --- a/app/models/trends/statuses.rb +++ b/app/models/trends/statuses.rb @@ -97,7 +97,7 @@ class Trends::Statuses < Trends::Base def calculate_scores(statuses, at_time) items = statuses.map do |status| expected = 1.0 - observed = (status.reblogs_count + status.favourites_count + status.emoji_reactions_count * 0.3).to_f + observed = (status.reblogs_count + status.favourites_count + status.emoji_reactions_count_per_account * 0.8).to_f score = if expected > observed || observed < options[:threshold] 0 diff --git a/db/migrate/20230414010523_add_emoji_reactions_count_per_account_to_status_stats.rb b/db/migrate/20230414010523_add_emoji_reactions_count_per_account_to_status_stats.rb new file mode 100644 index 0000000000..8a3eba8b2c --- /dev/null +++ b/db/migrate/20230414010523_add_emoji_reactions_count_per_account_to_status_stats.rb @@ -0,0 +1,5 @@ +class AddEmojiReactionsCountPerAccountToStatusStats < ActiveRecord::Migration[6.1] + def change + add_column :status_stats, :emoji_reactions_count_per_account, :integer, null: false, default: 0 + end +end diff --git a/db/schema.rb b/db/schema.rb index 991cfaf140..02b1025332 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_12_073021) do +ActiveRecord::Schema.define(version: 2023_04_14_010523) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -936,6 +936,7 @@ ActiveRecord::Schema.define(version: 2023_04_12_073021) do t.string "emoji_reactions" t.integer "emoji_reactions_count", default: 0, null: false t.integer "test", default: 0, null: false + t.integer "emoji_reactions_count_per_account", default: 0, null: false t.index ["status_id"], name: "index_status_stats_on_status_id", unique: true end