Resolve fetched promise when clearing messages

This fixes an issue where chats stay empty after reconnection when
`clear_messages_on_reconnection` is `true`.
This commit is contained in:
JC Brand 2022-04-08 11:00:36 +02:00
parent ca0953e4bd
commit 0c049dd364
3 changed files with 8 additions and 14 deletions

View File

@ -94,11 +94,11 @@ const ChatBox = ModelWithContact.extend({
this.messages.fetched.then(() => {
this.pruneHistoryWhenScrolledDown();
/**
* Triggered whenever a `_converse.ChatBox` instance has fetched its messages from
* `sessionStorage` but **NOT** from the server.
* Triggered whenever a { @link _converse.ChatBox } or ${ @link _converse.ChatRoom }
* has fetched its messages from the local cache.
* @event _converse#afterMessagesFetched
* @type {_converse.ChatBoxView | _converse.ChatRoomView}
* @example _converse.api.listen.on('afterMessagesFetched', view => { ... });
* @type { _converse.ChatBox| _converse.ChatRoom }
* @example _converse.api.listen.on('afterMessagesFetched', (chat) => { ... });
*/
api.trigger('afterMessagesFetched', this);
});
@ -270,9 +270,9 @@ const ChatBox = ModelWithContact.extend({
this.messages.trigger('reset');
log.error(e);
} finally {
delete this.msg_chain;
delete this.messages.fetched_flag;
this.messages.fetched = getOpenPromise();
// No point in fetching messages from the cache if it's been cleared.
// Make sure to resolve the fetched promise to avoid freezes.
this.messages.fetched.resolve();
}
},

View File

@ -325,12 +325,7 @@ const ChatRoomMixin = {
async onRoomEntered () {
await this.occupants.fetchMembers();
if (api.settings.get('clear_messages_on_reconnection')) {
// Don't call this.clearMessages because we don't want to
// recreate promises, since that will cause some existing
// awaiters to never proceed.
await this.messages.clearStore();
// A bit hacky. No need to fetch messages after clearing
this.messages.fetched.resolve();
await this.clearMessages();
} else {
await this.fetchMessages();
}

View File

@ -18,7 +18,6 @@ export default class MessageForm extends ElementView {
this.listenTo(this.model, 'change:composing_spoiler', () => this.render());
this.handleEmojiSelection = ({ detail }) => {
debugger;
if (this.model.get('jid') === detail.jid) {
this.insertIntoTextArea(detail.value, detail.autocompleting, false, detail.ac_position);
}