Commit 9750dcf3 authored by JC Brand's avatar JC Brand

Fixes #1142. Show confirmation dialog for editing messages

when the textarea contains an unsent message
parent 1dc73c1c
......@@ -114,7 +114,28 @@
}).c('body').t('Hello').up()
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree()
);
await new Promise((resolve, reject) => view.once('messageInserted', resolve));
expect(view.el.querySelectorAll('.chat-msg .chat-msg__action').length).toBe(1);
// Test confirmation dialog
spyOn(window, 'confirm').and.returnValue(true);
textarea.value = 'But soft, what light through yonder airlock breaks?';
action = view.el.querySelector('.chat-msg .chat-msg__action');
action.style.opacity = 1;
action.click();
expect(window.confirm).toHaveBeenCalledWith(
'You have an unsent message which will be lost if you continue. Are you sure?');
expect(view.model.messages.at(0).get('correcting')).toBe(true);
expect(textarea.value).toBe('But soft, what light through yonder window breaks?');
textarea.value = 'But soft, what light through yonder airlock breaks?'
action.click();
expect(view.model.messages.at(0).get('correcting')).toBe(false);
expect(window.confirm.calls.count()).toBe(2);
expect(window.confirm.calls.argsFor(0)).toEqual(
['You have an unsent message which will be lost if you continue. Are you sure?']);
expect(window.confirm.calls.argsFor(1)).toEqual(
['You have an unsent message which will be lost if you continue. Are you sure?']);
done();
}));
......
......@@ -1022,11 +1022,20 @@ converse.plugins.add('converse-chatview', {
onMessageEditButtonClicked (ev) {
ev.preventDefault();
const idx = this.model.messages.findLastIndex('correcting'),
currently_correcting = idx >=0 ? this.model.messages.at(idx) : null,
message_el = u.ancestor(ev.target, '.chat-msg'),
message = this.model.messages.findWhere({'msgid': message_el.getAttribute('data-msgid')});
const textarea = this.el.querySelector('.chat-textarea');
if (textarea.value &&
(currently_correcting === null || currently_correcting.get('message') !== textarea.value)) {
if (! confirm(__("You have an unsent message which will be lost if you continue. Are you sure?"))) {
return;
}
}
if (currently_correcting !== message) {
if (!_.isNil(currently_correcting)) {
currently_correcting.save('correcting', false);
......
......@@ -73,7 +73,7 @@ converse.plugins.add('converse-modal', {
/************************ BEGIN API ************************/
// We extend the default converse.js API to add methods specific to MUC chat rooms.
let alert
let alert;
Object.assign(_converse.api, {
'alert': {
......
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