diff options
author | Thibaut Girka <thib@sitedethib.com> | 2018-11-06 15:22:44 +0100 |
---|---|---|
committer | Thibaut Girka <thib@sitedethib.com> | 2018-11-06 15:22:44 +0100 |
commit | 36dab188fd83876ba5e0e08a4b6647a445e2f24f (patch) | |
tree | 28bdd407eac81bfcc2741ad2c1714192d774754a /app/models | |
parent | 34209c0340ca6b7c61de964a17f5f3fe2e0f7c7b (diff) | |
parent | 7775225d174bf7c413bcd41b89a5d50d32cc5cee (diff) |
Merge branch 'master' into glitch-soc/merge-upstream
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/status.rb | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/app/models/status.rb b/app/models/status.rb index f67a05b3c..e73f11503 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -85,6 +85,17 @@ class Status < ApplicationRecord scope :including_silenced_accounts, -> { left_outer_joins(:account).where(accounts: { silenced: true }) } scope :not_excluded_by_account, ->(account) { where.not(account_id: account.excluded_from_timeline_account_ids) } scope :not_domain_blocked_by_account, ->(account) { account.excluded_from_timeline_domains.blank? ? left_outer_joins(:account) : left_outer_joins(:account).where('accounts.domain IS NULL OR accounts.domain NOT IN (?)', account.excluded_from_timeline_domains) } + scope :tagged_with_all, ->(tags) { + Array(tags).map(&:id).map(&:to_i).reduce(self) do |result, id| + result.joins("INNER JOIN statuses_tags t#{id} ON t#{id}.status_id = statuses.id AND t#{id}.tag_id = #{id}") + end + } + scope :tagged_with_none, ->(tags) { + Array(tags).map(&:id).map(&:to_i).reduce(self) do |result, id| + result.joins("LEFT OUTER JOIN statuses_tags t#{id} ON t#{id}.status_id = statuses.id AND t#{id}.tag_id = #{id}") + .where("t#{id}.tag_id IS NULL") + end + } scope :not_local_only, -> { where(local_only: [false, nil]) } |