[REV] mail: prevent message loss during connection issue

This reverts commit e5479fcfdb.

This commit prevented an issue of losing messages on post in case
of connectivity loss. The implementation consists of keeping the
content in the composer until the server acknowledges handling the
message.

However, this solution introduces significant issues. For instance,
sending messages in quick succession will likely loose or duplicate
some content, based on how fast/slow the RPC `message_post` is
resolved. Plus, there was an issue on mobile because the input focus
was lost during the RPC. As a consequence, the virtual keyboard
flickered.

The intent was to fix a rare issue, and since the problems of this
solution clearly outweigh the gain, we decided to revert.

closes odoo/odoo#41544

X-original-commit: 36b2e99e08bfc6d92a821d0346e783695580abf9
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
This commit is contained in:
Alexandre Kühn
2019-12-09 09:26:25 +00:00
parent 4efe0e3b16
commit 42de9e129f
4 changed files with 5 additions and 61 deletions
@@ -523,10 +523,9 @@ var BasicComposer = Widget.extend({
clearTimeout(this._cannedTimeout);
var self = this;
this._preprocessMessage().then(function (message) {
self.trigger('post_message', message, function() {
self._clearComposerOnSend();
self.$input.focus();
});
self.trigger('post_message', message);
self._clearComposerOnSend();
self.$input.focus();
});
},
/**
+1 -3
View File
@@ -1490,9 +1490,8 @@ var Discuss = AbstractAction.extend({
/**
* @private
* @param {Object} messageData
* @param {Function} callback
*/
_onPostMessage: function (messageData, callback) {
_onPostMessage: function (messageData) {
var self = this;
var options = {};
if (this._selectedMessage) {
@@ -1513,7 +1512,6 @@ var Discuss = AbstractAction.extend({
} else {
self._threadWidget.scrollToBottom();
}
callback();
});
},
/**
@@ -372,9 +372,8 @@ var AbstractThreadWindow = Widget.extend({
*
* @private
* @param {Object} messageData
* @param {Function} callback
*/
_postMessage: function (messageData, callback) {
_postMessage: function (messageData) {
var self = this;
if (!this.hasThread()) {
return;
@@ -382,7 +381,6 @@ var AbstractThreadWindow = Widget.extend({
this._thread.postMessage(messageData)
.then(function () {
self._threadWidget.scrollToBottom();
callback && callback();
});
},
/**
-51
View File
@@ -1733,57 +1733,6 @@ QUnit.test('receive channel message notification then delayed needaction notific
discuss.destroy();
});
QUnit.test('input not cleared on unresolved message_post rpc', async function (assert) {
assert.expect(2);
// Promise to simulate late server response on message post
var messagePostPromise = testUtils.makeTestPromise();
this.data.initMessaging = {
channel_slots: {
channel_channel: [{
id: 1,
channel_type: "channel",
name: "general",
}],
},
};
var discuss = await createDiscuss({
id: 1,
context: {},
params: {},
data: this.data,
services: this.services,
mockRPC: function (route, args) {
if (args.method === 'message_post') {
return messagePostPromise;
}
return this._super.apply(this, arguments);
},
});
// Click on channel 'general'
var $general = discuss.$('.o_mail_discuss_sidebar').find('.o_mail_discuss_item[data-thread-id=1]');
await testUtils.dom.click($general);
// Type message
var $input = discuss.$('textarea.o_composer_text_field').first();
$input.focus();
$input.val('test message');
// Send message
await testUtils.fields.triggerKeydown($input, 'enter');
assert.strictEqual($input.val(), 'test message', "composer should not be cleared on send without server response");
// Simulate server response
messagePostPromise.resolve();
await testUtils.nextTick();
assert.strictEqual($input.val(), '', "composer should be cleared on send after server response");
discuss.destroy();
});
QUnit.test('messages marked as read move to "History" mailbox', async function (assert) {
assert.expect(3);