Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:User_Logout_NPE #153

Merged
merged 7 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,12 @@ public BaseResponse<NULLBody> p2pRoute(@RequestBody P2PReqVO p2pRequest) throws
public BaseResponse<NULLBody> offLine(@RequestBody ChatReqVO groupReqVO) {
BaseResponse<NULLBody> res = new BaseResponse();

CIMUserInfo cimUserInfo = userInfoCacheService.loadUserInfoByUserId(groupReqVO.getUserId());
if(userInfoCacheService.CheckUserLoginStatus(groupReqVO.getUserId())){
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not directly modify the return value of loadUserInfoByUserId to Optional<CIMUserInfo>, and then call the offLine function in ifPresent?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely, It is a good idea that it will be midified right now.

CIMUserInfo cimUserInfo = userInfoCacheService.loadUserInfoByUserId(groupReqVO.getUserId());

log.info("user [{}] offline!", cimUserInfo.toString());
accountService.offLine(groupReqVO.getUserId());
log.info("user [{}] offline!", cimUserInfo.toString());
accountService.offLine(groupReqVO.getUserId());
}

res.setCode(StatusEnum.SUCCESS.getCode());
res.setMessage(StatusEnum.SUCCESS.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ public interface UserInfoCacheService {
*/
boolean saveAndCheckUserLoginStatus(Long userId) throws Exception ;

/**
* 检查用户登录情况
* @param userId userId 用户唯一 ID
* @return true 为已登录 false 为未登录
* @throws Exception
*/
boolean CheckUserLoginStatus(Long userId) ;

/**
* query all online user
* @return online user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ public boolean saveAndCheckUserLoginStatus(Long userId) throws Exception {
}
}

@Override
public boolean CheckUserLoginStatus(Long userId){
return redisTemplate.opsForSet().isMember(LOGIN_STATUS_PREFIX, userId.toString());
}

@Override
public Set<CIMUserInfo> onlineUser() {
Set<CIMUserInfo> set = null ;
Expand Down
Loading