Search in sources :

Example 1 with RequestCreateThreadWithMessage

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);
    }
}
Also used : JsonArray(com.google.gson.JsonArray) ChatMessage(com.fanap.podchat.mainmodel.ChatMessage) JsonElement(com.google.gson.JsonElement) TypeToken(com.google.gson.reflect.TypeToken) GsonBuilder(com.google.gson.GsonBuilder) JsonObject(com.google.gson.JsonObject) RequestCreateThreadWithMessage(com.fanap.podchat.requestobject.RequestCreateThreadWithMessage) JSONException(org.json.JSONException) SentryException(io.sentry.core.protocol.SentryException) IOException(java.io.IOException) JsonSyntaxException(com.google.gson.JsonSyntaxException) PodChatException(com.fanap.podchat.util.PodChatException) RoomIntegrityException(com.fanap.podchat.persistance.RoomIntegrityException)

Aggregations

ChatMessage (com.fanap.podchat.mainmodel.ChatMessage)1 RoomIntegrityException (com.fanap.podchat.persistance.RoomIntegrityException)1 RequestCreateThreadWithMessage (com.fanap.podchat.requestobject.RequestCreateThreadWithMessage)1 PodChatException (com.fanap.podchat.util.PodChatException)1 GsonBuilder (com.google.gson.GsonBuilder)1 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 TypeToken (com.google.gson.reflect.TypeToken)1 SentryException (io.sentry.core.protocol.SentryException)1 IOException (java.io.IOException)1 JSONException (org.json.JSONException)1