From 2a917031c9bf685842b858c9d4b542743e2b46e8 Mon Sep 17 00:00:00 2001 From: ThibG Date: Sat, 11 May 2019 06:46:43 +0200 Subject: [PATCH] Add toot source to delete result to ease Delete & Redraft (#10669) * Return Status with raw text in raw_content when deleting a status * Use raw content if available on delete & redraft * Rename raw_content to text; do not serialize formatted content when source is requested --- app/controllers/api/v1/statuses_controller.rb | 2 +- app/javascript/mastodon/actions/statuses.js | 7 ++++--- app/javascript/mastodon/reducers/compose.js | 2 +- app/serializers/rest/status_serializer.rb | 9 ++++++++- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/controllers/api/v1/statuses_controller.rb b/app/controllers/api/v1/statuses_controller.rb index f9506971a0..b0e134554f 100644 --- a/app/controllers/api/v1/statuses_controller.rb +++ b/app/controllers/api/v1/statuses_controller.rb @@ -65,7 +65,7 @@ class Api::V1::StatusesController < Api::BaseController RemovalWorker.perform_async(@status.id) - render_empty + render json: @status, serializer: REST::StatusSerializer, source_requested: true end private diff --git a/app/javascript/mastodon/actions/statuses.js b/app/javascript/mastodon/actions/statuses.js index 1794538e2b..3916b9ac14 100644 --- a/app/javascript/mastodon/actions/statuses.js +++ b/app/javascript/mastodon/actions/statuses.js @@ -131,10 +131,11 @@ export function fetchStatusFail(id, error, skipLoading) { }; }; -export function redraft(status) { +export function redraft(status, raw_text) { return { type: REDRAFT, status, + raw_text, }; }; @@ -148,13 +149,13 @@ export function deleteStatus(id, router, withRedraft = false) { dispatch(deleteStatusRequest(id)); - api(getState).delete(`/api/v1/statuses/${id}`).then(() => { + api(getState).delete(`/api/v1/statuses/${id}`).then(response => { evictStatus(id); dispatch(deleteStatusSuccess(id)); dispatch(deleteFromTimelines(id)); if (withRedraft) { - dispatch(redraft(status)); + dispatch(redraft(status, response.data.text)); if (!getState().getIn(['compose', 'mounted'])) { router.push('/statuses/new'); diff --git a/app/javascript/mastodon/reducers/compose.js b/app/javascript/mastodon/reducers/compose.js index 39cc5bd817..85cbdfb17e 100644 --- a/app/javascript/mastodon/reducers/compose.js +++ b/app/javascript/mastodon/reducers/compose.js @@ -331,7 +331,7 @@ export default function compose(state = initialState, action) { })); case REDRAFT: return state.withMutations(map => { - map.set('text', unescapeHTML(expandMentions(action.status))); + map.set('text', action.raw_content || unescapeHTML(expandMentions(action.status))); map.set('in_reply_to', action.status.get('in_reply_to_id')); map.set('privacy', action.status.get('visibility')); map.set('media_attachments', action.status.get('media_attachments')); diff --git a/app/serializers/rest/status_serializer.rb b/app/serializers/rest/status_serializer.rb index 106777b6e9..c9b76cb162 100644 --- a/app/serializers/rest/status_serializer.rb +++ b/app/serializers/rest/status_serializer.rb @@ -3,7 +3,7 @@ class REST::StatusSerializer < ActiveModel::Serializer attributes :id, :created_at, :in_reply_to_id, :in_reply_to_account_id, :sensitive, :spoiler_text, :visibility, :language, - :uri, :content, :url, :replies_count, :reblogs_count, + :uri, :url, :replies_count, :reblogs_count, :favourites_count attribute :favourited, if: :current_user? @@ -11,6 +11,9 @@ class REST::StatusSerializer < ActiveModel::Serializer attribute :muted, if: :current_user? attribute :pinned, if: :pinnable? + attribute :content, unless: :source_requested? + attribute :text, if: :source_requested? + belongs_to :reblog, serializer: REST::StatusSerializer belongs_to :application, if: :show_application? belongs_to :account, serializer: REST::AccountSerializer @@ -105,6 +108,10 @@ class REST::StatusSerializer < ActiveModel::Serializer %w(public unlisted).include?(object.visibility) end + def source_requested? + instance_options[:source_requested] + end + def ordered_mentions object.active_mentions.to_a.sort_by(&:id) end