about summary refs log tree commit diff
path: root/app/controllers
diff options
context:
space:
mode:
authormultiple creatures <dev@multiple-creature.party>2020-01-10 20:07:15 -0600
committermultiple creatures <dev@multiple-creature.party>2020-01-10 20:07:15 -0600
commit1268277a8c203bcae515e0ccc8b3432119bafed2 (patch)
tree89fccc698a4a148f70a3ae10faf0ffef260200ec /app/controllers
parent0090aca0453285ed6f4d55758ccd05200025d11a (diff)
add custom filter master toggle, add media gallery mode, & fix various filter logic + caching bugs
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/api/v1/filters_controller.rb7
-rw-r--r--app/controllers/api/v1/timelines/home_controller.rb9
-rw-r--r--app/controllers/api/v1/timelines/list_controller.rb10
-rw-r--r--app/controllers/filters_controller.rb7
-rw-r--r--app/controllers/settings/preferences_controller.rb18
5 files changed, 41 insertions, 10 deletions
diff --git a/app/controllers/api/v1/filters_controller.rb b/app/controllers/api/v1/filters_controller.rb
index 514f7c8fa..ffef0b920 100644
--- a/app/controllers/api/v1/filters_controller.rb
+++ b/app/controllers/api/v1/filters_controller.rb
@@ -15,6 +15,7 @@ class Api::V1::FiltersController < Api::BaseController
 
   def create
     @filter = current_account.custom_filters.create!(resource_params)
+    toggle_filters
     render json: @filter, serializer: REST::FilterSerializer
   end
 
@@ -24,16 +25,22 @@ class Api::V1::FiltersController < Api::BaseController
 
   def update
     @filter.update!(resource_params)
+    toggle_filters
     render json: @filter, serializer: REST::FilterSerializer
   end
 
   def destroy
     @filter.destroy!
+    toggle_filters
     render_empty
   end
 
   private
 
+  def toggle_filters
+    current_account.user.update!(filters_enabled: !current_account.custom_filters.enabled.blank?)
+  end
+
   def set_filters
     @filters = params['all'].to_i == 1 ? current_account.custom_filters : []
   end
diff --git a/app/controllers/api/v1/timelines/home_controller.rb b/app/controllers/api/v1/timelines/home_controller.rb
index bd3bac0fe..589bc3486 100644
--- a/app/controllers/api/v1/timelines/home_controller.rb
+++ b/app/controllers/api/v1/timelines/home_controller.rb
@@ -23,11 +23,10 @@ class Api::V1::Timelines::HomeController < Api::BaseController
   end
 
   def cached_home_statuses
-    if current_account&.user&.hide_boosts
-      cache_collection home_statuses.without_reblogs, Status
-    else
-      cache_collection home_statuses, Status
-    end
+    statuses = home_statuses
+    statuses = statuses.without_reblogs if current_account&.user&.hide_boosts
+    statuses = statuses.with_media if current_account&.user&.media_only
+    cache_collection statuses, Status
   end
 
   def home_statuses
diff --git a/app/controllers/api/v1/timelines/list_controller.rb b/app/controllers/api/v1/timelines/list_controller.rb
index 7eb656745..b52f53bf9 100644
--- a/app/controllers/api/v1/timelines/list_controller.rb
+++ b/app/controllers/api/v1/timelines/list_controller.rb
@@ -25,11 +25,11 @@ class Api::V1::Timelines::ListController < Api::BaseController
   end
 
   def cached_list_statuses
-    if current_account&.user&.hide_boosts
-      cache_collection list_statuses.without_reblogs, Status
-    else
-      cache_collection list_statuses, Status
-    end
+    statuses = list_statuses
+    statuses = statuses.without_reblogs if current_account&.user&.hide_boosts
+    statuses = statuses.with_media if current_account&.user&.media_only
+
+    cache_collection statuses, Status
   end
 
   def list_statuses
diff --git a/app/controllers/filters_controller.rb b/app/controllers/filters_controller.rb
index f5cc00d2f..2b615923f 100644
--- a/app/controllers/filters_controller.rb
+++ b/app/controllers/filters_controller.rb
@@ -22,6 +22,7 @@ class FiltersController < ApplicationController
     @filter = current_account.custom_filters.build(resource_params)
 
     if @filter.save
+      toggle_filters
       redirect_to filters_path
     else
       render action: :new
@@ -32,6 +33,7 @@ class FiltersController < ApplicationController
 
   def update
     if @filter.update(resource_params)
+      toggle_filters
       redirect_to filters_path
     else
       render action: :edit
@@ -40,11 +42,16 @@ class FiltersController < ApplicationController
 
   def destroy
     @filter.destroy
+    toggle_filters
     redirect_to filters_path
   end
 
   private
 
+  def toggle_filters
+    current_user.update!(filters_enabled: !current_account.custom_filters.enabled.blank?)
+  end
+
   def set_pack
     use_pack 'settings'
   end
diff --git a/app/controllers/settings/preferences_controller.rb b/app/controllers/settings/preferences_controller.rb
index 2ff84ac80..ce3c84f77 100644
--- a/app/controllers/settings/preferences_controller.rb
+++ b/app/controllers/settings/preferences_controller.rb
@@ -14,6 +14,9 @@ class Settings::PreferencesController < Settings::BaseController
 
     if current_user.update(user_params)
       I18n.locale = current_user.locale
+      toggle_filters
+      remove_cache
+      update_feeds
       redirect_to settings_preferences_path, notice: I18n.t('generic.changes_saved_msg')
     else
       render :show
@@ -22,6 +25,18 @@ class Settings::PreferencesController < Settings::BaseController
 
   private
 
+  def toggle_filters
+    current_user.update!(filters_enabled: !current_account.custom_filters.enabled.blank?)
+  end
+
+  def update_feeds
+    FilterFeedsWorker.perform_async(current_user.account_id)
+  end
+
+  def remove_cache
+    redis.del("filtered_statuses:#{current_user.account_id}")
+  end
+
   def user_settings
     UserSettingsDecorator.new(current_user)
   end
@@ -29,8 +44,11 @@ class Settings::PreferencesController < Settings::BaseController
   def user_params
     params.require(:user).permit(
       :locale,
+      :filters_enabled,
       :hide_boosts,
       :only_known,
+      :media_only,
+      :filter_undescribed,
       :invert_filters,
       :filter_timelines_only,
       chosen_languages: []