about summary refs log tree commit diff
path: root/app/serializers/rest/status_serializer.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/serializers/rest/status_serializer.rb')
-rw-r--r--app/serializers/rest/status_serializer.rb61
1 files changed, 58 insertions, 3 deletions
diff --git a/app/serializers/rest/status_serializer.rb b/app/serializers/rest/status_serializer.rb
index b5dcf6208..4433713a7 100644
--- a/app/serializers/rest/status_serializer.rb
+++ b/app/serializers/rest/status_serializer.rb
@@ -6,6 +6,9 @@ class REST::StatusSerializer < ActiveModel::Serializer
              :uri, :url, :replies_count, :reblogs_count,
              :favourites_count
 
+  # Monsterfork additions
+  attributes :updated_at, :edited, :nest_level, :root
+
   attribute :favourited, if: :current_user?
   attribute :reblogged, if: :current_user?
   attribute :muted, if: :current_user?
@@ -13,22 +16,32 @@ class REST::StatusSerializer < ActiveModel::Serializer
   attribute :pinned, if: :pinnable?
   attribute :local_only if :local?
 
-  attribute :content, unless: :source_requested?
+  attribute :content
   attribute :text, if: :source_requested?
   attribute :content_type, if: :source_requested?
 
+  attribute :published if :local?
+  attribute :hidden, if: :current_user?
+  attribute :notify, if: :locally_owned?
+  attribute :title?, key: :article
+  attribute :article_content, if: :title?
+  attribute :publish_at, if: :locally_owned?
+  attribute :expires_at, if: :locally_owned?
+
   belongs_to :reblog, serializer: REST::StatusSerializer
   belongs_to :application, if: :show_application?
   belongs_to :account, serializer: REST::AccountSerializer
 
   has_many :media_attachments, serializer: REST::MediaAttachmentSerializer
   has_many :ordered_mentions, key: :mentions
-  has_many :tags
+  has_many :ordered_tags, key: :tags
   has_many :emojis, serializer: REST::CustomEmojiSerializer
 
   has_one :preview_card, key: :card, serializer: REST::PreviewCardSerializer
   has_one :preloadable_poll, key: :poll, serializer: REST::PollSerializer
 
+  has_many :domain_permissions, serializer: REST::StatusDomainPermissionSerializer, if: :locally_owned?
+
   def id
     object.id.to_s
   end
@@ -45,8 +58,22 @@ class REST::StatusSerializer < ActiveModel::Serializer
     !current_user.nil?
   end
 
+  def owned?
+    current_user? && current_user.account_id == object.account_id
+  end
+
+  def locally_owned?
+    object.local? && owned?
+  end
+
+  def title?
+    return @has_title if defined?(@has_title)
+
+    @has_title = object.title.present?
+  end
+
   def show_application?
-    object.account.user_shows_application? || (current_user? && current_user.account_id == object.account_id)
+    object.account.user_shows_application? || owned?
   end
 
   def visibility
@@ -72,14 +99,30 @@ class REST::StatusSerializer < ActiveModel::Serializer
     ActivityPub::TagManager.instance.uri_for(object)
   end
 
+  def spoiler_text
+    title? ? object.title : object.spoiler_text
+  end
+
   def content
     Formatter.instance.format(object)
   end
 
+  def article_content
+    Formatter.instance.format(object, article_content: true)
+  end
+
+  def text
+    object.original_text.presence || object.text
+  end
+
   def url
     ActivityPub::TagManager.instance.url_for(object)
   end
 
+  def root
+    object.conversation&.root
+  end
+
   def favourited
     if instance_options && instance_options[:relationships]
       instance_options[:relationships].favourites_map[object.id] || false
@@ -104,6 +147,14 @@ class REST::StatusSerializer < ActiveModel::Serializer
     end
   end
 
+  def hidden
+    if instance_options && instance_options[:relationships]
+      instance_options[:relationships].hidden_statuses_map[object.id] || false
+    else
+      current_user.account.muting_status?(object)
+    end
+  end
+
   def bookmarked
     if instance_options && instance_options[:relationships]
       instance_options[:relationships].bookmarks_map[object.id] || false
@@ -135,6 +186,10 @@ class REST::StatusSerializer < ActiveModel::Serializer
     object.active_mentions.to_a.sort_by(&:id)
   end
 
+  def ordered_tags
+    object.tags.order('name')
+  end
+
   class ApplicationSerializer < ActiveModel::Serializer
     attributes :name, :website
   end