Commit 7219c9b5 authored by 2458773093's avatar 2458773093

service + seerializer completed

parent cdc0b8dd
# frozen_string_literal: true
class REST::StatusSerializer < ActiveModel::Serializer
attributes :id, :created_at, :in_reply_to_id, :in_reply_to_account_id,
attributes :id, :created_at, :revised_at, :in_reply_to_id, :in_reply_to_account_id,
:sensitive, :spoiler_text, :visibility, :language,
:uri, :url, :replies_count, :reblogs_count,
:favourites_count, :quote_of_id
......
......@@ -25,9 +25,11 @@ class EditStatusService < BaseService
validate_media!
preprocess_attributes!
revision_text = prepare_revision_text
process_status!
postprocess_status!
create_revision! revision_text
redis.setex(idempotency_key, 3_600, @status.id) if idempotency_given?
......@@ -60,6 +62,25 @@ class EditStatusService < BaseService
LinkCrawlWorker.perform_async(@status.id) unless @status.spoiler_text?
end
def prepare_revision_text
text = @status.text
current_media_ids = @status.media_attachments.pluck(:id)
new_media_ids = @options[:media_ids].take(4).map(&:to_i)
if current_media_ids.sort != new_media_ids.sort
text = "" if text == @options[:text]
text += " [Media attachments changed]"
end
text.strip()
end
def create_revision!(text)
@status.revisions.create!({
text: text
})
end
def validate_media!
return if @options[:media_ids].blank? || !@options[:media_ids].is_a?(Enumerable)
......@@ -100,6 +121,7 @@ class EditStatusService < BaseService
def status_attributes
{
revised_at: Time.now,
text: @text,
media_attachments: @media || [],
sensitive: (@options[:sensitive].nil? ? @account.user&.setting_default_sensitive : @options[:sensitive]) || @options[:spoiler_text].present?,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment