mirror of
https://git.bsd.gay/fef/nyastodon.git
synced 2024-12-24 18:13:42 +01:00
Uploading/undoing media modifies status text. Also: status text trimmed before validation
This commit is contained in:
parent
b1a670af8d
commit
c6d893a71d
3 changed files with 34 additions and 12 deletions
|
@ -27,6 +27,32 @@ function statusToTextMentions(status) {
|
|||
return Immutable.OrderedSet([`@${status.getIn(['account', 'acct'])} `]).union(status.get('mentions').map(mention => `@${mention.get('acct')} `)).join('');
|
||||
};
|
||||
|
||||
function clearAll(state) {
|
||||
return state.withMutations(map => {
|
||||
map.set('text', '');
|
||||
map.set('is_submitting', false);
|
||||
map.set('in_reply_to', null);
|
||||
map.update('media_attachments', list => list.clear());
|
||||
});
|
||||
};
|
||||
|
||||
function appendMedia(state, media) {
|
||||
return state.withMutations(map => {
|
||||
map.update('media_attachments', list => list.push(media));
|
||||
map.set('is_uploading', false);
|
||||
map.update('text', oldText => `${oldText} ${media.get('text_url')}`.trim());
|
||||
});
|
||||
};
|
||||
|
||||
function removeMedia(state, mediaId) {
|
||||
const media = state.get('media_attachments').find(item => item.get('id') === mediaId);
|
||||
|
||||
return state.withMutations(map => {
|
||||
map.update('media_attachments', list => list.filterNot(item => item.get('id') === mediaId));
|
||||
map.update('text', text => text.replace(media.get('text_url'), '').trim());
|
||||
});
|
||||
};
|
||||
|
||||
export default function compose(state = initialState, action) {
|
||||
switch(action.type) {
|
||||
case COMPOSE_CHANGE:
|
||||
|
@ -44,25 +70,17 @@ export default function compose(state = initialState, action) {
|
|||
case COMPOSE_SUBMIT_REQUEST:
|
||||
return state.set('is_submitting', true);
|
||||
case COMPOSE_SUBMIT_SUCCESS:
|
||||
return state.withMutations(map => {
|
||||
map.set('text', '');
|
||||
map.set('is_submitting', false);
|
||||
map.set('in_reply_to', null);
|
||||
map.update('media_attachments', list => list.clear());
|
||||
});
|
||||
return clearAll(state);
|
||||
case COMPOSE_SUBMIT_FAIL:
|
||||
return state.set('is_submitting', false);
|
||||
case COMPOSE_UPLOAD_REQUEST:
|
||||
return state.set('is_uploading', true);
|
||||
case COMPOSE_UPLOAD_SUCCESS:
|
||||
return state.withMutations(map => {
|
||||
map.update('media_attachments', list => list.push(Immutable.fromJS(action.media)));
|
||||
map.set('is_uploading', false);
|
||||
});
|
||||
return appendMedia(state, Immutable.fromJS(action.media));
|
||||
case COMPOSE_UPLOAD_FAIL:
|
||||
return state.set('is_uploading', false);
|
||||
case COMPOSE_UPLOAD_UNDO:
|
||||
return state.update('media_attachments', list => list.filterNot(item => item.get('id') === action.media_id));
|
||||
return removeMedia(state, action.media_id);
|
||||
case COMPOSE_UPLOAD_PROGRESS:
|
||||
return state.set('progress', Math.round((action.loaded / action.total) * 100));
|
||||
case TIMELINE_DELETE:
|
||||
|
|
|
@ -2,7 +2,7 @@ class MediaController < ApplicationController
|
|||
before_action :set_media_attachment
|
||||
|
||||
def show
|
||||
redirect TagManager.instance.url_for(@media_attachment.status)
|
||||
redirect_to TagManager.instance.url_for(@media_attachment.status)
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -89,4 +89,8 @@ class Status < ApplicationRecord
|
|||
def self.reblogs_map(status_ids, account_id)
|
||||
self.where(reblog_of_id: status_ids).where(account_id: account_id).map { |s| [s.reblog_of_id, true] }.to_h
|
||||
end
|
||||
|
||||
before_validation do
|
||||
self.text.strip!
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue