2013-08-29 23:38:28 -04:00
|
|
|
/*global me*/
|
|
|
|
"use strict";
|
|
|
|
|
2013-09-03 22:18:31 -04:00
|
|
|
var HumanModel = require('human-model');
|
2013-08-20 13:45:06 -04:00
|
|
|
|
|
|
|
|
2013-09-05 19:53:23 -04:00
|
|
|
module.exports = HumanModel.define({
|
2013-08-29 23:38:28 -04:00
|
|
|
initialize: function (attrs) {
|
2013-08-20 13:45:06 -04:00
|
|
|
this._created = Date.now();
|
|
|
|
},
|
|
|
|
type: 'message',
|
|
|
|
props: {
|
2013-09-12 16:24:52 -04:00
|
|
|
id: ['string', true, ''],
|
2013-08-20 13:45:06 -04:00
|
|
|
to: ['string', true, ''],
|
|
|
|
from: ['string', true, ''],
|
|
|
|
body: ['string', true, ''],
|
|
|
|
type: ['string', true, 'normal'],
|
2013-09-12 16:24:52 -04:00
|
|
|
acked: ['bool', true, false],
|
|
|
|
archivedId: ['string', true, '']
|
2013-08-20 13:45:06 -04:00
|
|
|
},
|
|
|
|
derived: {
|
|
|
|
mine: {
|
|
|
|
deps: ['from'],
|
|
|
|
fn: function () {
|
|
|
|
return me.isMe(this.from);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
delayed: {
|
|
|
|
deps: ['delay'],
|
|
|
|
fn: function () {
|
|
|
|
return !!this.delay;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
created: {
|
|
|
|
deps: ['delay', '_created'],
|
|
|
|
fn: function () {
|
|
|
|
if (this.delay && this.delay.stamp) {
|
|
|
|
return this.delay.stamp;
|
|
|
|
}
|
|
|
|
return this._created;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
formattedTime: {
|
|
|
|
deps: ['created'],
|
|
|
|
fn: function () {
|
2013-08-29 23:38:28 -04:00
|
|
|
if (this.created) {
|
2013-08-30 01:37:24 -04:00
|
|
|
var month = this.created.getMonth();
|
|
|
|
var day = this.created.getDate();
|
|
|
|
var hour = this.created.getHours();
|
|
|
|
var minutes = this.created.getMinutes();
|
|
|
|
|
|
|
|
var m = (hour >= 12) ? 'p' : 'a';
|
|
|
|
var strDay = (day < 10) ? '0' + day : day;
|
|
|
|
var strHour = (hour < 10) ? '0' + hour : hour;
|
|
|
|
var strMin = (minutes < 10) ? '0' + minutes: minutes;
|
|
|
|
|
|
|
|
return '' + month + '/' + strDay + ' ' + strHour + ':' + strMin + m;
|
2013-08-29 23:38:28 -04:00
|
|
|
}
|
|
|
|
return undefined;
|
2013-08-20 13:45:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
session: {
|
|
|
|
_created: 'date',
|
|
|
|
receiptReceived: ['bool', true, false],
|
|
|
|
edited: ['bool', true, false],
|
2013-08-29 23:38:28 -04:00
|
|
|
delay: 'object'
|
2013-08-20 13:45:06 -04:00
|
|
|
},
|
|
|
|
correct: function (msg) {
|
2013-09-12 16:24:52 -04:00
|
|
|
if (this.from.full !== msg.from.full) return false;
|
2013-08-20 13:45:06 -04:00
|
|
|
|
|
|
|
delete msg.id;
|
|
|
|
|
|
|
|
this.set(msg);
|
|
|
|
this._created = Date.now();
|
|
|
|
this.edited = true;
|
2013-09-12 16:24:52 -04:00
|
|
|
|
|
|
|
return true;
|
2013-08-20 13:45:06 -04:00
|
|
|
}
|
|
|
|
});
|