2014-11-13 22:35:37 +00:00
|
|
|
/* vim: ts=4:sw=4:expandtab
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2014-05-12 00:13:09 +00:00
|
|
|
(function () {
|
2014-11-13 22:35:37 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
window.Whisper = window.Whisper || {};
|
2014-05-12 00:13:09 +00:00
|
|
|
|
2014-11-13 22:35:37 +00:00
|
|
|
var Message = Backbone.Model.extend({
|
|
|
|
database: Whisper.Database,
|
|
|
|
storeName: 'messages',
|
2014-11-20 23:43:51 +00:00
|
|
|
defaults: function() {
|
|
|
|
return {
|
|
|
|
timestamp: new Date().getTime(),
|
|
|
|
attachments: []
|
|
|
|
};
|
|
|
|
},
|
2014-11-13 22:35:37 +00:00
|
|
|
validate: function(attributes, options) {
|
|
|
|
var required = ['timestamp', 'conversationId'];
|
|
|
|
var missing = _.filter(required, function(attr) { return !attributes[attr]; });
|
|
|
|
if (missing.length) {
|
|
|
|
console.log("Message missing attributes: " + missing);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2014-05-18 21:26:55 +00:00
|
|
|
|
2014-11-13 22:35:37 +00:00
|
|
|
Whisper.MessageCollection = Backbone.Collection.extend({
|
|
|
|
model: Message,
|
|
|
|
database: Whisper.Database,
|
|
|
|
storeName: 'messages',
|
2014-11-21 00:30:52 +00:00
|
|
|
comparator: 'timestamp',
|
2014-11-13 22:35:37 +00:00
|
|
|
destroyAll: function () {
|
|
|
|
return Promise.all(this.models.map(function(m) {
|
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
|
m.destroy().then(resolve).fail(reject);
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
});
|
2014-05-12 00:13:09 +00:00
|
|
|
})()
|