about summary refs log tree commit diff
path: root/app/serializers
diff options
context:
space:
mode:
authorOndřej Hruška <ondra@ondrovo.com>2017-09-28 09:18:35 +0200
committerOndřej Hruška <ondra@ondrovo.com>2017-09-28 09:18:35 +0200
commit83bda6c1a813c5aeb131b18a0500fed0c07fa9c2 (patch)
tree32f197901b4b16ea7f94de682fee6cdc44686045 /app/serializers
parentfcf0d2078ea813e0dd318fa154d620018e7b7bcf (diff)
parentb9f59ebcc68e9da0a7158741a1a2ef3564e1321e (diff)
Merge commit 'b9f59ebcc68e9da0a7158741a1a2ef3564e1321e' into merging-upstream
Diffstat (limited to 'app/serializers')
-rw-r--r--app/serializers/activitypub/collection_serializer.rb25
-rw-r--r--app/serializers/activitypub/delete_serializer.rb2
-rw-r--r--app/serializers/activitypub/note_serializer.rb6
-rw-r--r--app/serializers/initial_state_serializer.rb18
-rw-r--r--app/serializers/rest/account_serializer.rb4
-rw-r--r--app/serializers/rest/application_serializer.rb4
-rw-r--r--app/serializers/rest/custom_emoji_serializer.rb11
-rw-r--r--app/serializers/rest/media_attachment_serializer.rb4
-rw-r--r--app/serializers/rest/notification_serializer.rb4
-rw-r--r--app/serializers/rest/relationship_serializer.rb4
-rw-r--r--app/serializers/rest/report_serializer.rb4
-rw-r--r--app/serializers/rest/status_serializer.rb28
12 files changed, 86 insertions, 28 deletions
diff --git a/app/serializers/activitypub/collection_serializer.rb b/app/serializers/activitypub/collection_serializer.rb
index d01dead28..9832133fc 100644
--- a/app/serializers/activitypub/collection_serializer.rb
+++ b/app/serializers/activitypub/collection_serializer.rb
@@ -3,23 +3,38 @@
 class ActivityPub::CollectionSerializer < ActiveModel::Serializer
   def self.serializer_for(model, options)
     return ActivityPub::ActivitySerializer if model.class.name == 'Status'
+    return ActivityPub::CollectionSerializer if model.class.name == 'ActivityPub::CollectionPresenter'
     super
   end
 
   attributes :id, :type, :total_items
+  attribute :next, if: -> { object.next.present? }
+  attribute :prev, if: -> { object.prev.present? }
+  attribute :part_of, if: -> { object.part_of.present? }
 
-  has_many :items, key: :ordered_items
+  has_one :first, if: -> { object.first.present? }
+  has_many :items, key: :items, if: -> { (object.items.present? || page?) && !ordered? }
+  has_many :items, key: :ordered_items, if: -> { (object.items.present? || page?) && ordered? }
 
   def type
-    case object.type
-    when :ordered
-      'OrderedCollection'
+    if page?
+      ordered? ? 'OrderedCollectionPage' : 'CollectionPage'
     else
-      'Collection'
+      ordered? ? 'OrderedCollection' : 'Collection'
     end
   end
 
   def total_items
     object.size
   end
+
+  private
+
+  def ordered?
+    object.type == :ordered
+  end
+
+  def page?
+    object.part_of.present?
+  end
 end
diff --git a/app/serializers/activitypub/delete_serializer.rb b/app/serializers/activitypub/delete_serializer.rb
index 87a43b95d..2bb65135f 100644
--- a/app/serializers/activitypub/delete_serializer.rb
+++ b/app/serializers/activitypub/delete_serializer.rb
@@ -13,7 +13,7 @@ class ActivityPub::DeleteSerializer < ActiveModel::Serializer
     end
 
     def atom_uri
-      ::TagManager.instance.uri_for(object)
+      OStatus::TagManager.instance.uri_for(object)
     end
   end
 
diff --git a/app/serializers/activitypub/note_serializer.rb b/app/serializers/activitypub/note_serializer.rb
index e5d8e3f03..f94c3b9dc 100644
--- a/app/serializers/activitypub/note_serializer.rb
+++ b/app/serializers/activitypub/note_serializer.rb
@@ -63,13 +63,13 @@ class ActivityPub::NoteSerializer < ActiveModel::Serializer
   def atom_uri
     return unless object.local?
 
-    ::TagManager.instance.uri_for(object)
+    OStatus::TagManager.instance.uri_for(object)
   end
 
   def in_reply_to_atom_uri
     return unless object.reply? && !object.thread.nil?
 
