|
@ -2884,7 +2884,66 @@ class Sessions extends RedisModel {
|
|
|
|
|
|
}
|
|
|
|
|
|
//把会话写入redis
|
|
|
fixSessionToRedis(sessionId,handler) {
|
|
|
let self = this;
|
|
|
let participants = new Participants();
|
|
|
let sessionKey = RedisModel.makeRedisKey(REDIS_KEYS.Session, sessionId);
|
|
|
let messageId = mongoose.Types.ObjectId().toString();
|
|
|
let sessionType =0;
|
|
|
|
|
|
redis.hmgetAsync(sessionKey, ["type", "name"]).then(function (res) {
|
|
|
sessionType = res[0];
|
|
|
let sessionName = res[1];
|
|
|
if (sessionType == null) {
|
|
|
self.getSessions(sessionId,function(err,res){
|
|
|
if (err){
|
|
|
logger.error("session data is error");
|
|
|
} else {
|
|
|
sessionName=res[0].name;
|
|
|
sessionType = res[0].type;
|
|
|
}
|
|
|
});
|
|
|
let participantArray = [];
|
|
|
let participantsStr="{";
|
|
|
ParticipantRepo.findAll(sessionId, function (err, participants) {
|
|
|
if (err) {
|
|
|
ModelUtil.emitError(self.eventEmitter, err.message);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
participants.forEach(function (participant) {
|
|
|
let participantId = participant.id;
|
|
|
let participantRole = participant.role;
|
|
|
let score = ObjectUtil.timestampToLong(participant.last_fetch_time||(new Date()));
|
|
|
participantsStr +="\""+participantId+"\":\""+participantRole+"\",";
|
|
|
});
|
|
|
|
|
|
participantsStr = participantsStr.substring(0,participantsStr.length-1)+'}';
|
|
|
participantsStr = JSON.parse(participantsStr);
|
|
|
for (let j in participantsStr) {
|
|
|
participantArray.push(j + ":" + participantsStr[j]);
|
|
|
}
|
|
|
//创建session到redis
|
|
|
self.createSessionToRedis(sessionId, sessionName, sessionType, participantArray, messageId, function (err, res) {
|
|
|
if (err) {
|
|
|
if (handler) {
|
|
|
handler(err, null);
|
|
|
}
|
|
|
ModelUtil.emitError(self.eventEmitter, {message: err, status: -1}, null);
|
|
|
} else {
|
|
|
if (handler) {
|
|
|
handler(null, res);
|
|
|
}
|
|
|
ModelUtil.emitOK(self.eventEmitter, {status: 200, data: res});
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
}else {
|
|
|
ModelUtil.emitOK(self.eventEmitter, {status: 200, data: res});
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// Expose class
|