09-09-修改

This commit is contained in:
2025-09-09 18:53:28 +08:00
parent 724ebf8dbd
commit c75563b46a

View File

@ -356,22 +356,7 @@ public class ChatServerHandler extends SimpleChannelInboundHandler<TextWebSocket
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
jsonObject.put("type", "0"); jsonObject.put("type", "0");
jsonObject.put("message", message); jsonObject.put("message", message);
//通过userId拿到该用户所有通道实例
List<ChannelHandlerContext> channelHandlerContexts = userChannelMap.get(userId.toString());
if (channelHandlerContexts != null && !channelHandlerContexts.isEmpty()) {
//给每个通道发送对应消息
for (ChannelHandlerContext handlerContext : channelHandlerContexts) {
//同时发送所有未读消息给前端进行渲染
HashMap<String,Object> temp = new HashMap<>();
userRoomCountMap.forEachKey(0, (value) -> {
if (value.contains(userId.toString())){
temp.put(value,userRoomCountMap.get(value));
}
});
jsonObject.put("countValue", temp);
sendMessage(handlerContext, jsonObject.toString());
}
}
//生成系统消息的聊天记录 //生成系统消息的聊天记录
LambdaQueryWrapper<ChatGroup> lambdaQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<ChatGroup> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(ChatGroup::getMembers,"[system, "+userId+"]"); lambdaQueryWrapper.eq(ChatGroup::getMembers,"[system, "+userId+"]");
@ -401,6 +386,23 @@ public class ChatServerHandler extends SimpleChannelInboundHandler<TextWebSocket
userRoomCountMap.put(userId+"+"+groupServiceOne.getId(), 1); userRoomCountMap.put(userId+"+"+groupServiceOne.getId(), 1);
} }
//通过userId拿到该用户所有通道实例
List<ChannelHandlerContext> channelHandlerContexts = userChannelMap.get(userId.toString());
if (channelHandlerContexts != null && !channelHandlerContexts.isEmpty()) {
//给每个通道发送对应消息
for (ChannelHandlerContext handlerContext : channelHandlerContexts) {
//同时发送所有未读消息给前端进行渲染
HashMap<String,Object> temp = new HashMap<>();
userRoomCountMap.forEachKey(0, (value) -> {
if (value.contains(userId.toString())){
temp.put(value,userRoomCountMap.get(value));
}
});
jsonObject.put("countValue", temp);
sendMessage(handlerContext, jsonObject.toString());
}
}
} }