muc: Move code into restoreSession method

This commit is contained in:
JC Brand 2019-12-11 10:06:26 +01:00
parent f3a1351a42
commit c379807d4c

View File

@ -381,14 +381,10 @@ converse.plugins.add('converse-muc', {
async initialize() { async initialize() {
this.initialized = u.getResolveablePromise(); this.initialized = u.getResolveablePromise();
const id = `muc.session-${this.get('jid')}`;
this.session = new MUCSession({id});
this.session.browserStorage = _converse.createStore(id, "session");
await new Promise(r => this.session.fetch({'success': r, 'error': r}));
this.setVCard(); this.setVCard();
this.set('box_id', `box-${btoa(this.get('jid'))}`); this.set('box_id', `box-${btoa(this.get('jid'))}`);
this.restoreSession();
this.initFeatures(); // sendChatState depends on this.features this.initFeatures(); // sendChatState depends on this.features
this.on('change:chat_state', this.sendChatState, this); this.on('change:chat_state', this.sendChatState, this);
this.session.on('change:connection_status', this.onConnectionStatusChanged, this); this.session.on('change:connection_status', this.onConnectionStatusChanged, this);
@ -518,6 +514,13 @@ converse.plugins.add('converse-muc', {
this.announceReconnection(); this.announceReconnection();
}, },
restoreSession () {
const id = `muc.session-${_converse.bare_jid}-${this.get('jid')}`;
this.session = new MUCSession({id});
this.session.browserStorage = _converse.createStore(id, "session");
return new Promise(r => this.session.fetch({'success': r, 'error': r}));
},
initFeatures () { initFeatures () {
const id = `converse.muc-features-${_converse.bare_jid}-${this.get('jid')}`; const id = `converse.muc-features-${_converse.bare_jid}-${this.get('jid')}`;
this.features = new Backbone.Model( this.features = new Backbone.Model(