From 4b92e59f4fea4486ee6e5af7421e7945d5f7f998 Mon Sep 17 00:00:00 2001 From: Claire Date: Wed, 18 Jan 2023 16:33:55 +0100 Subject: Add support for editing media description and focus point of already-posted statuses (#20878) * Add backend support for editing media attachments of existing posts * Allow editing media attachments of already-posted toots * Add tests --- app/services/update_status_service.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'app/services/update_status_service.rb') diff --git a/app/services/update_status_service.rb b/app/services/update_status_service.rb index c4c934976..f75fdf55d 100644 --- a/app/services/update_status_service.rb +++ b/app/services/update_status_service.rb @@ -10,6 +10,7 @@ class UpdateStatusService < BaseService # @param [Integer] account_id # @param [Hash] options # @option options [Array] :media_ids + # @option options [Array] :media_attributes # @option options [Hash] :poll # @option options [String] :text # @option options [String] :spoiler_text @@ -50,10 +51,18 @@ class UpdateStatusService < BaseService next_media_attachments = validate_media! added_media_attachments = next_media_attachments - previous_media_attachments + (@options[:media_attributes] || []).each do |attributes| + media = next_media_attachments.find { |attachment| attachment.id == attributes[:id].to_i } + next if media.nil? + + media.update!(attributes.slice(:thumbnail, :description, :focus)) + @media_attachments_changed ||= media.significantly_changed? + end + MediaAttachment.where(id: added_media_attachments.map(&:id)).update_all(status_id: @status.id) @status.ordered_media_attachment_ids = (@options[:media_ids] || []).map(&:to_i) & next_media_attachments.map(&:id) - @media_attachments_changed = previous_media_attachments.map(&:id) != @status.ordered_media_attachment_ids + @media_attachments_changed ||= previous_media_attachments.map(&:id) != @status.ordered_media_attachment_ids @status.media_attachments.reload end -- cgit