Archived
2
0
Fork 0

Gearheads: merge to Mastodon 4.2.0-beta2

This commit is contained in:
Ducky 2023-08-28 00:18:16 +01:00
commit cbd48a29b2
252 changed files with 3630 additions and 2405 deletions

View file

@ -50,6 +50,7 @@
# trendable :boolean
# reviewed_at :datetime
# requested_review_at :datetime
# indexable :boolean default(FALSE), not null
#
class Account < ApplicationRecord
@ -62,6 +63,8 @@ class Account < ApplicationRecord
trust_level
)
BACKGROUND_REFRESH_INTERVAL = 1.week.freeze
USERNAME_RE = /[a-z0-9_]+([a-z0-9_.-]+[a-z0-9_]+)?/i
MENTION_RE = %r{(?<=^|[^/[:word:]])@((#{USERNAME_RE})(?:@[[:word:].-]+[[:word:]]+)?)}i
URL_PREFIX_RE = %r{\Ahttp(s?)://[^/]+}
@ -208,6 +211,12 @@ class Account < ApplicationRecord
last_webfingered_at.nil? || last_webfingered_at <= 1.day.ago
end
def schedule_refresh_if_stale!
return unless last_webfingered_at.present? && last_webfingered_at <= BACKGROUND_REFRESH_INTERVAL.ago
AccountRefreshWorker.perform_in(rand(6.hours.to_i), id)
end
def refresh!
ResolveAccountService.new.call(acct) unless local?
end
@ -441,8 +450,21 @@ class Account < ApplicationRecord
EntityCache.instance.mention(username, domain)
end
end
def inverse_alias(key, original_key)
define_method("#{key}=") do |value|
public_send("#{original_key}=", !ActiveModel::Type::Boolean.new.cast(value))
end
define_method(key) do
!public_send(original_key)
end
end
end
inverse_alias :show_collections, :hide_collections
inverse_alias :unlocked, :locked
def emojis
@emojis ||= CustomEmoji.from_text(emojifiable_text, domain)
end

View file

@ -2,7 +2,7 @@
# == Schema Information
#
# Table name: follow_recommendations
# Table name: global_follow_recommendations
#
# account_id :bigint(8) primary key
# rank :decimal(, )
@ -11,6 +11,7 @@
class FollowRecommendation < ApplicationRecord
self.primary_key = :account_id
self.table_name = :global_follow_recommendations
belongs_to :account_summary, foreign_key: :account_id, inverse_of: false
belongs_to :account

View file

@ -48,7 +48,10 @@ class Report < ApplicationRecord
validate :validate_rule_ids
# entries here needs to be kept in sync with app/javascript/mastodon/features/notifications/components/report.jsx
# entries here need to be kept in sync with the front-end:
# - app/javascript/mastodon/features/notifications/components/report.jsx
# - app/javascript/mastodon/features/report/category.jsx
# - app/javascript/mastodon/components/admin/ReportReasonSelector.jsx
enum category: {
other: 0,
spam: 1_000,

View file

@ -367,13 +367,25 @@ class Status < ApplicationRecord
account_ids.uniq!
status_ids = cached_items.map { |item| item.reblog? ? item.reblog_of_id : item.id }.uniq
return if account_ids.empty?
accounts = Account.where(id: account_ids).includes(:account_stat, :user).index_by(&:id)
status_stats = StatusStat.where(status_id: status_ids).index_by(&:status_id)
cached_items.each do |item|
item.account = accounts[item.account_id]
item.reblog.account = accounts[item.reblog.account_id] if item.reblog?
if item.reblog?
status_stat = status_stats[item.reblog.id]
item.reblog.status_stat = status_stat if status_stat.present?
else
status_stat = status_stats[item.id]
item.status_stat = status_stat if status_stat.present?
end
end
end

View file

@ -16,6 +16,8 @@ class UserSettings
setting :default_sensitive, default: false
setting :default_privacy, default: nil, in: %w(public unlisted private)
setting_inverse_alias :indexable, :noindex
namespace :web do
setting :advanced_layout, default: false
setting :trends, default: true
@ -55,31 +57,26 @@ class UserSettings
end
def [](key)
key = key.to_sym
definition = self.class.definition_for(key)
raise KeyError, "Undefined setting: #{key}" unless self.class.definition_for?(key)
raise KeyError, "Undefined setting: #{key}" if definition.nil?
if @original_hash.key?(key)
@original_hash[key]
else
self.class.definition_for(key).default_value
end
definition.value_for(key, @original_hash[definition.key])
end
def []=(key, value)
key = key.to_sym
definition = self.class.definition_for(key)
raise KeyError, "Undefined setting: #{key}" unless self.class.definition_for?(key)
raise KeyError, "Undefined setting: #{key}" if definition.nil?
setting_definition = self.class.definition_for(key)
typecast_value = setting_definition.type_cast(value)
typecast_value = definition.type_cast(value)
raise ArgumentError, "Invalid value for setting #{key}: #{typecast_value}" if setting_definition.in.present? && setting_definition.in.exclude?(typecast_value)
raise ArgumentError, "Invalid value for setting #{definition.key}: #{typecast_value}" if definition.in.present? && definition.in.exclude?(typecast_value)
if typecast_value.nil?
@original_hash.delete(key)
@original_hash.delete(definition.key)
else
@original_hash[key] = typecast_value
@original_hash[definition.key] = definition.value_for(key, typecast_value)
end
end

View file

@ -10,6 +10,10 @@ module UserSettings::DSL
end
end
def setting_inverse_alias(key, original_key)
@definitions[key] = @definitions[original_key].inverse_of(key)
end
def namespace(key, &block)
@definitions ||= {}

View file

@ -10,6 +10,27 @@ class UserSettings::Setting
@in = options[:in]
end
def inverse_of(name)
@inverse_of = name.to_sym
self
end
def value_for(name, original_value)
value = begin
if original_value.nil?
default_value
else
original_value
end
end
if !@inverse_of.nil? && @inverse_of == name.to_sym
!value
else
value
end
end
def default_value
if @default_value.respond_to?(:call)
@default_value.call