Search in sources :

Example 1 with U2MessageBean

use of com.akaxin.site.storage.bean.U2MessageBean in project openzaly by akaxincom.

the class SyncU2MessageHandler method u2MessageToClient.

private long u2MessageToClient(Channel channel, List<U2MessageBean> u2MessageList) {
    long nextPointer = 0;
    ImStcMessageProto.ImStcMessageRequest.Builder requestBuilder = ImStcMessageProto.ImStcMessageRequest.newBuilder();
    for (U2MessageBean bean : u2MessageList) {
        try {
            nextPointer = NumUtils.getMax(nextPointer, bean.getId());
            switch(bean.getMsgType()) {
                case CoreProto.MsgType.TEXT_VALUE:
                    CoreProto.MsgText MsgText = CoreProto.MsgText.newBuilder().setMsgId(bean.getMsgId()).setSiteUserId(bean.getSendUserId()).setSiteFriendId(bean.getSiteUserId()).setText(ByteString.copyFromUtf8(bean.getContent())).setTime(bean.getMsgTime()).build();
                    ImStcMessageProto.MsgWithPointer textMsg = ImStcMessageProto.MsgWithPointer.newBuilder().setType(MsgType.TEXT).setPointer(bean.getId()).setText(MsgText).build();
                    // logger.info("[Syncing U2] text message OK. bean={}", u2Bean);
                    requestBuilder.addList(textMsg);
                    break;
                case CoreProto.MsgType.SECRET_TEXT_VALUE:
                    byte[] secretTexgt = Base64.getDecoder().decode(bean.getContent());
                    CoreProto.MsgSecretText secretText = CoreProto.MsgSecretText.newBuilder().setMsgId(bean.getMsgId()).setSiteUserId(bean.getSendUserId()).setSiteFriendId(bean.getSiteUserId()).setText(ByteString.copyFrom(secretTexgt)).setSiteDeviceId(String.valueOf(bean.getDeviceId())).setTsKey(bean.getTsKey()).setTime(bean.getMsgTime()).build();
                    ImStcMessageProto.MsgWithPointer secretTextMsg = ImStcMessageProto.MsgWithPointer.newBuilder().setType(MsgType.SECRET_TEXT).setPointer(bean.getId()).setSecretText(secretText).build();
                    // logger.info("[Syncing U2] secret text message OK. bean={}",
                    // u2Bean);
                    requestBuilder.addList(secretTextMsg);
                    break;
                case CoreProto.MsgType.IMAGE_VALUE:
                    CoreProto.MsgImage msgImage = CoreProto.MsgImage.newBuilder().setImageId(bean.getContent()).setMsgId(bean.getMsgId()).setSiteUserId(bean.getSendUserId()).setSiteFriendId(bean.getSiteUserId()).setTime(bean.getMsgTime()).setImageId(bean.getContent()).build();
                    ImStcMessageProto.MsgWithPointer imageMsgWithPointer = ImStcMessageProto.MsgWithPointer.newBuilder().setType(MsgType.IMAGE).setPointer(bean.getId()).setImage(msgImage).build();
                    // logger.info("[Syncing U2] image message OK. bean={}", u2Bean);
                    requestBuilder.addList(imageMsgWithPointer);
                    break;
                case CoreProto.MsgType.SECRET_IMAGE_VALUE:
                    CoreProto.MsgSecretImage secretImage = CoreProto.MsgSecretImage.newBuilder().setMsgId(bean.getMsgId()).setSiteUserId(bean.getSendUserId()).setSiteFriendId(bean.getSiteUserId()).setImageId(bean.getContent()).setSiteDeviceId(String.valueOf(bean.getDeviceId())).setTsKey(bean.getTsKey()).setTime(bean.getMsgTime()).build();
                    ImStcMessageProto.MsgWithPointer secretImageMsg = ImStcMessageProto.MsgWithPointer.newBuilder().setType(MsgType.SECRET_IMAGE).setPointer(bean.getId()).setSecretImage(secretImage).build();
                    // logger.info("[Syncing U2] secret image message OK. bean={}",
                    // u2Bean);
                    requestBuilder.addList(secretImageMsg);
                    break;
                case CoreProto.MsgType.VOICE_VALUE:
                    CoreProto.MsgVoice voice = CoreProto.MsgVoice.newBuilder().setMsgId(bean.getMsgId()).setSiteUserId(bean.getSendUserId()).setSiteFriendId(bean.getSiteUserId()).setVoiceId(bean.getContent()).setTime(bean.getMsgTime()).build();
                    ImStcMessageProto.MsgWithPointer voiceMsg = ImStcMessageProto.MsgWithPointer.newBuilder().setType(MsgType.VOICE).setPointer(bean.getId()).setVoice(voice).build();
                    // logger.info("[Syncing U2] voice message OK. bean={0}", u2Bean);
                    requestBuilder.addList(voiceMsg);
                    break;
                case CoreProto.MsgType.SECRET_VOICE_VALUE:
                    CoreProto.MsgSecretVoice secretVoice = CoreProto.MsgSecretVoice.newBuilder().setMsgId(bean.getMsgId()).setSiteUserId(bean.getSendUserId()).setSiteFriendId(bean.getSiteUserId()).setVoicdId(bean.getContent()).setSiteDeviceId(String.valueOf(bean.getDeviceId())).setTsKey(bean.getTsKey()).setTime(bean.getMsgTime()).build();
                    ImStcMessageProto.MsgWithPointer secretVoiceMsg = ImStcMessageProto.MsgWithPointer.newBuilder().setType(MsgType.SECRET_VOICE).setPointer(bean.getId()).setSecretVoice(secretVoice).build();
                    // logger.info("[Syncing U2] secret voice message OK. bean={}",
                    // u2Bean);
                    requestBuilder.addList(secretVoiceMsg);
                    break;
                case CoreProto.MsgType.U2_NOTICE_VALUE:
                    CoreProto.U2MsgNotice u2Notice = CoreProto.U2MsgNotice.newBuilder().setMsgId(bean.getMsgId()).setSiteUserId(bean.getSendUserId()).setSiteFriendId(bean.getSiteUserId()).setText(ByteString.copyFromUtf8(bean.getContent())).setTime(bean.getMsgTime()).build();
                    ImStcMessageProto.MsgWithPointer u2NoticeMsg = ImStcMessageProto.MsgWithPointer.newBuilder().setPointer(bean.getId()).setType(MsgType.U2_NOTICE).setU2MsgNotice(u2Notice).build();
                    requestBuilder.addList(u2NoticeMsg);
                    break;
                default:
                    logger.error("Message type error! when sync to client bean={}", bean);
                    break;
            }
        } catch (Exception e) {
            logger.error(StringHelper.format("sync u2 message error bean={}", bean), e);
        }
    }
    Map<Integer, String> header = new HashMap<Integer, String>();
    header.put(CoreProto.HeaderKey.SITE_SERVER_VERSION_VALUE, CommandConst.SITE_VERSION);
    ImStcMessageProto.ImStcMessageRequest request = requestBuilder.build();
    CoreProto.TransportPackageData data = CoreProto.TransportPackageData.newBuilder().putAllHeader(header).setData(ByteString.copyFrom(request.toByteArray())).build();
    channel.writeAndFlush(new RedisCommand().add(CommandConst.PROTOCOL_VERSION).add(CommandConst.IM_MSG_TOCLIENT).add(data.toByteArray()));
    return nextPointer;
}
Also used : CoreProto(com.akaxin.proto.core.CoreProto) HashMap(java.util.HashMap) ByteString(com.google.protobuf.ByteString) U2MessageBean(com.akaxin.site.storage.bean.U2MessageBean) ImStcMessageProto(com.akaxin.proto.client.ImStcMessageProto) RedisCommand(com.akaxin.common.command.RedisCommand)

