| 
															
																@ -11,6 +11,8 @@ let Users = require('../user/users'); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																let Participants = require('./Participants'); 
															 | 
															
															 | 
															
																let Participants = require('./Participants'); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																let SessionRepo = require('../../repository/mysql/session.repo'); 
															 | 
															
															 | 
															
																let SessionRepo = require('../../repository/mysql/session.repo'); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																let ParticipantRepo = require('../../repository/mysql/participant.repo'); 
															 | 
															
															 | 
															
																let ParticipantRepo = require('../../repository/mysql/participant.repo'); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																let MessageRepo = require('../../repository/mysql/message.repo'); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																let WechatClient = require("../client/wechat.client.js"); 
															 | 
															
															 | 
															
																let WechatClient = require("../client/wechat.client.js"); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																let AppClient = require("../client/app.client.js"); 
															 | 
															
															 | 
															
																let AppClient = require("../client/app.client.js"); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@ -46,85 +48,208 @@ class Sessions extends RedisModel { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     */ 
															 | 
															
															 | 
															
																     */ 
															 | 
														
													
												
													
														
															| 
															 | 
															
																    createSession(sessionId, name, type, participantArray, handler) { 
															 | 
															
															 | 
															
																    createSession(sessionId, name, type, participantArray, handler) { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																        let self = this; 
															 | 
															
															 | 
															
																        let self = this; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																        let messageId = mongoose.Types.ObjectId().toString(); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																        //创建session到mysql 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																        self.createSessionToMysql(sessionId, name, type, participantArray,messageId,function(err,res){ 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																            if(err){ 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                logger.error(err); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																            }else{ 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                logger.info("create session to mysql success :" +JSON.stringify(res)); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																            } 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																        }); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																        //创建session到redis 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																        self.createSessionToRedis(sessionId, name, type, participantArray,messageId, function(err,res){ 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																            if(err){ 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                if(handler){handler(err,null);return;}; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                ModelUtil.emitError(self.eventEmitter, {message:err}, null); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																            }else{ 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                if(handler){handler(null,res);return;}; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                ModelUtil.emitOK(self.eventEmitter,res); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																            } 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																        }); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																    } 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																    /** 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																     * 创建会话。REDIS 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																     * @param sessionId 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																     * @param name 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																     * @param type 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																     * @param participantArray 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																     * @param messageId 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																     * @param handler 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																     * @returns {boolean} 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																     */ 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																    createSessionToRedis(sessionId, name, type, participantArray,messageId, handler){ 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																        let self = this; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																        let messages = new Messages(); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																        var participantIdArray = []; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																        for (let i in participantArray) { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																            participantIdArray.push(participantArray[i].split(":")[0]); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																        } 
															 | 
														
													
												
													
														
															| 
															 | 
															
																        if (type == SESSION_TYPES.P2P||type==SESSION_TYPES.SYSTEM) { 
															 | 
															
															 | 
															
																        if (type == SESSION_TYPES.P2P||type==SESSION_TYPES.SYSTEM) { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																            var participantIdArray = []; 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																            for (let i in participantArray) { 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                participantIdArray.push(participantArray[i].split(":")[0]); 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																            if(sessionId){ 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                callBusinessType(sessionId); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                return; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																            } 
															 | 
															
															 | 
															
																            } 
															 | 
														
													
												
													
														
															| 
															 | 
															
																            if (participantIdArray.length != 2) { 
															 | 
															
															 | 
															
																            if (participantIdArray.length != 2) { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                ModelUtil.emitDataNotFound(self.eventEmitter, {message: "P2P session only allow 2 participants."}); 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                handler("P2P session only allow 2 participants.",null); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                return false; 
															 | 
															
															 | 
															
																                return false; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																            } 
															 | 
															
															 | 
															
																            } 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																            ParticipantRepo.findSessionIdByParticipantIds(participantIdArray[0], participantIdArray[1], function (err, res) { 
															 | 
															
															 | 
															
																            ParticipantRepo.findSessionIdByParticipantIds(participantIdArray[0], participantIdArray[1], function (err, res) { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                sessionId = res; 
															 | 
															
															 | 
															
																                sessionId = res; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                callBusinessType(sessionId); 
															 | 
															
															 | 
															
																                callBusinessType(sessionId); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																            }); 
															 | 
															
															 | 
															
																            }); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																        } else { 
															 | 
															
															 | 
															
																        } else { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																            if(!sessionId){ 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                handler("MUC OR GROUP session sessionId is not  allow null .",null); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                return; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																            } 
															 | 
														
													
												
													
														
															| 
															 | 
															
																            callBusinessType(sessionId); 
															 | 
															
															 | 
															
																            callBusinessType(sessionId); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																        } 
															 | 
															
															 | 
															
																        } 
															 | 
														
													
												
													
														
															| 
															 | 
															
																        var businessType = SESSION_BUSINESS_TYPE.DOCTOR; 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																        function callBusinessType(sessionId) { 
															 | 
															
															 | 
															
																        function callBusinessType(sessionId) { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																            for (var j = 0; j < participantArray.length; j++) 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                callIsPatient(j, participantArray.length); 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																            ParticipantRepo.getBusinessType(participantIdArray.join("','"),function(err,businessType){ 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                callCreate(sessionId, businessType); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																            }); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																        } 
															 | 
															
															 | 
															
																        } 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																        function callIsPatient(j, length) { 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																            Users.isPatientId(participantArray[j], function (isPatient) { 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                if (isPatient) { 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                    businessType = SESSION_BUSINESS_TYPE.PATIENT 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                } 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                if (length - 1 == j || businessType == SESSION_BUSINESS_TYPE.PATIENT) { 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                    callCreate(sessionId, businessType); 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                } 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																        function callCreate(sessionId, businessType) { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																            let createDate = new Date(); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																            let sessionKey = RedisModel.makeRedisKey(REDIS_KEYS.Session, sessionId); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																            let message = { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                sender_id: "system", 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                sender_name: "system", 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                content_type: 6, 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                content: "会话创建成功", 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                timestamp: createDate, 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                id:messageId 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																            }; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																            let session = { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                id :sessionId, 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                name:name, 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                type:type, 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                create_date:createDate.getTime(), 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                business_type:businessType, 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                last_sender_id : message.sender_id, 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                last_sender_name : message.sender_name, 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                last_message_time: message.timestamp.getTime(), 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                last_content  : message.content, 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                last_content_type : message.content_type 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																            } 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																            redis.hmsetAsync(sessionKey, session).then(function(){ 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                Participants.saveParticipantsToRedis(sessionId, participantArray, createDate, function (res) { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                    handler(null, session); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                    messages.saveMessageToRedisFromCreateSession(sessionId, messageId, message); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                }); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																            }) 
															 | 
															
															 | 
															
																            }) 
															 | 
														
													
												
													
														
															| 
															 | 
															
																        } 
															 | 
															
															 | 
															
																        } 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																    } 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																    /** 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																     * 创建会话。mysql 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																     * @param sessionId 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																     * @param name 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																     * @param type 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																     * @param participantArray 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																     * @param messageId 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																     * @param handler 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																     */ 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																    createSessionToMysql(sessionId, name, type, participantArray,messageId, handler){ 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																        let self = this; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																        //如果sessionId不存在则执行创建sessionId过程 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																        var participantIdArray = []; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																        for (let i in participantArray) { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																            participantIdArray.push(participantArray[i].split(":")[0]); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																        } 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																        //流程1-判断是否存在sessionId不存在则创建对应的sessionId; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																        if(!sessionId){ 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																            if (type == SESSION_TYPES.P2P||type==SESSION_TYPES.SYSTEM) { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                ParticipantRepo.findSessionIdByParticipantIds(participantIdArray[0], participantIdArray[1], function (err, res) { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                    sessionId = res; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                    callBusinessType(); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                }); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																            }else{ 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                handler("MUC模式和团队模式,不允许sessionId为空!",null); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                return; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																            } 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																        }else{ 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																            callBusinessType(); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																        } 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																        //流程2-判断session的业务类型; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																        function callBusinessType(){ 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																            ParticipantRepo.getBusinessType(participantIdArray.join("','"),function(err,businessType){ 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                if(err){handler(err,null);return;} 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                callCreateSession(businessType); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																            }); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																        } 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																        function callCreate(sessionId, businessType) { 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																        //流程3-发起session创建 返回session实例 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																        function callCreateSession(businessType){ 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																            //查找该sessionId是否存在存在则直接返回实例 
															 | 
														
													
												
													
														
															| 
															 | 
															
																            SessionRepo.findOne(sessionId, function (err, res) { 
															 | 
															
															 | 
															
																            SessionRepo.findOne(sessionId, function (err, res) { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                if (res.length > 0) { 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                    let session = res[0]; 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                    ModelUtil.emitOK(self.eventEmitter, { 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                        id: session.id, 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                        name: session.name, 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                        type: session.type, 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                        business_type: session.business_type || businessType, 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                        create_date: session.create_date 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                    }); 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                    return; 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                if (res.length > 0) {//已经存在 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                    handler(null,res[0]); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                }else{ 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                    let createDate = new Date(); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                    let session ={ 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                        id :sessionId, 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                        name:name, 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                        type:type, 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                        create_date:createDate.getTime(), 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                        business_type:businessType 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                    } 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                    //将session写入数据库 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                    self.saveSessionToMysql(sessionId, name, type, createDate, businessType, function (err, res) { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                        if(err){handler(err,null);return;}; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                        callCreateParticipants(session); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                    }) 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                } 
															 | 
															
															 | 
															
																                } 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																            }); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																        } 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                let createDate = new Date(); 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                let sessionKey = RedisModel.makeRedisKey(REDIS_KEYS.Session, sessionId); 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																        //流程4-发起session成员创建 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																        function callCreateParticipants(session){ 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																            Participants.saveParticipantsToMysql(sessionId, participantArray, function (err, res) { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                if(err){handler(err,null);return;}; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                callBeginTrans(session); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																            }) 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																        } 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                // 保存会话及成员至MySQL中 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                self.saveSessionToMysql(sessionId, name, type, createDate, businessType, function (err, res) { 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                    Participants.saveParticipantsToMysql(sessionId, participantArray, function (err, res) { 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                        if (err) { 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                            ModelUtil.emitError(self.eventEmitter, err.message); 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                            return; 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                        } 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                        let message = { 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                            sender_id: "System", 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                            sender_name: "System", 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                            content_type: 1, 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                            content: "", 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                            timestamp: createDate 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                        }; 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                        Messages.updateLastContent(sessionKey, type, name, message); 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                        Participants.saveParticipantsToRedis(sessionId, participantArray, createDate, function (res) { 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                            if (handler) { 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                                handler(true, sessionId); 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                            } else { 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                                ModelUtil.emitOK(self.eventEmitter, {id: sessionId}); 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                            } 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                        }); 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																        //流程5-发起session会话 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																        function callBeginTrans(session) { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																            let mesDate = new Date(); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																            let message = { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                sender_id: "system", 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                sender_name: "system", 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                content_type: 6, 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                content: "会话创建成功", 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                timestamp: mesDate, 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                id:messageId 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																            }; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																            session.last_sender_id = message.sender_id; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																            session.last_sender_name = message.sender_name; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																            session.last_message_time = mesDate.getTime(); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																            session.last_content  = message.content; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																            session.last_content_type = message.content_type; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																            MessageRepo.save(message,type,messageId,sessionId,function(err,res){ 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                SessionRepo.updateSessionLastStatus(message.sender_id, 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                    message.sender_name, 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                    message.timestamp, 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                    message.content, 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                    message.content_type, 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                    sessionId, function (err, res) { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                        if (err) {handler(err,null);return;}; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                        handler(null,session); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                    }); 
															 | 
															
															 | 
															
																                    }); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                }); 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																            }); 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																            }) 
															 | 
														
													
												
													
														
															| 
															 | 
															
																        } 
															 | 
															
															 | 
															
																        } 
															 | 
														
													
												
													
														
															| 
															 | 
															
																    } 
															 | 
															
															 | 
															
																    } 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@ -230,7 +355,6 @@ class Sessions extends RedisModel { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                                    }) 
															 | 
															
															 | 
															
																                                    }) 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                                }).catch(function (err) { 
															 | 
															
															 | 
															
																                                }).catch(function (err) { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                                    logger.error("Get sessions failed: ", ex); 
															 | 
															
															 | 
															
																                                    logger.error("Get sessions failed: ", ex); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                                    ModelUtil.emitError(self.eventEmitter, "Get sessions failed: " + err); 
															 | 
															
															 | 
															
																                                    ModelUtil.emitError(self.eventEmitter, "Get sessions failed: " + err); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                                }); 
															 | 
															
															 | 
															
																                                }); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                }); 
															 | 
															
															 | 
															
																                }); 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@ -238,6 +362,9 @@ class Sessions extends RedisModel { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																        ]); 
															 | 
															
															 | 
															
																        ]); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																    } 
															 | 
															
															 | 
															
																    } 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																    /** 
															 | 
															
															 | 
															
																    /** 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     * 获取会话消息。全部,不管已读/未读状态。 
															 | 
															
															 | 
															
																     * 获取会话消息。全部,不管已读/未读状态。 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     * 
															 | 
															
															 | 
															
																     * 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@ -548,6 +675,7 @@ class Sessions extends RedisModel { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																            } 
															 | 
															
															 | 
															
																            } 
															 | 
														
													
												
													
														
															| 
															 | 
															
																        }); 
															 | 
															
															 | 
															
																        }); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																    } 
															 | 
															
															 | 
															
																    } 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																    sendTopicMessages(topicId,message){ 
															 | 
															
															 | 
															
																    sendTopicMessages(topicId,message){ 
															 | 
														
													
												
													
														
															| 
															 | 
															
																        let self = this; 
															 | 
															
															 | 
															
																        let self = this; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																        let topicKey = RedisModel.makeRedisKey(REDIS_KEYS.Topic, topicId); 
															 | 
															
															 | 
															
																        let topicKey = RedisModel.makeRedisKey(REDIS_KEYS.Topic, topicId); 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@ -555,6 +683,7 @@ class Sessions extends RedisModel { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																            self.saveMessageBySession(topic.session_id,message); 
															 | 
															
															 | 
															
																            self.saveMessageBySession(topic.session_id,message); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																        }) 
															 | 
															
															 | 
															
																        }) 
															 | 
														
													
												
													
														
															| 
															 | 
															
																    } 
															 | 
															
															 | 
															
																    } 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																    /** 
															 | 
															
															 | 
															
																    /** 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     * 保存消息 
															 | 
															
															 | 
															
																     * 保存消息 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     * 
															 | 
															
															 | 
															
																     * 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@ -570,9 +699,7 @@ class Sessions extends RedisModel { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																        let self = this; 
															 | 
															
															 | 
															
																        let self = this; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																        let sessionType = 0; 
															 | 
															
															 | 
															
																        let sessionType = 0; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																        let sessionName = ""; 
															 | 
															
															 | 
															
																        let sessionName = ""; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																        message.id = messageId; 
															 | 
															
															 | 
															
																        message.id = messageId; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																        // 发送成员必须处于会话中 
															 | 
															
															 | 
															
																        // 发送成员必须处于会话中 
															 | 
														
													
												
													
														
															| 
															 | 
															
																        participants.existsParticipant(sessionId, message.sender_id, function (err, res) { 
															 | 
															
															 | 
															
																        participants.existsParticipant(sessionId, message.sender_id, function (err, res) { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																            if (res) { 
															 | 
															
															 | 
															
																            if (res) { 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@ -587,20 +714,20 @@ class Sessions extends RedisModel { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                    // 更新消息存储 
															 | 
															
															 | 
															
																                    // 更新消息存储 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                    messages.saveMessageToRedis(sessionId, sessionType, messageId, message); 
															 | 
															
															 | 
															
																                    messages.saveMessageToRedis(sessionId, sessionType, messageId, message); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                    messages.saveMessageToMysql(sessionId, sessionType, messageId, message); 
															 | 
															
															 | 
															
																                    messages.saveMessageToMysql(sessionId, sessionType, messageId, message); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                    // 更新会话最新状态及成员最后一次消息获取时间 
															 | 
															
															 | 
															
																                    // 更新会话最新状态及成员最后一次消息获取时间 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                    Sessions.updateParticipantLastFetchTime(sessionId, message.sender_id, message.timestamp.getTime()); 
															 | 
															
															 | 
															
																                    Sessions.updateParticipantLastFetchTime(sessionId, message.sender_id, message.timestamp.getTime()); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                    //更新最后一条消息 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                    Messages.updateLastContent(session_key, sessionType, sessionName, message); 
															 | 
															
															 | 
															
																                    Messages.updateLastContent(session_key, sessionType, sessionName, message); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                    //更新session实体的最后一条消息 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                    SessionRepo.updateSessionLastStatus(message.sender_id,message.sender_name,message.timestamp,message.content,message.content_type,sessionId); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                    handler(null, messageId); 
															 | 
															
															 | 
															
																                    handler(null, messageId); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                }).then(function (res) { 
															 | 
															
															 | 
															
																                }).then(function (res) { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                    // 推送消息 
															 | 
															
															 | 
															
																                    // 推送消息 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                    ParticipantRepo.findIds(sessionId, function (err, res) { 
															 | 
															
															 | 
															
																                    ParticipantRepo.findIds(sessionId, function (err, res) { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                        if (err) { 
															 | 
															
															 | 
															
																                        if (err) { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                            ModelUtil.logError("Push message from topic: get participant's id list failed: ", err); 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                            handler(err, messageId) 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                        } else { 
															 | 
															
															 | 
															
																                        } else { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                            message.session_id = sessionId; 
															 | 
															
															 | 
															
																                            message.session_id = sessionId; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                            res.forEach(function (participant) { 
															 | 
															
															 | 
															
																                            res.forEach(function (participant) { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                                if (participant.id !== message.sender_id) { 
															 | 
															
															 | 
															
																                                if (participant.id !== message.sender_id) { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                                    Sessions.pushNotification(participant.id, message); 
															 | 
															
															 | 
															
																                                    Sessions.pushNotification(participant.id, message); 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@ -609,7 +736,6 @@ class Sessions extends RedisModel { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                        } 
															 | 
															
															 | 
															
																                        } 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                    }) 
															 | 
															
															 | 
															
																                    }) 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                }).catch(function (err) { 
															 | 
															
															 | 
															
																                }).catch(function (err) { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                    ModelUtil.emitError(self.eventEmitter, "Error occurred while save message to topic: "); 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                    handler(err, messageId) 
															 | 
															
															 | 
															
																                    handler(err, messageId) 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                }) 
															 | 
															
															 | 
															
																                }) 
															 | 
														
													
												
													
														
															| 
															 | 
															
																            } else { 
															 | 
															
															 | 
															
																            } else { 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@ -709,6 +835,7 @@ class Sessions extends RedisModel { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																            } 
															 | 
															
															 | 
															
																            } 
															 | 
														
													
												
													
														
															| 
															 | 
															
																        }); 
															 | 
															
															 | 
															
																        }); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																    } 
															 | 
															
															 | 
															
																    } 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																} 
															 | 
															
															 | 
															
																} 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																// Expose class 
															 | 
															
															 | 
															
																// Expose class 
															 |