1
0
mirror of https://github.com/moparisthebest/kaiwa synced 2024-11-22 01:02:23 -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,54 +62,53 @@ 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;
if (rooms) { rooms = res.discoItems.items;
var roomNum = 0; var roomNum = 0;
rooms.forEach(function (room) {
client.getDiscoInfo(room.jid, '', function (err, res) { if (rooms) {
if (err) return; rooms.forEach (function (room) {
client.getDiscoInfo(room.jid, '', function (err, res) {
var features = res.discoInfo.features; roomNum++;
var persistent = features.indexOf("muc_persistent") > -1; if (err) return;
var mucInfo = {
id: room.jid.full,
name: room.name,
jid: room.jid,
nick: me.nick,
autoJoin: persistent,
persistent: persistent
};
app.mucInfos.push(mucInfo); var features = res.discoInfo.features;
var persistent = features.indexOf("muc_persistent") > -1;
var mucInfo = {
id: room.jid.full,
name: room.name,
jid: room.jid,
nick: me.nick,
autoJoin: persistent,
persistent: persistent
};
if (++roomNum == rooms.length) app.mucInfos.push(mucInfo);
cb();
});
}).then(function() {
if (cb && roomNum == rooms.length) cb();
}); });
} });
else {
cb();
}
} }
}).then(function() {
if (err) if (cb && !rooms.length) cb();
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) {