Add searchability support
This commit is contained in:
parent
a2e674af51
commit
af20b1d2aa
43 changed files with 716 additions and 65 deletions
|
@ -27,6 +27,7 @@
|
|||
# edited_at :datetime
|
||||
# trendable :boolean
|
||||
# ordered_media_attachment_ids :bigint(8) is an Array
|
||||
# searchability :integer
|
||||
#
|
||||
|
||||
require 'ostruct'
|
||||
|
@ -52,6 +53,7 @@ class Status < ApplicationRecord
|
|||
update_index('statuses', :proper)
|
||||
|
||||
enum visibility: { public: 0, unlisted: 1, private: 2, direct: 3, limited: 4, public_unlisted: 10 }, _suffix: :visibility
|
||||
enum searchability: { public: 0, unlisted: 1, private: 2, direct: 3, limited: 4, public_unlisted: 10 }, _suffix: :searchability
|
||||
|
||||
belongs_to :application, class_name: 'Doorkeeper::Application', optional: true
|
||||
|
||||
|
@ -115,6 +117,7 @@ class Status < ApplicationRecord
|
|||
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)
|
||||
}
|
||||
scope :unset_searchability, -> { where(searchability: nil, reblog_of_id: nil) }
|
||||
|
||||
cache_associated :application,
|
||||
:media_attachments,
|
||||
|
@ -255,6 +258,11 @@ class Status < ApplicationRecord
|
|||
ordered_media_attachments.any?
|
||||
end
|
||||
|
||||
def expired?
|
||||
false
|
||||
# !expired_at.nil?
|
||||
end
|
||||
|
||||
def with_preview_card?
|
||||
preview_cards.any?
|
||||
end
|
||||
|
@ -349,6 +357,10 @@ class Status < ApplicationRecord
|
|||
attributes['trendable'].nil? && account.requires_review_notification?
|
||||
end
|
||||
|
||||
def compute_searchability
|
||||
searchability || Status.searchabilities.invert.fetch([Account.searchabilities[account.searchability], Status.visibilities[visibility] || 0].max, nil) || 'direct'
|
||||
end
|
||||
|
||||
after_create_commit :increment_counter_caches
|
||||
after_destroy_commit :decrement_counter_caches
|
||||
|
||||
|
@ -358,6 +370,7 @@ class Status < ApplicationRecord
|
|||
before_validation :prepare_contents, if: :local?
|
||||
before_validation :set_reblog
|
||||
before_validation :set_visibility
|
||||
before_validation :set_searchability
|
||||
before_validation :set_conversation
|
||||
before_validation :set_local
|
||||
|
||||
|
@ -370,6 +383,10 @@ class Status < ApplicationRecord
|
|||
visibilities.keys - %w(direct limited)
|
||||
end
|
||||
|
||||
def selectable_searchabilities
|
||||
searchabilities.keys - %w(public_unlisted limited)
|
||||
end
|
||||
|
||||
def favourites_map(status_ids, account_id)
|
||||
Favourite.select('status_id').where(status_id: status_ids).where(account_id: account_id).each_with_object({}) { |f, h| h[f.status_id] = true }
|
||||
end
|
||||
|
@ -538,6 +555,12 @@ class Status < ApplicationRecord
|
|||
self.sensitive = false if sensitive.nil?
|
||||
end
|
||||
|
||||
def set_searchability
|
||||
return if searchability.nil?
|
||||
|
||||
self.searchability = [Status.searchabilities[searchability], Status.visibilities[visibility == 'public_unlisted' ? 'public' : visibility]].max
|
||||
end
|
||||
|
||||
def set_conversation
|
||||
self.thread = thread.reblog if thread&.reblog?
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue