Exemple #1
0
  private synchronized void postReceiveMessage(ECMessage ecMessage, boolean showNotice) {
    int userId = Integer.parseInt(ecMessage.getSessionId());
    Friend friend = FriendCache.getInstance(mContext).getFriend(userId);
    String message = ((ECTextMessageBody) ecMessage.getBody()).getMessage();
    History history = new History(message, userId, mContext);
    HistoryCache.getInstance(mContext).updateHistory(history, friend);
    ConversationCache.getInstance()
        .updateConversation(
            new Conversation(
                userId,
                String.format(mContext.getString(R.string.send_bomb_message), history.getTime())));
    if (history.getStatus() == History.accepted) {
      AlarmSetManager.setAlarm(mContext, history, friend);
    } else if (history.getStatus() == History.failed) {
      AlarmHelper.getInstance(mContext).stopAudio();
    }
    LogUtil.d(TAG, ecMessage.getBody().toString());
    if (mOnMessageReportCallback != null) {
      ArrayList<ECMessage> messages = new ArrayList<>();
      messages.add(ecMessage);
      mOnMessageReportCallback.onPushMessage();
    }

    // 是否状态栏提示
    if (showNotice) showNotification(ecMessage);
  }
Exemple #2
0
  public void sendMessage(final Friend friend, History history) {
    try {
      ECMessage msg = ECMessage.createECMessage(ECMessage.Type.TXT);
      msg.setForm(UserCache.getInstance().getClientUser().getUserId() + "");
      msg.setMsgTime(System.currentTimeMillis());

      msg.setTo(friend.getUserId() + "");
      msg.setSessionId(friend.getUserId() + "");
      msg.setDirection(ECMessage.Direction.SEND);

      String content =
          history.getScene().getSceneId() + "/" + history.getTime() + "/" + history.getStatus();
      ECTextMessageBody msgBody = new ECTextMessageBody(content);
      LogUtil.d(TAG, "The content is " + content);
      msg.setBody(msgBody);
      ECChatManager manager = ECDevice.getECChatManager();
      manager.sendMessage(msg, mOnSendMessageListener);
    } catch (Exception e) {
      LogUtil.e(TAG, "send message fail , e=" + e.getMessage());
    }
  }