|
@ -185,8 +185,8 @@ class Users extends RedisModel {
|
|
|
function (userInfo, callback) {
|
|
|
let multi = redisConn.multi()
|
|
|
.zadd(usersKey, lastLoginTime.getTime(), userId);
|
|
|
//.hmset(userKey, 'avatar', userInfo.avatar ? userInfo.avatar : '', 'birthdate', userInfo.birthdate ? userInfo.birthdate : '',
|
|
|
// 'name', userInfo.name, 'role', loginFromApp ? 'doctor' : 'patient');
|
|
|
//.hmset(userKey, 'avatar', userInfo.avatar ? userInfo.avatar : '', 'birthdate', userInfo.birthdate ? userInfo.birthdate : '',
|
|
|
// 'name', userInfo.name, 'role', loginFromApp ? 'doctor' : 'patient');
|
|
|
|
|
|
if (loginFromApp) {
|
|
|
// cache app status
|
|
@ -204,7 +204,7 @@ class Users extends RedisModel {
|
|
|
// cache sessions, participants, topics, messages
|
|
|
function (callback) {
|
|
|
SessionRepo.findAll(userId, function (err, sessions) {
|
|
|
for (let session in sessions) {
|
|
|
sessions.forEach(function (session) {
|
|
|
let sessionId = session.id;
|
|
|
let name = session.name;
|
|
|
let type = session.type;
|
|
@ -213,76 +213,76 @@ class Users extends RedisModel {
|
|
|
(function (sessionId, userId) {
|
|
|
// cache sessions
|
|
|
redisConn.multi()
|
|
|
.zadd(RedisModel.makeRedisKey(REDIS_KEYS.Sessions), lastLoginTime) // 会话的最后活动时间设置为此用户的登录时间
|
|
|
.zadd(RedisModel.makeRedisKey(REDIS_KEYS.UserSessions, userId), lastLoginTime) // 会话的最后活动时间设置为此用户的登录时间
|
|
|
.hmset(RedisModel.makeRedisKey(REDIS_KEYS.Session, sessionId, 'name', name, 'type', type, 'create_date', createDate))
|
|
|
.execAsync().then(function (res) {
|
|
|
|
|
|
// cache participants
|
|
|
let sessionParticipantsKey = RedisModel.makeRedisKey(REDIS_KEYS.SessionParticipants, sessionId);
|
|
|
let sessionParticipantsRoleKey = RedisModel.makeRedisKey(REDIS_KEYS.SessionParticipantsRole, sessionId);
|
|
|
ParticipantRepo.findParticipants(sessionId, function (err, participants) {
|
|
|
for (let participant in participants) {
|
|
|
let participantId = participant.participant_id;
|
|
|
let participantRole = participant.participant_role;
|
|
|
let score = new Date().getTime();
|
|
|
|
|
|
redisConn.multi()
|
|
|
.zadd(sessionParticipantsKey, participantId, score)
|
|
|
.hset(sessionParticipantsRoleKey, participantId, participantRole)
|
|
|
.execAsync().then(function (res) {
|
|
|
.zadd(REDIS_KEYS.Sessions, lastLoginTime.getTime(), sessionId) // 会话的最后活动时间设置为此用户的登录时间
|
|
|
.zadd(RedisModel.makeRedisKey(REDIS_KEYS.UserSessions, userId), lastLoginTime.getTime(), sessionId) // 会话的最后活动时间设置为此用户的登录时间
|
|
|
.hmset(RedisModel.makeRedisKey(REDIS_KEYS.Session, sessionId), 'name', name, 'type', type, 'create_date', createDate.getTime())
|
|
|
.execAsync()
|
|
|
.then(function (res) {
|
|
|
// cache participants
|
|
|
let sessionParticipantsKey = RedisModel.makeRedisKey(REDIS_KEYS.SessionParticipants, sessionId);
|
|
|
let sessionParticipantsRoleKey = RedisModel.makeRedisKey(REDIS_KEYS.SessionParticipantsRole, sessionId);
|
|
|
ParticipantRepo.findParticipants(sessionId, function (err, participants) {
|
|
|
participants.forEach(function (participant) {
|
|
|
let participantId = participant.participant_id;
|
|
|
let participantRole = participant.participant_role;
|
|
|
let score = new Date().getTime();
|
|
|
|
|
|
redisConn.multi()
|
|
|
.zadd(sessionParticipantsKey, participantId, score)
|
|
|
.hset(sessionParticipantsRoleKey, participantId, participantRole)
|
|
|
.execAsync().then(function (res) {
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
|
|
|
// cache messages
|
|
|
let messagesKey = RedisModel.makeRedisKey(REDIS_KEYS.Messages, sessionId);
|
|
|
let messagesByTimestampKey = RedisModel.makeRedisKey(REDIS_KEYS.MessagesByTimestamp, sessionId);
|
|
|
MessageRepo.findBySessionId(sessionId, 0, config.sessionConfig.maxMessageCount, function (err, messages) {
|
|
|
for (let message in messages) {
|
|
|
let id = message.id;
|
|
|
let msgJson = {
|
|
|
sessionId: message.session_id,
|
|
|
senderId: message.sender_id,
|
|
|
senderName: message.sender_name,
|
|
|
contentType: message.content_type,
|
|
|
content: message.content,
|
|
|
timestamp: message.timestamp
|
|
|
};
|
|
|
|
|
|
redisConn.multi()
|
|
|
.hset(messagesKey, id, msgJson)
|
|
|
.zadd(messagesByTimestampKey, id)
|
|
|
.execAsync()
|
|
|
.then(function (res) {
|
|
|
});
|
|
|
|
|
|
// cache messages
|
|
|
let messagesKey = RedisModel.makeRedisKey(REDIS_KEYS.Messages, sessionId);
|
|
|
let messagesByTimestampKey = RedisModel.makeRedisKey(REDIS_KEYS.MessagesByTimestamp, sessionId);
|
|
|
MessageRepo.findBySessionId(sessionId, 0, config.sessionConfig.maxMessageCount, function (err, messages) {
|
|
|
messages.forEach(function (message) {
|
|
|
let id = message.id;
|
|
|
let msgJson = {
|
|
|
sessionId: message.session_id,
|
|
|
senderId: message.sender_id,
|
|
|
senderName: message.sender_name,
|
|
|
contentType: message.content_type,
|
|
|
content: message.content,
|
|
|
timestamp: message.timestamp
|
|
|
};
|
|
|
|
|
|
redisConn.multi()
|
|
|
.hset(messagesKey, id, msgJson)
|
|
|
.zadd(messagesByTimestampKey, id)
|
|
|
.execAsync()
|
|
|
.then(function (res) {
|
|
|
});
|
|
|
});
|
|
|
});
|
|
|
|
|
|
// cache topics for MUC
|
|
|
let topicsKey = RedisModel.makeRedisKey(REDIS_KEYS.Topics, sessionId);
|
|
|
TopicRepo.findAll(sessionId, function (err, topics) {
|
|
|
topics.forEach(function (topic) {
|
|
|
let topicKey = RedisModel.makeRedisKey(REDIS_KEYS.Topic, topic.id);
|
|
|
let topicId = topic.id;
|
|
|
let name = topic.name;
|
|
|
let createTime = ObjectUtil.timestampToLong(topic.create_time);
|
|
|
let endBy = topic.end_by;
|
|
|
let endTime = ObjectUtil.timestampToLong(topic.end_time);
|
|
|
let startMessageId = topic.start_message_id;
|
|
|
let endMessageId = topic.end_message_id;
|
|
|
redisConn.multi()
|
|
|
.zadd(topicsKey, topicId)
|
|
|
.hmset(topicKey, 'name', name, 'session_id', sessionId, 'create_time',
|
|
|
createTime, 'end_by', endBy, 'end_time', endTime, 'start_message_id',
|
|
|
startMessageId, 'end_message_id', endMessageId)
|
|
|
.execAsync().then(function (res) {
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
|
|
|
// cache topics for MUC
|
|
|
let topicsKey = RedisModel.makeRedisKey(REDIS_KEYS.Topics, sessionId);
|
|
|
TopicRepo.findAll(sessionId, function (err, topics) {
|
|
|
for (let topic in topics) {
|
|
|
let topicKey = RedisModel.makeRedisKey(REDIS_KEYS.Topic, topic.id);
|
|
|
let topicId = topic.id;
|
|
|
let name = topic.name;
|
|
|
let createTime = ObjectUtil.timestampToLong(topic.create_time);
|
|
|
let endBy = topic.end_by;
|
|
|
let endTime = ObjectUtil.timestampToLong(topic.end_time);
|
|
|
let startMessageId = topic.start_message_id;
|
|
|
let endMessageId = topic.end_message_id;
|
|
|
redisConn.multi()
|
|
|
.zadd(topicsKey, topicId)
|
|
|
.hmset(topicKey, 'name', name, 'session_id', sessionId, 'create_time',
|
|
|
createTime, 'end_by', endBy, 'end_time', endTime, 'start_message_id',
|
|
|
startMessageId, 'end_message_id', endMessageId)
|
|
|
.execAsync().then(function (res) {
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
});
|
|
|
})(sessionId, userId);
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
|
|
|
callback(null, null);
|