Built motion from commit 1038d87.|0.0.141
[motion.git] / server / models / chat_room.js
index bf09a48..6c48356 100644 (file)
@@ -1 +1,74 @@
-var _0x4508=["\x63\x72\x79\x70\x74\x6F","\x65\x78\x70\x6F\x72\x74\x73","\x43\x68\x61\x74\x52\x6F\x6F\x6D","\x69\x6E\x74\x65\x72\x6E\x61\x6C","\x65\x78\x74\x65\x72\x6E\x61\x6C","\x53\x54\x52\x49\x4E\x47","\x74\x6F\x6B\x65\x6E","\x4F\x50\x45\x4E","\x43\x4C\x4F\x53\x45\x44","\x67\x6F\x6F\x64","\x62\x61\x64","\x54\x45\x58\x54","\x61\x67\x65\x6E\x74","\x72\x65\x71\x75\x65\x73\x74\x65\x72","\x49\x4E\x54\x45\x47\x45\x52","\x63\x68\x61\x74\x5F\x72\x6F\x6F\x6D\x73","\x68\x61\x73\x4D\x61\x6E\x79","\x62\x65\x6C\x6F\x6E\x67\x73\x54\x6F","\x55\x73\x65\x72\x48\x61\x73\x43\x68\x61\x74\x52\x6F\x6F\x6D","\x62\x65\x6C\x6F\x6E\x67\x73\x54\x6F\x4D\x61\x6E\x79","\x64\x65\x66\x69\x6E\x65"];var crypto=require(_0x4508[0]);module[_0x4508[1]]=function(_0x4f89x2,_0x4f89x3){var _0x4f89x4=_0x4f89x2[_0x4508[20]](_0x4508[2],{type:_0x4f89x3.ENUM(_0x4508[3],_0x4508[4]),token:{type:_0x4f89x3[_0x4508[5]],unique:_0x4508[6]},status:{type:_0x4f89x3.ENUM(_0x4508[7],_0x4508[8]),defaultValue:_0x4508[7]},rating:_0x4f89x3.ENUM(_0x4508[9],_0x4508[10]),ratingMessage:_0x4f89x3[_0x4508[11]],completeReason:_0x4f89x3.ENUM(_0x4508[12],_0x4508[13]),ChatVisitorId:{type:_0x4f89x3[_0x4508[14]],unique:_0x4508[6]}},{tableName:_0x4508[15],associate:function(_0x4f89x5){_0x4f89x4[_0x4508[16]](_0x4f89x5.ChatMessage);_0x4f89x4[_0x4508[17]](_0x4f89x5.ChatVisitor);_0x4f89x4[_0x4508[17]](_0x4f89x5.ChatWebsite);_0x4f89x4[_0x4508[19]](_0x4f89x5.User,{through:_0x4f89x5[_0x4508[18]]})}});return _0x4f89x4}
\ No newline at end of file
+'use strict';
+
+module.exports = function(sequelize, DataTypes) {
+
+       var ChatRoom = sequelize.define('ChatRoom', {
+               type: DataTypes.ENUM('internal', 'external', 'group'),
+               token: {
+                       type: DataTypes.STRING,
+                       unique: 'token'
+               },
+               status: {
+                       type: DataTypes.ENUM('NEW', 'OPEN', 'CLOSED', 'ABANDON', 'UNMANAGED'),
+                       defaultValue: 'NEW'
+               },
+               rating: DataTypes.ENUM('good', 'bad'),
+               ratingMessage: DataTypes.TEXT,
+               completeReason: DataTypes.ENUM('agent', 'requester'),
+               ChatVisitorId: {
+                       type: DataTypes.INTEGER,
+                       unique: 'token'
+               },
+               waiting: {
+                       type: DataTypes.BOOLEAN,
+                       defaultValue: false
+               },
+               tags: {
+                       type: DataTypes.TEXT,
+                       get: function() {
+                               var tags;
+                               if (this.getDataValue('tags')) {
+                                       tags = this.getDataValue('tags').split(';');
+                                       tags.pop();
+                               } else {
+                                       tags = [];
+                               }
+                               return tags;
+                       },
+                       set: function(val) {
+                               this.setDataValue('tags', val && val.length ? val.join(';') + ';' : null);
+                       }
+               },
+               disposition: {
+                       type: DataTypes.STRING
+               },
+               openReason: DataTypes.STRING,
+               contact: DataTypes.STRING,
+               website: DataTypes.STRING
+       }, {
+               tableName: 'chat_rooms',
+               associate: function(models) {
+                       ChatRoom.hasMany(models.ChatMessage);
+                       ChatRoom.belongsTo(models.ChatVisitor);
+                       ChatRoom.belongsTo(models.ChatWebsite);
+                       ChatRoom.belongsToMany(models.User, {
+                               through: models.UserHasChatRoom
+                       });
+                       ChatRoom.addScope('online', {
+                               where: {
+                                       $and: [{
+                                               type: 'external'
+                                       }, {
+                                               $or: [{
+                                                       status: 'CLOSED'
+                                               }, {
+                                                       status: 'OPEN'
+                                               }]
+                                       }]
+                               }
+                       });
+               }
+       });
+
+       return ChatRoom;
+};