Skip to content

Commit c9d1ece

Browse files
ClearlyClairehiyuki2578
authored andcommitted
Add toot source to delete result to ease Delete & Redraft (mastodon#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
1 parent 80d875e commit c9d1ece

4 files changed

Lines changed: 14 additions & 6 deletions

File tree

app/controllers/api/v1/statuses_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def destroy
6565

6666
RemovalWorker.perform_async(@status.id)
6767

68-
render_empty
68+
render json: @status, serializer: REST::StatusSerializer, source_requested: true
6969
end
7070

7171
private

app/javascript/mastodon/actions/statuses.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,11 @@ export function fetchStatusFail(id, error, skipLoading) {
131131
};
132132
};
133133

134-
export function redraft(status) {
134+
export function redraft(status, raw_text) {
135135
return {
136136
type: REDRAFT,
137137
status,
138+
raw_text,
138139
};
139140
};
140141

@@ -148,13 +149,13 @@ export function deleteStatus(id, router, withRedraft = false) {
148149

149150
dispatch(deleteStatusRequest(id));
150151

151-
api(getState).delete(`/api/v1/statuses/${id}`).then(() => {
152+
api(getState).delete(`/api/v1/statuses/${id}`).then(response => {
152153
evictStatus(id);
153154
dispatch(deleteStatusSuccess(id));
154155
dispatch(deleteFromTimelines(id));
155156

156157
if (withRedraft) {
157-
dispatch(redraft(status));
158+
dispatch(redraft(status, response.data.text));
158159

159160
if (!getState().getIn(['compose', 'mounted'])) {
160161
router.push('/statuses/new');

app/javascript/mastodon/reducers/compose.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ export default function compose(state = initialState, action) {
331331
}));
332332
case REDRAFT:
333333
return state.withMutations(map => {
334-
map.set('text', unescapeHTML(expandMentions(action.status)));
334+
map.set('text', action.raw_content || unescapeHTML(expandMentions(action.status)));
335335
map.set('in_reply_to', action.status.get('in_reply_to_id'));
336336
map.set('privacy', action.status.get('visibility'));
337337
map.set('media_attachments', action.status.get('media_attachments'));

app/serializers/rest/status_serializer.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@
33
class REST::StatusSerializer < ActiveModel::Serializer
44
attributes :id, :created_at, :in_reply_to_id, :in_reply_to_account_id,
55
:sensitive, :spoiler_text, :visibility, :language,
6-
:uri, :content, :url, :replies_count, :reblogs_count,
6+
:uri, :url, :replies_count, :reblogs_count,
77
:favourites_count
88

99
attribute :favourited, if: :current_user?
1010
attribute :reblogged, if: :current_user?
1111
attribute :muted, if: :current_user?
1212
attribute :pinned, if: :pinnable?
1313

14+
attribute :content, unless: :source_requested?
15+
attribute :text, if: :source_requested?
16+
1417
belongs_to :reblog, serializer: REST::StatusSerializer
1518
belongs_to :application, if: :show_application?
1619
belongs_to :account, serializer: REST::AccountSerializer
@@ -105,6 +108,10 @@ def pinnable?
105108
%w(public unlisted).include?(object.visibility)
106109
end
107110

111+
def source_requested?
112+
instance_options[:source_requested]
113+
end
114+
108115
def ordered_mentions
109116
object.active_mentions.to_a.sort_by(&:id)
110117
end

0 commit comments

Comments
 (0)