Ejemplo n.º 1
0
  public void sendMessage(Message message) throws JSONException {
    JSONObject json = new JSONObject();
    json.put("text", message.getText());
    json.put("roomId", message.getRoomId());
    if (message.getFileAddress() != null && message.getFileAddress().length() > 0) {
      json.put("file", message.getFileAddress());
    } else {
      json.put("file", "");
    }
    NetworkManager.sendRequest(
        MethodsName.SEND_MESSAGE,
        json,
        new NetworkReceiver() {
          @Override
          public void onResponse(Object response) {
            // todo change message status to sent
            Log.wtf("SEND_MESSAGE", response.toString());
          }

          @Override
          public void onErrorResponse(BerimNetworkException error) {
            // todo show error for message.
            Log.wtf("SEND_MESSAGE", error.getMessage());
          }
        });
    addMessage(message);
  }
Ejemplo n.º 2
0
  public void seenMessagesOnServer(final ArrayList<Message> messages, final boolean retry)
      throws JSONException {
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("status", "seen");
    JSONArray messageIdArray = new JSONArray();
    for (Message message : messages) {
      if (message.getSender().getId() != mMe.getId()) {
        messageIdArray.put(message.getId());
      }
    }
    jsonObject.put("messages", messageIdArray);
    if (messageIdArray.length() == 0) {
      return;
    }
    NetworkManager.sendRequest(
        MethodsName.bULK_CHANGE_MESSAGE_STATUS_GOT,
        jsonObject,
        new NetworkReceiver() {
          @Override
          public void onResponse(Object response) {
            // message seen in server side
          }

          @Override
          public void onErrorResponse(BerimNetworkException error) {
            if (retry) {
              try {
                seenMessagesOnServer(messages, false);
              } catch (JSONException e) {

              }
            }
          }
        });
  }
Ejemplo n.º 3
0
 public void addMessage(Message message) {
   // add message to list
   mMessages.add(message);
   mAdapter.notifyDataSetChanged();
   mMessageInput.setText("");
   if (message.getSender().getId().equals(mMe.getId())) {
     DatabaseHelper.getInstance(mContext).InsertMessageNoUpdate(message);
   }
 }