1
0
mirror of https://github.com/moparisthebest/kaiwa synced 2024-11-25 02:32:26 -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 (client.sessionStarted) {
var rooms = [];
client.getDiscoItems(SERVER_CONFIG.muc, '', function (err, res) {
if (!err) {
var rooms = res.discoItems.items;
if (err) return;
if (rooms) {
var roomNum = 0;
rooms.forEach(function (room) {
rooms = res.discoItems.items;
var roomNum = 0;
client.getDiscoInfo(room.jid, '', function (err, res) {
if (err) return;
if (rooms) {
rooms.forEach (function (room) {
client.getDiscoInfo(room.jid, '', function (err, res) {
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
};
roomNum++;
if (err) return;
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)
cb();
});
app.mucInfos.push(mucInfo);
}).then(function() {
if (cb && roomNum == rooms.length) cb();
});
}
else {
cb();
}
});
}
if (err)
cb();
}).then(function() {
if (cb && !rooms.length) cb();
});
} else {
app.whenConnected(function () {
self.fetch(function () {});
self.fetch(cb);
});
}
} else {
cb();
return;
}
if (cb) cb();
},
update: function () {
if (SERVER_CONFIG.muc) {