~cytrogen/masto-fe

ref: 937dc42f101be905e3af41b879901a4445b0223a masto-fe/app/models/concerns/status_search_concern.rb -rw-r--r-- 1.4 KiB
937dc42f — Matt Jankowski Extract methods for file movement in `CLI::Upgrade` (#25120) 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# frozen_string_literal: true

module StatusSearchConcern
  extend ActiveSupport::Concern

  included do
    scope :indexable, -> { without_reblogs.where(visibility: :public).joins(:account).where(account: { indexable: true }) }
  end

  def searchable_by
    @searchable_by ||= begin
      ids = []

      ids << account_id if local?

      ids += local_mentioned.pluck(:id)
      ids += local_favorited.pluck(:id)
      ids += local_reblogged.pluck(:id)
      ids += local_bookmarked.pluck(:id)
      ids += preloadable_poll.local_voters.pluck(:id) if preloadable_poll.present?

      ids.uniq
    end
  end

  def searchable_text
    [
      spoiler_text,
      FormattingHelper.extract_status_plain_text(self),
      preloadable_poll&.options&.join("\n\n"),
      ordered_media_attachments.map(&:description).join("\n\n"),
    ].compact.join("\n\n")
  end

  def searchable_properties
    [].tap do |properties|
      properties << 'image' if ordered_media_attachments.any?(&:image?)
      properties << 'video' if ordered_media_attachments.any?(&:video?)
      properties << 'audio' if ordered_media_attachments.any?(&:audio?)
      properties << 'media' if with_media?
      properties << 'poll' if with_poll?
      properties << 'link' if with_preview_card?
      properties << 'embed' if preview_cards.any?(&:video?)
      properties << 'sensitive' if sensitive?
      properties << 'reply' if reply?
    end
  end
end