1
0
Fork 0
forked from gitea/nas

Merge commit '3a1a6ba39e' into kb_migration_development

This commit is contained in:
KMY 2023-05-01 15:08:16 +09:00
commit 81a7272ce7
288 changed files with 1345 additions and 1343 deletions

View file

@ -113,8 +113,8 @@ class Account < ApplicationRecord
scope :bots, -> { where(actor_type: %w(Application Service)) }
scope :groups, -> { where(actor_type: 'Group') }
scope :alphabetic, -> { order(domain: :asc, username: :asc) }
scope :matches_username, ->(value) { where('lower((username)::text) ~ lower(?)', "#{value}") }
scope :matches_display_name, ->(value) { where(arel_table[:display_name].matches_regexp("#{value}")) }
scope :matches_username, ->(value) { where('lower((username)::text) ~ lower(?)', value.to_s) }
scope :matches_display_name, ->(value) { where(arel_table[:display_name].matches_regexp(value.to_s)) }
scope :matches_domain, ->(value) { where(arel_table[:domain].matches("%#{value}%")) }
scope :without_unapproved, -> { left_outer_joins(:user).remote.or(left_outer_joins(:user).merge(User.approved.confirmed)) }
scope :searchable, -> { without_unapproved.without_suspended.where(moved_to_account_id: nil) }
@ -185,11 +185,19 @@ class Account < ApplicationRecord
alias group group?
def my_actor_type
actor_type == 'Service' ? 'bot' : actor_type == 'Group' ? 'group' : 'person'
if actor_type == 'Service'
'bot'
else
actor_type == 'Group' ? 'group' : 'person'
end
end
def my_actor_type=(val)
self.actor_type = val == 'bot' ? 'Service' : val == 'group' ? 'Group' : 'Person'
self.actor_type = if val == 'bot'
'Service'
else
val == 'group' ? 'Group' : 'Person'
end
end
def acct

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: antennas
@ -64,10 +66,10 @@ class Antenna < ApplicationRecord
def context
context = []
context << 'domain' if !any_domains
context << 'tag' if !any_tags
context << 'keyword' if !any_keywords
context << 'account' if !any_accounts
context << 'domain' unless any_domains
context << 'tag' unless any_tags
context << 'keyword' unless any_keywords
context << 'account' unless any_accounts
context
end
@ -81,7 +83,7 @@ class Antenna < ApplicationRecord
end
def keywords_raw
return '' if !keywords.present?
return '' if keywords.blank?
keywords.join("\n")
end
@ -89,17 +91,17 @@ class Antenna < ApplicationRecord
def keywords_raw=(raw)
keywords = raw.split(/\R/).filter { |r| r.present? && r.length >= 2 }.uniq
self[:keywords] = keywords
self[:any_keywords] = !keywords.any?
self[:any_keywords] = keywords.none?
end
def exclude_keywords_raw
return '' if !exclude_keywords.present?
return '' if exclude_keywords.blank?
exclude_keywords.join("\n")
end
def exclude_keywords_raw=(raw)
exclude_keywords = raw.split(/\R/).filter { |r| r.present? }.uniq
exclude_keywords = raw.split(/\R/).filter(&:present?).uniq
self[:exclude_keywords] = exclude_keywords
end
@ -110,17 +112,18 @@ class Antenna < ApplicationRecord
def tags_raw=(raw)
return if tags_raw == raw
tag_names = raw.split(/\R/).filter { |r| r.present? }.map { |r| r.start_with?('#') ? r[1..-1] : r }.uniq
tag_names = raw.split(/\R/).filter(&:present?).map { |r| r.start_with?('#') ? r[1..] : r }.uniq
antenna_tags.where(exclude: false).destroy_all
Tag.find_or_create_by_names(tag_names).each do |tag|
antenna_tags.create!(tag: tag, exclude: false)
end
self[:any_tags] = !tag_names.any?
self[:any_tags] = tag_names.none?
end
def exclude_tags_raw
return '' if !exclude_tags.present?
return '' if exclude_tags.blank?
Tag.where(id: exclude_tags).map(&:name).join("\n")
end
@ -128,7 +131,7 @@ class Antenna < ApplicationRecord
return if exclude_tags_raw == raw
tags = []
tag_names = raw.split(/\R/).filter { |r| r.present? }.map { |r| r.start_with?('#') ? r[1..-1] : r }.uniq
tag_names = raw.split(/\R/).filter(&:present?).map { |r| r.start_with?('#') ? r[1..] : r }.uniq
Tag.find_or_create_by_names(tag_names).each do |tag|
tags << tag.id
end
@ -142,24 +145,25 @@ class Antenna < ApplicationRecord
def domains_raw=(raw)
return if domains_raw == raw
domain_names = raw.split(/\R/).filter { |r| r.present? }.uniq
domain_names = raw.split(/\R/).filter(&:present?).uniq
antenna_domains.where(exclude: false).destroy_all
domain_names.each do |domain|
antenna_domains.create!(name: domain, exclude: false)
end
self[:any_domains] = !domain_names.any?
self[:any_domains] = domain_names.none?
end
def exclude_domains_raw
return '' if !exclude_domains.present?
return '' if exclude_domains.blank?
exclude_domains.join("\n")
end
def exclude_domains_raw=(raw)
return if exclude_domains_raw == raw
domain_names = raw.split(/\R/).filter { |r| r.present? }.uniq
domain_names = raw.split(/\R/).filter(&:present?).uniq
self[:exclude_domains] = domain_names
end
@ -170,7 +174,7 @@ class Antenna < ApplicationRecord
def accounts_raw=(raw)
return if accounts_raw == raw
account_names = raw.split(/\R/).filter { |r| r.present? }.map { |r| r.start_with?('@') ? r[1..-1] : r }.uniq
account_names = raw.split(/\R/).filter(&:present?).map { |r| r.start_with?('@') ? r[1..] : r }.uniq
hit = false
antenna_accounts.where(exclude: false).destroy_all
@ -186,24 +190,22 @@ class Antenna < ApplicationRecord
end
def exclude_accounts_raw
return '' if !exclude_accounts.present?
return '' if exclude_accounts.blank?
Account.where(id: exclude_accounts).map { |account| account.domain ? "@#{account.username}@#{account.domain}" : "@#{account.username}" }.join("\n")
end
def exclude_accounts_raw=(raw)
return if exclude_accounts_raw == raw
account_names = raw.split(/\R/).filter { |r| r.present? }.map { |r| r.start_with?('@') ? r[1..-1] : r }.uniq
account_names = raw.split(/\R/).filter(&:present?).map { |r| r.start_with?('@') ? r[1..] : r }.uniq
accounts = []
account_names.each do |name|
username, domain = name.split('@')
account = Account.find_by(username: username, domain: domain)
if account.present?
accounts << account.id
end
accounts << account.id if account.present?
end
self[:exclude_accounts] = accounts
end
end

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: antenna_accounts
@ -10,10 +12,6 @@
# updated_at :datetime not null
#
class AntennaAccount < ApplicationRecord
belongs_to :antenna
belongs_to :account
validates :account_id, uniqueness: { scope: :antenna_id }
end

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: antenna_domains
@ -10,7 +12,5 @@
# updated_at :datetime not null
#
class AntennaDomain < ApplicationRecord
belongs_to :antenna
end

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: antenna_tags
@ -10,8 +12,6 @@
# updated_at :datetime not null
#
class AntennaTag < ApplicationRecord
belongs_to :antenna
belongs_to :tag
end

View file

@ -19,7 +19,7 @@ class Appeal < ApplicationRecord
MAX_STRIKE_AGE = 20.days
belongs_to :account
belongs_to :strike, class_name: 'AccountWarning', foreign_key: 'account_warning_id'
belongs_to :strike, class_name: 'AccountWarning', foreign_key: 'account_warning_id', inverse_of: :appeal
belongs_to :approved_by_account, class_name: 'Account', optional: true
belongs_to :rejected_by_account, class_name: 'Account', optional: true

View file

@ -81,8 +81,10 @@ module AccountInteractions
# Follow relations
has_many :follow_requests, dependent: :destroy
has_many :active_relationships, class_name: 'Follow', foreign_key: 'account_id', dependent: :destroy
has_many :passive_relationships, class_name: 'Follow', foreign_key: 'target_account_id', dependent: :destroy
with_options class_name: 'Follow', dependent: :destroy do
has_many :active_relationships, foreign_key: 'account_id', inverse_of: :account
has_many :passive_relationships, foreign_key: 'target_account_id', inverse_of: :target_account
end
has_many :following, -> { order('follows.id desc') }, through: :active_relationships, source: :target_account
has_many :followers, -> { order('follows.id desc') }, through: :passive_relationships, source: :account
@ -91,15 +93,19 @@ module AccountInteractions
has_many :account_notes, dependent: :destroy
# Block relationships
has_many :block_relationships, class_name: 'Block', foreign_key: 'account_id', dependent: :destroy
with_options class_name: 'Block', dependent: :destroy do
has_many :block_relationships, foreign_key: 'account_id', inverse_of: :account
has_many :blocked_by_relationships, foreign_key: :target_account_id, inverse_of: :target_account
end
has_many :blocking, -> { order('blocks.id desc') }, through: :block_relationships, source: :target_account
has_many :blocked_by_relationships, class_name: 'Block', foreign_key: :target_account_id, dependent: :destroy
has_many :blocked_by, -> { order('blocks.id desc') }, through: :blocked_by_relationships, source: :account
# Mute relationships
has_many :mute_relationships, class_name: 'Mute', foreign_key: 'account_id', dependent: :destroy
with_options class_name: 'Mute', dependent: :destroy do
has_many :mute_relationships, foreign_key: 'account_id', inverse_of: :account
has_many :muted_by_relationships, foreign_key: :target_account_id, inverse_of: :target_account
end
has_many :muting, -> { order('mutes.id desc') }, through: :mute_relationships, source: :target_account
has_many :muted_by_relationships, class_name: 'Mute', foreign_key: :target_account_id, dependent: :destroy
has_many :muted_by, -> { order('mutes.id desc') }, through: :muted_by_relationships, source: :account
has_many :conversation_mutes, dependent: :destroy
has_many :domain_blocks, class_name: 'AccountDomainBlock', dependent: :destroy

