Skip to content

Commit

Permalink
Add toot source to delete result to ease Delete & Redraft (mastodon#1…
Browse files Browse the repository at this point in the history
…0669)

* 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
  • Loading branch information
ClearlyClaire authored and Gargron committed May 11, 2019
1 parent 7d31438 commit f93586e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/controllers/api/v1/statuses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def destroy

RemovalWorker.perform_async(@status.id)

render_empty
render json: @status, serializer: REST::StatusSerializer, source_requested: true
end

private
Expand Down
7 changes: 4 additions & 3 deletions app/javascript/mastodon/actions/statuses.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
};

Expand All @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/mastodon/reducers/compose.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
9 changes: 8 additions & 1 deletion app/serializers/rest/status_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
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?
attribute :reblogged, if: :current_user?
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
Expand Down Expand Up @@ -105,6 +108,10 @@ def pinnable?
%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
Expand Down

0 comments on commit f93586e

Please sign in to comment.