1
0
mirror of https://github.com/moparisthebest/kaiwa synced 2024-11-25 10:42:17 -05:00

Fix: Update MUCs list every 30 secs

This commit is contained in:
Sébastien Hut 2015-02-11 17:39:46 +01:00 committed by Sébastien Hut
parent 87e2cb8a27
commit 85e4e06d5a

View File

@ -62,15 +62,19 @@ module.exports = BaseCollection.extend({
if (SERVER_CONFIG.muc) { if (SERVER_CONFIG.muc) {
if (client.sessionStarted) { if (client.sessionStarted) {
var rooms = [];
client.getDiscoItems(SERVER_CONFIG.muc, '', function (err, res) { client.getDiscoItems(SERVER_CONFIG.muc, '', function (err, res) {
if (!err) { if (err) return;
var rooms = res.discoItems.items;
rooms = res.discoItems.items;
var roomNum = 0;
if (rooms) { if (rooms) {
var roomNum = 0; rooms.forEach (function (room) {
rooms.forEach(function (room) {
client.getDiscoInfo(room.jid, '', function (err, res) { client.getDiscoInfo(room.jid, '', function (err, res) {
roomNum++;
if (err) return; if (err) return;
var features = res.discoInfo.features; var features = res.discoInfo.features;
@ -86,30 +90,25 @@ module.exports = BaseCollection.extend({
app.mucInfos.push(mucInfo); app.mucInfos.push(mucInfo);
if (++roomNum == rooms.length) }).then(function() {
cb(); if (cb && roomNum == rooms.length) cb();
}); });
}); });
} }
else { }).then(function() {
cb(); if (cb && !rooms.length) cb();
}
}
if (err)
cb();
}); });
} else { } else {
app.whenConnected(function () { app.whenConnected(function () {
self.fetch(function () {}); self.fetch(cb);
}); });
} }
} else { return;
cb();
} }
if (cb) cb();
}, },
update: function () { update: function () {
if (SERVER_CONFIG.muc) { if (SERVER_CONFIG.muc) {