diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/account.rb | 4 | ||||
-rw-r--r-- | app/models/concerns/account_interactions.rb | 23 | ||||
-rw-r--r-- | app/models/content_retention_policy.rb | 25 | ||||
-rw-r--r-- | app/models/export.rb | 4 | ||||
-rw-r--r-- | app/models/follow.rb | 4 | ||||
-rw-r--r-- | app/models/follow_request.rb | 4 | ||||
-rw-r--r-- | app/models/form/admin_settings.rb | 4 | ||||
-rw-r--r-- | app/models/user.rb | 2 |
8 files changed, 55 insertions, 15 deletions
diff --git a/app/models/account.rb b/app/models/account.rb index f75750838..33870beda 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -262,6 +262,10 @@ class Account < ApplicationRecord update!(memorial: true) end + def trendable + boolean_with_default('trendable', Setting.trendable_by_default) + end + def sign? true end diff --git a/app/models/concerns/account_interactions.rb b/app/models/concerns/account_interactions.rb index 9b358d338..15c49f2fe 100644 --- a/app/models/concerns/account_interactions.rb +++ b/app/models/concerns/account_interactions.rb @@ -9,6 +9,7 @@ module AccountInteractions mapping[follow.target_account_id] = { reblogs: follow.show_reblogs?, notify: follow.notify?, + languages: follow.languages, } end end @@ -38,6 +39,7 @@ module AccountInteractions mapping[follow_request.target_account_id] = { reblogs: follow_request.show_reblogs?, notify: follow_request.notify?, + languages: follow_request.languages, } end end @@ -100,12 +102,13 @@ module AccountInteractions has_many :announcement_mutes, dependent: :destroy end - def follow!(other_account, reblogs: nil, notify: nil, uri: nil, rate_limit: false, bypass_limit: false) - rel = active_relationships.create_with(show_reblogs: reblogs.nil? ? true : reblogs, notify: notify.nil? ? false : notify, uri: uri, rate_limit: rate_limit, bypass_follow_limit: bypass_limit) + def follow!(other_account, reblogs: nil, notify: nil, languages: nil, uri: nil, rate_limit: false, bypass_limit: false) + rel = active_relationships.create_with(show_reblogs: reblogs.nil? ? true : reblogs, notify: notify.nil? ? false : notify, languages: languages, uri: uri, rate_limit: rate_limit, bypass_follow_limit: bypass_limit) .find_or_create_by!(target_account: other_account) - rel.show_reblogs = reblogs unless reblogs.nil? - rel.notify = notify unless notify.nil? + rel.show_reblogs = reblogs unless reblogs.nil? + rel.notify = notify unless notify.nil? + rel.languages = languages unless languages.nil? rel.save! if rel.changed? @@ -114,12 +117,13 @@ module AccountInteractions rel end - def request_follow!(other_account, reblogs: nil, notify: nil, uri: nil, rate_limit: false, bypass_limit: false) - rel = follow_requests.create_with(show_reblogs: reblogs.nil? ? true : reblogs, notify: notify.nil? ? false : notify, uri: uri, rate_limit: rate_limit, bypass_follow_limit: bypass_limit) + def request_follow!(other_account, reblogs: nil, notify: nil, languages: nil, uri: nil, rate_limit: false, bypass_limit: false) + rel = follow_requests.create_with(show_reblogs: reblogs.nil? ? true : reblogs, notify: notify.nil? ? false : notify, uri: uri, languages: languages, rate_limit: rate_limit, bypass_follow_limit: bypass_limit) .find_or_create_by!(target_account: other_account) - rel.show_reblogs = reblogs unless reblogs.nil? - rel.notify = notify unless notify.nil? + rel.show_reblogs = reblogs unless reblogs.nil? + rel.notify = notify unless notify.nil? + rel.languages = languages unless languages.nil? rel.save! if rel.changed? @@ -288,8 +292,7 @@ module AccountInteractions private - def remove_potential_friendship(other_account, mutual = false) + def remove_potential_friendship(other_account) PotentialFriendshipTracker.remove(id, other_account.id) - PotentialFriendshipTracker.remove(other_account.id, id) if mutual end end diff --git a/app/models/content_retention_policy.rb b/app/models/content_retention_policy.rb new file mode 100644 index 000000000..b5e922c8c --- /dev/null +++ b/app/models/content_retention_policy.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +class ContentRetentionPolicy + def self.current + new + end + + def media_cache_retention_period + retention_period Setting.media_cache_retention_period + end + + def content_cache_retention_period + retention_period Setting.content_cache_retention_period + end + + def backups_retention_period + retention_period Setting.backups_retention_period + end + + private + + def retention_period(value) + value.days if value.is_a?(Integer) && value.positive? + end +end diff --git a/app/models/export.rb b/app/models/export.rb index 5216eed5e..2457dcc15 100644 --- a/app/models/export.rb +++ b/app/models/export.rb @@ -30,9 +30,9 @@ class Export end def to_following_accounts_csv - CSV.generate(headers: ['Account address', 'Show boosts'], write_headers: true) do |csv| + CSV.generate(headers: ['Account address', 'Show boosts', 'Notify on new posts', 'Languages'], write_headers: true) do |csv| account.active_relationships.includes(:target_account).reorder(id: :desc).each do |follow| - csv << [acct(follow.target_account), follow.show_reblogs] + csv << [acct(follow.target_account), follow.show_reblogs, follow.notify, follow.languages&.join(', ')] end end end diff --git a/app/models/follow.rb b/app/models/follow.rb index a5e3fe809..e5cecbbc1 100644 --- a/app/models/follow.rb +++ b/app/models/follow.rb @@ -11,6 +11,7 @@ # show_reblogs :boolean default(TRUE), not null # uri :string # notify :boolean default(FALSE), not null +# languages :string is an Array # class Follow < ApplicationRecord @@ -27,6 +28,7 @@ class Follow < ApplicationRecord has_one :notification, as: :activity, dependent: :destroy validates :account_id, uniqueness: { scope: :target_account_id } + validates :languages, language: true scope :recent, -> { reorder(id: :desc) } @@ -35,7 +37,7 @@ class Follow < ApplicationRecord end def revoke_request! - FollowRequest.create!(account: account, target_account: target_account, show_reblogs: show_reblogs, notify: notify, uri: uri) + FollowRequest.create!(account: account, target_account: target_account, show_reblogs: show_reblogs, notify: notify, languages: languages, uri: uri) destroy! end diff --git a/app/models/follow_request.rb b/app/models/follow_request.rb index 0b6f7629a..9034250c0 100644 --- a/app/models/follow_request.rb +++ b/app/models/follow_request.rb @@ -11,6 +11,7 @@ # show_reblogs :boolean default(TRUE), not null # uri :string # notify :boolean default(FALSE), not null +# languages :string is an Array # class FollowRequest < ApplicationRecord @@ -27,9 +28,10 @@ class FollowRequest < ApplicationRecord has_one :notification, as: :activity, dependent: :destroy validates :account_id, uniqueness: { scope: :target_account_id } + validates :languages, language: true def authorize! - account.follow!(target_account, reblogs: show_reblogs, notify: notify, uri: uri, bypass_limit: true) + account.follow!(target_account, reblogs: show_reblogs, notify: notify, languages: languages, uri: uri, bypass_limit: true) MergeWorker.perform_async(target_account.id, account.id) if account.local? destroy! end diff --git a/app/models/form/admin_settings.rb b/app/models/form/admin_settings.rb index 4c100ba6b..68c98d43f 100644 --- a/app/models/form/admin_settings.rb +++ b/app/models/form/admin_settings.rb @@ -40,6 +40,9 @@ class Form::AdminSettings outgoing_spoilers require_invite_text captcha_enabled + media_cache_retention_period + content_cache_retention_period + backups_retention_period ).freeze BOOLEAN_KEYS = %i( @@ -81,6 +84,7 @@ class Form::AdminSettings validates :bootstrap_timeline_accounts, existing_username: { multiple: true } validates :show_domain_blocks, inclusion: { in: %w(disabled users all) } validates :show_domain_blocks_rationale, inclusion: { in: %w(disabled users all) } + validates :media_cache_retention_period, :content_cache_retention_period, :backups_retention_period, numericality: { only_integer: true }, allow_blank: true def initialize(_attributes = {}) super diff --git a/app/models/user.rb b/app/models/user.rb index 962ca68ff..de59fe4b3 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -282,7 +282,7 @@ class User < ApplicationRecord end def preferred_posting_language - valid_locale_cascade(settings.default_language, locale) + valid_locale_cascade(settings.default_language, locale, I18n.locale) end def setting_default_privacy |