Example 2 with U2MessageBean

use of com.akaxin.site.storage.bean.U2MessageBean in project openzaly by akaxincom.

the class U2MessageImageSecretHandler method handle.

public Boolean handle(Command command) {
    ChannelSession channelSession = command.getChannelSession();
    try {
        ImCtsMessageProto.ImCtsMessageRequest request = ImCtsMessageProto.ImCtsMessageRequest.parseFrom(command.getParams());
        int type = request.getType().getNumber();
        if (CoreProto.MsgType.SECRET_IMAGE_VALUE == type) {
            String siteUserId = request.getSecretImage().getSiteUserId();
            String siteFriendId = request.getSecretImage().getSiteFriendId();
            String msgId = request.getSecretImage().getMsgId();
            String tsKey = request.getSecretImage().getTsKey();
            String ts_device_id = request.getSecretImage().getSiteDeviceId();
            String imageId = request.getSecretImage().getImageId();
            command.setSiteUserId(siteUserId);
            command.setSiteFriendId(siteFriendId);
            U2MessageBean u2Bean = new U2MessageBean();
            u2Bean.setMsgId(msgId);
            u2Bean.setMsgType(type);
            u2Bean.setSendUserId(siteUserId);
            u2Bean.setSiteUserId(siteFriendId);
            u2Bean.setContent(imageId);
            u2Bean.setTsKey(tsKey);
            u2Bean.setDeviceId(ts_device_id);
            long msgTime = System.currentTimeMillis();
            u2Bean.setMsgTime(System.currentTimeMillis());
            LogUtils.requestDebugLog(logger, command, u2Bean.toString());
            boolean success = messageDao.saveU2Message(u2Bean);
            msgStatusResponse(command, msgId, msgTime, success);
            return success;
        }
        return true;
    } catch (Exception e) {
        LogUtils.requestErrorLog(logger, command, this.getClass(), e);
    }
    return false;
}
Also used : U2MessageBean(com.akaxin.site.storage.bean.U2MessageBean) ChannelSession(com.akaxin.common.channel.ChannelSession) ImCtsMessageProto(com.akaxin.proto.site.ImCtsMessageProto)

