| 
					
				 | 
			
			
				@ -496,7 +496,7 @@ class Sessions extends RedisModel { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                start_msg_id = res[0]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                self.getMessagesByPage(sessionId, user, end_msg_id, start_msg_id, page, pagesize, isoffset, function (err, res) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                self.getMessagesByPage(sessionId, user, start_msg_id,end_msg_id , page, pagesize, isoffset, function (err, res) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    if (err) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        if (handler) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            handler(err, null); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -520,7 +520,7 @@ class Sessions extends RedisModel { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                end_msg_id = res[0]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                self.getMessagesByPage(sessionId, user, start_msg_id, end_msg_id, page, pagesize, isoffset, function (err, res) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                self.getMessagesByPage(sessionId, user, end_msg_id,start_msg_id, page, pagesize, isoffset, function (err, res) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    if (err) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        if (handler) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            handler(err, null); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -596,26 +596,46 @@ class Sessions extends RedisModel { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            handler(null, []); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        if(endMsgScore>startMsgScore){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            redis.zrangebyscoreAsync(messagesTimestampKey, startMsgScore, endMsgScore, "limit", offset, count) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                .then(function (res) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    if (res.length == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        handler(null, []); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        // 从消息时间表中过滤出要获取的消息ID列表,倒序取出消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        redis.zrevrangebyscoreAsync(messagesTimestampKey, startMsgScore, endMsgScore, "limit", offset, count) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            .then(function (res) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                if (res.length == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    handler(null, []); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    redis.hmgetAsync(messagesKey, res).then(function (messages) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        handler(null, messages); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    }).then(function () { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        Sessions.updateParticipantLastFetchTime(sessionId, userId, new Date().getTime()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    }) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                }) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                .catch(function (err) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    logger.error("Get message by page failed: ", err); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                redis.hmgetAsync(messagesKey, res).then(function (messages) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    handler(null, messages); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                }).then(function () { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    Sessions.updateParticipantLastFetchTime(sessionId, userId, new Date().getTime()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    handler(err, false); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                }) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            }) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            .catch(function (err) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                logger.error("Get message by page failed: ", err); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        }else{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            // 从消息时间表中过滤出要获取的消息ID列表,倒序取出消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            redis.zrevrangebyscoreAsync(messagesTimestampKey, startMsgScore, endMsgScore, "limit", offset, count) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                .then(function (res) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    if (res.length == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        handler(null, []); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                handler(err, false); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            }) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    redis.hmgetAsync(messagesKey, res).then(function (messages) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        handler(null, messages); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    }).then(function () { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        Sessions.updateParticipantLastFetchTime(sessionId, userId, new Date().getTime()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    }) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                }) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                .catch(function (err) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    logger.error("Get message by page failed: ", err); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    handler(err, false); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                }) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    }) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }) 
			 |