View file

@ -46,7 +46,7 @@ module Attachmentable
def set_file_extension(attachment) # rubocop:disable Naming/AccessorMethodName
return if attachment.blank?
attachment.instance_write :file_name, [Paperclip::Interpolations.basename(attachment, :original), appropriate_extension(attachment)].delete_if(&:blank?).join('.')
attachment.instance_write :file_name, [Paperclip::Interpolations.basename(attachment, :original), appropriate_extension(attachment)].compact_blank!.join('.')
end
def check_image_dimension(attachment)

View file

@ -36,7 +36,7 @@ class CustomEmoji < ApplicationRecord
IMAGE_MIME_TYPES = %w(image/png image/gif image/webp image/jpeg).freeze
belongs_to :category, class_name: 'CustomEmojiCategory', optional: true
has_one :local_counterpart, -> { where(domain: nil) }, class_name: 'CustomEmoji', primary_key: :shortcode, foreign_key: :shortcode
has_one :local_counterpart, -> { where(domain: nil) }, class_name: 'CustomEmoji', primary_key: :shortcode, foreign_key: :shortcode, inverse_of: false
has_many :emoji_reactions, inverse_of: :custom_emoji, dependent: :destroy
has_attached_file :image, styles: { static: { format: 'png', convert_options: '-coalesce +profile "!icc,*" +set modify-date +set create-date' } }, validate_media_type: false
@ -77,7 +77,7 @@ class CustomEmoji < ApplicationRecord
end
def update_size
set_size(Rails.configuration.x.use_s3 ? image.url : image.path)
size(Rails.configuration.x.use_s3 ? image.url : image.path)
end
class << self
@ -108,13 +108,11 @@ class CustomEmoji < ApplicationRecord
def set_post_size
image.queued_for_write.each do |style, file|
if style == :original
set_size(file.path)
end
size(file.path) if style == :original
end
end
def set_size(path)
def size(path)
image_size = FastImage.size(path)
self.image_width = image_size[0]
self.image_height = image_size[1]

