mirror of
https://git.kescher.at/CatCatNya/catstodon.git
synced 2024-11-27 03:31:36 +01:00
30c191aaa0
Co-authored-by: Eugen Rochko <eugen@zeonfederated.com> Co-authored-by: Claire <claire.github-309c@sitedethib.com>
54 lines
1.8 KiB
Ruby
54 lines
1.8 KiB
Ruby
# 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(preloaded = nil)
|
|
ids = []
|
|
|
|
ids << account_id if local?
|
|
|
|
if preloaded.nil?
|
|
ids += mentions.joins(:account).merge(Account.local).active.pluck(:account_id)
|
|
ids += favourites.joins(:account).merge(Account.local).pluck(:account_id)
|
|
ids += reblogs.joins(:account).merge(Account.local).pluck(:account_id)
|
|
ids += bookmarks.joins(:account).merge(Account.local).pluck(:account_id)
|
|
ids += poll.votes.joins(:account).merge(Account.local).pluck(:account_id) if poll.present?
|
|
else
|
|
ids += preloaded.mentions[id] || []
|
|
ids += preloaded.favourites[id] || []
|
|
ids += preloaded.reblogs[id] || []
|
|
ids += preloaded.bookmarks[id] || []
|
|
ids += preloaded.votes[id] || []
|
|
end
|
|
|
|
ids.uniq
|
|
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
|