Example 3 with U2MessageBean

use of com.akaxin.site.storage.bean.U2MessageBean in project openzaly by akaxincom.

the class U2MessageTextHandler method handle.

public Boolean handle(Command command) {
    try {
        ImCtsMessageProto.ImCtsMessageRequest request = ImCtsMessageProto.ImCtsMessageRequest.parseFrom(command.getParams());
        int type = request.getType().getNumber();
        if (CoreProto.MsgType.TEXT_VALUE == type) {
            String siteUserId = command.getSiteUserId();
            String siteFriendId = request.getText().getSiteFriendId();
            String msgId = request.getText().getMsgId();
            ByteString byteStr = request.getText().getText();
            String msgText = byteStr.toString(Charset.forName("UTF-8"));
            command.setSiteFriendId(siteFriendId);
            long msgTime = System.currentTimeMillis();
            U2MessageBean u2Bean = new U2MessageBean();
            u2Bean.setMsgId(msgId);
            u2Bean.setMsgType(type);
            u2Bean.setSendUserId(siteUserId);
            u2Bean.setSiteUserId(siteFriendId);
            u2Bean.setContent(msgText);
            u2Bean.setMsgTime(msgTime);
            LogUtils.requestDebugLog(logger, command, u2Bean.toString());
            boolean success = messageDao.saveU2Message(u2Bean);
            msgStatusResponse(command, msgId, msgTime, success);
            return success;
        }
        return true;
    } catch (Exception e) {
        LogUtils.requestErrorLog(logger, command, this.getClass(), e);
    }
    return false;
}
Also used : U2MessageBean(com.akaxin.site.storage.bean.U2MessageBean) ByteString(com.google.protobuf.ByteString) ByteString(com.google.protobuf.ByteString) ImCtsMessageProto(com.akaxin.proto.site.ImCtsMessageProto)

Example 4 with U2MessageBean

use of com.akaxin.site.storage.bean.U2MessageBean in project openzaly by akaxincom.

the class U2MessageTextSecretHandler method handle.

