about summary refs log tree commit diff
path: root/app/serializers/rest
diff options
context:
space:
mode:
Diffstat (limited to 'app/serializers/rest')
-rw-r--r--app/serializers/rest/admin/domain_allow_serializer.rb9
-rw-r--r--app/serializers/rest/admin/report_serializer.rb2
-rw-r--r--app/serializers/rest/filter_keyword_serializer.rb9
-rw-r--r--app/serializers/rest/filter_result_serializer.rb6
-rw-r--r--app/serializers/rest/filter_serializer.rb8
-rw-r--r--app/serializers/rest/notification_serializer.rb5
-rw-r--r--app/serializers/rest/report_serializer.rb5
-rw-r--r--app/serializers/rest/status_serializer.rb9
-rw-r--r--app/serializers/rest/v1/filter_serializer.rb26
9 files changed, 75 insertions, 4 deletions
diff --git a/app/serializers/rest/admin/domain_allow_serializer.rb b/app/serializers/rest/admin/domain_allow_serializer.rb
new file mode 100644
index 000000000..ebdf33815
--- /dev/null
+++ b/app/serializers/rest/admin/domain_allow_serializer.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+class REST::Admin::DomainAllowSerializer < ActiveModel::Serializer
+  attributes :id, :domain, :created_at
+
+  def id
+    object.id.to_s
+  end
+end
diff --git a/app/serializers/rest/admin/report_serializer.rb b/app/serializers/rest/admin/report_serializer.rb
index 237f41d8e..44b4726e4 100644
--- a/app/serializers/rest/admin/report_serializer.rb
+++ b/app/serializers/rest/admin/report_serializer.rb
@@ -2,7 +2,7 @@
 
 class REST::Admin::ReportSerializer < ActiveModel::Serializer
   attributes :id, :action_taken, :action_taken_at, :category, :comment,
-             :created_at, :updated_at
+             :forwarded, :created_at, :updated_at
 
   has_one :account, serializer: REST::Admin::AccountSerializer
   has_one :target_account, serializer: REST::Admin::AccountSerializer
diff --git a/app/serializers/rest/filter_keyword_serializer.rb b/app/serializers/rest/filter_keyword_serializer.rb
new file mode 100644
index 000000000..dd2ebac6e
--- /dev/null
+++ b/app/serializers/rest/filter_keyword_serializer.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+class REST::FilterKeywordSerializer < ActiveModel::Serializer
+  attributes :id, :keyword, :whole_word
+
+  def id
+    object.id.to_s
+  end
+end
diff --git a/app/serializers/rest/filter_result_serializer.rb b/app/serializers/rest/filter_result_serializer.rb
new file mode 100644
index 000000000..0ef4db79a
--- /dev/null
+++ b/app/serializers/rest/filter_result_serializer.rb
@@ -0,0 +1,6 @@
+# frozen_string_literal: true
+
+class REST::FilterResultSerializer < ActiveModel::Serializer
+  belongs_to :filter, serializer: REST::FilterSerializer
+  has_many :keyword_matches
+end
diff --git a/app/serializers/rest/filter_serializer.rb b/app/serializers/rest/filter_serializer.rb
index 57205630b..98d7edb17 100644
--- a/app/serializers/rest/filter_serializer.rb
+++ b/app/serializers/rest/filter_serializer.rb
@@ -1,10 +1,14 @@
 # frozen_string_literal: true
 
 class REST::FilterSerializer < ActiveModel::Serializer
-  attributes :id, :phrase, :context, :whole_word, :expires_at,
-             :irreversible
+  attributes :id, :title, :context, :expires_at, :filter_action
+  has_many :keywords, serializer: REST::FilterKeywordSerializer, if: :rules_requested?
 
   def id
     object.id.to_s
   end
+
+  def rules_requested?
+    instance_options[:rules_requested]
+  end
 end
diff --git a/app/serializers/rest/notification_serializer.rb b/app/serializers/rest/notification_serializer.rb
index 69b81f6de..137fc53dd 100644
--- a/app/serializers/rest/notification_serializer.rb
+++ b/app/serializers/rest/notification_serializer.rb
@@ -5,6 +5,7 @@ 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
+  belongs_to :report, if: :report_type?, serializer: REST::ReportSerializer
 
   def id
     object.id.to_s
@@ -13,4 +14,8 @@ class REST::NotificationSerializer < ActiveModel::Serializer
   def status_type?
     [:favourite, :reblog, :status, :mention, :poll, :update].include?(object.type)
   end
+
+  def report_type?
+    object.type == :'admin.report'
+  end
 end
diff --git a/app/serializers/rest/report_serializer.rb b/app/serializers/rest/report_serializer.rb
index ecb88d653..de68dfc6d 100644
--- a/app/serializers/rest/report_serializer.rb
+++ b/app/serializers/rest/report_serializer.rb
@@ -1,7 +1,10 @@
 # frozen_string_literal: true
 
 class REST::ReportSerializer < ActiveModel::Serializer
-  attributes :id, :action_taken
+  attributes :id, :action_taken, :action_taken_at, :category, :comment,
+             :forwarded, :created_at, :status_ids, :rule_ids
+
+  has_one :target_account, serializer: REST::AccountSerializer
 
   def id
     object.id.to_s
diff --git a/app/serializers/rest/status_serializer.rb b/app/serializers/rest/status_serializer.rb
index ef2c6c6e5..659c45b83 100644
--- a/app/serializers/rest/status_serializer.rb
+++ b/app/serializers/rest/status_serializer.rb
@@ -14,6 +14,7 @@ class REST::StatusSerializer < ActiveModel::Serializer
   attribute :bookmarked, if: :current_user?
   attribute :pinned, if: :pinnable?
   attribute :local_only if :local?
+  has_many :filtered, serializer: REST::FilterResultSerializer, if: :current_user?
 
   attribute :content, unless: :source_requested?
   attribute :text, if: :source_requested?
@@ -122,6 +123,14 @@ class REST::StatusSerializer < ActiveModel::Serializer
     end
   end
 
+  def filtered
+    if instance_options && instance_options[:relationships]
+      instance_options[:relationships].filters_map[object.id] || []
+    else
+      current_user.account.status_matches_filters(object)
+    end
+  end
+
   def pinnable?
     current_user? &&
       current_user.account_id == object.account_id &&
diff --git a/app/serializers/rest/v1/filter_serializer.rb b/app/serializers/rest/v1/filter_serializer.rb
new file mode 100644
index 000000000..455f17efd
--- /dev/null
+++ b/app/serializers/rest/v1/filter_serializer.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+class REST::V1::FilterSerializer < ActiveModel::Serializer
+  attributes :id, :phrase, :context, :whole_word, :expires_at,
+             :irreversible
+
+  delegate :context, :expires_at, to: :custom_filter
+
+  def id
+    object.id.to_s
+  end
+
+  def phrase
+    object.keyword
+  end
+
+  def irreversible
+    custom_filter.irreversible?
+  end
+
+  private
+
+  def custom_filter
+    object.custom_filter
+  end
+end