about summary refs log tree commit diff
path: root/app/models
diff options
context:
space:
mode:
authorAkihiko Odaki (@fn_aki@pawoo.net) <akihiko.odaki.4i@stu.hosei.ac.jp>2017-06-21 03:41:23 +0900
committerEugen Rochko <eugen@zeonfederated.com>2017-06-20 20:41:23 +0200
commitbab5a18232a163b0c3c6a245f7f95d50d7022b36 (patch)
treeed0445cf66870d2a12827a6a3be06c914878a5d8 /app/models
parenta20cf3b64e93d764f1dfe88ecdb39f3fd4eefe03 (diff)
Filter direct statuses in Status.as_home_timeline (#3842)
The classes using Status.as_home_timeline, namely Feed and
PrecomputeFeedService are expected to filter direct statuses as
FanOutWriteService does, but their filtering were incomplete or missing.

This commit solves the problem by filtering direct statuses in
as_home_timeline as the other similar methods such as as_public_timeline
does.
Diffstat (limited to 'app/models')
-rw-r--r--app/models/status.rb10
1 files changed, 9 insertions, 1 deletions
diff --git a/app/models/status.rb b/app/models/status.rb
index 24d3db2bf..544d2e005 100644
--- a/app/models/status.rb
+++ b/app/models/status.rb
@@ -131,7 +131,15 @@ class Status < ApplicationRecord
     end
 
     def as_home_timeline(account)
-      where(account: [account] + account.following)
+      # 'references' is a workaround for the following issue:
+      # Inconsistent results with #or in ActiveRecord::Relation with respect to documentation Issue #24055 rails/rails
+      # https://github.com/rails/rails/issues/24055
+      references(:mentions)
+        .where.not(visibility: :direct)
+        .or(where(mentions: { account: account }))
+        .where(follows: { account_id: account })
+        .or(references(:mentions, :follows).where(account: account))
+        .left_outer_joins(account: :followers).left_outer_joins(:mentions).group(:id)
     end
 
     def as_public_timeline(account = nil, local_only = false)