about summary refs log tree commit diff
path: root/app/models/status.rb
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2022-11-28 11:33:34 +0100
committerClaire <claire.github-309c@sitedethib.com>2022-11-28 11:33:34 +0100
commita2e7997592dd86baa7595c41eed274be4c200d07 (patch)
treeb4c21af8bdf541d8156beb29e9f53766bd1fbadd /app/models/status.rb
parent6517b7b9f02f8590a8f9c5aa04e3ef9efeb4e757 (diff)
parentcec1e902e006730f68bde0a4334e5b819a12a475 (diff)
Merge branch 'main' into glitch-soc/merge-upstream
Conflicts:
- `README.md`:
  Our README is completely different.
  Discarded upstream changes.
Diffstat (limited to 'app/models/status.rb')
-rw-r--r--app/models/status.rb15
1 files changed, 8 insertions, 7 deletions
diff --git a/app/models/status.rb b/app/models/status.rb
index 044816be7..6cfe19d23 100644
--- a/app/models/status.rb
+++ b/app/models/status.rb
@@ -68,6 +68,7 @@ class Status < ApplicationRecord
   has_many :reblogged_by_accounts, through: :reblogs, class_name: 'Account', source: :account
   has_many :replies, foreign_key: 'in_reply_to_id', class_name: 'Status', inverse_of: :thread
   has_many :mentions, dependent: :destroy, inverse_of: :status
+  has_many :mentioned_accounts, through: :mentions, source: :account, class_name: 'Account'
   has_many :active_mentions, -> { active }, class_name: 'Mention', inverse_of: :status
   has_many :media_attachments, dependent: :nullify
 
@@ -146,11 +147,11 @@ class Status < ApplicationRecord
     ids << account_id if local?
 
     if preloaded.nil?
-      ids += mentions.where(account: Account.local, silent: false).pluck(:account_id)
-      ids += favourites.where(account: Account.local).pluck(:account_id)
-      ids += reblogs.where(account: Account.local).pluck(:account_id)
-      ids += bookmarks.where(account: Account.local).pluck(:account_id)
-      ids += poll.votes.where(account: Account.local).pluck(:account_id) if poll.present?
+      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] || []
@@ -590,8 +591,8 @@ class Status < ApplicationRecord
   def unlink_from_conversations
     return unless direct_visibility?
 
-    mentioned_accounts = (association(:mentions).loaded? ? mentions : mentions.includes(:account)).map(&:account)
-    inbox_owners       = mentioned_accounts.select(&:local?) + (account.local? ? [account] : [])
+    inbox_owners = mentioned_accounts.local
+    inbox_owners += [account] if account.local?
 
     inbox_owners.each do |inbox_owner|
       AccountConversation.remove_status(inbox_owner, self)