|
@ -159,11 +159,11 @@ class Users extends RedisModel {
|
|
*/
|
|
*/
|
|
login(userId, platform, token, clientId) {
|
|
login(userId, platform, token, clientId) {
|
|
let self = this;
|
|
let self = this;
|
|
let loginFromApp = platform === PLATFORMS.Wechat;
|
|
|
|
|
|
let loginFromApp = platform !== PLATFORMS.Wechat;
|
|
|
|
|
|
let usersKey = REDIS_KEYS.Users;
|
|
let usersKey = REDIS_KEYS.Users;
|
|
let userKey = self.makeRedisKey(REDIS_KEYS.User, userId);
|
|
let userKey = self.makeRedisKey(REDIS_KEYS.User, userId);
|
|
let userStatusKey = self.makeRedisKey(loginFromApp ? REDIS_KEYS.UserWechatStatus : REDIS_KEYS.UserWechatStatus, userId);
|
|
|
|
|
|
let userStatusKey = self.makeRedisKey(loginFromApp ? REDIS_KEYS.UserAppStatus : REDIS_KEYS.UserWechatStatus, userId);
|
|
let lastLoginTime = new Date();
|
|
let lastLoginTime = new Date();
|
|
|
|
|
|
async.waterfall([
|
|
async.waterfall([
|
|
@ -180,9 +180,9 @@ class Users extends RedisModel {
|
|
},
|
|
},
|
|
// cache user info and app/wechat status
|
|
// cache user info and app/wechat status
|
|
function (userInfo, callback) {
|
|
function (userInfo, callback) {
|
|
let multi = redisConn.multiAsync()
|
|
|
|
|
|
let multi = redisConn.multi()
|
|
.zadd(usersKey, lastLoginTime.getMilliseconds(), userId)
|
|
.zadd(usersKey, lastLoginTime.getMilliseconds(), userId)
|
|
.hmset(userKey, 'avatar', userInfo.avatar, 'birthdate', userInfo.birthdate,
|
|
|
|
|
|
.hmset(userKey, 'avatar', userInfo.avatar ? userInfo.avatar : '', 'birthdate', userInfo.birthdate? userInfo.birthdate : '',
|
|
'name', userInfo.name, 'role', loginFromApp ? 'doctor' : 'patient');
|
|
'name', userInfo.name, 'role', loginFromApp ? 'doctor' : 'patient');
|
|
|
|
|
|
if (loginFromApp) {
|
|
if (loginFromApp) {
|
|
@ -201,15 +201,15 @@ class Users extends RedisModel {
|
|
// cache sessions, participants, topics, messages
|
|
// cache sessions, participants, topics, messages
|
|
function (callback) {
|
|
function (callback) {
|
|
SessionRepo.findAll(userId, function (err, sessions) {
|
|
SessionRepo.findAll(userId, function (err, sessions) {
|
|
for (let i = 0; i < sessions.length; ++i) {
|
|
|
|
let sessionId = sessions[i].id;
|
|
|
|
let name = sessions[i].name;
|
|
|
|
let type = sessions[i].type;
|
|
|
|
let createDate = sessions[i].create_date;
|
|
|
|
|
|
for (let session in sessions) {
|
|
|
|
let sessionId = session.id;
|
|
|
|
let name = session.name;
|
|
|
|
let type = session.type;
|
|
|
|
let createDate = session.create_date;
|
|
|
|
|
|
(function (sessionId, userId) {
|
|
(function (sessionId, userId) {
|
|
// cache sessions
|
|
// cache sessions
|
|
redisConn.multiAsync()
|
|
|
|
|
|
redisConn.multi()
|
|
.zadd(self.makeRedisKey(REDIS_KEYS.UserSessions, userId))
|
|
.zadd(self.makeRedisKey(REDIS_KEYS.UserSessions, userId))
|
|
.hmset(self.makeRedisKey(REDIS_KEYS.Session, sessionId, 'name', name, 'type', type, 'create_date', createDate))
|
|
.hmset(self.makeRedisKey(REDIS_KEYS.Session, sessionId, 'name', name, 'type', type, 'create_date', createDate))
|
|
.execAsync().then(function (res) {
|
|
.execAsync().then(function (res) {
|
|
@ -223,9 +223,9 @@ class Users extends RedisModel {
|
|
let participantRole = participant.participant_role;
|
|
let participantRole = participant.participant_role;
|
|
let score = new Date().getMilliseconds();
|
|
let score = new Date().getMilliseconds();
|
|
|
|
|
|
redisConn.multiAsync()
|
|
|
|
.zaddAsync(sessionParticipantsKey, participantId, score)
|
|
|
|
.hsetAsync(sessionParticipantsRoleKey, participantId, participantRole)
|
|
|
|
|
|
redisConn.multi()
|
|
|
|
.zadd(sessionParticipantsKey, participantId, score)
|
|
|
|
.hset(sessionParticipantsRoleKey, participantId, participantRole)
|
|
.execAsync().then(function (res) {
|
|
.execAsync().then(function (res) {
|
|
});
|
|
});
|
|
}
|
|
}
|
|
@ -246,7 +246,7 @@ class Users extends RedisModel {
|
|
timestamp: message.timestamp
|
|
timestamp: message.timestamp
|
|
};
|
|
};
|
|
|
|
|
|
redisConn.multiAsync()
|
|
|
|
|
|
redisConn.multi()
|
|
.hset(messagesKey, id, msgJson)
|
|
.hset(messagesKey, id, msgJson)
|
|
.zadd(messagesByTimestampKey, id)
|
|
.zadd(messagesByTimestampKey, id)
|
|
.execAsync()
|
|
.execAsync()
|
|
@ -266,7 +266,7 @@ class Users extends RedisModel {
|
|
let endBy = topic.end_by;
|
|
let endBy = topic.end_by;
|
|
let startMesssageId = topic.start_message_id;
|
|
let startMesssageId = topic.start_message_id;
|
|
let endMessageId = topic.end_message_id;
|
|
let endMessageId = topic.end_message_id;
|
|
redisConn.multiAsync()
|
|
|
|
|
|
redisConn.multi()
|
|
.zadd(topicsKey, topicId)
|
|
.zadd(topicsKey, topicId)
|
|
.hmset(topicKey, 'name', name, 'session_id', sessionId, 'create_time',
|
|
.hmset(topicKey, 'name', name, 'session_id', sessionId, 'create_time',
|
|
createTime, 'end_by', endBy, 'start_message_id',
|
|
createTime, 'end_by', endBy, 'start_message_id',
|