-    ::TagManager.instance.uri_for(object.thread)
+    OStatus::TagManager.instance.uri_for(object.thread)
   end
 
   def conversation
@@ -78,7 +78,7 @@ class ActivityPub::NoteSerializer < ActiveModel::Serializer
     if object.conversation.uri?
       object.conversation.uri
     else
-      TagManager.instance.unique_tag(object.conversation.created_at, object.conversation.id, 'Conversation')
+      OStatus::TagManager.instance.unique_tag(object.conversation.created_at, object.conversation.id, 'Conversation')
     end
   end
 
diff --git a/app/serializers/initial_state_serializer.rb b/app/serializers/initial_state_serializer.rb
index 32ffcc688..e2f15a601 100644
--- a/app/serializers/initial_state_serializer.rb
+++ b/app/serializers/initial_state_serializer.rb
@@ -4,17 +4,23 @@ class InitialStateSerializer < ActiveModel::Serializer
   attributes :meta, :compose, :accounts,
              :media_attachments, :settings, :push_subscription
 
+  has_many :custom_emojis, serializer: REST::CustomEmojiSerializer
+
+  def custom_emojis
+    CustomEmoji.local
+  end
+
   def meta
     store = {
       streaming_api_base_url: Rails.configuration.x.streaming_api_base_url,
       access_token: object.token,
       locale: I18n.locale,
       domain: Rails.configuration.x.local_domain,
-      admin: object.admin&.id,
+      admin: object.admin&.id&.to_s,
     }
 
     if object.current_account
-      store[:me]             = object.current_account.id
+      store[:me]             = object.current_account.id.to_s
       store[:unfollow_modal] = object.current_account.user.setting_unfollow_modal
       store[:boost_modal]    = object.current_account.user.setting_boost_modal
       store[:delete_modal]   = object.current_account.user.setting_delete_modal
@@ -28,7 +34,7 @@ class InitialStateSerializer < ActiveModel::Serializer
     store = {}
 
     if object.current_account
-      store[:me]                = object.current_account.id
+      store[:me]                = object.current_account.id.to_s
       store[:default_privacy]   = object.current_account.user.setting_default_privacy
       store[:default_sensitive] = object.current_account.user.setting_default_sensitive
     end
@@ -40,12 +46,12 @@ class InitialStateSerializer < ActiveModel::Serializer
 
   def accounts
     store = {}
-    store[object.current_account.id] = ActiveModelSerializers::SerializableResource.new(object.current_account, serializer: REST::AccountSerializer) if object.current_account
-    store[object.admin.id]           = ActiveModelSerializers::SerializableResource.new(object.admin, serializer: REST::AccountSerializer) if object.admin
+    store[object.current_account.id.to_s] = ActiveModelSerializers::SerializableResource.new(object.current_account, serializer: REST::AccountSerializer) if object.current_account
+    store[object.admin.id.to_s]           = ActiveModelSerializers::SerializableResource.new(object.admin, serializer: REST::AccountSerializer) if object.admin
     store
   end
 
   def media_attachments
-    { accept_content_types: MediaAttachment::IMAGE_MIME_TYPES + MediaAttachment::VIDEO_MIME_TYPES }
+    { accept_content_types: MediaAttachment::IMAGE_FILE_EXTENSIONS + MediaAttachment::VIDEO_FILE_EXTENSIONS + MediaAttachment::IMAGE_MIME_TYPES + MediaAttachment::VIDEO_MIME_TYPES }
   end
 end
diff --git a/app/serializers/rest/account_serializer.rb b/app/serializers/rest/account_serializer.rb
index 012a4fd18..65fdb0308 100644
--- a/app/serializers/rest/account_serializer.rb
+++ b/app/serializers/rest/account_serializer.rb
@@ -7,6 +7,10 @@ class REST::AccountSerializer < ActiveModel::Serializer
              :note, :url, :avatar, :avatar_static, :header, :header_static,
              :followers_count, :following_count, :statuses_count
 
+  def id
+    object.id.to_s
+  end
+
   def note
     Formatter.instance.simplified_format(object)
   end
diff --git a/app/serializers/rest/application_serializer.rb b/app/serializers/rest/application_serializer.rb
index 868a62f1e..a8945f66e 100644
--- a/app/serializers/rest/application_serializer.rb
+++ b/app/serializers/rest/application_serializer.rb
@@ -4,6 +4,10 @@ class REST::ApplicationSerializer < ActiveModel::Serializer
   attributes :id, :name, :website, :redirect_uri,
              :client_id, :client_secret
 
+  def id
+    object.id.to_s
+  end
+
   def client_id
     object.uid
   end
