Refactor the rosterview.fetch method
So that we can also fetch the roster also without the controlbox and rosterview.
This commit is contained in:
parent
decea0e33b
commit
7030495275
|
@ -262,7 +262,10 @@
|
||||||
*/
|
*/
|
||||||
converse.rosterview = new converse.RosterView({model: converse.rostergroups});
|
converse.rosterview = new converse.RosterView({model: converse.rostergroups});
|
||||||
this.contactspanel.$el.append(converse.rosterview.$el);
|
this.contactspanel.$el.append(converse.rosterview.$el);
|
||||||
converse.rosterview.render().fetch().update();
|
converse.rosterview.render().populate().then(function () {
|
||||||
|
converse.rosterview.update();
|
||||||
|
converse.sendInitialPresence();
|
||||||
|
});
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -677,6 +677,13 @@
|
||||||
}, null, 'presence', null);
|
}, null, 'presence', null);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
this.sendInitialPresence = function () {
|
||||||
|
if (converse.send_initial_presence) {
|
||||||
|
converse.xmppstatus.sendPresence();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
this.onStatusInitialized = function () {
|
this.onStatusInitialized = function () {
|
||||||
this.registerIntervalHandler();
|
this.registerIntervalHandler();
|
||||||
this.initRoster();
|
this.initRoster();
|
||||||
|
@ -865,6 +872,36 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
fetchRosterContacts: function () {
|
||||||
|
/* Fetches the roster contacts, first by trying the
|
||||||
|
* sessionStorage cache, and if that's empty, then by querying
|
||||||
|
* the XMPP server.
|
||||||
|
*
|
||||||
|
* Returns a promise which resolves once the contacts have been
|
||||||
|
* fetched.
|
||||||
|
*/
|
||||||
|
var deferred = new $.Deferred();
|
||||||
|
this.fetch({
|
||||||
|
add: true,
|
||||||
|
success: function (collection) {
|
||||||
|
if (collection.length === 0) {
|
||||||
|
/* We don't have any roster contacts stored in sessionStorage,
|
||||||
|
* so lets fetch the roster from the XMPP server. We pass in
|
||||||
|
* 'sendPresence' as callback method, because after initially
|
||||||
|
* fetching the roster we are ready to receive presence
|
||||||
|
* updates from our contacts.
|
||||||
|
*/
|
||||||
|
converse.send_initial_presence = true;
|
||||||
|
converse.roster.fetchFromServer(deferred.resolve);
|
||||||
|
} else {
|
||||||
|
converse.emit('cachedRoster', collection);
|
||||||
|
deferred.resolve();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return deferred.promise();
|
||||||
|
},
|
||||||
|
|
||||||
subscribeToSuggestedItems: function (msg) {
|
subscribeToSuggestedItems: function (msg) {
|
||||||
$(msg).find('item').each(function (i, items) {
|
$(msg).find('item').each(function (i, items) {
|
||||||
if (this.getAttribute('action') === 'add') {
|
if (this.getAttribute('action') === 'add') {
|
||||||
|
@ -1204,6 +1241,22 @@
|
||||||
|
|
||||||
this.RosterGroups = Backbone.Collection.extend({
|
this.RosterGroups = Backbone.Collection.extend({
|
||||||
model: converse.RosterGroup,
|
model: converse.RosterGroup,
|
||||||
|
|
||||||
|
fetchRosterGroups: function () {
|
||||||
|
/* Fetches all the roster groups from sessionStorage.
|
||||||
|
*
|
||||||
|
* Returns a promise which resolves once the groups have been
|
||||||
|
* returned.
|
||||||
|
*/
|
||||||
|
var deferred = new $.Deferred();
|
||||||
|
this.fetch({
|
||||||
|
silent: true, // We need to first have all groups before
|
||||||
|
// we can start positioning them, so we set
|
||||||
|
// 'silent' to true.
|
||||||
|
success: deferred.resolve
|
||||||
|
});
|
||||||
|
return deferred.promise();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -296,43 +296,16 @@
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
fetch: function () {
|
populate: function () {
|
||||||
this.model.fetch({
|
/* Fetch the roster groups, position them and then fetch
|
||||||
silent: true, // We use the success handler to handle groups that were added,
|
* the roster contacts.
|
||||||
// we need to first have all groups before positionFetchedGroups
|
|
||||||
// will work properly.
|
|
||||||
success: function (collection, resp, options) {
|
|
||||||
if (collection.length !== 0) {
|
|
||||||
this.positionFetchedGroups(collection, resp, options);
|
|
||||||
}
|
|
||||||
converse.roster.fetch({
|
|
||||||
add: true,
|
|
||||||
success: function (collection) {
|
|
||||||
if (collection.length === 0) {
|
|
||||||
/* We don't have any roster contacts stored in sessionStorage,
|
|
||||||
* so lets fetch the roster from the XMPP server. We pass in
|
|
||||||
* 'sendPresence' as callback method, because after initially
|
|
||||||
* fetching the roster we are ready to receive presence
|
|
||||||
* updates from our contacts.
|
|
||||||
*/
|
*/
|
||||||
converse.roster.fetchFromServer(
|
var deferred = new $.Deferred();
|
||||||
converse.xmppstatus.sendPresence.bind(converse.xmppstatus));
|
this.model.fetchRosterGroups().then(function () {
|
||||||
} else {
|
this.positionFetchedGroups.apply(this, arguments);
|
||||||
converse.emit('cachedRoster', collection);
|
converse.roster.fetchRosterContacts().then(deferred.resolve);
|
||||||
if (converse.send_initial_presence) {
|
}.bind(this));
|
||||||
/* We're not going to fetch the roster again because we have
|
return deferred.promise();
|
||||||
* it already cached in sessionStorage, but we still need to
|
|
||||||
* send out a presence stanza because this is a new session.
|
|
||||||
* See: https://github.com/jcbrand/converse.js/issues/536
|
|
||||||
*/
|
|
||||||
converse.xmppstatus.sendPresence();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}.bind(this)
|
|
||||||
});
|
|
||||||
return this;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
filter: function (query, type) {
|
filter: function (query, type) {
|
||||||
|
@ -448,6 +421,9 @@
|
||||||
* positioned aren't already in inserted into the
|
* positioned aren't already in inserted into the
|
||||||
* roster DOM element.
|
* roster DOM element.
|
||||||
*/
|
*/
|
||||||
|
if (model.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
model.sort();
|
model.sort();
|
||||||
model.each(function (group, idx) {
|
model.each(function (group, idx) {
|
||||||
var view = this.get(group.get('name'));
|
var view = this.get(group.get('name'));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user