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