diff --git a/app/serializers/rest/custom_emoji_serializer.rb b/app/serializers/rest/custom_emoji_serializer.rb
new file mode 100644
index 000000000..b744dd4ec
--- /dev/null
+++ b/app/serializers/rest/custom_emoji_serializer.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+class REST::CustomEmojiSerializer < ActiveModel::Serializer
+  include RoutingHelper
+
+  attributes :shortcode, :url
+
+  def url
+    full_asset_url(object.image.url)
+  end
+end
diff --git a/app/serializers/rest/media_attachment_serializer.rb b/app/serializers/rest/media_attachment_serializer.rb
index 31189406a..f6e7c79d1 100644
--- a/app/serializers/rest/media_attachment_serializer.rb
+++ b/app/serializers/rest/media_attachment_serializer.rb
@@ -6,6 +6,10 @@ class REST::MediaAttachmentSerializer < ActiveModel::Serializer
   attributes :id, :type, :url, :preview_url,
              :remote_url, :text_url, :meta
 
+  def id
+    object.id.to_s
+  end
+
   def url
     if object.needs_redownload?
       media_proxy_url(object.id, :original)
diff --git a/app/serializers/rest/notification_serializer.rb b/app/serializers/rest/notification_serializer.rb
index f95d099a3..541a6b8b5 100644
--- a/app/serializers/rest/notification_serializer.rb
+++ b/app/serializers/rest/notification_serializer.rb
@@ -6,6 +6,10 @@ class REST::NotificationSerializer < ActiveModel::Serializer
   belongs_to :from_account, key: :account, serializer: REST::AccountSerializer
   belongs_to :target_status, key: :status, if: :status_type?, serializer: REST::StatusSerializer
 
+  def id
+    object.id.to_s
+  end
+
   def status_type?
     [:favourite, :reblog, :mention].include?(object.type)
   end
diff --git a/app/serializers/rest/relationship_serializer.rb b/app/serializers/rest/relationship_serializer.rb
index 1d431aa1b..998727e37 100644
--- a/app/serializers/rest/relationship_serializer.rb
+++ b/app/serializers/rest/relationship_serializer.rb
@@ -4,6 +4,10 @@ class REST::RelationshipSerializer < ActiveModel::Serializer
   attributes :id, :following, :followed_by, :blocking,
              :muting, :requested, :domain_blocking
 
+  def id
+    object.id.to_s
+  end
+
   def following
     instance_options[:relationships].following[object.id] || false
   end
diff --git a/app/serializers/rest/report_serializer.rb b/app/serializers/rest/report_serializer.rb
index 0c6bd6556..ecb88d653 100644
--- a/app/serializers/rest/report_serializer.rb
+++ b/app/serializers/rest/report_serializer.rb
@@ -2,4 +2,8 @@
 
 class REST::ReportSerializer < ActiveModel::Serializer
   attributes :id, :action_taken
+
+  def id
+    object.id.to_s
+  end
 end
diff --git a/app/serializers/rest/status_serializer.rb b/app/serializers/rest/status_serializer.rb
index d8efa8e60..e6270f902 100644
--- a/app/serializers/rest/status_serializer.rb
+++ b/app/serializers/rest/status_serializer.rb
@@ -17,14 +17,26 @@ class REST::StatusSerializer < ActiveModel::Serializer
   has_many :media_attachments, serializer: REST::MediaAttachmentSerializer
   has_many :mentions
   has_many :tags
-  has_many :emojis
+  has_many :emojis, serializer: REST::CustomEmojiSerializer
+
+  def id
+    object.id.to_s
+  end
+
+  def in_reply_to_id
+    object.in_reply_to_id&.to_s
+  end
+
+  def in_reply_to_account_id
+    object.in_reply_to_account_id&.to_s
+  end
 
   def current_user?
     !current_user.nil?
   end
 
   def uri
-    TagManager.instance.uri_for(object)
+    OStatus::TagManager.instance.uri_for(object)
   end
 
   def content
@@ -82,7 +94,7 @@ class REST::StatusSerializer < ActiveModel::Serializer
     attributes :id, :username, :url, :acct
 
     def id
-      object.account_id
+      object.account_id.to_s
     end
 
     def username
@@ -107,14 +119,4 @@ class REST::StatusSerializer < ActiveModel::Serializer
       tag_url(object)
     end
   end
-
-  class CustomEmojiSerializer < ActiveModel::Serializer
-    include RoutingHelper
-
-    attributes :shortcode, :url
-
-    def url
-      full_asset_url(object.image.url)
-    end
-  end
 end