/** * Copyright 2018-2028 Akaxin Group * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.windchat.im.message.group.handler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.windchat.common.command.Command; import com.windchat.common.logs.LogUtils; import com.akaxin.proto.core.CoreProto; import com.akaxin.proto.site.ImCtsMessageProto; import com.windchat.im.storage.api.IMessageDao; import com.windchat.im.storage.bean.GroupMessageBean; import com.windchat.im.storage.service.MessageDaoService; /** * 群图片消息 * * @author Sam{@link an.guoyue254@gmail.com} * @since 2018-02-05 11:50:30 */ public class GroupMessageImageHandler extends AbstractGroupHandler { private static final Logger logger = LoggerFactory.getLogger(GroupMessageImageHandler.class); private IMessageDao messageDao = new MessageDaoService(); public Boolean handle(Command command) { try { int type = command.getMsgType(); if (CoreProto.MsgType.GROUP_IMAGE_VALUE == type) { ImCtsMessageProto.ImCtsMessageRequest request = ImCtsMessageProto.ImCtsMessageRequest .parseFrom(command.getParams()); String siteUserId = command.getSiteUserId(); String deviceId = command.getDeviceId(); String proxySiteUserId = request.getGroupImage().getSiteUserId(); String gmsgId = request.getGroupImage().getMsgId(); String groupId = request.getGroupImage().getSiteGroupId(); String groupImageId = request.getGroupImage().getImageId(); long msgTime = System.currentTimeMillis(); GroupMessageBean gmsgBean = new GroupMessageBean(); gmsgBean.setMsgId(gmsgId); gmsgBean.setSendUserId(command.isProxy() ? proxySiteUserId : siteUserId); // gmsgBean.setSendUserId(siteUserId); gmsgBean.setSendDeviceId(deviceId); gmsgBean.setSiteGroupId(groupId); gmsgBean.setContent(groupImageId); 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; } // private void msgResponse(Channel channel, Command command, String from, // String to, String msgId, long msgTime) { // CoreProto.MsgStatus status = // CoreProto.MsgStatus.newBuilder().setMsgId(msgId).setMsgServerTime(msgTime) // .setMsgStatus(1).build(); // // ImStcMessageProto.MsgWithPointer statusMsg = // ImStcMessageProto.MsgWithPointer.newBuilder() // .setType(MsgType.MSG_STATUS).setStatus(status).build(); // // ImStcMessageProto.ImStcMessageRequest request = // ImStcMessageProto.ImStcMessageRequest.newBuilder() // .addList(0, statusMsg).build(); // // CoreProto.TransportPackageData data = // CoreProto.TransportPackageData.newBuilder() // .setData(request.toByteString()).build(); // // channel.writeAndFlush(new // RedisCommand().add(CommandConst.PROTOCOL_VERSION).add(CommandConst.IM_MSG_TOCLIENT) // .add(data.toByteArray())); // // } }