7 rokov pred
rodič
commit
3e4aee94cc

+ 14 - 0
src/server/endpoints/v2/session.endpoint.js

@ -89,6 +89,20 @@ router.get("/", function (req, res) {
});
router.get(APIv2.Sessions.Session,function(req,res){
    let sessionId = req.params.session_id;
    let userId = req.query.user_id;
    if (!sessionId) {
        throw {httpStatus: 406, message: 'Missing sessionId.'};
    }
    if (!userId) {
        throw {httpStatus: 406, message: 'Missing user.'};
    }
    let sessions = new Sessions();
    ControllerUtil.regModelEventHandler(sessions, res);
    sessions.getSession(sessionId,userId);
})
/**
 * 最近会话列表。
 *

+ 1 - 1
src/server/endpoints/v2/user.endpoint.js

@ -42,7 +42,7 @@ router.post(APIv2.Users.Login, function (req, res) {
    let users = new Users();
    ControllerUtil.regModelEventHandler(users, res);
    
    users.login(payload.user_id, payload.platform, payload.token, payload.client_id);
});

+ 30 - 0
src/server/models/sessions/sessions.js

@ -317,6 +317,36 @@ class Sessions extends RedisModel {
        SessionRepo.findOne(sessionId, handler);
    }
    getSession(sessionId,userId,handler){
        let self = this;
        let sessionKey = RedisModel.makeRedisKey(REDIS_KEYS.Session, sessionId);
        redis.hgetallAsync(sessionKey).then(function(session){
            if(session.type==SESSION_TYPES.P2P){
                ParticipantRepo.findNameById(userId, function (err, res) {
                    session.name = res[0].name;
                    if(handler){
                        handler(null,session);
                        return;
                    }
                    ModelUtil.emitOK(self.eventEmitter, session);
                })
            }else{
                if(handler){
                    handler(null,session);
                    return;
                }
                ModelUtil.emitOK(self.eventEmitter, session);
            }
        }).catch(function (err) {
            logger.error("Get session failed: ", err);
            if(handler){
                handler(null,session);
                return;
            }
            ModelUtil.emitError(self.eventEmitter, {message: err, status: -1}, null);
        })
    }
    /**
     * 根据用户ID获取用户的session列表
     * @param userId