Skip to content

Commit

Permalink
fix: local only and content type passing to composer in edit mode
Browse files Browse the repository at this point in the history
  • Loading branch information
mashirozx committed Mar 31, 2022
1 parent ebdb2af commit fec195f
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 7 deletions.
6 changes: 4 additions & 2 deletions app/controllers/api/v1/statuses_controller.rb
Expand Up @@ -52,7 +52,7 @@ def create
with_rate_limit: true,
content_type: status_params[:content_type], #'text/markdown'
local_only: status_params[:local_only],
quote_id: status_params[:quote_id].presence),
quote_id: status_params[:quote_id].presence,
)

render json: @status, serializer: @status.is_a?(ScheduledStatus) ? REST::ScheduledStatusSerializer : REST::StatusSerializer
Expand All @@ -69,7 +69,9 @@ def update
media_ids: status_params[:media_ids],
sensitive: status_params[:sensitive],
spoiler_text: status_params[:spoiler_text],
poll: status_params[:poll]
poll: status_params[:poll],
content_type: status_params[:content_type],
local_only: status_params[:local_only],
)

render json: @status, serializer: REST::StatusSerializer
Expand Down
4 changes: 3 additions & 1 deletion app/javascript/mastodon/actions/compose.js
Expand Up @@ -89,12 +89,14 @@ export const ensureComposeIsVisible = (getState, routerHistory) => {
}
};

export function setComposeToStatus(status, text, spoiler_text) {
export function setComposeToStatus(status, text, spoiler_text, content_type, local_only) {
return{
type: COMPOSE_SET_STATUS,
status,
text,
spoiler_text,
content_type,
local_only,
};
};

Expand Down
3 changes: 2 additions & 1 deletion app/javascript/mastodon/actions/statuses.js
Expand Up @@ -101,9 +101,10 @@ export const editStatus = (id, routerHistory) => (dispatch, getState) => {
dispatch(fetchStatusSourceRequest());

api(getState).get(`/api/v1/statuses/${id}/source`).then(response => {
const { text, spoiler_text, content_type, local_only } = response.data;
dispatch(fetchStatusSourceSuccess());
ensureComposeIsVisible(getState, routerHistory);
dispatch(setComposeToStatus(status, response.data.text, response.data.spoiler_text));
dispatch(setComposeToStatus(status, text, spoiler_text, content_type, local_only));
}).catch(error => {
dispatch(fetchStatusSourceFail(error));
});
Expand Down
4 changes: 3 additions & 1 deletion app/javascript/mastodon/reducers/compose.js
Expand Up @@ -127,7 +127,7 @@ function clearAll(state) {
map.set('is_changing_upload', false);
map.set('in_reply_to', null);
map.set('quote_from', null);
map.set('quote_from_url', action.status.get('url'));
map.set('quote_from_url', null);
map.set('privacy', state.get('default_privacy'));
map.set('federation', state.get('default_federation'));
map.set('content_type', state.get('default_content_type'));
Expand Down Expand Up @@ -524,6 +524,8 @@ export default function compose(state = initialState, action) {
map.set('text', action.text);
map.set('in_reply_to', action.status.get('in_reply_to_id'));
map.set('privacy', action.status.get('visibility'));
map.set('federation', !action.status.get('local_only'));
map.set('content_type', action.status.get('content_type'));
map.set('media_attachments', action.status.get('media_attachments'));
map.set('focusDate', new Date());
map.set('caretPosition', null);
Expand Down
4 changes: 3 additions & 1 deletion app/models/concerns/status_snapshot_concern.rb
Expand Up @@ -25,7 +25,9 @@ def build_snapshot(account_id: nil, at_time: nil, rate_limit: true)
poll_options: preloadable_poll&.options&.dup,
account_id: account_id || self.account_id,
created_at: at_time || edited_at,
rate_limit: rate_limit
rate_limit: rate_limit,
content_type: content_type || 'text/plain',
local_only: !!local_only
)
end

Expand Down
2 changes: 2 additions & 0 deletions app/models/status_edit.rb
Expand Up @@ -14,6 +14,8 @@
# media_descriptions :text is an Array
# poll_options :string is an Array
# sensitive :boolean
# content_type :string
# local_only :boolean
#

class StatusEdit < ApplicationRecord
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/rest/status_source_serializer.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class REST::StatusSourceSerializer < ActiveModel::Serializer
attributes :id, :text, :spoiler_text
attributes :id, :text, :spoiler_text, :content_type, :local_only

def id
object.id.to_s
Expand Down
2 changes: 2 additions & 0 deletions app/services/update_status_service.rb
Expand Up @@ -103,6 +103,8 @@ def update_immediate_attributes!
@status.spoiler_text = @options[:spoiler_text] || '' if @options.key?(:spoiler_text)
@status.sensitive = @options[:sensitive] || @options[:spoiler_text].present? if @options.key?(:sensitive) || @options.key?(:spoiler_text)
@status.language = valid_locale_cascade(@options[:language], @status.language, @status.account.user&.preferred_posting_language, I18n.default_locale)
@status.content_type = @options[:content_type] || 'text/plain'
@status.local_only = !!@options[:local_only]

# We raise here to rollback the entire transaction
raise NoChangesSubmittedError unless significant_changes?
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20220210022831_add_content_type_to_status_edits.rb
@@ -0,0 +1,5 @@
class AddContentTypeToStatusEdits < ActiveRecord::Migration[6.1]
def change
add_column :status_edits, :content_type, :string
end
end
5 changes: 5 additions & 0 deletions db/migrate/20220210024616_add_local_only_to_status_edits.rb
@@ -0,0 +1,5 @@
class AddLocalOnlyToStatusEdits < ActiveRecord::Migration[6.1]
def change
add_column :status_edits, :local_only, :boolean
end
end
2 changes: 2 additions & 0 deletions db/schema.rb
Expand Up @@ -850,6 +850,8 @@
t.text "media_descriptions", array: true
t.string "poll_options", array: true
t.boolean "sensitive"
t.string "content_type"
t.boolean "local_only"
t.index ["account_id"], name: "index_status_edits_on_account_id"
t.index ["status_id"], name: "index_status_edits_on_status_id"
end
Expand Down

0 comments on commit fec195f

Please sign in to comment.