Search in sources :

Example 6 with GroupMessageBean

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

the class GroupMessageVoiceHandler 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.GROUP_VOICE_VALUE == type) {
            String siteUserId = command.getSiteUserId();
            String deviceId = command.getDeviceId();
            String gmsgId = request.getGroupVoice().getMsgId();
            String groupId = request.getGroupVoice().getSiteGroupId();
            String groupVoiceId = request.getGroupVoice().getVoiceId();
            long msgTime = System.currentTimeMillis();
            GroupMessageBean gmsgBean = new GroupMessageBean();
            gmsgBean.setMsgId(gmsgId);
            gmsgBean.setSendUserId(siteUserId);
            gmsgBean.setSiteGroupId(groupId);
            gmsgBean.setSendDeviceId(deviceId);
            gmsgBean.setContent(groupVoiceId);
            gmsgBean.setMsgType(type);
            gmsgBean.setMsgTime(msgTime);
            LogUtils.requestDebugLog(logger, command, gmsgBean.toString());
            boolean success = messageDao.saveGroupMessage(gmsgBean);
            msgStatusResponse(command, gmsgId, msgTime, success);
            return success;
        }
        return true;
    } catch (Exception e) {
        LogUtils.requestErrorLog(logger, command, this.getClass(), e);
    }
    return false;
}
Also used : ChannelSession(com.akaxin.common.channel.ChannelSession) ImCtsMessageProto(com.akaxin.proto.site.ImCtsMessageProto) GroupMessageBean(com.akaxin.site.storage.bean.GroupMessageBean)

Example 7 with GroupMessageBean

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

the class SyncGroupMessageHandler method groupMessageToClient.

