about summary refs log tree commit diff
path: root/app/models
diff options
context:
space:
mode:
authorThibaut Girka <thib@sitedethib.com>2018-06-21 20:49:57 +0200
committerThibaut Girka <thib@sitedethib.com>2018-06-21 20:49:57 +0200
commitab5f450700085ce73621b28b813f2edc5f199785 (patch)
tree766214b52ed217903ae821285391f8e2d4b5f545 /app/models
parent26c20a4ec7868753b284670575f28f201a5cef9f (diff)
parent7f59206944193591d7aef5cbd73edc7f5303add7 (diff)
Merge branch 'master' into glitch-soc/merge-upstream
Conflicts:
	app/models/user.rb

Resolved by adding :default_language to user settings fields
Diffstat (limited to 'app/models')
-rw-r--r--app/models/account.rb2
-rw-r--r--app/models/concerns/attachmentable.rb4
-rw-r--r--app/models/status.rb6
-rw-r--r--app/models/user.rb7
4 files changed, 12 insertions, 7 deletions
diff --git a/app/models/account.rb b/app/models/account.rb
index 48f284785..5099e4953 100644
--- a/app/models/account.rb
+++ b/app/models/account.rb
@@ -144,7 +144,7 @@ class Account < ApplicationRecord
            prefix: true,
            allow_nil: true
 
-  delegate :filtered_languages, to: :user, prefix: false, allow_nil: true
+  delegate :chosen_languages, to: :user, prefix: false, allow_nil: true
 
   def local?
     domain.nil?
diff --git a/app/models/concerns/attachmentable.rb b/app/models/concerns/attachmentable.rb
index 6f8489b89..db63c3eca 100644
--- a/app/models/concerns/attachmentable.rb
+++ b/app/models/concerns/attachmentable.rb
@@ -41,7 +41,9 @@ module Attachmentable
 
     extensions_for_mime_type = mime_type.empty? ? [] : mime_type.first.extensions
     original_extension       = Paperclip::Interpolations.extension(attachment, :original)
+    proper_extension         = extensions_for_mime_type.first.to_s
+    proper_extension         = 'jpeg' if proper_extension == 'jpe'
 
-    extensions_for_mime_type.include?(original_extension) ? original_extension : extensions_for_mime_type.first
+    extensions_for_mime_type.include?(original_extension) ? original_extension : proper_extension
   end
 end
diff --git a/app/models/status.rb b/app/models/status.rb
index c0e241ddd..398462302 100644
--- a/app/models/status.rb
+++ b/app/models/status.rb
@@ -197,8 +197,8 @@ class Status < ApplicationRecord
   before_validation :set_local
 
   class << self
-    def not_in_filtered_languages(account)
-      where(language: nil).or where.not(language: account.filtered_languages)
+    def in_chosen_languages(account)
+      where(language: nil).or where(language: account.chosen_languages)
     end
 
     def as_home_timeline(account)
@@ -344,7 +344,7 @@ class Status < ApplicationRecord
     def filter_timeline_for_account(query, account, local_only)
       query = query.not_excluded_by_account(account)
       query = query.not_domain_blocked_by_account(account) unless local_only
-      query = query.not_in_filtered_languages(account) if account.filtered_languages.present?
+      query = query.in_chosen_languages(account) if account.chosen_languages.present?
       query.merge(account_silencing_filter(account))
     end
 
diff --git a/app/models/user.rb b/app/models/user.rb
index ef48282fd..3e1b82962 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -35,6 +35,7 @@
 #  moderator                 :boolean          default(FALSE), not null
 #  invite_id                 :bigint(8)
 #  remember_token            :string
+#  chosen_languages          :string           is an Array
 #
 
 class User < ApplicationRecord
@@ -88,7 +89,7 @@ class User < ApplicationRecord
 
   delegate :auto_play_gif, :default_sensitive, :unfollow_modal, :boost_modal, :favourite_modal, :delete_modal,
            :reduce_motion, :system_font_ui, :noindex, :flavour, :skin, :display_sensitive_media, :hide_network,
-           to: :settings, prefix: :setting, allow_nil: false
+           :default_language, to: :settings, prefix: :setting, allow_nil: false
 
   attr_accessor :invite_code
 
@@ -317,7 +318,9 @@ class User < ApplicationRecord
   private
 
   def sanitize_languages
-    filtered_languages.reject!(&:blank?)
+    return if chosen_languages.nil?
+    chosen_languages.reject!(&:blank?)
+    self.chosen_languages = nil if chosen_languages.empty?
   end
 
   def prepare_new_user!