Merge branch 'main' into glitch-soc/merge-upstream
Conflicts: - `.github/dependabot.yml`: Upstream made changes while we have dropped this file. Keep the file deleted. - `.prettierignore`: Upstream made changes at the end of the file, where we had our extra lines. Just moved our extra lines back at the end. - `app/serializers/initial_state_serializer.rb`: Upstream code style changes. Applied them. - `app/services/backup_service.rb`: Upstream code style changes. Applied them.
This commit is contained in:
@@ -313,9 +313,7 @@ class Account < ApplicationRecord
|
||||
|
||||
previous = old_fields.find { |item| item['value'] == attr[:value] }
|
||||
|
||||
if previous && previous['verified_at'].present?
|
||||
attr[:verified_at] = previous['verified_at']
|
||||
end
|
||||
attr[:verified_at] = previous['verified_at'] if previous && previous['verified_at'].present?
|
||||
|
||||
fields << attr
|
||||
end
|
||||
@@ -459,13 +457,12 @@ class Account < ApplicationRecord
|
||||
return [] if text.blank?
|
||||
|
||||
text.scan(MENTION_RE).map { |match| match.first.split('@', 2) }.uniq.filter_map do |(username, domain)|
|
||||
domain = begin
|
||||
if TagManager.instance.local_domain?(domain)
|
||||
nil
|
||||
else
|
||||
TagManager.instance.normalize_domain(domain)
|
||||
end
|
||||
end
|
||||
domain = if TagManager.instance.local_domain?(domain)
|
||||
nil
|
||||
else
|
||||
TagManager.instance.normalize_domain(domain)
|
||||
end
|
||||
|
||||
EntityCache.instance.mention(username, domain)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -25,13 +25,11 @@ class Account::Field < ActiveModelSerializers::Model
|
||||
end
|
||||
|
||||
def value_for_verification
|
||||
@value_for_verification ||= begin
|
||||
if account.local?
|
||||
value
|
||||
else
|
||||
extract_url_from_html
|
||||
end
|
||||
end
|
||||
@value_for_verification ||= if account.local?
|
||||
value
|
||||
else
|
||||
extract_url_from_html
|
||||
end
|
||||
end
|
||||
|
||||
def verifiable?
|
||||
|
||||
@@ -122,9 +122,7 @@ class AccountStatusesCleanupPolicy < ApplicationRecord
|
||||
# may need to be deleted, so we'll have to start again.
|
||||
redis.del("account_cleanup:#{account.id}")
|
||||
end
|
||||
if EXCEPTION_THRESHOLDS.map { |name| attribute_change_to_be_saved(name) }.compact.any? { |old, new| old.present? && (new.nil? || new > old) }
|
||||
redis.del("account_cleanup:#{account.id}")
|
||||
end
|
||||
redis.del("account_cleanup:#{account.id}") if EXCEPTION_THRESHOLDS.map { |name| attribute_change_to_be_saved(name) }.compact.any? { |old, new| old.present? && (new.nil? || new > old) }
|
||||
end
|
||||
|
||||
def validate_local_account
|
||||
@@ -141,9 +139,7 @@ class AccountStatusesCleanupPolicy < ApplicationRecord
|
||||
# has switched to snowflake IDs significantly over 2 years ago anyway.
|
||||
snowflake_id = Mastodon::Snowflake.id_at(min_status_age.seconds.ago, with_random: false)
|
||||
|
||||
if max_id.nil? || snowflake_id < max_id
|
||||
max_id = snowflake_id
|
||||
end
|
||||
max_id = snowflake_id if max_id.nil? || snowflake_id < max_id
|
||||
|
||||
Status.where(Status.arel_table[:id].lteq(max_id))
|
||||
end
|
||||
|
||||
@@ -166,13 +166,11 @@ class Admin::AccountAction
|
||||
end
|
||||
|
||||
def reports
|
||||
@reports ||= begin
|
||||
if type == 'none'
|
||||
with_report? ? [report] : []
|
||||
else
|
||||
Report.where(target_account: target_account).unresolved
|
||||
end
|
||||
end
|
||||
@reports ||= if type == 'none'
|
||||
with_report? ? [report] : []
|
||||
else
|
||||
Report.where(target_account: target_account).unresolved
|
||||
end
|
||||
end
|
||||
|
||||
def warning_preset
|
||||
|
||||
@@ -54,13 +54,11 @@ class Announcement < ApplicationRecord
|
||||
end
|
||||
|
||||
def statuses
|
||||
@statuses ||= begin
|
||||
if status_ids.nil?
|
||||
[]
|
||||
else
|
||||
Status.where(id: status_ids, visibility: [:public, :unlisted])
|
||||
end
|
||||
end
|
||||
@statuses ||= if status_ids.nil?
|
||||
[]
|
||||
else
|
||||
Status.where(id: status_ids, visibility: [:public, :unlisted])
|
||||
end
|
||||
end
|
||||
|
||||
def tags
|
||||
|
||||
@@ -18,5 +18,5 @@ class Backup < ApplicationRecord
|
||||
belongs_to :user, inverse_of: :backups
|
||||
|
||||
has_attached_file :dump
|
||||
do_not_validate_attachment_file_type :dump
|
||||
validates_attachment_content_type :dump, content_type: /\Aapplication/
|
||||
end
|
||||
|
||||
@@ -151,9 +151,7 @@ module AccountInteractions
|
||||
remove_potential_friendship(other_account)
|
||||
|
||||
# When toggling a mute between hiding and allowing notifications, the mute will already exist, so the find_or_create_by! call will return the existing Mute without updating the hide_notifications attribute. Therefore, we check that hide_notifications? is what we want and set it if it isn't.
|
||||
if mute.hide_notifications? != notifications
|
||||
mute.update!(hide_notifications: notifications)
|
||||
end
|
||||
mute.update!(hide_notifications: notifications) if mute.hide_notifications? != notifications
|
||||
|
||||
mute
|
||||
end
|
||||
|
||||
@@ -21,11 +21,9 @@ module AccountMerging
|
||||
|
||||
owned_classes.each do |klass|
|
||||
klass.where(account_id: other_account.id).find_each do |record|
|
||||
begin
|
||||
record.update_attribute(:account_id, id)
|
||||
rescue ActiveRecord::RecordNotUnique
|
||||
next
|
||||
end
|
||||
record.update_attribute(:account_id, id)
|
||||
rescue ActiveRecord::RecordNotUnique
|
||||
next
|
||||
end
|
||||
end
|
||||
|
||||
@@ -36,11 +34,9 @@ module AccountMerging
|
||||
|
||||
target_classes.each do |klass|
|
||||
klass.where(target_account_id: other_account.id).find_each do |record|
|
||||
begin
|
||||
record.update_attribute(:target_account_id, id)
|
||||
rescue ActiveRecord::RecordNotUnique
|
||||
next
|
||||
end
|
||||
record.update_attribute(:target_account_id, id)
|
||||
rescue ActiveRecord::RecordNotUnique
|
||||
next
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ module Expireable
|
||||
end
|
||||
|
||||
def expires_in=(interval)
|
||||
self.expires_at = interval.present? ? interval.to_i.seconds.from_now : nil
|
||||
self.expires_at = interval.present? ? interval.to_i.seconds.from_now : nil
|
||||
@expires_in = interval
|
||||
end
|
||||
|
||||
|
||||
@@ -56,9 +56,7 @@ module Omniauthable
|
||||
user = User.new(user_params_from_auth(email, auth))
|
||||
|
||||
begin
|
||||
if /\A#{URI::DEFAULT_PARSER.make_regexp(%w(http https))}\z/.match?(auth.info.image)
|
||||
user.account.avatar_remote_url = auth.info.image
|
||||
end
|
||||
user.account.avatar_remote_url = auth.info.image if /\A#{URI::DEFAULT_PARSER.make_regexp(%w(http https))}\z/.match?(auth.info.image)
|
||||
rescue Mastodon::UnexpectedResponseError
|
||||
user.account.avatar_remote_url = nil
|
||||
end
|
||||
|
||||
@@ -4,7 +4,7 @@ module Paginable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
scope :paginate_by_max_id, ->(limit, max_id = nil, since_id = nil) {
|
||||
scope :paginate_by_max_id, lambda { |limit, max_id = nil, since_id = nil|
|
||||
query = order(arel_table[:id].desc).limit(limit)
|
||||
query = query.where(arel_table[:id].lt(max_id)) if max_id.present?
|
||||
query = query.where(arel_table[:id].gt(since_id)) if since_id.present?
|
||||
@@ -14,7 +14,7 @@ module Paginable
|
||||
# Differs from :paginate_by_max_id in that it gives the results immediately following min_id,
|
||||
# whereas since_id gives the items with largest id, but with since_id as a cutoff.
|
||||
# Results will be in ascending order by id.
|
||||
scope :paginate_by_min_id, ->(limit, min_id = nil, max_id = nil) {
|
||||
scope :paginate_by_min_id, lambda { |limit, min_id = nil, max_id = nil|
|
||||
query = reorder(arel_table[:id]).limit(limit)
|
||||
query = query.where(arel_table[:id].gt(min_id)) if min_id.present?
|
||||
query = query.where(arel_table[:id].lt(max_id)) if max_id.present?
|
||||
|
||||
@@ -42,13 +42,11 @@ module PamAuthenticable
|
||||
def self.pam_get_user(attributes = {})
|
||||
return nil unless attributes[:email]
|
||||
|
||||
resource = begin
|
||||
if Devise.check_at_sign && !attributes[:email].index('@')
|
||||
joins(:account).find_by(accounts: { username: attributes[:email] })
|
||||
else
|
||||
find_by(email: attributes[:email])
|
||||
end
|
||||
end
|
||||
resource = if Devise.check_at_sign && !attributes[:email].index('@')
|
||||
joins(:account).find_by(accounts: { username: attributes[:email] })
|
||||
else
|
||||
find_by(email: attributes[:email])
|
||||
end
|
||||
|
||||
if resource.nil?
|
||||
resource = new(email: attributes[:email], agreement: true)
|
||||
|
||||
@@ -69,13 +69,11 @@ class EmailDomainBlock < ApplicationRecord
|
||||
|
||||
def extract_uris(domain_or_domains)
|
||||
Array(domain_or_domains).map do |str|
|
||||
domain = begin
|
||||
if str.include?('@')
|
||||
str.split('@', 2).last
|
||||
else
|
||||
str
|
||||
end
|
||||
end
|
||||
domain = if str.include?('@')
|
||||
str.split('@', 2).last
|
||||
else
|
||||
str
|
||||
end
|
||||
|
||||
Addressable::URI.new.tap { |u| u.host = domain.strip } if domain.present?
|
||||
rescue Addressable::URI::InvalidURIError, IDN::Idna::IdnaError
|
||||
|
||||
@@ -93,13 +93,11 @@ class Form::AdminSettings
|
||||
define_method(key) do
|
||||
return instance_variable_get("@#{key}") if instance_variable_defined?("@#{key}")
|
||||
|
||||
stored_value = begin
|
||||
if UPLOAD_KEYS.include?(key)
|
||||
SiteUpload.where(var: key).first_or_initialize(var: key)
|
||||
else
|
||||
Setting.public_send(key)
|
||||
end
|
||||
end
|
||||
stored_value = if UPLOAD_KEYS.include?(key)
|
||||
SiteUpload.where(var: key).first_or_initialize(var: key)
|
||||
else
|
||||
Setting.public_send(key)
|
||||
end
|
||||
|
||||
instance_variable_set("@#{key}", stored_value)
|
||||
end
|
||||
|
||||
@@ -36,13 +36,11 @@ class Form::CustomEmojiBatch
|
||||
def update!
|
||||
custom_emojis.each { |custom_emoji| authorize(custom_emoji, :update?) }
|
||||
|
||||
category = begin
|
||||
if category_id.present?
|
||||
CustomEmojiCategory.find(category_id)
|
||||
elsif category_name.present?
|
||||
CustomEmojiCategory.find_or_create_by!(name: category_name)
|
||||
end
|
||||
end
|
||||
category = if category_id.present?
|
||||
CustomEmojiCategory.find(category_id)
|
||||
elsif category_name.present?
|
||||
CustomEmojiCategory.find_or_create_by!(name: category_name)
|
||||
end
|
||||
|
||||
custom_emojis.each do |custom_emoji|
|
||||
custom_emoji.update(category_id: category&.id)
|
||||
|
||||
@@ -87,13 +87,11 @@ class Notification < ApplicationRecord
|
||||
|
||||
class << self
|
||||
def browserable(types: [], exclude_types: [], from_account_id: nil)
|
||||
requested_types = begin
|
||||
if types.empty?
|
||||
TYPES
|
||||
else
|
||||
types.map(&:to_sym) & TYPES
|
||||
end
|
||||
end
|
||||
requested_types = if types.empty?
|
||||
TYPES
|
||||
else
|
||||
types.map(&:to_sym) & TYPES
|
||||
end
|
||||
|
||||
requested_types -= exclude_types.map(&:to_sym)
|
||||
|
||||
|
||||
@@ -36,13 +36,11 @@ class RemoteFollow
|
||||
|
||||
username, domain = value.strip.gsub(/\A@/, '').split('@')
|
||||
|
||||
domain = begin
|
||||
if TagManager.instance.local_domain?(domain)
|
||||
nil
|
||||
else
|
||||
TagManager.instance.normalize_domain(domain)
|
||||
end
|
||||
end
|
||||
domain = if TagManager.instance.local_domain?(domain)
|
||||
nil
|
||||
else
|
||||
TagManager.instance.normalize_domain(domain)
|
||||
end
|
||||
|
||||
[username, domain].compact.join('@')
|
||||
rescue Addressable::URI::InvalidURIError
|
||||
|
||||
@@ -104,12 +104,12 @@ class Status < ApplicationRecord
|
||||
scope :including_silenced_accounts, -> { left_outer_joins(:account).where.not(accounts: { silenced_at: nil }) }
|
||||
scope :not_excluded_by_account, ->(account) { where.not(account_id: account.excluded_from_timeline_account_ids) }
|
||||
scope :not_domain_blocked_by_account, ->(account) { account.excluded_from_timeline_domains.blank? ? left_outer_joins(:account) : left_outer_joins(:account).where('accounts.domain IS NULL OR accounts.domain NOT IN (?)', account.excluded_from_timeline_domains) }
|
||||
scope :tagged_with_all, ->(tag_ids) {
|
||||
scope :tagged_with_all, lambda { |tag_ids|
|
||||
Array(tag_ids).map(&:to_i).reduce(self) do |result, id|
|
||||
result.joins("INNER JOIN statuses_tags t#{id} ON t#{id}.status_id = statuses.id AND t#{id}.tag_id = #{id}")
|
||||
end
|
||||
}
|
||||
scope :tagged_with_none, ->(tag_ids) {
|
||||
scope :tagged_with_none, lambda { |tag_ids|
|
||||
where('NOT EXISTS (SELECT * FROM statuses_tags forbidden WHERE forbidden.status_id = statuses.id AND forbidden.tag_id IN (?))', tag_ids)
|
||||
}
|
||||
|
||||
@@ -415,13 +415,12 @@ class Status < ApplicationRecord
|
||||
return [] if text.blank?
|
||||
|
||||
text.scan(FetchLinkCardService::URL_PATTERN).map(&:second).uniq.filter_map do |url|
|
||||
status = begin
|
||||
if TagManager.instance.local_url?(url)
|
||||
ActivityPub::TagManager.instance.uri_to_resource(url, Status)
|
||||
else
|
||||
EntityCache.instance.status(url)
|
||||
end
|
||||
end
|
||||
status = if TagManager.instance.local_url?(url)
|
||||
ActivityPub::TagManager.instance.uri_to_resource(url, Status)
|
||||
else
|
||||
EntityCache.instance.status(url)
|
||||
end
|
||||
|
||||
status&.distributable? ? status : nil
|
||||
end
|
||||
end
|
||||
|
||||
@@ -52,14 +52,12 @@ class StatusEdit < ApplicationRecord
|
||||
def ordered_media_attachments
|
||||
return @ordered_media_attachments if defined?(@ordered_media_attachments)
|
||||
|
||||
@ordered_media_attachments = begin
|
||||
if ordered_media_attachment_ids.nil?
|
||||
[]
|
||||
else
|
||||
map = status.media_attachments.index_by(&:id)
|
||||
ordered_media_attachment_ids.map.with_index { |media_attachment_id, index| PreservedMediaAttachment.new(media_attachment: map[media_attachment_id], description: media_descriptions[index]) }
|
||||
end
|
||||
end
|
||||
@ordered_media_attachments = if ordered_media_attachment_ids.nil?
|
||||
[]
|
||||
else
|
||||
map = status.media_attachments.index_by(&:id)
|
||||
ordered_media_attachment_ids.map.with_index { |media_attachment_id, index| PreservedMediaAttachment.new(media_attachment: map[media_attachment_id], description: media_descriptions[index]) }
|
||||
end
|
||||
end
|
||||
|
||||
def proper
|
||||
|
||||
@@ -14,7 +14,7 @@ class SystemKey < ApplicationRecord
|
||||
|
||||
before_validation :set_key
|
||||
|
||||
scope :expired, ->(now = Time.now.utc) { where(arel_table[:created_at].lt(now - ROTATION_PERIOD * 3)) }
|
||||
scope :expired, ->(now = Time.now.utc) { where(arel_table[:created_at].lt(now - (ROTATION_PERIOD * 3))) }
|
||||
|
||||
class << self
|
||||
def current_key
|
||||
|
||||
@@ -49,7 +49,7 @@ class Tag < ApplicationRecord
|
||||
scope :listable, -> { where(listable: [true, nil]) }
|
||||
scope :trendable, -> { Setting.trendable_by_default ? where(trendable: [true, nil]) : where(trendable: true) }
|
||||
scope :not_trendable, -> { where(trendable: false) }
|
||||
scope :recently_used, ->(account) {
|
||||
scope :recently_used, lambda { |account|
|
||||
joins(:statuses)
|
||||
.where(statuses: { id: account.statuses.select(:id).limit(1000) })
|
||||
.group(:id).order(Arel.sql('count(*) desc'))
|
||||
|
||||
@@ -113,13 +113,11 @@ class Trends::Links < Trends::Base
|
||||
max_score = preview_card.max_score
|
||||
max_score = 0 if max_time.nil? || max_time < (at_time - options[:max_score_cooldown])
|
||||
|
||||
score = begin
|
||||
if expected > observed || observed < options[:threshold]
|
||||
0
|
||||
else
|
||||
((observed - expected)**2) / expected
|
||||
end
|
||||
end
|
||||
score = if expected > observed || observed < options[:threshold]
|
||||
0
|
||||
else
|
||||
((observed - expected)**2) / expected
|
||||
end
|
||||
|
||||
if score > max_score
|
||||
max_score = score
|
||||
@@ -129,13 +127,11 @@ class Trends::Links < Trends::Base
|
||||
preview_card.update_columns(max_score: max_score, max_score_at: max_time)
|
||||
end
|
||||
|
||||
decaying_score = begin
|
||||
if max_score.zero? || !valid_locale?(preview_card.language)
|
||||
0
|
||||
else
|
||||
max_score * (0.5**((at_time.to_f - max_time.to_f) / options[:max_score_halflife].to_f))
|
||||
end
|
||||
end
|
||||
decaying_score = if max_score.zero? || !valid_locale?(preview_card.language)
|
||||
0
|
||||
else
|
||||
max_score * (0.5**((at_time.to_f - max_time.to_f) / options[:max_score_halflife].to_f))
|
||||
end
|
||||
|
||||
[decaying_score, preview_card]
|
||||
end
|
||||
|
||||
@@ -99,21 +99,17 @@ class Trends::Statuses < Trends::Base
|
||||
expected = 1.0
|
||||
observed = (status.reblogs_count + status.favourites_count).to_f
|
||||
|
||||
score = begin
|
||||
if expected > observed || observed < options[:threshold]
|
||||
0
|
||||
else
|
||||
((observed - expected)**2) / expected
|
||||
end
|
||||
end
|
||||
score = if expected > observed || observed < options[:threshold]
|
||||
0
|
||||
else
|
||||
((observed - expected)**2) / expected
|
||||
end
|
||||
|
||||
decaying_score = begin
|
||||
if score.zero? || !eligible?(status)
|
||||
0
|
||||
else
|
||||
score * (0.5**((at_time.to_f - status.created_at.to_f) / options[:score_halflife].to_f))
|
||||
end
|
||||
end
|
||||
decaying_score = if score.zero? || !eligible?(status)
|
||||
0
|
||||
else
|
||||
score * (0.5**((at_time.to_f - status.created_at.to_f) / options[:score_halflife].to_f))
|
||||
end
|
||||
|
||||
[decaying_score, status]
|
||||
end
|
||||
|
||||
@@ -13,13 +13,11 @@ class Trends::TagFilter
|
||||
end
|
||||
|
||||
def results
|
||||
scope = begin
|
||||
if params[:status] == 'pending_review'
|
||||
Tag.unscoped
|
||||
else
|
||||
trending_scope
|
||||
end
|
||||
end
|
||||
scope = if params[:status] == 'pending_review'
|
||||
Tag.unscoped
|
||||
else
|
||||
trending_scope
|
||||
end
|
||||
|
||||
params.each do |key, value|
|
||||
next if key.to_s == 'page'
|
||||
|
||||
@@ -63,13 +63,11 @@ class Trends::Tags < Trends::Base
|
||||
max_score = tag.max_score
|
||||
max_score = 0 if max_time.nil? || max_time < (at_time - options[:max_score_cooldown])
|
||||
|
||||
score = begin
|
||||
if expected > observed || observed < options[:threshold]
|
||||
0
|
||||
else
|
||||
((observed - expected)**2) / expected
|
||||
end
|
||||
end
|
||||
score = if expected > observed || observed < options[:threshold]
|
||||
0
|
||||
else
|
||||
((observed - expected)**2) / expected
|
||||
end
|
||||
|
||||
if score > max_score
|
||||
max_score = score
|
||||
|
||||
@@ -53,25 +53,21 @@ class Web::PushSubscription < ApplicationRecord
|
||||
def associated_user
|
||||
return @associated_user if defined?(@associated_user)
|
||||
|
||||
@associated_user = begin
|
||||
if user_id.nil?
|
||||
session_activation.user
|
||||
else
|
||||
user
|
||||
end
|
||||
end
|
||||
@associated_user = if user_id.nil?
|
||||
session_activation.user
|
||||
else
|
||||
user
|
||||
end
|
||||
end
|
||||
|
||||
def associated_access_token
|
||||
return @associated_access_token if defined?(@associated_access_token)
|
||||
|
||||
@associated_access_token = begin
|
||||
if access_token_id.nil?
|
||||
find_or_create_access_token.token
|
||||
else
|
||||
access_token.token
|
||||
end
|
||||
end
|
||||
@associated_access_token = if access_token_id.nil?
|
||||
find_or_create_access_token.token
|
||||
else
|
||||
access_token.token
|
||||
end
|
||||
end
|
||||
|
||||
class << self
|
||||
|
||||
@@ -18,5 +18,5 @@ class WebauthnCredential < ApplicationRecord
|
||||
validates :external_id, uniqueness: true
|
||||
validates :nickname, uniqueness: { scope: :user_id }
|
||||
validates :sign_count,
|
||||
numericality: { only_integer: true, greater_than_or_equal_to: 0, less_than_or_equal_to: 2**63 - 1 }
|
||||
numericality: { only_integer: true, greater_than_or_equal_to: 0, less_than_or_equal_to: (2**63) - 1 }
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user