public Boolean handle(Command command) {
    ChannelSession channelSession = command.getChannelSession();
    try {
        ImCtsMessageProto.ImCtsMessageRequest request = ImCtsMessageProto.ImCtsMessageRequest.parseFrom(command.getParams());
        int type = request.getType().getNumber();
        if (CoreProto.MsgType.SECRET_TEXT_VALUE == type) {
            String siteUserId = command.getSiteUserId();
            String siteFriendId = command.getSiteFriendId();
            String msgId = request.getSecretText().getMsgId();
            String tsKey = request.getSecretText().getTsKey();
            String tsDeviceId = request.getSecretText().getSiteDeviceId();
            ByteString byteStr = request.getSecretText().getText();
            String msgText = Base64.getEncoder().encodeToString(byteStr.toByteArray());
            long msgTime = System.currentTimeMillis();
            U2MessageBean u2Bean = new U2MessageBean();
            u2Bean.setMsgId(msgId);
            u2Bean.setMsgType(type);
            u2Bean.setSendUserId(siteUserId);
            u2Bean.setSiteUserId(siteFriendId);
            u2Bean.setContent(msgText);
            u2Bean.setTsKey(tsKey);
            u2Bean.setDeviceId(tsDeviceId);
            u2Bean.setMsgTime(msgTime);
            LogUtils.requestDebugLog(logger, command, u2Bean.toString());
            boolean success = messageDao.saveU2Message(u2Bean);
            msgStatusResponse(command, msgId, msgTime, success);
            return success;
        }
        return true;
    } catch (Exception e) {
        LogUtils.requestErrorLog(logger, command, this.getClass(), e);
    }
    return false;
}
Also used : U2MessageBean(com.akaxin.site.storage.bean.U2MessageBean) ChannelSession(com.akaxin.common.channel.ChannelSession) ByteString(com.google.protobuf.ByteString) ByteString(com.google.protobuf.ByteString) ImCtsMessageProto(com.akaxin.proto.site.ImCtsMessageProto)

Example 5 with U2MessageBean

use of com.akaxin.site.storage.bean.U2MessageBean in project openzaly by akaxincom.

the class U2MessageVoiceSecretHandler method handle.

public Boolean handle(Command command) {
    try {
        ImCtsMessageProto.ImCtsMessageRequest request = ImCtsMessageProto.ImCtsMessageRequest.parseFrom(command.getParams());
        int type = request.getType().getNumber();
        if (CoreProto.MsgType.SECRET_VOICE_VALUE == type) {
            String siteUserId = command.getSiteUserId();
            String siteFriendId = command.getSiteFriendId();
            String msgId = request.getSecretVoice().getMsgId();
            String tsKey = request.getSecretVoice().getTsKey();
            String toDeviceId = request.getSecretVoice().getSiteDeviceId();
            String secretVoiceId = request.getSecretVoice().getVoicdId();
            long msgTime = System.currentTimeMillis();
            U2MessageBean u2Bean = new U2MessageBean();
            u2Bean.setMsgId(msgId);
            u2Bean.setMsgType(type);
            u2Bean.setSendUserId(siteUserId);
            u2Bean.setSiteUserId(siteFriendId);
            u2Bean.setContent(secretVoiceId);
            u2Bean.setTsKey(tsKey);
            u2Bean.setDeviceId(toDeviceId);
            u2Bean.setMsgTime(msgTime);
            LogUtils.requestDebugLog(logger, command, u2Bean.toString());
            boolean success = messageDao.saveU2Message(u2Bean);
            msgStatusResponse(command, msgId, msgTime, success);
            return success;
        }
        return true;
    } catch (Exception e) {
        logger.error("U2 Message Secret Voice error!", e);
    }
    return false;
}
Also used : U2MessageBean(com.akaxin.site.storage.bean.U2MessageBean) ImCtsMessageProto(com.akaxin.proto.site.ImCtsMessageProto)

Aggregations

U2MessageBean (com.akaxin.site.storage.bean.U2MessageBean)10 ImCtsMessageProto (com.akaxin.proto.site.ImCtsMessageProto)7 ByteString (com.google.protobuf.ByteString)4 ChannelSession (com.akaxin.common.channel.ChannelSession)3 RedisCommand (com.akaxin.common.command.RedisCommand)1 ImStcMessageProto (com.akaxin.proto.client.ImStcMessageProto)1 CoreProto (com.akaxin.proto.core.CoreProto)1 ImSyncMessageProto (com.akaxin.proto.site.ImSyncMessageProto)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1