|
@ -262,6 +262,66 @@ class Messages extends RedisModel {
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
* 清洗数据
|
|
|
* @param message
|
|
|
*/
|
|
|
dataMessage(sessionId) {
|
|
|
let self = this;
|
|
|
let messagesKey = RedisModel.makeRedisKey(REDIS_KEYS.Messages, sessionId);
|
|
|
let message_timestamp_key = RedisModel.makeRedisKey(REDIS_KEYS.MessagesByTimestamp, sessionId);
|
|
|
MessageRepo.findBySessionId(sessionId, 0, config.sessionConfig.maxMessageCount, null, function (err, messages) {
|
|
|
if (err) {
|
|
|
ModelUtil.emitError(self.eventEmitter, {status: -1, message: "没有找到对应sessionId的聊天记录----"+sessionId});
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
let multi = redis.multi();
|
|
|
if(messages){
|
|
|
messages.forEach(function (message) {
|
|
|
let msgJson = {
|
|
|
id: message.id,
|
|
|
sender_id: message.sender_id,
|
|
|
sender_name: message.sender_name,
|
|
|
timestamp: ObjectUtil.timestampToLong(message.timestamp),
|
|
|
content_type: message.content_type,
|
|
|
content: message.content
|
|
|
};
|
|
|
|
|
|
multi = multi.hset(messagesKey, message.id, JSON.stringify(msgJson))
|
|
|
.zadd(message_timestamp_key, ObjectUtil.timestampToLong(message.timestamp), message.id);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
|
|
|
multi.execAsync()
|
|
|
.then(function (res) {
|
|
|
ModelUtil.emitOK(self.eventEmitter, {status:200,message:"存入redis成功!"});
|
|
|
})
|
|
|
.catch(function (ex) {
|
|
|
log.error("Login failed while caching messages: ", ex);
|
|
|
ModelUtil.emitOK(self.eventEmitter, res);
|
|
|
return;
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
* 清洗数据
|
|
|
* @param message
|
|
|
*/
|
|
|
cleanMessageToReids(session_id_str) {
|
|
|
let self = this;
|
|
|
console.log(session_id_str)
|
|
|
let sessionArray=session_id_str.split(",");
|
|
|
sessionArray.forEach(function (sessionId) {
|
|
|
console.log(sessionId);
|
|
|
self.dataMessage(sessionId);
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// Expose class
|