2014-05-12 02:13:09 +02:00
|
|
|
var Whisper = Whisper || {};
|
|
|
|
|
|
|
|
(function () {
|
|
|
|
'use strict';
|
|
|
|
|
2014-05-18 23:26:55 +02:00
|
|
|
var Message = Backbone.Model.extend({
|
2014-05-17 06:48:46 +02:00
|
|
|
validate: function(attributes, options) {
|
2014-10-30 04:29:36 +01:00
|
|
|
var required = ['timestamp', 'threadId'];
|
2014-05-17 06:48:46 +02:00
|
|
|
var missing = _.filter(required, function(attr) { return !attributes[attr]; });
|
2014-06-04 04:37:10 +02:00
|
|
|
if (missing.length) { console.log("Message missing attributes: " + missing); }
|
2014-05-17 06:48:46 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
thread: function() {
|
|
|
|
return Whisper.Threads.get(this.get('threadId'));
|
2014-05-18 23:26:55 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-07-22 16:14:33 +02: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 02:13:09 +02:00
|
|
|
})()
|