Helius
2021-05-27 0918083443d3920335c5b09a5d28e4f8d1bb3f45
src/main/java/com/xcong/excoin/netty/logic/WebSocketLogic.java
@@ -79,16 +79,22 @@
        ChatRequest chat = JSONObject.parseObject(chatStr, ChatRequest.class);
        Channel channel = ChannelManager.findWebSocketChannel(requestBean.getChannelId());
        channel.writeAndFlush(NettyTools.webSocketJson(ResponseBean.ok(chat)));
        ResponseBean res = ResponseBean.ok(chat);
        res.setType(2);
        channel.writeAndFlush(NettyTools.webSocketJson(res));
        // 判断是否在线
        Channel targetChannel = ChannelManager.findWsChannel(Long.parseLong(chat.getTo()));
        Channel targetChannel = ChannelManager.findWsChannel(chat.getTargetId());
        if (targetChannel != null) {
            targetChannel.writeAndFlush(NettyTools.webSocketBytes(JSONObject.toJSONString(ResponseBean.ok(chat))));
            chat.setIsSelf(2);
            ResponseBean toRes = ResponseBean.ok(chat);
            res.setType(2);
            targetChannel.writeAndFlush(NettyTools.webSocketJson(toRes));
            chatProducer.sendMsgHistory(chat);
        } else {
            // 在redis中保存用户未在线时,给该用户发送的消息条数
            String key = AppContants.MSG_NOTICE + chat.getTo();
            String key = AppContants.MSG_NOTICE + chat.getTargetId();
            String value = redisUtils.getString(key);
            if (StrUtil.isEmpty(value)) {
                redisUtils.set(key , 1);