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