From 39cc9fde8a2e34da0639d83688d4d6d6d6240382 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Mon, 5 Dec 2016 22:59:30 +0100 Subject: Add account suspension --- app/models/status.rb | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'app/models/status.rb') diff --git a/app/models/status.rb b/app/models/status.rb index 1f5cf9b46..9d1dae963 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -104,22 +104,20 @@ class Status < ApplicationRecord def as_public_timeline(account = nil) query = joins('LEFT OUTER JOIN accounts ON statuses.account_id = accounts.id') .where(visibility: :public) - .where('accounts.silenced = FALSE') .where('(statuses.in_reply_to_id IS NULL OR statuses.in_reply_to_account_id = statuses.account_id)') .where('statuses.reblog_of_id IS NULL') - query = filter_timeline(query, account) unless account.nil? - query + + account.nil? ? filter_timeline_default(query) : filter_timeline(query, account) end def as_tag_timeline(tag, account = nil) query = tag.statuses .joins('LEFT OUTER JOIN accounts ON statuses.account_id = accounts.id') .where(visibility: :public) - .where('accounts.silenced = FALSE') .where('(statuses.in_reply_to_id IS NULL OR statuses.in_reply_to_account_id = statuses.account_id)') .where('statuses.reblog_of_id IS NULL') - query = filter_timeline(query, account) unless account.nil? - query + + account.nil? ? filter_timeline_default(query) : filter_timeline(query, account) end def favourites_map(status_ids, account_id) @@ -150,8 +148,13 @@ class Status < ApplicationRecord def filter_timeline(query, account) blocked = Block.where(account: account).pluck(:target_account_id) - return query if blocked.empty? - query.where('statuses.account_id NOT IN (?)', blocked) + query = query.where('statuses.account_id NOT IN (?)', blocked) unless blocked.empty? + query = query.where('accounts.silenced = TRUE') if account.silenced? + query + end + + def filter_timeline_default(query) + query.where('accounts.silenced = FALSE') end end -- cgit