about summary refs log tree commit diff
path: root/app/serializers
diff options
context:
space:
mode:
authorStarfall <root@starfall.blue>2020-02-04 17:44:29 -0600
committerStarfall <root@starfall.blue>2020-02-04 17:44:29 -0600
commit6d24d3bcb84abd04f31da95f97f6d60ef0afdc00 (patch)
treee7c38251a9e92bdf3a464b4aa7f1880aa5139bf0 /app/serializers
parentc0c9529df269816f52915a9802e5e30fbce9576b (diff)
parent885e9227c6e8e1ce5e4a5625d5126ba76dce2c00 (diff)
Merge branch 'glitch'
Diffstat (limited to 'app/serializers')
-rw-r--r--app/serializers/rest/account_serializer.rb8
-rw-r--r--app/serializers/rest/announcement_serializer.rb45
-rw-r--r--app/serializers/rest/reaction_serializer.rb31
3 files changed, 84 insertions, 0 deletions
diff --git a/app/serializers/rest/account_serializer.rb b/app/serializers/rest/account_serializer.rb
index 7bdb5d7ff..4e497cdbd 100644
--- a/app/serializers/rest/account_serializer.rb
+++ b/app/serializers/rest/account_serializer.rb
@@ -24,6 +24,10 @@ class REST::AccountSerializer < ActiveModel::Serializer
     object.id.to_s
   end
 
+  def acct
+    object.pretty_acct
+  end
+
   def note
     Formatter.instance.simplified_format(object)
   end
@@ -52,6 +56,10 @@ class REST::AccountSerializer < ActiveModel::Serializer
     object.moved? && object.moved_to_account.moved_to_account_id.nil?
   end
 
+  def last_status_at
+    object.last_status_at&.to_date&.iso8601
+  end
+
   def followers_count
     (Setting.hide_followers_count || object.user&.setting_hide_followers_count) ? -1 : object.followers_count
   end
diff --git a/app/serializers/rest/announcement_serializer.rb b/app/serializers/rest/announcement_serializer.rb
new file mode 100644
index 000000000..ae72f9ace
--- /dev/null
+++ b/app/serializers/rest/announcement_serializer.rb
@@ -0,0 +1,45 @@
+# frozen_string_literal: true
+
+class REST::AnnouncementSerializer < ActiveModel::Serializer
+  attributes :id, :content, :starts_at, :ends_at, :all_day,
+             :published_at, :updated_at
+
+  attribute :read, if: :current_user?
+
+  has_many :mentions
+  has_many :tags, serializer: REST::StatusSerializer::TagSerializer
+  has_many :emojis, serializer: REST::CustomEmojiSerializer
+  has_many :reactions, serializer: REST::ReactionSerializer
+
+  def current_user?
+    !current_user.nil?
+  end
+
+  def id
+    object.id.to_s
+  end
+
+  def read
+    object.announcement_mutes.where(account: current_user.account).exists?
+  end
+
+  def content
+    Formatter.instance.linkify(object.text)
+  end
+
+  def reactions
+    object.reactions(current_user&.account)
+  end
+
+  class AccountSerializer < ActiveModel::Serializer
+    attributes :id, :username, :url, :acct
+
+    def id
+      object.id.to_s
+    end
+
+    def url
+      ActivityPub::TagManager.instance.url_for(object)
+    end
+  end
+end
diff --git a/app/serializers/rest/reaction_serializer.rb b/app/serializers/rest/reaction_serializer.rb
new file mode 100644
index 000000000..1a5dca018
--- /dev/null
+++ b/app/serializers/rest/reaction_serializer.rb
@@ -0,0 +1,31 @@
+# frozen_string_literal: true
+
+class REST::ReactionSerializer < ActiveModel::Serializer
+  include RoutingHelper
+
+  attributes :name, :count
+
+  attribute :me, if: :current_user?
+  attribute :url, if: :custom_emoji?
+  attribute :static_url, if: :custom_emoji?
+
+  def count
+    object.respond_to?(:count) ? object.count : 0
+  end
+
+  def current_user?
+    !current_user.nil?
+  end
+
+  def custom_emoji?
+    object.custom_emoji.present?
+  end
+
+  def url
+    full_asset_url(object.custom_emoji.image.url)
+  end
+
+  def static_url
+    full_asset_url(object.custom_emoji.image.url(:static))
+  end
+end