2014-05-11 17:13:09 -07:00
|
|
|
var Whisper = Whisper || {};
|
|
|
|
|
|
|
|
(function () {
|
|
|
|
'use strict';
|
|
|
|
|
2014-05-18 14:26:55 -07:00
|
|
|
var Message = Backbone.Model.extend({
|
2014-05-16 21:48:46 -07:00
|
|
|
validate: function(attributes, options) {
|
2014-10-29 20:29:36 -07:00
|
|
|
var required = ['timestamp', 'threadId'];
|
2014-05-16 21:48:46 -07:00
|
|
|
var missing = _.filter(required, function(attr) { return !attributes[attr]; });
|
2014-06-03 19:37:10 -07:00
|
|
|
if (missing.length) { console.log("Message missing attributes: " + missing); }
|
2014-05-16 21:48:46 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
thread: function() {
|
|
|
|
return Whisper.Threads.get(this.get('threadId'));
|
2014-05-18 14:26:55 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-07-22 04:14:33 -10:00
|
|
|
Whisper.MessageCollection = Backbone.Collection.extend({
|
|
|
|
model: Message,
|
|
|
|
comparator: 'timestamp',
|
|
|
|
initialize: function(models, options) {
|
|
|
|
this.localStorage = new Backbone.LocalStorage("Messages-" + options.threadId);
|
|
|
|
}
|
|
|
|
});
|
2014-05-11 17:13:09 -07:00
|
|
|
})()
|