Avoid unnecessarily sending out a presence stanza

- Set roster_fetched flag when we get an empty IQ[type="result"] stanza
- Set `restored` flag when resuming in converse-smacks
- Don't trigger change event when fetching xmppstatus values
- Removed two events, since we can just listen to `change` on `_converse.xmppstatus`.
This commit is contained in:
JC Brand 2019-06-13 13:29:55 +02:00
parent ba9d28b5c2
commit f3c4dbc344
4 changed files with 14 additions and 24 deletions

View File

@ -51,6 +51,9 @@
- Remove the `expose_rid_and_sid` configuration setting.
- A `prebind_url` is now mandatory when setting `authentication` to `prebind`.
It's no longer possible to pass in `rid` and `sid` values to `converse.initialize.
- Removed events `statusChanged` and `statusMessageChanged`. Instead, you can
listen on the `change:status` or `change:status\_message` events on
`_converse.xmppstatus`.
### API changes

View File

@ -1003,7 +1003,8 @@ _converse.initialize = async function (settings, callback) {
_converse.xmppstatus.browserStorage = new BrowserStorage.session(id);
_converse.xmppstatus.fetch({
'success': _.partial(_converse.onStatusInitialized, reconnecting),
'error': _.partial(_converse.onStatusInitialized, reconnecting)
'error': _.partial(_converse.onStatusInitialized, reconnecting),
'silent': true
});
}
}
@ -1152,28 +1153,13 @@ _converse.initialize = async function (settings, callback) {
},
initialize () {
this.on('change:status', (item) => {
const status = this.get('status');
this.sendPresence(status);
/**
* Triggered when the current user's status has changed
* @event _converse#statusChanged
* @type { string }
* @example _converse.api.listen.on('statusChanged', status => { ... });
*/
_converse.api.trigger('statusChanged', status);
});
this.on('change:status_message', () => {
const status_message = this.get('status_message');
this.sendPresence(this.get('status'), status_message);
/**
* Triggered when the current user's custom status message has changed.
* @event _converse#statusMessageChanged
* @type { string }
* @example _converse.api.listen.on('statusMessageChanged', message => { ... });
*/
_converse.api.trigger('statusMessageChanged', status_message);
this.on('change', item => {
if (!_.isObject(item.changed)) {
return;
}
if ('status' in item.changed || 'status_message' in item.changed) {
this.sendPresence(this.get('status'), this.get('status_message'));
}
});
},

View File

@ -672,8 +672,8 @@ converse.plugins.add('converse-roster', {
const items = sizzle(`item`, query);
_.each(items, (item) => this.updateContact(item));
this.data.save('version', query.getAttribute('ver'));
_converse.session.save('roster_fetched', true);
}
_converse.session.save('roster_fetched', true);
/**
* When the roster has been received from the XMPP server.
* See also the `cachedRoster` event further up, which gets called instead of

View File

@ -149,6 +149,7 @@ converse.plugins.add('converse-smacks', {
resendUnackedStanzas();
_converse.connection.do_bind = false; // No need to bind our resource anymore
_converse.connection.authenticated = true;
_converse.connection.restored = true;
_converse.connection._changeConnectStatus(Strophe.Status.CONNECTED, null);
}