Commit c490ba21 authored by JC Brand's avatar JC Brand

converse-muc: Avoid refetching messages from cache

We want to fetch messages from cache only once. For one-on-one chats
this is the case because messages are fetched only in the `initialize`
method.

This used to be the case for MUCs as well, until we added the option
`clear_messages_on_reconnection`.

Now we only fetch messages after the user has entered the MUC.
parent e45bd5fc
......@@ -323,6 +323,10 @@ converse.plugins.add('converse-chatboxes', {
},
fetchMessages () {
if (this.messages.fetched) {
_converse.log(`Not re-fetching messages for ${this.get('jid')}`, Strophe.LogLevel.INFO);
return;
}
this.messages.fetched = u.getResolveablePromise();
const resolve = this.messages.fetched.resolve;
this.messages.fetch({
......@@ -334,11 +338,13 @@ converse.plugins.add('converse-chatboxes', {
clearMessages () {
try {
this.messages.models.forEach(m => m.destroy());
this.messages.reset();
} catch (e) {
this.messages.trigger('reset');
_converse.log(e, Strophe.LogLevel.ERROR);
} finally {
delete this.messages.fetched;
this.messages.browserStorage._clear();
}
},
......
......@@ -397,8 +397,7 @@ converse.plugins.add('converse-muc', {
Strophe.LogLevel.DEBUG
);
if (conn_status !== converse.ROOMSTATUS.ENTERED) {
// We're not restoring a room from cache, so let's clear
// the cache (which might be stale).
// We're not restoring a room from cache, so let's clear the potentially stale cache.
this.removeNonMembers();
await this.refreshRoomFeatures();
if (_converse.clear_messages_on_reconnection) {
......@@ -411,6 +410,7 @@ converse.plugins.add('converse-muc', {
}
this.join();
} else if (!(await this.rejoinIfNecessary())) {
// We've restored the room from cache and we're still joined.
this.features.fetch();
this.fetchMessages();
}
......@@ -1519,6 +1519,7 @@ converse.plugins.add('converse-muc', {
if (forwarded) {
stanza = forwarded.querySelector('message');
}
const message = await this.getDuplicateMessage(original_stanza);
if (message) {
this.updateMessage(message, original_stanza);
......
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