View file

@ -38,7 +38,7 @@ class DomainBlock < ApplicationRecord
validates :domain, presence: true, uniqueness: true, domain: true
has_many :accounts, foreign_key: :domain, primary_key: :domain
has_many :accounts, foreign_key: :domain, primary_key: :domain, inverse_of: false
delegate :count, to: :accounts, prefix: true
scope :matches_domain, ->(value) { where(arel_table[:domain].matches("%#{value}%")) }
@ -67,8 +67,7 @@ class DomainBlock < ApplicationRecord
reject_straight_follow? ? :reject_straight_follow : nil,
reject_new_follow? ? :reject_new_follow : nil,
detect_invalid_subscription? ? :detect_invalid_subscription : nil,
reject_reports? ? :reject_reports : nil
].reject { |policy| policy == :noop || policy.nil? }
reject_reports? ? :reject_reports : nil].reject { |policy| policy == :noop || policy.nil? }
end
end

View file

@ -17,7 +17,7 @@
class EmojiReaction < ApplicationRecord
include Paginable
EMOJI_REACTION_LIMIT = 32767
EMOJI_REACTION_LIMIT = 32_767
EMOJI_REACTION_PER_ACCOUNT_LIMIT = 3
update_index('statuses', :status)
@ -55,14 +55,14 @@ class EmojiReaction < ApplicationRecord
end
def status_same_emoji_reaction
if status && account && status.emoji_reactions.where(account: account).where(name: name).where(custom_emoji_id: custom_emoji_id).any?
raise Mastodon::ValidationError, I18n.t('reactions.errors.duplication')
end
return unless status && account && status.emoji_reactions.where(account: account).where(name: name).where(custom_emoji_id: custom_emoji_id).any?
raise Mastodon::ValidationError, I18n.t('reactions.errors.duplication')
end
def status_emoji_reactions_count
if status && account && status.emoji_reactions.where(account: account).count >= EMOJI_REACTION_PER_ACCOUNT_LIMIT
raise Mastodon::ValidationError, I18n.t('reactions.errors.limit_reached')
end
end
return unless status && account && status.emoji_reactions.where(account: account).count >= EMOJI_REACTION_PER_ACCOUNT_LIMIT
raise Mastodon::ValidationError, I18n.t('reactions.errors.limit_reached')
end
end

View file

@ -12,7 +12,7 @@
class FollowRecommendation < ApplicationRecord
self.primary_key = :account_id
belongs_to :account_summary, foreign_key: :account_id
belongs_to :account_summary, foreign_key: :account_id, inverse_of: false
belongs_to :account
scope :localized, ->(locale) { joins(:account_summary).merge(AccountSummary.localized(locale)) }

View file

@ -8,6 +8,5 @@ class Form::MediaAttachmentsBatch
attr_accessor :query
def save
end
def save; end
end

View file

@ -13,11 +13,13 @@ class Instance < ApplicationRecord
attr_accessor :failure_days
has_many :accounts, foreign_key: :domain, primary_key: :domain
has_many :accounts, foreign_key: :domain, primary_key: :domain, inverse_of: false
belongs_to :domain_block, foreign_key: :domain, primary_key: :domain
belongs_to :domain_allow, foreign_key: :domain, primary_key: :domain
belongs_to :unavailable_domain, foreign_key: :domain, primary_key: :domain # skipcq: RB-RL1031
with_options foreign_key: :domain, primary_key: :domain, inverse_of: false do
belongs_to :domain_block
belongs_to :domain_allow
belongs_to :unavailable_domain # skipcq: RB-RL1031
end
scope :matches_domain, ->(value) { where(arel_table[:domain].matches("%#{value}%")) }

View file

