Commit 7219c9b5 authored by 2458773093's avatar 2458773093

service + seerializer completed

parent cdc0b8dd
# frozen_string_literal: true # frozen_string_literal: true
class REST::StatusSerializer < ActiveModel::Serializer 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, :sensitive, :spoiler_text, :visibility, :language,
:uri, :url, :replies_count, :reblogs_count, :uri, :url, :replies_count, :reblogs_count,
:favourites_count, :quote_of_id :favourites_count, :quote_of_id
......
...@@ -25,9 +25,11 @@ class EditStatusService < BaseService ...@@ -25,9 +25,11 @@ class EditStatusService < BaseService
validate_media! validate_media!
preprocess_attributes! preprocess_attributes!
revision_text = prepare_revision_text
process_status! process_status!
postprocess_status! postprocess_status!
create_revision! revision_text
redis.setex(idempotency_key, 3_600, @status.id) if idempotency_given? redis.setex(idempotency_key, 3_600, @status.id) if idempotency_given?
...@@ -60,6 +62,25 @@ class EditStatusService < BaseService ...@@ -60,6 +62,25 @@ class EditStatusService < BaseService
LinkCrawlWorker.perform_async(@status.id) unless @status.spoiler_text? LinkCrawlWorker.perform_async(@status.id) unless @status.spoiler_text?
end 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! def validate_media!
return if @options[:media_ids].blank? || !@options[:media_ids].is_a?(Enumerable) return if @options[:media_ids].blank? || !@options[:media_ids].is_a?(Enumerable)
...@@ -100,6 +121,7 @@ class EditStatusService < BaseService ...@@ -100,6 +121,7 @@ class EditStatusService < BaseService
def status_attributes def status_attributes
{ {
revised_at: Time.now,
text: @text, text: @text,
media_attachments: @media || [], media_attachments: @media || [],
sensitive: (@options[:sensitive].nil? ? @account.user&.setting_default_sensitive : @options[:sensitive]) || @options[:spoiler_text].present?, 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