about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
authorMatt Jankowski <mjankowski@thoughtbot.com>2017-05-01 11:42:13 -0400
committerEugen Rochko <eugen@zeonfederated.com>2017-05-01 17:42:13 +0200
commitf025cc67827a5b1b1faf10dec9d5a1e14e67fa5f (patch)
tree8c077d9b08ebbe4088490c5f55e7a5ec806e1176 /app
parent3988f2dade8a75cb642db8c239097bfcf8943a0d (diff)
Filter on allowed user language preferences (#2361)
* Naive approached to timeline filtering

* Convert allowed_languages into a db column

* Allow users to choose languages to see statuses in

* Style list items as two columns

* Add a hint to explain language filtering preference
Diffstat (limited to 'app')
-rw-r--r--app/assets/stylesheets/forms.scss7
-rw-r--r--app/controllers/settings/preferences_controller.rb3
-rw-r--r--app/models/account.rb2
-rw-r--r--app/models/status.rb5
-rw-r--r--app/views/settings/preferences/show.html.haml10
5 files changed, 26 insertions, 1 deletions
diff --git a/app/assets/stylesheets/forms.scss b/app/assets/stylesheets/forms.scss
index 890a00510..18258099b 100644
--- a/app/assets/stylesheets/forms.scss
+++ b/app/assets/stylesheets/forms.scss
@@ -326,3 +326,10 @@ code {
     flex: 0 0 auto;
   }
 }
+
+.user_allowed_languages {
+  li {
+    float: left;
+    width: 50%;
+  }
+}
diff --git a/app/controllers/settings/preferences_controller.rb b/app/controllers/settings/preferences_controller.rb
index 6762faee4..04a85849d 100644
--- a/app/controllers/settings/preferences_controller.rb
+++ b/app/controllers/settings/preferences_controller.rb
@@ -25,7 +25,8 @@ class Settings::PreferencesController < ApplicationController
 
   def user_params
     params.require(:user).permit(
-      :locale
+      :locale,
+      allowed_languages: []
     )
   end
 
diff --git a/app/models/account.rb b/app/models/account.rb
index 03584b4e6..c5fc6d7ab 100644
--- a/app/models/account.rb
+++ b/app/models/account.rb
@@ -82,6 +82,8 @@ class Account < ApplicationRecord
            prefix: true,
            allow_nil: true
 
+  delegate :allowed_languages, to: :user, prefix: false, allow_nil: true
+
   def follow!(other_account)
     active_relationships.where(target_account: other_account).first_or_create!(target_account: other_account)
   end
diff --git a/app/models/status.rb b/app/models/status.rb
index f005813e5..3243d1ecb 100644
--- a/app/models/status.rb
+++ b/app/models/status.rb
@@ -119,6 +119,10 @@ class Status < ApplicationRecord
   end
 
   class << self
+    def in_allowed_languages(account)
+      where(language: account.allowed_languages)
+    end
+
     def as_home_timeline(account)
       where(account: [account] + account.following)
     end
@@ -198,6 +202,7 @@ class Status < ApplicationRecord
 
     def filter_timeline_for_account(query, account)
       query = query.not_excluded_by_account(account)
+      query = query.in_allowed_languages(account) if account.allowed_languages.present?
       query.merge(account_silencing_filter(account))
     end
 
diff --git a/app/views/settings/preferences/show.html.haml b/app/views/settings/preferences/show.html.haml
index 8a4113ab4..10618ebf6 100644
--- a/app/views/settings/preferences/show.html.haml
+++ b/app/views/settings/preferences/show.html.haml
@@ -7,6 +7,16 @@
   .fields-group
     = f.input :locale, collection: I18n.available_locales, wrapper: :with_label, include_blank: false, label_method: lambda { |locale| human_locale(locale) }
 
+    = f.input :allowed_languages,
+      collection: I18n.available_locales,
+      wrapper: :with_label,
+      include_blank: false,
+      label_method: lambda { |locale| human_locale(locale) },
+      required: false,
+      as: :check_boxes,
+      collection_wrapper_tag: 'ul',
+      item_wrapper_tag: 'li'
+
     = f.input :setting_default_privacy, collection: Status.visibilities.keys - ['direct'], wrapper: :with_label, include_blank: false, label_method: lambda { |visibility| safe_join([I18n.t("statuses.visibilities.#{visibility}"), content_tag(:span, I18n.t("statuses.visibilities.#{visibility}_long"), class: 'hint')]) }, required: false, as: :radio_buttons, collection_wrapper_tag: 'ul', item_wrapper_tag: 'li'
 
   .fields-group