This commit is contained in:
2458773093 2019-08-17 14:09:15 +03:00
parent dd73e1b00e
commit 2fdeccd1c6
7 changed files with 40 additions and 3 deletions

View File

@ -151,7 +151,13 @@ export function submitCompose(routerHistory, group) {
dispatch(submitComposeRequest()); dispatch(submitComposeRequest());
dispatch(closeModal()); dispatch(closeModal());
api(getState).post('/api/v1/statuses', { const id = getState().getIn(['compose', 'id']);
const endpoint = id === null
? '/api/v1/statuses'
: `/api/v1/statuses/${id}`;
const method = id === null ? 'post' : 'put';
api(getState)[method](endpoint, {
status, status,
in_reply_to_id: getState().getIn(['compose', 'in_reply_to'], null), in_reply_to_id: getState().getIn(['compose', 'in_reply_to'], null),
quote_of_id: getState().getIn(['compose', 'quote_of_id'], null), quote_of_id: getState().getIn(['compose', 'quote_of_id'], null),

View File

@ -140,6 +140,18 @@ export function redraft(status, raw_text) {
}; };
}; };
export function editStatus(status) {
return dispatch => {
dispatch({
type: REDRAFT,
edit: true,
status,
});
dispatch(openModal('COMPOSE'));
};
};
export function deleteStatus(id, routerHistory, withRedraft = false) { export function deleteStatus(id, routerHistory, withRedraft = false) {
return (dispatch, getState) => { return (dispatch, getState) => {
if (!me) return; if (!me) return;

View File

@ -71,6 +71,7 @@ class Status extends ImmutablePureComponent {
onFavourite: PropTypes.func, onFavourite: PropTypes.func,
onReblog: PropTypes.func, onReblog: PropTypes.func,
onDelete: PropTypes.func, onDelete: PropTypes.func,
onEdit: PropTypes.func,
onDirect: PropTypes.func, onDirect: PropTypes.func,
onMention: PropTypes.func, onMention: PropTypes.func,
onPin: PropTypes.func, onPin: PropTypes.func,

View File

@ -14,6 +14,7 @@ import { Link } from 'react-router-dom';
const messages = defineMessages({ const messages = defineMessages({
delete: { id: 'status.delete', defaultMessage: 'Delete' }, delete: { id: 'status.delete', defaultMessage: 'Delete' },
redraft: { id: 'status.redraft', defaultMessage: 'Delete & re-draft' }, redraft: { id: 'status.redraft', defaultMessage: 'Delete & re-draft' },
edit: { id: 'status.edit', defaultMessage: 'Edit' },
direct: { id: 'status.direct', defaultMessage: 'Direct message @{name}' }, direct: { id: 'status.direct', defaultMessage: 'Direct message @{name}' },
mention: { id: 'status.mention', defaultMessage: 'Mention @{name}' }, mention: { id: 'status.mention', defaultMessage: 'Mention @{name}' },
mute: { id: 'account.mute', defaultMessage: 'Mute @{name}' }, mute: { id: 'account.mute', defaultMessage: 'Mute @{name}' },
@ -116,6 +117,10 @@ class StatusActionBar extends ImmutablePureComponent {
this.props.onDelete(this.props.status, this.context.router.history, true); this.props.onDelete(this.props.status, this.context.router.history, true);
} }
handleEditClick = () => {
this.props.onEdit(this.props.status);
}
handlePinClick = () => { handlePinClick = () => {
this.props.onPin(this.props.status); this.props.onPin(this.props.status);
} }
@ -218,6 +223,7 @@ class StatusActionBar extends ImmutablePureComponent {
menu.push({ text: intl.formatMessage(messages.delete), action: this.handleDeleteClick }); menu.push({ text: intl.formatMessage(messages.delete), action: this.handleDeleteClick });
menu.push({ text: intl.formatMessage(messages.redraft), action: this.handleRedraftClick }); menu.push({ text: intl.formatMessage(messages.redraft), action: this.handleRedraftClick });
menu.push({ text: intl.formatMessage(messages.edit), action: this.handleEditClick });
} else { } else {
menu.push({ text: intl.formatMessage(messages.mention, { name: status.getIn(['account', 'username']) }), action: this.handleMentionClick }); menu.push({ text: intl.formatMessage(messages.mention, { name: status.getIn(['account', 'username']) }), action: this.handleMentionClick });
//menu.push({ text: intl.formatMessage(messages.direct, { name: status.getIn(['account', 'username']) }), action: this.handleDirectClick }); //menu.push({ text: intl.formatMessage(messages.direct, { name: status.getIn(['account', 'username']) }), action: this.handleDirectClick });

View File

@ -21,6 +21,7 @@ import {
muteStatus, muteStatus,
unmuteStatus, unmuteStatus,
deleteStatus, deleteStatus,
editStatus,
hideStatus, hideStatus,
revealStatus, revealStatus,
} from '../actions/statuses'; } from '../actions/statuses';
@ -141,6 +142,10 @@ const mapDispatchToProps = (dispatch, { intl }) => ({
} }
}, },
onEdit (status) {
dispatch(editStatus(status));
},
onDirect (account, router) { onDirect (account, router) {
dispatch(directCompose(account, router)); dispatch(directCompose(account, router));
}, },

View File

@ -20,6 +20,7 @@ const mapStateToProps = state => {
return { return {
account: state.getIn(['accounts', me]), account: state.getIn(['accounts', me]),
composeText: state.getIn(['compose', 'text']), composeText: state.getIn(['compose', 'text']),
composeId: state.getIn(['compose', 'id']),
}; };
}; };
@ -34,9 +35,9 @@ class ComposeModal extends ImmutablePureComponent {
}; };
onClickClose = () => { onClickClose = () => {
const {composeText, dispatch, onClose, intl} = this.props; const {composeText, composeId, dispatch, onClose, intl} = this.props;
if (composeText) { if (!composeId && composeText) {
dispatch(openModal('CONFIRM', { dispatch(openModal('CONFIRM', {
message: <FormattedMessage id='confirmations.delete.message' defaultMessage='Are you sure you want to delete this status?' />, message: <FormattedMessage id='confirmations.delete.message' defaultMessage='Are you sure you want to delete this status?' />,
confirm: intl.formatMessage(messages.confirm), confirm: intl.formatMessage(messages.confirm),

View File

@ -46,6 +46,7 @@ import { me } from '../initial_state';
import { unescapeHTML } from '../utils/html'; import { unescapeHTML } from '../utils/html';
const initialState = ImmutableMap({ const initialState = ImmutableMap({
id: null,
mounted: 0, mounted: 0,
sensitive: false, sensitive: false,
spoiler: false, spoiler: false,
@ -279,6 +280,7 @@ export default function compose(state = initialState, action) {
case COMPOSE_REPLY_CANCEL: case COMPOSE_REPLY_CANCEL:
case COMPOSE_RESET: case COMPOSE_RESET:
return state.withMutations(map => { return state.withMutations(map => {
map.set('id', null);
map.set('quote_of_id', null); map.set('quote_of_id', null);
map.set('in_reply_to', null); map.set('in_reply_to', null);
map.set('text', ''); map.set('text', '');
@ -353,6 +355,10 @@ export default function compose(state = initialState, action) {
})); }));
case REDRAFT: case REDRAFT:
return state.withMutations(map => { return state.withMutations(map => {
if (action.edit === true) {
map.set('id', action.status.get('id'));
}
map.set('text', action.raw_text || unescapeHTML(expandMentions(action.status))); map.set('text', action.raw_text || unescapeHTML(expandMentions(action.status)));
map.set('in_reply_to', action.status.get('in_reply_to_id')); map.set('in_reply_to', action.status.get('in_reply_to_id'));
map.set('quote_of_id', action.status.get('quote_of_id')); map.set('quote_of_id', action.status.get('quote_of_id'));