/** * 消息重发 * * @param msg * @return */ public static long reSendECMessage(ECMessage msg) { ECChatManager manager = getInstance().mChatManager; if (manager != null) { // 调用接口发送IM消息 String oldMsgId = msg.getMsgId(); manager.sendMessage(msg, getInstance().mListener); if (msg.getType() == ECMessage.Type.IMAGE) { ImgInfo imgInfo = ImgInfoSqlManager.getInstance().getImgInfo(oldMsgId); if (imgInfo == null || TextUtils.isEmpty(imgInfo.getBigImgPath())) { return -1; } String bigImagePath = new File(FileAccessor.getImagePathName(), imgInfo.getBigImgPath()).getAbsolutePath(); imgInfo.setMsglocalid(msg.getMsgId()); ECFileMessageBody body = (ECFileMessageBody) msg.getBody(); body.setLocalUrl(bigImagePath); BitmapFactory.Options options = DemoUtils.getBitmapOptions( new File(FileAccessor.IMESSAGE_IMAGE, imgInfo.getThumbImgPath()).getAbsolutePath()); msg.setUserData( "outWidth://" + options.outWidth + ",outHeight://" + options.outHeight + ",THUMBNAIL://" + msg.getMsgId()); ImgInfoSqlManager.getInstance().updateImageInfo(imgInfo); } // 保存发送的消息到数据库 return IMessageSqlManager.changeResendMsg(msg.getId(), msg); } return -1; }
public static long sendImageMessage(ImgInfo imgInfo, ECMessage message) { ECChatManager manager = getInstance().mChatManager; if (manager != null) { // 调用接口发送IM消息 manager.sendMessage(message, getInstance().mListener); if (TextUtils.isEmpty(message.getMsgId())) { return -1; } imgInfo.setMsglocalid(message.getMsgId()); BitmapFactory.Options options = DemoUtils.getBitmapOptions( new File(FileAccessor.IMESSAGE_IMAGE, imgInfo.getThumbImgPath()).getAbsolutePath()); message.setUserData( "outWidth://" + options.outWidth + ",outHeight://" + options.outHeight + ",THUMBNAIL://" + message.getMsgId() + ",PICGIF://" + imgInfo.isGif); long row = IMessageSqlManager.insertIMessage(message, ECMessage.Direction.SEND.ordinal()); if (row != -1) { return ImgInfoSqlManager.getInstance().insertImageInfo(imgInfo); } } return -1; }
private synchronized void postDowloadMessageResult(ECMessage message) { if (message == null) { return; } if (message.getType() == ECMessage.Type.VOICE) { ECVoiceMessageBody voiceBody = (ECVoiceMessageBody) message.getBody(); voiceBody.setDuration(DemoUtils.calculateVoiceTime(voiceBody.getLocalUrl())); } else if (message.getType() == ECMessage.Type.IMAGE) { ImgInfo thumbImgInfo = ImgInfoSqlManager.getInstance().getThumbImgInfo(message); if (thumbImgInfo == null) { return; } ImgInfoSqlManager.getInstance().insertImageInfo(thumbImgInfo); BitmapFactory.Options options = DemoUtils.getBitmapOptions( new File(FileAccessor.getImagePathName(), thumbImgInfo.getThumbImgPath()) .getAbsolutePath()); message.setUserData( "outWidth://" + options.outWidth + ",outHeight://" + options.outHeight + ",THUMBNAIL://" + message.getMsgId() + ",PICGIF://" + thumbImgInfo.isGif); } if (IMessageSqlManager.updateIMessageDownload(message) <= 0) { return; } if (mOnMessageReportCallback != null) { mOnMessageReportCallback.onMessageReport(null, message); } boolean showNotice = true; SyncMsgEntry remove = syncMessage.remove(message.getMsgId()); if (remove != null) { showNotice = remove.showNotice; if (mOnMessageReportCallback != null && remove.msg != null) { ArrayList<ECMessage> msgs = new ArrayList<ECMessage>(); msgs.add(remove.msg); mOnMessageReportCallback.onPushMessage(remove.msg.getSessionId(), msgs); } } if (showNotice) showNotification(message); }