about summary refs log tree commit diff
path: root/app/models
diff options
context:
space:
mode:
authorkibigo! <marrus-sh@users.noreply.github.com>2017-07-12 02:03:17 -0700
committerkibigo! <marrus-sh@users.noreply.github.com>2017-07-12 02:03:17 -0700
commit79d898ae0ad8c0e66bd63ec3e0904e9e5e7894e8 (patch)
treeee8d832ed2f11e9afe62daf0e586a86004eb8d98 /app/models
parentbcf7ee48e94cd2e4d2de28e8854e7f0e2b5cad1f (diff)
parent056b5ed72f6d980bceeb49eb249b8365fe8fce66 (diff)
Merge upstream!! #64 <3 <3
Diffstat (limited to 'app/models')
-rw-r--r--app/models/concerns/remotable.rb23
-rw-r--r--app/models/context.rb5
-rw-r--r--app/models/feed.rb3
-rw-r--r--app/models/form/admin_settings.rb29
-rw-r--r--app/models/media_attachment.rb2
-rw-r--r--app/models/search.rb5
-rw-r--r--app/models/session_activation.rb4
-rw-r--r--app/models/user.rb8
8 files changed, 70 insertions, 9 deletions
diff --git a/app/models/concerns/remotable.rb b/app/models/concerns/remotable.rb
index 4a412ee3d..b4f169649 100644
--- a/app/models/concerns/remotable.rb
+++ b/app/models/concerns/remotable.rb
@@ -6,11 +6,16 @@ module Remotable
 
   included do
     attachment_definitions.each_key do |attachment_name|
-      attribute_name = "#{attachment_name}_remote_url".to_sym
-      method_name = "#{attribute_name}=".to_sym
+      attribute_name  = "#{attachment_name}_remote_url".to_sym
+      method_name     = "#{attribute_name}=".to_sym
+      alt_method_name = "reset_#{attachment_name}!".to_sym
 
       define_method method_name do |url|
-        parsed_url = Addressable::URI.parse(url).normalize
+        begin
+          parsed_url = Addressable::URI.parse(url).normalize
+        rescue Addressable::URI::InvalidURIError
+          return
+        end
 
         return if !%w(http https).include?(parsed_url.scheme) || parsed_url.host.empty? || self[attribute_name] == url
 
@@ -26,10 +31,20 @@ module Remotable
           send("#{attachment_name}_file_name=", filename)
 
           self[attribute_name] = url if has_attribute?(attribute_name)
-        rescue HTTP::TimeoutError, OpenSSL::SSL::SSLError, Paperclip::Errors::NotIdentifiedByImageMagickError => e
+        rescue HTTP::TimeoutError, HTTP::ConnectionError, OpenSSL::SSL::SSLError, Paperclip::Errors::NotIdentifiedByImageMagickError, Addressable::URI::InvalidURIError => e
           Rails.logger.debug "Error fetching remote #{attachment_name}: #{e}"
+          nil
         end
       end
+
+      define_method alt_method_name do
+        url = self[attribute_name]
+
+        return if url.blank?
+
+        self[attribute_name] = ''
+        send(method_name, url)
+      end
     end
   end
 end
diff --git a/app/models/context.rb b/app/models/context.rb
new file mode 100644
index 000000000..cc667999e
--- /dev/null
+++ b/app/models/context.rb
@@ -0,0 +1,5 @@
+# frozen_string_literal: true
+
+class Context < ActiveModelSerializers::Model
+  attributes :ancestors, :descendants
+end
diff --git a/app/models/feed.rb b/app/models/feed.rb
index 5125e51ff..beb4a8de3 100644
--- a/app/models/feed.rb
+++ b/app/models/feed.rb
@@ -20,8 +20,7 @@ class Feed
     max_id     = '+inf' if max_id.blank?
     since_id   = '-inf' if since_id.blank?
     unhydrated = redis.zrevrangebyscore(key, "(#{max_id}", "(#{since_id}", limit: [0, limit], with_scores: true).map(&:last).map(&:to_i)
-    status_map = Status.where(id: unhydrated).cache_ids.map { |s| [s.id, s] }.to_h
-    unhydrated.map { |id| status_map[id] }.compact
+    Status.where(id: unhydrated).cache_ids
   end
 
   def from_database(limit, max_id, since_id)
diff --git a/app/models/form/admin_settings.rb b/app/models/form/admin_settings.rb
new file mode 100644
index 000000000..c3a04ba65
--- /dev/null
+++ b/app/models/form/admin_settings.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+class Form::AdminSettings
+  include ActiveModel::Model
+
+  delegate(
+    :site_contact_username,
+    :site_contact_username=,
+    :site_contact_email,
+    :site_contact_email=,
+    :site_title,
+    :site_title=,
+    :site_description,
+    :site_description=,
+    :site_extended_description,
+    :site_extended_description=,
+    :site_terms,
+    :site_terms=,
+    :open_registrations,
+    :open_registrations=,
+    :closed_registrations_message,
+    :closed_registrations_message=,
+    :open_deletion,
+    :open_deletion=,
+    :timeline_preview,
+    :timeline_preview=,
+    to: Setting
+  )
+end
diff --git a/app/models/media_attachment.rb b/app/models/media_attachment.rb
index 340109ab6..1e8c6d00a 100644
--- a/app/models/media_attachment.rb
+++ b/app/models/media_attachment.rb
@@ -18,6 +18,8 @@
 #  file_meta         :json
 #
 
+require 'mime/types'
+
 class MediaAttachment < ApplicationRecord
   self.inheritance_column = nil
 
diff --git a/app/models/search.rb b/app/models/search.rb
new file mode 100644
index 000000000..676c2a7f8
--- /dev/null
+++ b/app/models/search.rb
@@ -0,0 +1,5 @@
+# frozen_string_literal: true
+
+class Search < ActiveModelSerializers::Model
+  attributes :accounts, :statuses, :hashtags
+end
diff --git a/app/models/session_activation.rb b/app/models/session_activation.rb
index 02a918e8a..887e3e3bd 100644
--- a/app/models/session_activation.rb
+++ b/app/models/session_activation.rb
@@ -69,9 +69,7 @@ class SessionActivation < ApplicationRecord
   def assign_access_token
     superapp = Doorkeeper::Application.find_by(superapp: true)
 
-    return if superapp.nil?
-
-    self.access_token = Doorkeeper::AccessToken.create!(application_id: superapp.id,
+    self.access_token = Doorkeeper::AccessToken.create!(application_id: superapp&.id,
                                                         resource_owner_id: user_id,
                                                         scopes: 'read write follow',
                                                         expires_in: Doorkeeper.configuration.access_token_expires_in,
diff --git a/app/models/user.rb b/app/models/user.rb
index c31a0c644..c80115a08 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -79,6 +79,10 @@ class User < ApplicationRecord
     settings.default_privacy || (account.locked? ? 'private' : 'public')
   end
 
+  def setting_default_sensitive
+    settings.default_sensitive
+  end
+
   def setting_boost_modal
     settings.boost_modal
   end
@@ -91,6 +95,10 @@ class User < ApplicationRecord
     settings.auto_play_gif
   end
 
+  def setting_system_font_ui
+    settings.system_font_ui
+  end
+
   def activate_session(request)
     session_activations.activate(session_id: SecureRandom.hex,
                                  user_agent: request.user_agent,