1
0
mirror of https://github.com/moparisthebest/kaiwa synced 2024-11-06 01:25:31 -05:00
kaiwa/clientapp/models/mucs.js

58 lines
1.6 KiB
JavaScript
Raw Normal View History

2013-09-16 19:12:00 -04:00
/*global app, client*/
"use strict";
var async = require('async');
var BaseCollection = require('./baseCollection');
var MUC = require('./muc');
module.exports = BaseCollection.extend({
type: 'mucs',
model: MUC,
comparator: function (model1, model2) {
var name1 = model1.displayName.toLowerCase();
var name2 = model2.displayName.toLowerCase();
if (name1 === name2) {
return 0;
}
if (name1 < name2) {
return -1;
}
return 1;
},
initialize: function (model, options) {
this.bind('change', this.sort, this);
},
fetch: function () {
var self = this;
app.whenConnected(function () {
client.getBookmarks(function (err, res) {
if (err) return;
var mucs = res.privateStorage.bookmarks.conferences;
mucs.forEach(function (muc) {
self.add(muc);
2013-12-17 12:36:47 -05:00
if (muc.autoJoin) {
self.get(muc.jid).join();
}
2013-09-16 19:12:00 -04:00
});
});
});
},
save: function (cb) {
var self = this;
app.whenConnected(function () {
var models = [];
self.models.forEach(function (model) {
models.push({
name: model.name,
jid: model.jid,
nick: model.nick,
autoJoin: model.autoJoin
});
});
client.setBookmarks({conferences: models}, cb);
});
}
});