|
@ -342,6 +342,7 @@ class Sessions extends RedisModel {
|
|
|
* @param userId
|
|
|
* @param page
|
|
|
* @param size
|
|
|
* @param businessType
|
|
|
*/
|
|
|
getUserSessions(userId, page, size, businessType) {
|
|
|
let userSessionKey = RedisModel.makeRedisKey(REDIS_KEYS.UserSessions, userId);
|
|
@ -369,12 +370,12 @@ class Sessions extends RedisModel {
|
|
|
function (sessionIds) {
|
|
|
let sessionList = [];
|
|
|
let functionList = [];
|
|
|
for (var j = 0; j < sessionIds.length; j++) {
|
|
|
for (let j = 0; j < sessionIds.length; j++) {
|
|
|
let fun = function (index, callback) {
|
|
|
if (!callback) {
|
|
|
callback = index, index = 0
|
|
|
}
|
|
|
;
|
|
|
|
|
|
let sessionId = sessionIds[index]
|
|
|
let sessionKey = RedisModel.makeRedisKey(REDIS_KEYS.Session, sessionId);
|
|
|
let participantsRoleKey = RedisModel.makeRedisKey(REDIS_KEYS.SessionParticipantsRole, sessionId);
|
|
@ -394,7 +395,7 @@ class Sessions extends RedisModel {
|
|
|
let sessionName = "";
|
|
|
let otheruserId = "";
|
|
|
if (session.type == SESSION_TYPES.P2P) {
|
|
|
for (var j in users) {
|
|
|
for (let j in users) {
|
|
|
if (users[j] != userId) {
|
|
|
otheruserId = users[j];
|
|
|
}
|
|
@ -402,6 +403,7 @@ class Sessions extends RedisModel {
|
|
|
}
|
|
|
if (!role) role = 0;
|
|
|
if (!lastFetchTime) lastFetchTime = new Date().getTime();
|
|
|
|
|
|
// 计算未读消息数
|
|
|
let messagesByTimestampKey = RedisModel.makeRedisKey(REDIS_KEYS.MessagesByTimestamp, sessionId);
|
|
|
redis.zcountAsync(messagesByTimestampKey, lastFetchTime, new Date().getTime())
|
|
@ -413,6 +415,7 @@ class Sessions extends RedisModel {
|
|
|
} else {
|
|
|
sessionName = res[0].name;
|
|
|
}
|
|
|
|
|
|
sessionList.push({
|
|
|
id: sessionId,
|
|
|
name: sessionName,
|
|
@ -426,22 +429,24 @@ class Sessions extends RedisModel {
|
|
|
business_type: session.business_type,
|
|
|
my_role: role
|
|
|
});
|
|
|
|
|
|
index = (parseInt(index) + 1);
|
|
|
if (index == sessionIds.length) {
|
|
|
ModelUtil.emitOK(self.eventEmitter, sessionList);
|
|
|
} else {
|
|
|
callback(null, index);
|
|
|
}
|
|
|
|
|
|
})
|
|
|
})
|
|
|
}).catch(function (err) {
|
|
|
logger.error("Get sessions failed: ", err);
|
|
|
});
|
|
|
}
|
|
|
})
|
|
|
.catch(function (err) {
|
|
|
logger.error("Get sessions failed: ", err);
|
|
|
});
|
|
|
};
|
|
|
|
|
|
functionList.push(fun);
|
|
|
}
|
|
|
;
|
|
|
|
|
|
async.waterfall(functionList);
|
|
|
}
|
|
|
]);
|
|
@ -887,7 +892,7 @@ class Sessions extends RedisModel {
|
|
|
sessionName = res[1];
|
|
|
if (!sessionType || !sessionName) {
|
|
|
logger.error("Unknown session key " + session_key);
|
|
|
if(handler) return handler(new Error("Unknown session key " + session_key));
|
|
|
if (handler) return handler(new Error("Unknown session key " + session_key));
|
|
|
}
|
|
|
}).then(function (res) {
|
|
|
// 更新消息存储REDIS
|
|
@ -901,12 +906,12 @@ class Sessions extends RedisModel {
|
|
|
//更新session实体的最后一条消息
|
|
|
SessionRepo.updateSessionLastStatus(message.sender_id, message.sender_name, message.timestamp, message.content, message.content_type, sessionId);
|
|
|
|
|
|
if(handler) handler(null, messageId);
|
|
|
if (handler) handler(null, messageId);
|
|
|
}).then(function (res) {
|
|
|
// 推送消息
|
|
|
ParticipantRepo.findIds(sessionId, function (err, res) {
|
|
|
if (err) {
|
|
|
if(handler) handler(err, messageId)
|
|
|
if (handler) handler(err, messageId)
|
|
|
} else {
|
|
|
message.session_id = sessionId;
|
|
|
res.forEach(function (participant) {
|
|
@ -917,10 +922,10 @@ class Sessions extends RedisModel {
|
|
|
}
|
|
|
})
|
|
|
}).catch(function (err) {
|
|
|
if(handler) handler(err, messageId)
|
|
|
if (handler) handler(err, messageId)
|
|
|
})
|
|
|
} else {
|
|
|
if(handler) handler("用户不在此会话当中!", messageId);
|
|
|
if (handler) handler("用户不在此会话当中!", messageId);
|
|
|
}
|
|
|
})
|
|
|
}
|