about summary refs log tree commit diff
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/favourite.rb2
-rw-r--r--app/models/status.rb18
2 files changed, 20 insertions, 0 deletions
diff --git a/app/models/favourite.rb b/app/models/favourite.rb
index 2b1271f31..fa1884b86 100644
--- a/app/models/favourite.rb
+++ b/app/models/favourite.rb
@@ -13,6 +13,8 @@
 class Favourite < ApplicationRecord
   include Paginable
 
+  update_index('statuses#status', :status) if Chewy.enabled?
+
   belongs_to :account, inverse_of: :favourites
   belongs_to :status,  inverse_of: :favourites, counter_cache: true
 
diff --git a/app/models/status.rb b/app/models/status.rb
index 26ff40bf7..0de89ad4e 100644
--- a/app/models/status.rb
+++ b/app/models/status.rb
@@ -31,6 +31,8 @@ class Status < ApplicationRecord
   include Cacheable
   include StatusThreadingConcern
 
+  update_index('statuses#status', :proper) if Chewy.enabled?
+
   enum visibility: [:public, :unlisted, :private, :direct], _suffix: :visibility
 
   belongs_to :application, class_name: 'Doorkeeper::Application', optional: true
@@ -78,6 +80,22 @@ class Status < ApplicationRecord
 
   delegate :domain, to: :account, prefix: true
 
+  def searchable_by(preloaded = nil)
+    ids = [account_id]
+
+    if preloaded.nil?
+      ids += mentions.pluck(:account_id)
+      ids += favourites.pluck(:account_id)
+      ids += reblogs.pluck(:account_id)
+    else
+      ids += preloaded.mentions[id] || []
+      ids += preloaded.favourites[id] || []
+      ids += preloaded.reblogs[id] || []
+    end
+
+    ids.uniq
+  end
+
   def reply?
     !in_reply_to_id.nil? || attributes['reply']
   end