0
0
Fork 0

Revamp notification policy options (#31343)

This commit is contained in:
Claire 2024-08-09 15:30:55 +02:00 committed by GitHub
parent e29c401f77
commit cbdd8edf68
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 442 additions and 109 deletions

View file

@ -4,17 +4,25 @@
#
# Table name: notification_policies
#
# id :bigint(8) not null, primary key
# account_id :bigint(8) not null
# filter_not_following :boolean default(FALSE), not null
# filter_not_followers :boolean default(FALSE), not null
# filter_new_accounts :boolean default(FALSE), not null
# filter_private_mentions :boolean default(TRUE), not null
# created_at :datetime not null
# updated_at :datetime not null
# id :bigint(8) not null, primary key
# account_id :bigint(8) not null
# created_at :datetime not null
# updated_at :datetime not null
# for_not_following :integer default("accept"), not null
# for_not_followers :integer default("accept"), not null
# for_new_accounts :integer default("accept"), not null
# for_private_mentions :integer default("filter"), not null
# for_limited_accounts :integer default("filter"), not null
#
class NotificationPolicy < ApplicationRecord
self.ignored_columns += %w(
filter_not_following
filter_not_followers
filter_new_accounts
filter_private_mentions
)
belongs_to :account
has_many :notification_requests, primary_key: :account_id, foreign_key: :account_id, dependent: nil, inverse_of: false
@ -23,11 +31,34 @@ class NotificationPolicy < ApplicationRecord
MAX_MEANINGFUL_COUNT = 100
enum :for_not_following, { accept: 0, filter: 1, drop: 2 }, suffix: :not_following
enum :for_not_followers, { accept: 0, filter: 1, drop: 2 }, suffix: :not_followers
enum :for_new_accounts, { accept: 0, filter: 1, drop: 2 }, suffix: :new_accounts
enum :for_private_mentions, { accept: 0, filter: 1, drop: 2 }, suffix: :private_mentions
enum :for_limited_accounts, { accept: 0, filter: 1, drop: 2 }, suffix: :limited_accounts
def summarize!
@pending_requests_count = pending_notification_requests.first
@pending_notifications_count = pending_notification_requests.last
end
# Compat helpers with V1
def filter_not_following=(value)
self.for_not_following = value ? :filter : :accept
end
def filter_not_followers=(value)
self.for_not_followers = value ? :filter : :accept
end
def filter_new_accounts=(value)
self.for_new_accounts = value ? :filter : :accept
end
def filter_private_mentions=(value)
self.for_private_mentions = value ? :filter : :accept
end
private
def pending_notification_requests