From 1268277a8c203bcae515e0ccc8b3432119bafed2 Mon Sep 17 00:00:00 2001 From: multiple creatures Date: Fri, 10 Jan 2020 20:07:15 -0600 Subject: add custom filter master toggle, add media gallery mode, & fix various filter logic + caching bugs --- app/models/account.rb | 1 - app/models/status.rb | 10 ++++++---- app/models/user.rb | 3 +++ 3 files changed, 9 insertions(+), 5 deletions(-) (limited to 'app/models') diff --git a/app/models/account.rb b/app/models/account.rb index 66fe554d5..e43db63bd 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -55,7 +55,6 @@ # force_private :boolean default(FALSE), not null # unboostable :boolean default(FALSE), not null # block_anon :boolean default(FALSE), not null -# filter_undescribed :boolean default(FALSE), not null # class Account < ApplicationRecord diff --git a/app/models/status.rb b/app/models/status.rb index 5a1d38932..5d257ba6c 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -119,9 +119,10 @@ class Status < ApplicationRecord scope :search, ->(needle) { where("tsv @@ websearch_to_tsquery('fedi', ?)", needle) } scope :search_not, ->(needle) { where.not("tsv @@ websearch_to_tsquery('fedi', ?)", needle) } - scope :search_filtered_by_account, ->(account_id) { where('tsv @@ (SELECT tsquery_union(websearch_to_tsquery(phrase)) FROM custom_filters WHERE account_id = ? AND is_enabled)', account_id) } - scope :search_not_filtered_by_account, ->(account_id) { where.not('tsv @@ (SELECT tsquery_union(websearch_to_tsquery(phrase)) FROM custom_filters WHERE account_id = ? AND is_enabled)', account_id) } + scope :search_filtered_by_account, ->(account_id) { where("tsv @@ (SELECT tsquery_union(websearch_to_tsquery('fedi', phrase)) FROM custom_filters WHERE account_id = ? AND is_enabled)", account_id) } + scope :search_not_filtered_by_account, ->(account_id) { where.not("tsv @@ (SELECT tsquery_union(websearch_to_tsquery('fedi', phrase)) FROM custom_filters WHERE account_id = ? AND is_enabled)", account_id) } + scope :with_media, -> { joins(:media_attachments).select('statuses.*') } scope :not_missing_media_desc, -> { left_outer_joins(:media_attachments).select('statuses.*').where('media_attachments.id IS NULL OR media_attachments.description IS NOT NULL') } scope :only_followers_of, ->(account) { where(account: [account] + account.following) } @@ -578,14 +579,15 @@ class Status < ApplicationRecord query = query.in_chosen_languages(account) if account.chosen_languages.present? query = query.reply_not_excluded_by_account(account) unless tag_timeline query = query.mention_not_excluded_by_account(account) - unless account.custom_filters.enabled.empty? + unless !account.user.filters_enabled || account.custom_filters.enabled.blank? if account.user.invert_filters query = query.search_filtered_by_account(account.id) else query = query.search_not_filtered_by_account(account.id) end end - query = query.not_missing_media_desc if account.filter_undescribed? + query = query.with_media if account.user.media_only? + query = query.not_missing_media_desc if account.user.filter_undescribed? query.merge(account_silencing_filter(account)) end diff --git a/app/models/user.rb b/app/models/user.rb index 2ee304e81..b519e9b15 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -43,6 +43,9 @@ # only_known :boolean # invert_filters :boolean default(FALSE), not null # filter_timelines_only :boolean default(FALSE), not null +# media_only :boolean default(FALSE), not null +# filter_undescribed :boolean default(FALSE), not null +# filters_enabled :boolean default(FALSE), not null # class User < ApplicationRecord -- cgit