Bugfix. Retracted messages shouldn't be editable.
This commit is contained in:
parent
004d2b7f23
commit
227b70339c
@ -285,6 +285,12 @@
|
|||||||
view.model.sendMessage('hello world');
|
view.model.sendMessage('hello world');
|
||||||
await u.waitUntil(() => view.el.querySelectorAll('.chat-msg').length === 1);
|
await u.waitUntil(() => view.el.querySelectorAll('.chat-msg').length === 1);
|
||||||
|
|
||||||
|
const message = view.model.messages.at(0);
|
||||||
|
expect(view.model.messages.length).toBe(1);
|
||||||
|
expect(message.get('retracted')).toBeFalsy();
|
||||||
|
expect(message.get('editable')).toBeTruthy();
|
||||||
|
|
||||||
|
|
||||||
const retract_button = await u.waitUntil(() => view.el.querySelector('.chat-msg__content .chat-msg__action-retract'));
|
const retract_button = await u.waitUntil(() => view.el.querySelector('.chat-msg__content .chat-msg__action-retract'));
|
||||||
retract_button.click();
|
retract_button.click();
|
||||||
await u.waitUntil(() => u.isVisible(document.querySelector('#converse-modals .modal')));
|
await u.waitUntil(() => u.isVisible(document.querySelector('#converse-modals .modal')));
|
||||||
@ -304,9 +310,9 @@
|
|||||||
`</apply-to>`+
|
`</apply-to>`+
|
||||||
`</message>`);
|
`</message>`);
|
||||||
|
|
||||||
const message = view.model.messages.at(0);
|
|
||||||
expect(view.model.messages.length).toBe(1);
|
expect(view.model.messages.length).toBe(1);
|
||||||
expect(message.get('retracted')).toBeTruthy();
|
expect(message.get('retracted')).toBeTruthy();
|
||||||
|
expect(message.get('editable')).toBeFalsy();
|
||||||
expect(view.el.querySelectorAll('.chat-msg--retracted').length).toBe(1);
|
expect(view.el.querySelectorAll('.chat-msg--retracted').length).toBe(1);
|
||||||
const el = view.el.querySelector('.chat-msg--retracted .chat-msg__message');
|
const el = view.el.querySelector('.chat-msg--retracted .chat-msg__message');
|
||||||
expect(el.textContent.trim()).toBe('Romeo Montague has removed this message');
|
expect(el.textContent.trim()).toBe('Romeo Montague has removed this message');
|
||||||
@ -565,7 +571,8 @@
|
|||||||
|
|
||||||
const message = view.model.messages.at(0);
|
const message = view.model.messages.at(0);
|
||||||
expect(message.get('retracted')).toBeTruthy();
|
expect(message.get('retracted')).toBeTruthy();
|
||||||
expect(message.get('is_ephemeral')).toBe(false);
|
expect(message.get('is_ephemeral')).toBeTruthy();
|
||||||
|
expect(message.get('editable')).toBeFalsy();
|
||||||
|
|
||||||
const stanza_id = message.get(`stanza_id ${muc_jid}`);
|
const stanza_id = message.get(`stanza_id ${muc_jid}`);
|
||||||
// The server responds with a retraction message
|
// The server responds with a retraction message
|
||||||
@ -584,7 +591,8 @@
|
|||||||
|
|
||||||
expect(view.model.messages.length).toBe(1);
|
expect(view.model.messages.length).toBe(1);
|
||||||
expect(view.model.messages.at(0).get('retracted')).toBeTruthy();
|
expect(view.model.messages.at(0).get('retracted')).toBeTruthy();
|
||||||
expect(view.model.messages.at(0).get('is_ephemeral')).toBe(false);
|
expect(view.model.messages.at(0).get('is_ephemeral')).toBe(true);
|
||||||
|
expect(view.model.messages.at(0).get('editable')).toBe(false);
|
||||||
expect(view.el.querySelectorAll('.chat-msg--retracted').length).toBe(1);
|
expect(view.el.querySelectorAll('.chat-msg--retracted').length).toBe(1);
|
||||||
const el = view.el.querySelector('.chat-msg--retracted .chat-msg__message div');
|
const el = view.el.querySelector('.chat-msg--retracted .chat-msg__message div');
|
||||||
expect(el.textContent).toBe('romeo has removed this message');
|
expect(el.textContent).toBe('romeo has removed this message');
|
||||||
@ -628,7 +636,6 @@
|
|||||||
|
|
||||||
_converse.connection._dataRecv(test_utils.createRequest(error));
|
_converse.connection._dataRecv(test_utils.createRequest(error));
|
||||||
await u.waitUntil(() => view.el.querySelectorAll('.chat-error').length === 1);
|
await u.waitUntil(() => view.el.querySelectorAll('.chat-error').length === 1);
|
||||||
|
|
||||||
await u.waitUntil(() => view.el.querySelectorAll('.chat-msg--retracted').length === 0);
|
await u.waitUntil(() => view.el.querySelectorAll('.chat-msg--retracted').length === 0);
|
||||||
expect(view.model.messages.length).toBe(1);
|
expect(view.model.messages.length).toBe(1);
|
||||||
expect(view.model.messages.at(0).get('retracted')).toBeFalsy();
|
expect(view.model.messages.at(0).get('retracted')).toBeFalsy();
|
||||||
|
@ -960,21 +960,6 @@ converse.plugins.add('converse-chatview', {
|
|||||||
this.insertIntoTextArea('', true, false);
|
this.insertIntoTextArea('', true, false);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* Retract one of your messages in this chat
|
|
||||||
* @private
|
|
||||||
* @method _converse.ChatBoxView#retractOwnMessage
|
|
||||||
* @param { _converse.Message } message - The message which we're retracting.
|
|
||||||
*/
|
|
||||||
retractOwnMessage(message) {
|
|
||||||
this.model.sendRetractionMessage(message);
|
|
||||||
message.save({
|
|
||||||
'retracted': (new Date()).toISOString(),
|
|
||||||
'retracted_id': message.get('origin_id'),
|
|
||||||
'is_ephemeral': true
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
async onMessageRetractButtonClicked (ev) {
|
async onMessageRetractButtonClicked (ev) {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
const msg_el = u.ancestor(ev.target, '.message');
|
const msg_el = u.ancestor(ev.target, '.message');
|
||||||
@ -995,7 +980,7 @@ converse.plugins.add('converse-chatview', {
|
|||||||
}
|
}
|
||||||
const result = await _converse.api.confirm(__('Confirm'), messages);
|
const result = await _converse.api.confirm(__('Confirm'), messages);
|
||||||
if (result) {
|
if (result) {
|
||||||
this.retractOwnMessage(message);
|
this.model.retractOwnMessage(message);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -969,12 +969,8 @@ converse.plugins.add('converse-muc-views', {
|
|||||||
* @param { _converse.Message } message - The message which we're retracting.
|
* @param { _converse.Message } message - The message which we're retracting.
|
||||||
*/
|
*/
|
||||||
retractOwnMessage(message) {
|
retractOwnMessage(message) {
|
||||||
this.model.sendRetractionMessage(message)
|
this.model.retractOwnMessage(message)
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
message.save({
|
|
||||||
'retracted': undefined,
|
|
||||||
'retracted_id': undefined
|
|
||||||
});
|
|
||||||
const errmsg = __('Sorry, something went wrong while trying to retract your message.');
|
const errmsg = __('Sorry, something went wrong while trying to retract your message.');
|
||||||
if (u.isErrorStanza(e)) {
|
if (u.isErrorStanza(e)) {
|
||||||
this.showErrorMessage(errmsg);
|
this.showErrorMessage(errmsg);
|
||||||
@ -984,10 +980,6 @@ converse.plugins.add('converse-muc-views', {
|
|||||||
}
|
}
|
||||||
log.error(e);
|
log.error(e);
|
||||||
});
|
});
|
||||||
message.save({
|
|
||||||
'retracted': (new Date()).toISOString(),
|
|
||||||
'retracted_id': message.get('origin_id')
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -708,6 +708,22 @@ converse.plugins.add('converse-chat', {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retract one of your messages in this chat
|
||||||
|
* @private
|
||||||
|
* @method _converse.ChatBoxView#retractOwnMessage
|
||||||
|
* @param { _converse.Message } message - The message which we're retracting.
|
||||||
|
*/
|
||||||
|
retractOwnMessage(message) {
|
||||||
|
this.sendRetractionMessage(message)
|
||||||
|
message.save({
|
||||||
|
'retracted': (new Date()).toISOString(),
|
||||||
|
'retracted_id': message.get('origin_id'),
|
||||||
|
'is_ephemeral': true,
|
||||||
|
'editable': false
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a message stanza to retract a message in this chat
|
* Sends a message stanza to retract a message in this chat
|
||||||
* @private
|
* @private
|
||||||
@ -899,8 +915,7 @@ converse.plugins.add('converse-chat', {
|
|||||||
}
|
}
|
||||||
if (_converse.allow_message_corrections === 'all') {
|
if (_converse.allow_message_corrections === 'all') {
|
||||||
attrs.editable = !(attrs.file || attrs.retracted || 'oob_url' in attrs);
|
attrs.editable = !(attrs.file || attrs.retracted || 'oob_url' in attrs);
|
||||||
} else if ((_converse.allow_message_corrections === 'last') &&
|
} else if ((_converse.allow_message_corrections === 'last') && (send_time > this.get('time_sent'))) {
|
||||||
(send_time > this.get('time_sent'))) {
|
|
||||||
this.set({'time_sent': send_time});
|
this.set({'time_sent': send_time});
|
||||||
const msg = this.messages.findWhere({'editable': true});
|
const msg = this.messages.findWhere({'editable': true});
|
||||||
if (msg) {
|
if (msg) {
|
||||||
|
@ -647,6 +647,35 @@ converse.plugins.add('converse-muc', {
|
|||||||
return promise;
|
return promise;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retract one of your messages in this chat
|
||||||
|
* @private
|
||||||
|
* @method _converse.ChatRoom#retractOwnMessage
|
||||||
|
* @param { _converse.Message } message - The message which we're retracting.
|
||||||
|
*/
|
||||||
|
async retractOwnMessage(message) {
|
||||||
|
const editable = message.get('editable');
|
||||||
|
const is_ephemeral = message.get('is_ephemeral');
|
||||||
|
// Optimistic save
|
||||||
|
message.save({
|
||||||
|
'retracted': (new Date()).toISOString(),
|
||||||
|
'retracted_id': message.get('origin_id'),
|
||||||
|
'is_ephemeral': true,
|
||||||
|
'editable': false
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
await this.sendRetractionMessage(message)
|
||||||
|
} catch (e) {
|
||||||
|
message.save({
|
||||||
|
is_ephemeral,
|
||||||
|
editable,
|
||||||
|
'retracted': undefined,
|
||||||
|
'retracted_id': undefined,
|
||||||
|
});
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a message stanza to retract a message in this groupchat.
|
* Sends a message stanza to retract a message in this groupchat.
|
||||||
* @private
|
* @private
|
||||||
|
Loading…
Reference in New Issue
Block a user