mirror of
https://github.com/funamitech/mastodon
synced 2024-12-01 08:18:53 +09:00
Uploading/undoing media modifies status text. Also: status text trimmed before validation
This commit is contained in:
parent
b1a670af8d
commit
c6d893a71d
@ -27,6 +27,32 @@ function statusToTextMentions(status) {
|
|||||||
return Immutable.OrderedSet([`@${status.getIn(['account', 'acct'])} `]).union(status.get('mentions').map(mention => `@${mention.get('acct')} `)).join('');
|
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) {
|
export default function compose(state = initialState, action) {
|
||||||
switch(action.type) {
|
switch(action.type) {
|
||||||
case COMPOSE_CHANGE:
|
case COMPOSE_CHANGE:
|
||||||
@ -44,25 +70,17 @@ export default function compose(state = initialState, action) {
|
|||||||
case COMPOSE_SUBMIT_REQUEST:
|
case COMPOSE_SUBMIT_REQUEST:
|
||||||
return state.set('is_submitting', true);
|
return state.set('is_submitting', true);
|
||||||
case COMPOSE_SUBMIT_SUCCESS:
|
case COMPOSE_SUBMIT_SUCCESS:
|
||||||
return state.withMutations(map => {
|
return clearAll(state);
|
||||||
map.set('text', '');
|
|
||||||
map.set('is_submitting', false);
|
|
||||||
map.set('in_reply_to', null);
|
|
||||||
map.update('media_attachments', list => list.clear());
|
|
||||||
});
|
|
||||||
case COMPOSE_SUBMIT_FAIL:
|
case COMPOSE_SUBMIT_FAIL:
|
||||||
return state.set('is_submitting', false);
|
return state.set('is_submitting', false);
|
||||||
case COMPOSE_UPLOAD_REQUEST:
|
case COMPOSE_UPLOAD_REQUEST:
|
||||||
return state.set('is_uploading', true);
|
return state.set('is_uploading', true);
|
||||||
case COMPOSE_UPLOAD_SUCCESS:
|
case COMPOSE_UPLOAD_SUCCESS:
|
||||||
return state.withMutations(map => {
|
return appendMedia(state, Immutable.fromJS(action.media));
|
||||||
map.update('media_attachments', list => list.push(Immutable.fromJS(action.media)));
|
|
||||||
map.set('is_uploading', false);
|
|
||||||
});
|
|
||||||
case COMPOSE_UPLOAD_FAIL:
|
case COMPOSE_UPLOAD_FAIL:
|
||||||
return state.set('is_uploading', false);
|
return state.set('is_uploading', false);
|
||||||
case COMPOSE_UPLOAD_UNDO:
|
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:
|
case COMPOSE_UPLOAD_PROGRESS:
|
||||||
return state.set('progress', Math.round((action.loaded / action.total) * 100));
|
return state.set('progress', Math.round((action.loaded / action.total) * 100));
|
||||||
case TIMELINE_DELETE:
|
case TIMELINE_DELETE:
|
||||||
|
@ -2,7 +2,7 @@ class MediaController < ApplicationController
|
|||||||
before_action :set_media_attachment
|
before_action :set_media_attachment
|
||||||
|
|
||||||
def show
|
def show
|
||||||
redirect TagManager.instance.url_for(@media_attachment.status)
|
redirect_to TagManager.instance.url_for(@media_attachment.status)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -89,4 +89,8 @@ class Status < ApplicationRecord
|
|||||||
def self.reblogs_map(status_ids, account_id)
|
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
|
self.where(reblog_of_id: status_ids).where(account_id: account_id).map { |s| [s.reblog_of_id, true] }.to_h
|
||||||
end
|
end
|
||||||
|
|
||||||
|
before_validation do
|
||||||
|
self.text.strip!
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user