Commit 3922072b authored by Djorkaeff Alexandre's avatar Djorkaeff Alexandre
Browse files

Fix quote on editing

parent 1984a4e0
......@@ -62,6 +62,8 @@ class MessageBox extends Component {
rid: PropTypes.string.isRequired,
baseUrl: PropTypes.string.isRequired,
message: PropTypes.object,
editingMessage: PropTypes.object,
replyingMessage: PropTypes.object,
replying: PropTypes.bool,
editing: PropTypes.bool,
threadsEnabled: PropTypes.bool,
......@@ -618,6 +620,21 @@ class MessageBox extends Component {
this.setState({ showEmojiKeyboard: false });
}
generateReplyOrQuote = async(message) => {
const {
user, roomType, replyWithMention, replyingMessage
} = this.props;
const permalink = await this.getPermalink(replyingMessage);
let msg = `[ ](${ permalink }) `;
// if original message wasn't sent by current user and neither from a direct room
if (user.username !== replyingMessage.u.username && roomType !== 'd' && replyWithMention) {
msg += `@${ replyingMessage.u.username } `;
}
return `${ msg } ${ message }`;
}
submit = async() => {
const {
onSubmit, rid: roomId
......@@ -655,16 +672,24 @@ class MessageBox extends Component {
return;
}
}
// Edit
if (editing) {
const { message: editingMessage, editRequest } = this.props;
let msg = message;
const {
editingMessage, editRequest, replyCancel
} = this.props;
const { id, subscription: { id: rid } } = editingMessage;
editRequest({ id, msg: message, rid });
if (replying) {
msg = await this.generateReplyOrQuote(message);
replyCancel();
}
editRequest({ id, msg, rid });
// Reply
} else if (replying) {
} else if (replying && !editing) {
const {
message: replyingMessage, replyCancel, threadsEnabled, replyWithMention
replyingMessage, replyCancel, threadsEnabled, replyWithMention
} = this.props;
// Thread
......@@ -673,16 +698,7 @@ class MessageBox extends Component {
// Legacy reply or quote (quote is a reply without mention)
} else {
const { user, roomType } = this.props;
const permalink = await this.getPermalink(replyingMessage);
let msg = `[ ](${ permalink }) `;
// if original message wasn't sent by current user and neither from a direct room
if (user.username !== replyingMessage.u.username && roomType !== 'd' && replyWithMention) {
msg += `@${ replyingMessage.u.username } `;
}
msg = `${ msg } ${ message }`;
const msg = await this.generateReplyOrQuote(message);
onSubmit(msg);
}
replyCancel();
......
......@@ -133,6 +133,8 @@ class RoomView extends React.Component {
reactionsModalVisible: false,
selectedAttachment: {},
selectedMessage: selectedMessage || {},
editingMessage: {},
replyingMessage: {},
canAutoTranslate: false,
loading: true,
showActions: false,
......@@ -366,15 +368,15 @@ class RoomView extends React.Component {
}
onEditInit = (message) => {
this.setState({ selectedMessage: message, editing: true, showActions: false });
this.setState({ editingMessage: message, editing: true, showActions: false });
}
onEditCancel = () => {
this.setState({ selectedMessage: {}, editing: false });
this.setState({ editingMessage: {}, editing: false });
}
onEditRequest = async(message) => {
this.setState({ selectedMessage: {}, editing: false });
this.setState({ editingMessage: {}, editing: false });
try {
await RocketChat.editMessage(message);
} catch (e) {
......@@ -384,12 +386,12 @@ class RoomView extends React.Component {
onReplyInit = (message, mention) => {
this.setState({
selectedMessage: message, replying: true, showActions: false, replyWithMention: mention
replyingMessage: message, replying: true, showActions: false, replyWithMention: mention
});
}
onReplyCancel = () => {
this.setState({ selectedMessage: {}, replying: false });
this.setState({ replyingMessage: {}, replying: false });
}
onReactionInit = (message) => {
......@@ -692,7 +694,7 @@ class RoomView extends React.Component {
renderFooter = () => {
const {
joined, room, selectedMessage, editing, replying, replyWithMention
joined, room, selectedMessage, editing, replying, replyWithMention, editingMessage, replyingMessage
} = this.state;
const { navigation } = this.props;
......@@ -734,6 +736,8 @@ class RoomView extends React.Component {
roomType={room.t}
isFocused={navigation.isFocused()}
message={selectedMessage}
editingMessage={editingMessage}
replyingMessage={replyingMessage}
editing={editing}
editRequest={this.onEditRequest}
editCancel={this.onEditCancel}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment