1
0
mirror of https://github.com/moparisthebest/kaiwa synced 2024-11-14 21:45:08 -05:00
kaiwa/clientapp/app/models/message.js
2013-08-20 10:45:06 -07:00

61 lines
1.5 KiB
JavaScript

var StrictModel = require('strictmodel').Model;
module.exports = StrictModel.extend({
init: function (attrs) {
this._created = Date.now();
},
type: 'message',
props: {
to: ['string', true, ''],
from: ['string', true, ''],
body: ['string', true, ''],
type: ['string', true, 'normal'],
acked: ['bool', true, false],
},
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 () {
return this.created.format('{MM}/{dd} {h}:{mm}{t}');
}
}
},
session: {
_created: 'date',
receiptReceived: ['bool', true, false],
edited: ['bool', true, false],
delay: 'object',
},
correct: function (msg) {
if (this.from !== msg.from) return;
delete msg.id;
this.set(msg);
this._created = Date.now();
this.edited = true;
}
});