09-10-netty优化已读返回

This commit is contained in:
2025-09-11 15:18:53 +08:00
parent 00dcc00b05
commit 8bf12d04cd

View File

@ -241,12 +241,13 @@ public class ChatServerHandler extends SimpleChannelInboundHandler<TextWebSocket
//前端判断当前聊天框跟消息接收ID一致后收到消息后主动发送消息给服务端确认该消息收到 //前端判断当前聊天框跟消息接收ID一致后收到消息后主动发送消息给服务端确认该消息收到
//当发送消息后,给接收方推送未读消息 //当发送消息后,给接收方推送未读消息
SysUserVo sysUserVo = sysUserService.selectUserById(Long.valueOf(channelUserMap.get(ctx)));
JSONObject jsonObject = JSONObject.parseObject(msg.text()); JSONObject jsonObject = JSONObject.parseObject(msg.text());
String type = jsonObject.get("type").toString(); String type = jsonObject.get("type").toString();
if ("0".equals(type)) { if ("0".equals(type)) {
//来自哪个用户 //来自哪个用户
SysUserVo sysUserVo = sysUserService.selectUserById(Long.valueOf(channelUserMap.get(ctx)));
jsonObject.put("from", sysUserVo); jsonObject.put("from", sysUserVo);
// jsonObject.put("name", sysUserVo.getNickName()); // jsonObject.put("name", sysUserVo.getNickName());
log.info("收到客户端消息:{}", jsonObject); log.info("收到客户端消息:{}", jsonObject);
@ -318,17 +319,18 @@ public class ChatServerHandler extends SimpleChannelInboundHandler<TextWebSocket
//将该房间未读消息 清空 //将该房间未读消息 清空
userRoomCountMap.put(channelUserMap.get(ctx) + "+" + jsonObject.get("roomId"), 0); userRoomCountMap.put(channelUserMap.get(ctx) + "+" + jsonObject.get("roomId"), 0);
// if(userRoomCountMap.get(channelUserMap.get(ctx) + "+" + jsonObject.get("roomId")) != null && userRoomCountMap.get(channelUserMap.get(ctx) + "+" + jsonObject.get("roomId")) > 0) { //清空过后返回其余房间未读消息
// userRoomCountMap.put(channelUserMap.get(ctx) + "+" + jsonObject.get("roomId"), userRoomCountMap.get(channelUserMap.get(ctx) + "+" + jsonObject.get("roomId")) - 1); HashMap<String,Object> temp = new HashMap<>();
// }else { userRoomCountMap.forEachKey(0,key ->{
// userRoomCountMap.put(channelUserMap.get(ctx) + "+" + jsonObject.get("roomId"), 0); if (key.contains(sysUserVo.getUserId().toString())){
// } temp.put(key,userRoomCountMap.get(key));
}
});
//构建消息
JSONObject message = new JSONObject();
message.put("type", "1");
message.put("unReadCount", temp);
} }
// else if ("2".equals(type)){
// //前端点击某个聊天房间进入时 仅需发送type2 清空该房间的未读消息数
// userRoomCountMap.put(channelUserMap.get(ctx) + "+" + jsonObject.get("roomId"), 0);
// //将该房间对应消息都置为已读
// }
} }
// 处理异常 // 处理异常