Commit 5ea7a4d1 authored by JC Brand's avatar JC Brand

MUC: Small updates to message fetching and queueing

- Always clear queue after fetching messages from cache
- Empty `message_queue` without waiting for all messages to first be processed.
- Don't assume that `this.messages` is set by the time `queueMessage` is called
parent df9612f9
...@@ -413,7 +413,6 @@ converse.plugins.add('converse-muc', { ...@@ -413,7 +413,6 @@ converse.plugins.add('converse-muc', {
await new Promise(resolve => this.features.fetch({'success': resolve, 'error': resolve})); await new Promise(resolve => this.features.fetch({'success': resolve, 'error': resolve}));
await this.fetchOccupants(); await this.fetchOccupants();
await this.fetchMessages(); await this.fetchMessages();
await this.clearMessageQueue();
return true; return true;
} else { } else {
await this.clearCache(); await this.clearCache();
...@@ -457,6 +456,13 @@ converse.plugins.add('converse-muc', { ...@@ -457,6 +456,13 @@ converse.plugins.add('converse-muc', {
return this; return this;
}, },
async fetchMessages () {
await _converse.ChatBox.prototype.fetchMessages.call(this);
const queued_messages = this.message_queue.map(m => this.queueMessage(m));
this.message_queue = [];
return Promise.all(queued_messages);
},
async clearCache () { async clearCache () {
this.session.save('connection_status', converse.ROOMSTATUS.DISCONNECTED); this.session.save('connection_status', converse.ROOMSTATUS.DISCONNECTED);
if (this.occupants.length) { if (this.occupants.length) {
...@@ -509,20 +515,14 @@ converse.plugins.add('converse-muc', { ...@@ -509,20 +515,14 @@ converse.plugins.add('converse-muc', {
}, },
initMessages () { initMessages () {
_converse.ChatBox.prototype.initMessages.call(this);
this.message_queue = [];
},
async clearMessageQueue () {
await Promise.all(this.message_queue.map(m => this.queueMessage(m)));
this.message_queue = []; this.message_queue = [];
_converse.ChatBox.prototype.initMessages.call(this);
}, },
async onConnectionStatusChanged () { async onConnectionStatusChanged () {
if (this.session.get('connection_status') === converse.ROOMSTATUS.ENTERED) { if (this.session.get('connection_status') === converse.ROOMSTATUS.ENTERED) {
await this.occupants.fetchMembers(); await this.occupants.fetchMembers();
await this.fetchMessages(); await this.fetchMessages();
await this.clearMessageQueue();
/** /**
* Triggered when the user has entered a new MUC * Triggered when the user has entered a new MUC
* @event _converse#enteredNewRoom * @event _converse#enteredNewRoom
...@@ -1896,7 +1896,7 @@ converse.plugins.add('converse-muc', { ...@@ -1896,7 +1896,7 @@ converse.plugins.add('converse-muc', {
* @param { XMLElement } stanza - The message stanza. * @param { XMLElement } stanza - The message stanza.
*/ */
queueMessage (stanza) { queueMessage (stanza) {
if (this.messages.fetched) { if (this.messages?.fetched) {
this.msg_chain = (this.msg_chain || this.messages.fetched); this.msg_chain = (this.msg_chain || this.messages.fetched);
this.msg_chain = this.msg_chain.then(() => this.onMessage(stanza)); this.msg_chain = this.msg_chain.then(() => this.onMessage(stanza));
return this.msg_chain; return this.msg_chain;
......
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