mirror of
https://github.com/mastodon/mastodon.git
synced 2025-02-06 15:05:07 +00:00
![Claire](/assets/img/avatar_default.png)
Some checks failed
Check i18n / check-i18n (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
CodeQL / Analyze (ruby) (push) Waiting to run
Check formatting / lint (push) Waiting to run
CSS Linting / lint (push) Waiting to run
Ruby Testing / build (production) (push) Waiting to run
Ruby Testing / build (test) (push) Waiting to run
Ruby Testing / test (.ruby-version) (push) Blocked by required conditions
Ruby Testing / test (3.1) (push) Blocked by required conditions
Ruby Testing / test (3.2) (push) Blocked by required conditions
Ruby Testing / Libvips tests (.ruby-version) (push) Blocked by required conditions
Ruby Testing / Libvips tests (3.1) (push) Blocked by required conditions
Ruby Testing / Libvips tests (3.2) (push) Blocked by required conditions
Ruby Testing / End to End testing (.ruby-version) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.1) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.10.2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.1, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.2, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
JavaScript Linting / lint (push) Has been cancelled
Ruby Linting / lint (push) Has been cancelled
JavaScript Testing / test (push) Has been cancelled
Historical data migration test / test (14-alpine) (push) Has been cancelled
Historical data migration test / test (15-alpine) (push) Has been cancelled
68 lines
2.3 KiB
Ruby
68 lines
2.3 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
# == Schema Information
|
|
#
|
|
# Table name: notification_policies
|
|
#
|
|
# 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
|
|
|
|
attr_reader :pending_requests_count, :pending_notifications_count
|
|
|
|
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
|
|
@pending_notification_requests ||= notification_requests.without_suspended.limit(MAX_MEANINGFUL_COUNT).pick(Arel.sql('count(*), coalesce(sum(notifications_count), 0)::bigint'))
|
|
end
|
|
end
|