@ -58,14 +58,16 @@ class Notification < ApplicationRecord
belongs_to :from_account, class_name: 'Account', optional: true
belongs_to :activity, polymorphic: true, optional: true
belongs_to :mention, foreign_key: 'activity_id', optional: true
belongs_to :status, foreign_key: 'activity_id', optional: true
belongs_to :follow, foreign_key: 'activity_id', optional: true
belongs_to :follow_request, foreign_key: 'activity_id', optional: true
belongs_to :favourite, foreign_key: 'activity_id', optional: true
belongs_to :emoji_reaction, foreign_key: 'activity_id', optional: true
belongs_to :poll, foreign_key: 'activity_id', optional: true
belongs_to :report, foreign_key: 'activity_id', optional: true
with_options foreign_key: 'activity_id', optional: true do
belongs_to :mention, inverse_of: :notification
belongs_to :status, inverse_of: :notification
belongs_to :follow, inverse_of: :notification
belongs_to :follow_request, inverse_of: :notification
belongs_to :favourite, inverse_of: :notification
belongs_to :emoji_reaction, inverse_of: :notification
belongs_to :poll, inverse_of: false
belongs_to :report, inverse_of: false
end
validates :type, inclusion: { in: TYPES }

View file

@ -101,7 +101,7 @@ class Poll < ApplicationRecord
end
def prepare_options
self.options = options.map(&:strip).reject(&:blank?)
self.options = options.map(&:strip).compact_blank
end
def reset_parent_cache

View file

@ -61,7 +61,7 @@ class Status < ApplicationRecord
belongs_to :account, inverse_of: :statuses
belongs_to :in_reply_to_account, class_name: 'Account', optional: true
belongs_to :conversation, optional: true
belongs_to :preloadable_poll, class_name: 'Poll', foreign_key: 'poll_id', optional: true
belongs_to :preloadable_poll, class_name: 'Poll', foreign_key: 'poll_id', optional: true, inverse_of: false
belongs_to :thread, foreign_key: 'in_reply_to_id', class_name: 'Status', inverse_of: :replies, optional: true
belongs_to :reblog, foreign_key: 'reblog_of_id', class_name: 'Status', inverse_of: :reblogs, optional: true
@ -343,7 +343,7 @@ class Status < ApplicationRecord
end
def generate_emoji_reactions_grouped_by_account
# TODO for serializer
# TODO: for serializer
EmojiReaction.where(status_id: id).group_by(&:account)
end
@ -365,15 +365,17 @@ class Status < ApplicationRecord
def compute_searchability
# Fedibird code
#searchability || Status.searchabilities.invert.fetch([Account.searchabilities[account.searchability], Status.visibilities[visibility] || 0].max, nil) || 'direct'
# searchability || Status.searchabilities.invert.fetch([Account.searchabilities[account.searchability], Status.visibilities[visibility] || 0].max, nil) || 'direct'
# Reactions only (generic: direct)
return searchability if searchability
return account.searchability if account.local? && account.searchability
'private'
end
def compute_searchability_activitypub
return 'unlisted' if public_unlisted_visibility? && public_searchability?
compute_searchability
end

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
class StatusEmojiReactionsGroupedByAccountObject
def initialize(account, emoji_reactions)
@account = account

View file

@ -91,13 +91,13 @@ class Trends::Statuses < Trends::Base
private
def eligible?(status)
(status.searchability.nil? || status.public_searchability?) && (status.public_visibility? || status.public_unlisted_visibility?) && status.account.discoverable? && !status.account.silenced? && status.spoiler_text.blank? && (!status.sensitive? || !status.media_attachments.any?) && !status.reply? && valid_locale?(status.language)
(status.searchability.nil? || status.public_searchability?) && (status.public_visibility? || status.public_unlisted_visibility?) && status.account.discoverable? && !status.account.silenced? && status.spoiler_text.blank? && (!status.sensitive? || status.media_attachments.none?) && !status.reply? && valid_locale?(status.language)
end
def calculate_scores(statuses, at_time)
items = statuses.map do |status|
expected = 1.0
observed = (status.reblogs_count + status.favourites_count + status.emoji_reaction_accounts_count * 0.8).to_f
observed = (status.reblogs_count + status.favourites_count + (status.emoji_reaction_accounts_count * 0.8)).to_f
score = if expected > observed || observed < options[:threshold]
0

View file

@ -445,7 +445,6 @@ class User < ApplicationRecord
return if chosen_languages.nil?
chosen_languages.compact_blank!
self.chosen_languages = nil if chosen_languages.empty?
end