|
@ -102,14 +102,16 @@ class Sessions extends RedisModel {
|
|
|
callBusinessType(sessionId);
|
|
|
return;
|
|
|
}
|
|
|
if (participantIdArray.length != 2) {
|
|
|
else if (participantIdArray.length != 2) {
|
|
|
handler("P2P session only allow 2 participants.", null);
|
|
|
return false;
|
|
|
}else{
|
|
|
ParticipantRepo.findSessionIdByParticipantIds(participantIdArray[0], participantIdArray[1], function (err, res) {
|
|
|
sessionId = res;
|
|
|
callBusinessType(sessionId);
|
|
|
return;
|
|
|
});
|
|
|
}
|
|
|
ParticipantRepo.findSessionIdByParticipantIds(participantIdArray[0], participantIdArray[1], function (err, res) {
|
|
|
sessionId = res;
|
|
|
callBusinessType(sessionId);
|
|
|
});
|
|
|
} else {
|
|
|
if (!sessionId) {
|
|
|
handler("MUC OR GROUP session sessionId is not allow null .", null);
|
|
@ -350,12 +352,11 @@ class Sessions extends RedisModel {
|
|
|
let sessionKey = RedisModel.makeRedisKey(REDIS_KEYS.Session, sessionId);
|
|
|
let participantsRoleKey = RedisModel.makeRedisKey(REDIS_KEYS.SessionParticipantsRole, sessionId);
|
|
|
let sessionParticipantsKey = RedisModel.makeRedisKey(REDIS_KEYS.SessionParticipants, sessionId);
|
|
|
let participantsKey = RedisModel.makeRedisKey(REDIS_KEYS.SessionParticipants, sessionId);
|
|
|
redis.multi()
|
|
|
.hgetall(sessionKey) // 会话实体
|
|
|
.hget(participantsRoleKey, userId) // 用户在此会话中的角色
|
|
|
.zscore(sessionParticipantsKey, userId) // 用户在此会话中最后一次获取未读消息的时间
|
|
|
.zrange(participantsKey, 0, -1)
|
|
|
.zrange(sessionParticipantsKey, 0, -1)
|
|
|
.zrange(sessionParticipantsKey, 0,-1,'withscores') // 所有用户在此会话中最后一次获取未读消息的时间
|
|
|
.execAsync()
|
|
|
.then(function (res) {
|
|
@ -583,7 +584,8 @@ class Sessions extends RedisModel {
|
|
|
getMessagesByPage(sessionId, userId, startMsgId, endMsgId, page, size, isoffset, handler) {
|
|
|
let messagesTimestampKey = RedisModel.makeRedisKey(REDIS_KEYS.MessagesByTimestamp, sessionId);
|
|
|
let messagesKey = RedisModel.makeRedisKey(REDIS_KEYS.Messages, sessionId);
|
|
|
|
|
|
let sessionKey = RedisModel.makeRedisKey(REDIS_KEYS.Session, sessionId);
|
|
|
let sessionParticipantsKey = RedisModel.makeRedisKey(REDIS_KEYS.SessionParticipants, sessionId);
|
|
|
let participants = new Participants();
|
|
|
let offset = (page - 1 < 0 ? 0 : page - 1) * size;
|
|
|
let count = size;
|
|
@ -599,11 +601,14 @@ class Sessions extends RedisModel {
|
|
|
redis.multi()
|
|
|
.zscore(messagesTimestampKey, startMsgId)
|
|
|
.zscore(messagesTimestampKey, endMsgId)
|
|
|
.hgetall(sessionKey)
|
|
|
.zrange(sessionParticipantsKey, 0, -1)
|
|
|
.execAsync()
|
|
|
.then(function (res) {
|
|
|
let startMsgScore = res[1];
|
|
|
let endMsgScore = res[0];
|
|
|
|
|
|
let session = res[2];
|
|
|
let users = res[3];
|
|
|
if (startMsgScore == null || endMsgScore == null || (startMsgScore == endMsgScore && isoffset == 1)) {
|
|
|
handler(null, []);
|
|
|
return;
|
|
@ -620,6 +625,13 @@ class Sessions extends RedisModel {
|
|
|
handler(null, messages);
|
|
|
}).then(function () {
|
|
|
Sessions.updateParticipantLastFetchTime(sessionId, userId, new Date().getTime());
|
|
|
if(session.type != SESSION_TYPES.GROUP){
|
|
|
for(var j in users){
|
|
|
if(users[j]==userId)continue;
|
|
|
WechatClient.sendAllRead(users[j]);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
})
|
|
|
})
|
|
|
.catch(function (err) {
|