Merge remote-tracking branch 'parent/main' into upstream-20240426

This commit is contained in:
KMY 2024-04-26 09:16:08 +09:00
commit c4017eb993
22 changed files with 389 additions and 146 deletions

View file

@ -1,5 +1,16 @@
# frozen_string_literal: true
class REST::AccountWarningSerializer < ActiveModel::Serializer
attributes :id, :action, :text, :status_ids
attributes :id, :action, :text, :status_ids, :created_at
has_one :target_account, serializer: REST::AccountSerializer
has_one :appeal, serializer: REST::AppealSerializer
def id
object.id.to_s
end
def status_ids
object&.status_ids&.map(&:to_s)
end
end

View file

@ -0,0 +1,15 @@
# frozen_string_literal: true
class REST::AppealSerializer < ActiveModel::Serializer
attributes :text, :state
def state
if object.approved?
'approved'
elsif object.rejected?
'rejected'
else
'pending'
end
end
end

View file

@ -3,20 +3,24 @@
class REST::NotificationSerializer < ActiveModel::Serializer
attributes :id, :type, :created_at
has_many :statuses, serializer: REST::StatusSerializer, if: :warning_type?
belongs_to :from_account_web, key: :account, serializer: REST::AccountSerializer
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
belongs_to :emoji_reaction, if: :emoji_reaction_type?, serializer: REST::NotifyEmojiReactionSerializer
belongs_to :account_warning, if: :warning_type?, serializer: REST::AccountWarningSerializer
belongs_to :list, if: :list_status_type?, serializer: REST::ListSerializer
belongs_to :account_relationship_severance_event, key: :event, if: :relationship_severance_event?, serializer: REST::AccountRelationshipSeveranceEventSerializer
belongs_to :account_warning, key: :moderation_warning, if: :moderation_warning_event?, serializer: REST::AccountWarningSerializer
def id
object.id.to_s
end
def from_account
return object.account if moderation_warning_event? # Hide moderator account
object.from_account
end
def status_type?
[:favourite, :emoji_reaction, :reaction, :reblog, :status_reference, :status, :list_status, :mention, :poll, :update].include?(object.type)
end
@ -25,10 +29,6 @@ class REST::NotificationSerializer < ActiveModel::Serializer
object.type == :'admin.report'
end
def warning_type?
object.type == :warning
end
def emoji_reaction_type?
object.type == :emoji_reaction
end
@ -45,7 +45,7 @@ class REST::NotificationSerializer < ActiveModel::Serializer
object.type == :severed_relationships
end
def statuses
Status.where(id: object.account_warning.status_ids).to_a
def moderation_warning_event?
object.type == :moderation_warning
end
end