09-12-netty房间创建后发送确认消息
This commit is contained in:
		| @ -418,4 +418,21 @@ public class ChatServerHandler extends SimpleChannelInboundHandler<TextWebSocket | ||||
|     } | ||||
|  | ||||
|  | ||||
|     //用于房间创建后发送确认消息 | ||||
|     public void sendRoomInfo(Long userId,ChatGroup chatGroup){ | ||||
|         //通过ID找到所有通道 发送消息 | ||||
|         List<ChannelHandlerContext> channelHandlerContexts = userChannelMap.get(userId.toString()); | ||||
|         if (channelHandlerContexts == null||channelHandlerContexts.isEmpty()){ | ||||
|             return; | ||||
|         } | ||||
|         for (ChannelHandlerContext channelHandlerContext : channelHandlerContexts) { | ||||
|             JSONObject jsonObject = new JSONObject(); | ||||
|             jsonObject.put("type", "5"); | ||||
|             jsonObject.put("roomInfo", chatGroup); | ||||
|             sendMessage(channelHandlerContext, String.valueOf(jsonObject)); | ||||
|             log.info("发送房间创建确认消息:{}",jsonObject); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|  | ||||
| } | ||||
|  | ||||
| @ -10,6 +10,7 @@ import org.dromara.common.mybatis.core.page.TableDataInfo; | ||||
| import org.dromara.common.satoken.utils.LoginHelper; | ||||
| import org.dromara.system.domain.vo.SysUserVo; | ||||
| import org.dromara.system.service.impl.SysUserServiceImpl; | ||||
| import org.dromara.websocket.ChatServerHandler; | ||||
| import org.dromara.websocket.domain.ChatGroup; | ||||
| import org.dromara.websocket.domain.ChatHistory; | ||||
| import org.dromara.websocket.domain.vo.ChatHistoryVo; | ||||
| @ -35,6 +36,8 @@ public class ChatGroupController { | ||||
|     private ChatHistoryServiceImpl chatHistoryService; | ||||
|     @Autowired | ||||
|     private SysUserServiceImpl sysUserService; | ||||
|     @Autowired | ||||
|     private ChatServerHandler chatServerHandler; | ||||
|  | ||||
|     /*** | ||||
|      * 新建聊天房间 不论单群 | ||||
| @ -84,10 +87,13 @@ public class ChatGroupController { | ||||
|  | ||||
|         boolean save = chatGroupService.save(chatGroup); | ||||
|         if (save) { | ||||
|             //最后发送聊天房间创建确认消息 | ||||
|             chatServerHandler.sendRoomInfo(userId,chatGroup); | ||||
|             return R.ok(chatGroup); | ||||
|         }else { | ||||
|             return R.fail("创建群聊关系失败"); | ||||
|         } | ||||
|  | ||||
|     } | ||||
|  | ||||
|  | ||||
|  | ||||
		Reference in New Issue
	
	Block a user