def following
results = Follow.where(account: @account).paginate_by_max_id(DEFAULT_ACCOUNTS_LIMIT, params[:max_id], params[:since_id])
- @accounts = Account.where(id: results.map(&:account_id)).with_counters.to_a
+ @accounts = Account.where(id: results.map(&:target_account_id)).with_counters.to_a
next_path = following_api_v1_account_url(max_id: results.last.id) if results.size == DEFAULT_ACCOUNTS_LIMIT
prev_path = following_api_v1_account_url(since_id: results.first.id) if results.size > 0
filter_from_home?(status, receiver)
elsif timeline_type == :mentions
filter_from_mentions?(status, receiver)
+ elsif timeline_type == :public
+ filter_from_public?(status, receiver)
else
false
end
should_filter = should_filter || receiver.blocking?(status.account) # or it's from someone I blocked
should_filter
end
+
+ def filter_from_public?(status, receiver)
+ should_filter = receiver.blocking?(status.account)
+
+ if status.reply? && !status.thread.account.nil?
+ should_filter = should_filter || receiver.blocking?(status.thread.account)
+ elsif status.reblog?
+ should_filter = should_filter || receiver.blocking?(status.reblog.account)
+ end
+
+ should_filter
+ end
end
end
def as_public_timeline(account = nil)
- query = joins('LEFT OUTER JOIN statuses AS reblogs ON statuses.reblog_of_id = reblogs.id')
- .joins('LEFT OUTER JOIN accounts ON statuses.account_id = accounts.id')
- .where('accounts.silenced = FALSE')
+ query = joins('LEFT OUTER JOIN accounts ON statuses.account_id = accounts.id').where('accounts.silenced = FALSE')
unless account.nil?
- query = query.where('(reblogs.account_id IS NULL OR reblogs.account_id NOT IN (SELECT target_account_id FROM blocks WHERE account_id = ?)) AND statuses.account_id NOT IN (SELECT target_account_id FROM blocks WHERE account_id = ?)', account.id, account.id)
+ query = filter_timeline(query, account)
end
query.with_includes.with_counters
def as_tag_timeline(tag, account = nil)
query = tag.statuses
- .joins('LEFT OUTER JOIN statuses AS reblogs ON statuses.reblog_of_id = reblogs.id')
.joins('LEFT OUTER JOIN accounts ON statuses.account_id = accounts.id')
.where('accounts.silenced = FALSE')
unless account.nil?
- query = query.where('(reblogs.account_id IS NULL OR reblogs.account_id NOT IN (SELECT target_account_id FROM blocks WHERE account_id = ?)) AND statuses.account_id NOT IN (SELECT target_account_id FROM blocks WHERE account_id = ?)', account.id, account.id)
+ query = filter_timeline(query, account)
end
query.with_includes.with_counters
def reblogs_map(status_ids, account_id)
select('reblog_of_id').where(reblog_of_id: status_ids).where(account_id: account_id).map { |s| [s.reblog_of_id, true] }.to_h
end
+
+ private
+
+ def filter_timeline(query, account)
+ blocked = Block.where(account: account).pluck(:target_account_id)
+
+ query
+ .joins('LEFT OUTER JOIN statuses AS parents ON statuses.in_reply_to_id = parents.id')
+ .joins('LEFT OUTER JOIN statuses AS reblogs ON statuses.reblog_of_id = reblogs.id')
+ .where('parents.account_id NOT IN (?)', blocked)
+ .where('statuses.account_id NOT IN (?)', blocked)
+ .where('(reblogs.id IS NULL OR reblogs.account_id NOT IN (?))', blocked)
+ end
end
before_validation do