Commit bb0c0fcd authored by JC Brand's avatar JC Brand

Remove message views when messages get reset

parent b4b7fedf
...@@ -339,7 +339,10 @@ converse.plugins.add('converse-chatview', { ...@@ -339,7 +339,10 @@ converse.plugins.add('converse-chatview', {
this.initDebounced(); this.initDebounced();
this.model.messages.on('add', this.onMessageAdded, this); this.model.messages.on('add', this.onMessageAdded, this);
this.model.messages.on('rendered', this.scrollDown, this); this.model.messages.on('rendered', this.scrollDown, this);
this.model.messages.on('reset', () => (this.content.innerHTML = '')); this.model.messages.on('reset', () => {
this.content.innerHTML = '';
this.removeAll();
});
this.model.on('show', this.show, this); this.model.on('show', this.show, this);
this.model.on('destroy', this.remove, this); this.model.on('destroy', this.remove, this);
......
...@@ -152,7 +152,7 @@ converse.plugins.add('converse-mam-views', { ...@@ -152,7 +152,7 @@ converse.plugins.add('converse-mam-views', {
*/ */
const { _converse } = this; const { _converse } = this;
/* Event handlers */ /************************ BEGIN Event Handlers ************************/
_converse.api.listen.on('afterMessagesFetched', chatbox => chatbox.fetchNewestMessages()); _converse.api.listen.on('afterMessagesFetched', chatbox => chatbox.fetchNewestMessages());
_converse.api.listen.on('reconnected', () => { _converse.api.listen.on('reconnected', () => {
...@@ -161,5 +161,6 @@ converse.plugins.add('converse-mam-views', { ...@@ -161,5 +161,6 @@ converse.plugins.add('converse-mam-views', {
); );
_.each(private_chats, view => view.model.fetchNewestMessages()) _.each(private_chats, view => view.model.fetchNewestMessages())
}); });
/************************ END Event Handlers ************************/
} }
}); });
...@@ -541,7 +541,10 @@ converse.plugins.add('converse-muc-views', { ...@@ -541,7 +541,10 @@ converse.plugins.add('converse-muc-views', {
this.model.messages.on('add', this.onMessageAdded, this); this.model.messages.on('add', this.onMessageAdded, this);
this.model.messages.on('rendered', this.scrollDown, this); this.model.messages.on('rendered', this.scrollDown, this);
this.model.messages.on('reset', () => (this.content.innerHTML = '')); this.model.messages.on('reset', () => {
this.content.innerHTML = '';
this.removeAll();
});
this.model.on('change:affiliation', this.renderHeading, this); this.model.on('change:affiliation', this.renderHeading, this);
this.model.on('change:connection_status', this.onConnectionStatusChanged, this); this.model.on('change:connection_status', this.onConnectionStatusChanged, this);
......
...@@ -301,7 +301,6 @@ converse.plugins.add('converse-chatboxes', { ...@@ -301,7 +301,6 @@ converse.plugins.add('converse-chatboxes', {
this.messages.browserStorage = new Backbone.BrowserStorage.session( this.messages.browserStorage = new Backbone.BrowserStorage.session(
`converse.messages-${this.get('jid')}-${_converse.bare_jid}`); `converse.messages-${this.get('jid')}-${_converse.bare_jid}`);
this.messages.chatbox = this; this.messages.chatbox = this;
this.messages.fetched = u.getResolveablePromise();
this.messages.on('change:upload', (message) => { this.messages.on('change:upload', (message) => {
if (message.get('upload') === _converse.SUCCESS) { if (message.get('upload') === _converse.SUCCESS) {
...@@ -323,6 +322,7 @@ converse.plugins.add('converse-chatboxes', { ...@@ -323,6 +322,7 @@ converse.plugins.add('converse-chatboxes', {
}, },
fetchMessages () { fetchMessages () {
this.messages.fetched = u.getResolveablePromise();
const resolve = this.messages.fetched.resolve; const resolve = this.messages.fetched.resolve;
this.messages.fetch({ this.messages.fetch({
'add': true, 'add': true,
......
...@@ -216,8 +216,8 @@ converse.plugins.add('converse-muc', { ...@@ -216,8 +216,8 @@ converse.plugins.add('converse-muc', {
this.initFeatures(); this.initFeatures();
this.initOccupants(); this.initOccupants();
this.initMessages();
this.registerHandlers(); this.registerHandlers();
this.initMessages();
}, },
async onConnectionStatusChanged () { async onConnectionStatusChanged () {
...@@ -1532,10 +1532,11 @@ converse.plugins.add('converse-muc', { ...@@ -1532,10 +1532,11 @@ converse.plugins.add('converse-muc', {
*/ */
_converse.chatboxes _converse.chatboxes
.filter(m => (m.get('type') === _converse.CHATROOMS_TYPE)) .filter(m => (m.get('type') === _converse.CHATROOMS_TYPE))
.forEach(m => m.save('connection_status', converse.ROOMSTATUS.DISCONNECTED))
.forEach(room => { .forEach(room => {
room.save('connection_status', converse.ROOMSTATUS.DISCONNECTED);
room.clearMessages(); room.clearMessages();
room.registerHandlers(); room.registerHandlers();
room.fetchMessages();
room.join(); room.join();
}); });
} }
......
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