Ejemplo n.º 1
0
 private void postCheckDownFailMsg() {
   List<ECMessage> downdFailMsg = IMessageSqlManager.getDowndFailMsg();
   if (downdFailMsg == null || downdFailMsg.isEmpty()) {
     return;
   }
   for (ECMessage msg : downdFailMsg) {
     ECImageMessageBody body = (ECImageMessageBody) msg.getBody();
     body.setThumbnailFileUrl(body.getRemoteUrl() + "_thum");
     if (syncMessage != null) {
       syncMessage.put(msg.getMsgId(), new SyncMsgEntry(false, true, msg));
     }
     if (mChatManager != null) {
       mChatManager.downloadThumbnailMessage(msg, this);
     }
   }
 }
Ejemplo n.º 2
0
  /**
   * 处理接收消息
   *
   * @param msg
   * @param showNotice
   */
  private synchronized void postReceiveMessage(ECMessage msg, boolean showNotice) {
    // 接收到的IM消息,根据IM消息类型做不同的处理
    // IM消息类型:ECMessage.Type
    if (msg.getType() != ECMessage.Type.TXT) {
      ECFileMessageBody body = (ECFileMessageBody) msg.getBody();
      FileAccessor.initFileAccess();
      if (!TextUtils.isEmpty(body.getRemoteUrl())) {
        boolean thumbnail = false;
        String fileExt = DemoUtils.getExtensionName(body.getRemoteUrl());
        if (msg.getType() == ECMessage.Type.VOICE) {
          body.setLocalUrl(
              new File(
                      FileAccessor.getVoicePathName(),
                      DemoUtils.md5(String.valueOf(System.currentTimeMillis())) + ".amr")
                  .getAbsolutePath());
        } else if (msg.getType() == ECMessage.Type.IMAGE) {
          ECImageMessageBody imageBody = (ECImageMessageBody) body;
          thumbnail = !TextUtils.isEmpty(imageBody.getThumbnailFileUrl());
          imageBody.setLocalUrl(
              new File(
                      FileAccessor.getImagePathName(),
                      DemoUtils.md5(
                              thumbnail
                                  ? imageBody.getThumbnailFileUrl()
                                  : imageBody.getRemoteUrl())
                          + "."
                          + fileExt)
                  .getAbsolutePath());
        } else {
          body.setLocalUrl(
              new File(
                      FileAccessor.getFilePathName(),
                      DemoUtils.md5(String.valueOf(System.currentTimeMillis())) + "." + fileExt)
                  .getAbsolutePath());
        }
        if (syncMessage != null) {
          syncMessage.put(msg.getMsgId(), new SyncMsgEntry(showNotice, thumbnail, msg));
        }
        if (mChatManager != null) {
          if (thumbnail) {
            mChatManager.downloadThumbnailMessage(msg, this);
          } else {
            mChatManager.downloadMediaMessage(msg, this);
          }
        }
        if (TextUtils.isEmpty(body.getFileName()) && !TextUtils.isEmpty(body.getRemoteUrl())) {
          body.setFileName(FileAccessor.getFileName(body.getRemoteUrl()));
        }
        msg.setUserData("fileName=" + body.getFileName());
        if (IMessageSqlManager.insertIMessage(msg, msg.getDirection().ordinal()) > 0) {
          return;
        }
      } else {
        LogUtil.e(TAG, "ECMessage fileUrl: null");
      }
    }
    if (IMessageSqlManager.insertIMessage(msg, msg.getDirection().ordinal()) <= 0) {
      return;
    }

    if (mOnMessageReportCallback != null) {
      ArrayList<ECMessage> msgs = new ArrayList<ECMessage>();
      msgs.add(msg);
      mOnMessageReportCallback.onPushMessage(msg.getSessionId(), msgs);
    }

    // 是否状态栏提示
    if (showNotice) showNotification(msg);
  }