Merge remote-tracking branch 'parent/main' into upstream-20240731

This commit is contained in:
KMY 2024-07-31 13:00:13 +09:00
commit 8b09a57a91
320 changed files with 3132 additions and 1643 deletions

View file

@ -39,7 +39,7 @@ class Tag < ApplicationRecord
HASHTAG_LAST_SEQUENCE = '([[:word:]_]*[[:alpha:]][[:word:]_]*)'
HASHTAG_NAME_PAT = "#{HASHTAG_FIRST_SEQUENCE}|#{HASHTAG_LAST_SEQUENCE}"
HASHTAG_RE = %r{(?<![=/)\p{Alnum}])#(#{HASHTAG_NAME_PAT})}i
HASHTAG_RE = %r{(?<![=/)\p{Alnum}])#(#{HASHTAG_NAME_PAT})}
HASHTAG_NAME_RE = /\A(#{HASHTAG_NAME_PAT})\z/i
HASHTAG_INVALID_CHARS_RE = /[^[:alnum:]\u0E47-\u0E4E#{HASHTAG_SEPARATORS}]/
@ -54,6 +54,7 @@ class Tag < ApplicationRecord
scope :unreviewed, -> { where(reviewed_at: nil) }
scope :pending_review, -> { unreviewed.where.not(requested_review_at: nil) }
scope :usable, -> { where(usable: [true, nil]) }
scope :not_usable, -> { where(usable: false) }
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) }
@ -76,6 +77,10 @@ class Tag < ApplicationRecord
attributes['display_name'] || name
end
def formatted_name
"##{display_name}"
end
def usable
boolean_with_default('usable', true)
end
@ -134,8 +139,10 @@ class Tag < ApplicationRecord
def search_for(term, limit = 5, offset = 0, options = {})
stripped_term = term.strip
options.reverse_merge!({ exclude_unlistable: true, exclude_unreviewed: false })
query = Tag.listable.matches_name(stripped_term)
query = Tag.matches_name(stripped_term)
query = query.merge(Tag.listable) if options[:exclude_unlistable]
query = query.merge(matching_name(stripped_term).or(where.not(reviewed_at: nil))) if options[:exclude_unreviewed]
query.order(Arel.sql('length(name) ASC, name ASC'))