* Chat Website Model
*/
-var crypto = require('crypto');
+var _ = require('lodash');
module.exports = function(sequelize, DataTypes) {
messageId: DataTypes.STRING,
inReplyTo: DataTypes.STRING,
subject: DataTypes.STRING,
- from: DataTypes.STRING,
- to: DataTypes.STRING,
- cc: DataTypes.STRING,
+ from: {
+ type: DataTypes.STRING,
+ get: function() {
+ return this.getDataValue('from') ? this.getDataValue('from').split(';') : [];
+ },
+ set: function(val) {
+ this.setDataValue('from', val.join(';'));
+ }
+ },
+ to: {
+ type: DataTypes.TEXT,
+ get: function() {
+ return this.getDataValue('to') ? this.getDataValue('to').split(';') : [];
+ },
+ set: function(val) {
+ this.setDataValue('to', val.join(';'));
+ }
+ },
+ cc: {
+ type: DataTypes.TEXT,
+ get: function() {
+ return this.getDataValue('cc') ? this.getDataValue('cc').split(';') : [];
+ },
+ set: function(val) {
+ this.setDataValue('cc', val.join(';'));
+ }
+ },
+ bcc: {
+ type: DataTypes.TEXT,
+ get: function() {
+ return this.getDataValue('bcc') ? this.getDataValue('bcc').split(';') : [];
+ },
+ set: function(val) {
+ this.setDataValue('bcc', val.join(';'));
+ }
+ },
+ fromId: {
+ type: DataTypes.INTEGER
+ },
attachment: DataTypes.TEXT,
- html: DataTypes.TEXT,
- text: DataTypes.TEXT,
+ text: {
+ type: DataTypes.BLOB,
+ get: function() {
+ if (this.getDataValue('text')) {
+ return _.toString(this.getDataValue('text'));
+ }
+ }
+ },
+ html: {
+ type: DataTypes.BLOB,
+ get: function() {
+ if (this.getDataValue('html')) {
+ if (this.getDataValue('html')) {
+ return _.toString(this.getDataValue('html'));
+ }
+ }
+ },
+ },
reason: DataTypes.TEXT,
status: {
- type: DataTypes.ENUM('SENT', 'SENDING', 'RECEIVED', 'FAILED')
- }
+ type: DataTypes.ENUM('SENDING', 'SENT', 'RECEIVED', 'FAILED', 'NOTE'),
+ defaultValue: 'SENDING'
+ },
+ retry: {
+ type: DataTypes.INTEGER,
+ defaultValue: 0
+ },
+ voiceSource: DataTypes.STRING
}, {
tableName: 'mail_messages',
+ paranoid: true,
associate: function(models) {
- MailMessage.belongsTo(models.MailRoom);
-
- MailMessage.belongsTo(models.Contact, {
- as: 'From',
- onDelete: 'cascade'
- });
-
- MailMessage.belongsToMany(models.Contact, {
- as: 'To',
- through: 'mail_message_has_to',
- onDelete: 'cascade'
- });
-
- MailMessage.belongsToMany(models.Contact, {
- as: 'Cc',
- through: 'mail_message_has_cc',
- onDelete: 'cascade'
- });
-
- MailMessage.belongsToMany(models.MailAttachment, {
- through: 'mail_message_has_attachment',
+ MailMessage.hasMany(models.MailAttachment);
+ MailMessage.belongsTo(models.User);
+ MailMessage.belongsTo(models.MailRoom, {
onDelete: 'cascade'
});
}