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
This commit is contained in:
parent
be851321c0
commit
6d44f2441b
4 changed files with 14 additions and 6 deletions
|
@ -65,7 +65,7 @@ class Api::V1::StatusesController < Api::BaseController
|
||||||
|
|
||||||
RemovalWorker.perform_async(@status.id)
|
RemovalWorker.perform_async(@status.id)
|
||||||
|
|
||||||
render_empty
|
render json: @status, serializer: REST::StatusSerializer, source_requested: true
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -131,10 +131,11 @@ export function fetchStatusFail(id, error, skipLoading) {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export function redraft(status) {
|
export function redraft(status, raw_text) {
|
||||||
return {
|
return {
|
||||||
type: REDRAFT,
|
type: REDRAFT,
|
||||||
status,
|
status,
|
||||||
|
raw_text,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -148,13 +149,13 @@ export function deleteStatus(id, router, withRedraft = false) {
|
||||||
|
|
||||||
dispatch(deleteStatusRequest(id));
|
dispatch(deleteStatusRequest(id));
|
||||||
|
|
||||||
api(getState).delete(`/api/v1/statuses/${id}`).then(() => {
|
api(getState).delete(`/api/v1/statuses/${id}`).then(response => {
|
||||||
evictStatus(id);
|
evictStatus(id);
|
||||||
dispatch(deleteStatusSuccess(id));
|
dispatch(deleteStatusSuccess(id));
|
||||||
dispatch(deleteFromTimelines(id));
|
dispatch(deleteFromTimelines(id));
|
||||||
|
|
||||||
if (withRedraft) {
|
if (withRedraft) {
|
||||||
dispatch(redraft(status));
|
dispatch(redraft(status, response.data.text));
|
||||||
|
|
||||||
if (!getState().getIn(['compose', 'mounted'])) {
|
if (!getState().getIn(['compose', 'mounted'])) {
|
||||||
router.push('/statuses/new');
|
router.push('/statuses/new');
|
||||||
|
|
|
@ -331,7 +331,7 @@ export default function compose(state = initialState, action) {
|
||||||
}));
|
}));
|
||||||
case REDRAFT:
|
case REDRAFT:
|
||||||
return state.withMutations(map => {
|
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('in_reply_to', action.status.get('in_reply_to_id'));
|
||||||
map.set('privacy', action.status.get('visibility'));
|
map.set('privacy', action.status.get('visibility'));
|
||||||
map.set('media_attachments', action.status.get('media_attachments'));
|
map.set('media_attachments', action.status.get('media_attachments'));
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
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, :in_reply_to_id, :in_reply_to_account_id,
|
||||||
:sensitive, :spoiler_text, :visibility, :language,
|
:sensitive, :spoiler_text, :visibility, :language,
|
||||||
:uri, :content, :url, :replies_count, :reblogs_count,
|
:uri, :url, :replies_count, :reblogs_count,
|
||||||
:favourites_count
|
:favourites_count
|
||||||
|
|
||||||
attribute :favourited, if: :current_user?
|
attribute :favourited, if: :current_user?
|
||||||
|
@ -11,6 +11,9 @@ class REST::StatusSerializer < ActiveModel::Serializer
|
||||||
attribute :muted, if: :current_user?
|
attribute :muted, if: :current_user?
|
||||||
attribute :pinned, if: :pinnable?
|
attribute :pinned, if: :pinnable?
|
||||||
|
|
||||||
|
attribute :content, unless: :source_requested?
|
||||||
|
attribute :text, if: :source_requested?
|
||||||
|
|
||||||
belongs_to :reblog, serializer: REST::StatusSerializer
|
belongs_to :reblog, serializer: REST::StatusSerializer
|
||||||
belongs_to :application, if: :show_application?
|
belongs_to :application, if: :show_application?
|
||||||
belongs_to :account, serializer: REST::AccountSerializer
|
belongs_to :account, serializer: REST::AccountSerializer
|
||||||
|
@ -105,6 +108,10 @@ class REST::StatusSerializer < ActiveModel::Serializer
|
||||||
%w(public unlisted).include?(object.visibility)
|
%w(public unlisted).include?(object.visibility)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def source_requested?
|
||||||
|
instance_options[:source_requested]
|
||||||
|
end
|
||||||
|
|
||||||
def ordered_mentions
|
def ordered_mentions
|
||||||
object.active_mentions.to_a.sort_by(&:id)
|
object.active_mentions.to_a.sort_by(&:id)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue