This is actually called whenever save() is called on a backbone model, to
prevent badly formatted models from being written. It can definitely be
made stricter. It should also have tests.


On Tue, May 27, 2014 at 10:51 AM, codedust <notifications@github.com> wrote:

> In js/models/threads.js:
>
> > +      return {
> > +        image: '/images/default.png',
> > +        unreadCount: 0,
> > +        timestamp: new Date().getTime()
> > +      };
> > +    },
> > +
> > +    validate: function(attributes, options) {
> > +      var required = ['id', 'type', 'recipients', 'timestamp', 'image', 'name'];
> > +      var missing = _.filter(required, function(attr) { return !attributes[attr]; });
> > +      if (missing.length) { return "Thread must have " + missing; }
> > +      if (attributes.recipients.length === 0) {
> > +        return "No recipients for thread " + this.id;
> > +      }
> > +      for (var person in attributes.recipients) {
> > +        if (!person) return "Invalid recipient";
>
> I guess validate() is only for debugging - otherwise (!person) might not
> be enought imo.
>
> —
> Reply to this email directly or view it on GitHub<https://github.com/WhisperSystems/TextSecure-Browser/pull/38/files#r13091418>
> .
>