use of com.fanap.podchat.requestobject.RequestCreateThreadWithMessage in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method createThreadWithMessage.
private void createThreadWithMessage(RequestCreateThreadWithFile request, String requestUniqueId, String innerMessageUniqueId, List<String> forwardUniqueIds) {
RequestCreateThreadWithMessage rctm = new RequestCreateThreadWithMessage.Builder(request.getType(), request.getInvitees(), request.getMessageType()).message(request.getMessage()).build();
JsonObject asyncRequestObject = null;
JsonObject innerMessageObj = null;
try {
if (chatReady) {
innerMessageObj = (JsonObject) gson.toJsonTree(request.getMessage());
if (Util.isNullOrEmpty(request.getMessage().getType())) {
innerMessageObj.remove("type");
}
if (Util.isNullOrEmpty(request.getMessage().getText())) {
innerMessageObj.remove("message");
} else {
innerMessageObj.addProperty("uniqueId", innerMessageUniqueId);
setCallBacks(true, true, true, true, Constants.MESSAGE, null, innerMessageUniqueId);
}
if (!Util.isNullOrEmpty(forwardUniqueIds)) {
JsonElement forwardMessageUniqueIdsJsonElement = gson.toJsonTree(forwardUniqueIds, new TypeToken<List<Long>>() {
}.getType());
JsonArray jsonArray = forwardMessageUniqueIdsJsonElement.getAsJsonArray();
innerMessageObj.add("forwardedUniqueIds", jsonArray);
} else {
innerMessageObj.remove("forwardedUniqueIds");
innerMessageObj.remove("forwardedMessageIds");
}
JsonObject jsonObjectCreateThread = (JsonObject) gson.toJsonTree(rctm);
jsonObjectCreateThread.remove("count");
jsonObjectCreateThread.remove("offset");
jsonObjectCreateThread.add("message", innerMessageObj);
ChatMessage chatMessage = new ChatMessage();
chatMessage.setContent(jsonObjectCreateThread.toString());
chatMessage.setType(Constants.INVITATION);
chatMessage.setUniqueId(requestUniqueId);
chatMessage.setToken(getToken());
chatMessage.setTokenIssuer("1");
asyncRequestObject = (JsonObject) gson.toJsonTree(chatMessage);
asyncRequestObject.remove("repliedTo");
asyncRequestObject.remove("subjectId");
asyncRequestObject.remove("systemMetadata");
asyncRequestObject.remove("contentCount");
String typeCode = request.getTypeCode();
if (Util.isNullOrEmpty(typeCode)) {
if (Util.isNullOrEmpty(getTypeCode())) {
asyncRequestObject.remove("typeCode");
} else {
asyncRequestObject.addProperty("typeCode", getTypeCode());
}
} else {
asyncRequestObject.addProperty("typeCode", typeCode);
}
setCallBacks(null, null, null, true, Constants.INVITATION, null, requestUniqueId);
handlerSend.put(requestUniqueId, new ChatHandler() {
});
sendAsyncMessage(asyncRequestObject.toString(), AsyncAckType.Constants.WITHOUT_ACK, "SEND_CREATE_THREAD_WITH_FILE");
} else {
captureError(ChatConstant.ERROR_CHAT_READY, ChatConstant.ERROR_CODE_CHAT_READY, requestUniqueId);
}
} catch (Exception e) {
captureError(ChatConstant.ERROR_UNKNOWN_EXCEPTION, ChatConstant.ERROR_CODE_UNKNOWN_EXCEPTION, requestUniqueId, e);
}
}
Aggregations