Commit e7ceb22a authored by JC Brand's avatar JC Brand

Avoid duplication by keeping track of message views

parent 0fa6bcdc
...@@ -309,7 +309,7 @@ converse.plugins.add('converse-chatview', { ...@@ -309,7 +309,7 @@ converse.plugins.add('converse-chatview', {
* @namespace _converse.ChatBoxView * @namespace _converse.ChatBoxView
* @memberOf _converse * @memberOf _converse
*/ */
_converse.ChatBoxView = Backbone.NativeView.extend({ _converse.ChatBoxView = Backbone.Overview.extend({
length: 200, length: 200,
className: 'chatbox hidden', className: 'chatbox hidden',
is_chatroom: false, // Leaky abstraction from MUC is_chatroom: false, // Leaky abstraction from MUC
...@@ -804,7 +804,7 @@ converse.plugins.add('converse-chatview', { ...@@ -804,7 +804,7 @@ converse.plugins.add('converse-chatview', {
// text to show. // text to show.
return message.destroy(); return message.destroy();
} }
const view = new _converse.MessageView({'model': message}); const view = this.add(message.get('id'), new _converse.MessageView({'model': message}));
await view.render(); await view.render();
// Clear chat state notifications // Clear chat state notifications
...@@ -838,8 +838,12 @@ converse.plugins.add('converse-chatview', { ...@@ -838,8 +838,12 @@ converse.plugins.add('converse-chatview', {
* @method _converse.ChatBoxView#onMessageAdded * @method _converse.ChatBoxView#onMessageAdded
* @param { object } message - The message Backbone object that was added. * @param { object } message - The message Backbone object that was added.
*/ */
onMessageAdded (message) { async onMessageAdded (message) {
this.showMessage(message); if (this.get(message.get('id'))) {
// We already have a view for this message
return;
}
await this.showMessage(message);
if (message.get('correcting')) { if (message.get('correcting')) {
this.insertIntoTextArea(message.get('message'), true, true); this.insertIntoTextArea(message.get('message'), true, true);
} }
......
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