private long groupMessageToClient(Channel channel, String userId, List<GroupMessageBean> groupMessageList) {
    long nextPointer = 0;
    ImStcMessageProto.ImStcMessageRequest.Builder requestBuilder = ImStcMessageProto.ImStcMessageRequest.newBuilder();
    for (GroupMessageBean bean : groupMessageList) {
        try {
            nextPointer = NumUtils.getMax(nextPointer, bean.getId());
            switch(bean.getMsgType()) {
                case CoreProto.MsgType.GROUP_TEXT_VALUE:
                    CoreProto.GroupText groupText = CoreProto.GroupText.newBuilder().setMsgId(bean.getMsgId()).setSiteUserId(bean.getSendUserId()).setSiteGroupId(bean.getSiteGroupId()).setText(ByteString.copyFromUtf8(bean.getContent())).setTime(bean.getMsgTime()).build();
                    ImStcMessageProto.MsgWithPointer gmsg = ImStcMessageProto.MsgWithPointer.newBuilder().setType(MsgType.GROUP_TEXT).setPointer(bean.getId()).setGroupText(groupText).build();
                    requestBuilder.addList(gmsg);
                    break;
                case CoreProto.MsgType.GROUP_SECRET_TEXT_VALUE:
                    // do nothing
                    break;
                case CoreProto.MsgType.GROUP_IMAGE_VALUE:
                    CoreProto.GroupImage groupImage = CoreProto.GroupImage.newBuilder().setMsgId(bean.getMsgId()).setSiteUserId(bean.getSendUserId()).setSiteGroupId(bean.getSiteGroupId()).setImageId(bean.getContent()).setTime(bean.getMsgTime()).build();
                    ImStcMessageProto.MsgWithPointer groupImageMsg = ImStcMessageProto.MsgWithPointer.newBuilder().setType(MsgType.GROUP_IMAGE).setPointer(bean.getId()).setGroupImage(groupImage).build();
                    requestBuilder.addList(groupImageMsg);
                    break;
                case CoreProto.MsgType.GROUP_SECRET_IMAGE_VALUE:
                    // do nothing
                    break;
                case CoreProto.MsgType.GROUP_VOICE_VALUE:
                    CoreProto.GroupVoice groupVoice = CoreProto.GroupVoice.newBuilder().setMsgId(bean.getMsgId()).setSiteUserId(bean.getSendUserId()).setSiteGroupId(bean.getSiteGroupId()).setVoiceId(bean.getContent()).setTime(bean.getMsgTime()).build();
                    ImStcMessageProto.MsgWithPointer groupVoiceMsg = ImStcMessageProto.MsgWithPointer.newBuilder().setType(MsgType.GROUP_VOICE).setPointer(bean.getId()).setGroupVoice(groupVoice).build();
                    requestBuilder.addList(groupVoiceMsg);
                    break;
                case CoreProto.MsgType.GROUP_SECRET_VOICE_VALUE:
                    // do nothing
                    break;
                case CoreProto.MsgType.GROUP_NOTICE_VALUE:
                    CoreProto.GroupMsgNotice groupNotice = CoreProto.GroupMsgNotice.newBuilder().setMsgId(bean.getMsgId()).setSiteUserId(bean.getSendUserId()).setSiteGroupId(bean.getSiteGroupId()).setText(ByteString.copyFromUtf8((bean.getContent()))).setTime(bean.getMsgTime()).build();
                    ImStcMessageProto.MsgWithPointer groupMsgNotice = ImStcMessageProto.MsgWithPointer.newBuilder().setPointer(bean.getId()).setType(MsgType.GROUP_NOTICE).setGroupMsgNotice(groupNotice).build();
                    requestBuilder.addList(groupMsgNotice);
                    break;
            }
        } catch (Exception e) {
            logger.error(StringHelper.format("sync group 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 datas = 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(datas.toByteArray()));
    return nextPointer;
}
Also used : CoreProto(com.akaxin.proto.core.CoreProto) HashMap(java.util.HashMap) ByteString(com.google.protobuf.ByteString) ImStcMessageProto(com.akaxin.proto.client.ImStcMessageProto) RedisCommand(com.akaxin.common.command.RedisCommand) GroupMessageBean(com.akaxin.site.storage.bean.GroupMessageBean)

Example 8 with GroupMessageBean

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

the class GroupMessageNoticeHandler method handle.

@Override
public Boolean handle(Command command) {
    try {
        ImCtsMessageProto.ImCtsMessageRequest request = ImCtsMessageProto.ImCtsMessageRequest.parseFrom(command.getParams());
        int type = request.getType().getNumber();
        if (CoreProto.MsgType.GROUP_NOTICE_VALUE == type) {
            String siteUserId = command.getSiteUserId();
            String groupId = request.getGroupMsgNotice().getSiteGroupId();
            String groupNoticeText = request.getGroupMsgNotice().getText().toStringUtf8();
            String msgId = request.getGroupMsgNotice().getMsgId();
            GroupMessageBean bean = new GroupMessageBean();
            bean.setMsgId(msgId);
            bean.setSendUserId(siteUserId);
            bean.setSendDeviceId("");
            bean.setSiteGroupId(groupId);
            bean.setContent(groupNoticeText);
            bean.setMsgType(type);
            bean.setMsgTime(System.currentTimeMillis());
            LogUtils.requestDebugLog(logger, command, bean.toString());
            return messageDao.saveGroupMessage(bean);
        }
        return true;
    } catch (Exception e) {
        LogUtils.requestErrorLog(logger, command, this.getClass(), e);
    }
    return false;
}
Also used : ImCtsMessageProto(com.akaxin.proto.site.ImCtsMessageProto) GroupMessageBean(com.akaxin.site.storage.bean.GroupMessageBean)

Example 9 with GroupMessageBean

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

the class GroupMessageTextSecretHandler 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.GROUP_SECRET_TEXT_VALUE == type) {
            String gmsg_id = request.getGroupSecretText().getMsgId();
            String group_user_id = request.getGroupSecretText().getSiteUserId();
            String group_id = request.getGroupSecretText().getSiteGroupId();
            String group_text = request.getGroupSecretText().getText().toStringUtf8();
            command.setSiteGroupId(group_id);
            // command.setField("group_id", group_id);
            System.out.println("GroupMsg = id=" + gmsg_id + "," + group_user_id + "," + group_id + "," + group_text + ",");
            long msgTime = System.currentTimeMillis();
            GroupMessageBean gmsgBean = new GroupMessageBean();
            gmsgBean.setMsgTime(msgTime);
            messageDao.saveGroupMessage(gmsgBean);
            msgResponse(channelSession.getChannel(), command, group_user_id, group_id, gmsg_id, msgTime);
            return true;
        }
        return true;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}
Also used : ChannelSession(com.akaxin.common.channel.ChannelSession) ImCtsMessageProto(com.akaxin.proto.site.ImCtsMessageProto) GroupMessageBean(com.akaxin.site.storage.bean.GroupMessageBean)

Aggregations

GroupMessageBean (com.akaxin.site.storage.bean.GroupMessageBean)9 ChannelSession (com.akaxin.common.channel.ChannelSession)6 ImCtsMessageProto (com.akaxin.proto.site.ImCtsMessageProto)6 ByteString (com.google.protobuf.ByteString)2 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