Search in sources :

Example 31 with ChatMessage

use of com.fanap.podchat.mainmodel.ChatMessage 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)

Example 32 with ChatMessage

use of com.fanap.podchat.mainmodel.ChatMessage in project pod-chat-android-sdk by FanapSoft.

the class ChatCore method getNotSeenDuration.

public String getNotSeenDuration(RequestGetLastSeens requestGetLastSeens) {
    String uniqueId = generateUniqueId();
    ArrayList<Integer> userIdsList = requestGetLastSeens.getUserIds();
    JsonObject jObj = new JsonObject();
    JsonElement jsonElement = gson.toJsonTree(userIdsList);
    jObj.add("userIds", jsonElement);
    if (chatReady) {
        ChatMessage chatMessage = new ChatMessage();
        chatMessage.setType(Constants.GET_NOT_SEEN_DURATION);
        chatMessage.setContent(jObj.toString());
        chatMessage.setToken(getToken());
        chatMessage.setTokenIssuer("1");
        chatMessage.setUniqueId(uniqueId);
        JsonObject jsonObject = (JsonObject) gson.toJsonTree(chatMessage);
        jsonObject.remove("systemMetadata");
        jsonObject.remove("metadata");
        jsonObject.remove("repliedTo");
        jsonObject.remove("contentCount");
        jsonObject.remove("time");
        jsonObject.remove("subjectId");
        if (Util.isNullOrEmpty(getTypeCode())) {
            jsonObject.remove("typeCode");
        } else {
            jsonObject.remove("typeCode");
            jsonObject.addProperty("typeCode", getTypeCode());
        }
        String asyncContent = jsonObject.toString();
        setCallBacks(null, null, null, true, Constants.GET_NOT_SEEN_DURATION, null, uniqueId);
        sendAsyncMessage(asyncContent, AsyncAckType.Constants.WITHOUT_ACK, "SEND_GET_NOT_SEEN_DURATION");
    }
    return uniqueId;
}
Also used : ChatMessage(com.fanap.podchat.mainmodel.ChatMessage) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject)

Example 33 with ChatMessage

use of com.fanap.podchat.mainmodel.ChatMessage in project pod-chat-android-sdk by FanapSoft.

the class ChatCore method muteThread.

/**
 * It Mutes the thread so notification is set to off for that thread
 */
public String muteThread(long threadId, ChatHandler handler) {
    String uniqueId;
    uniqueId = generateUniqueId();
    JsonObject jsonObject;
    try {
        if (chatReady) {
            // long threadId = request.getThreadId();
            // String typeCode = request.getTypeCode();
            ChatMessage chatMessage = new ChatMessage();
            chatMessage.setType(Constants.MUTE_THREAD);
            chatMessage.setToken(getToken());
            chatMessage.setTokenIssuer("1");
            chatMessage.setSubjectId(threadId);
            chatMessage.setUniqueId(uniqueId);
            jsonObject = (JsonObject) gson.toJsonTree(chatMessage);
            jsonObject.remove("contentCount");
            jsonObject.remove("systemMetadata");
            jsonObject.remove("metadata");
            jsonObject.remove("repliedTo");
            if (Util.isNullOrEmpty(typeCode)) {
                if (Util.isNullOrEmpty(getTypeCode())) {
                    jsonObject.remove("typeCode");
                } else {
                    jsonObject.addProperty("typeCode", getTypeCode());
                }
            } else {
                jsonObject.addProperty("typeCode", typeCode);
            }
            setCallBacks(null, null, null, true, Constants.MUTE_THREAD, null, uniqueId);
            sendAsyncMessage(jsonObject.toString(), AsyncAckType.Constants.WITHOUT_ACK, "SEND_MUTE_THREAD");
            if (handler != null) {
                handler.onMuteThread(uniqueId);
            }
        } else {
            captureError(ChatConstant.ERROR_CHAT_READY, ChatConstant.ERROR_CODE_CHAT_READY, uniqueId);
        }
    } catch (Exception e) {
        showErrorLog(e.getMessage());
        onUnknownException(uniqueId, e);
    }
    return uniqueId;
}
Also used : ChatMessage(com.fanap.podchat.mainmodel.ChatMessage) JsonObject(com.google.gson.JsonObject) 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)

Example 34 with ChatMessage

use of com.fanap.podchat.mainmodel.ChatMessage in project pod-chat-android-sdk by FanapSoft.

the class ChatCore method handleForwardMessage.

private void handleForwardMessage(ChatMessage chatMessage) {
    MessageVO messageVO = gson.fromJson(chatMessage.getContent(), MessageVO.class);
    ChatResponse<ResultNewMessage> chatResponse = new ChatResponse<>();
    ResultNewMessage resultMessage = new ResultNewMessage();
    resultMessage.setThreadId(chatMessage.getSubjectId());
    resultMessage.setMessageVO(messageVO);
    chatResponse.setResult(resultMessage);
    String json = gson.toJson(chatResponse);
    long ownerId = 0;
    if (messageVO != null) {
        ownerId = messageVO.getParticipant().getId();
    }
    if (sentryResponseLog) {
        showLog("RECEIVED_FORWARD_MESSAGE", json);
    } else {
        showLog("RECEIVED_FORWARD_MESSAGE");
    }
    if (ownerId != getUserId()) {
        ChatMessage message = null;
        if (messageVO != null) {
            message = getChatMessage(messageVO);
        }
        String asyncContent = gson.toJson(message);
        showLog("SEND_DELIVERY_MESSAGE", asyncContent);
        async.sendMessage(asyncContent, AsyncAckType.Constants.WITHOUT_ACK);
    }
    if (cache) {
        dataSource.saveMessageResultFromServer(messageVO, chatMessage.getSubjectId());
    }
    listenerManager.callOnNewMessage(json, chatResponse);
}
Also used : ResultNewMessage(com.fanap.podchat.model.ResultNewMessage) ChatMessage(com.fanap.podchat.mainmodel.ChatMessage) ChatResponse(com.fanap.podchat.model.ChatResponse) GapMessageVO(com.fanap.podchat.cachemodel.GapMessageVO) CacheMessageVO(com.fanap.podchat.cachemodel.CacheMessageVO) MessageVO(com.fanap.podchat.mainmodel.MessageVO)

Example 35 with ChatMessage

use of com.fanap.podchat.mainmodel.ChatMessage in project pod-chat-android-sdk by FanapSoft.

the class ChatCore method sendTextMessageWithFile.

private void sendTextMessageWithFile(String description, long threadId, String metaData, String systemMetadata, String uniqueId, String typeCode, Integer messageType) {
    /* Add to sending Queue*/
    SendingQueueCache sendingQueue = new SendingQueueCache();
    if (systemMetadata != null)
        sendingQueue.setSystemMetadata(systemMetadata);
    else
        sendingQueue.setSystemMetadata("");
    if (messageType != null)
        sendingQueue.setMessageType(messageType);
    else
        sendingQueue.setMessageType(0);
    sendingQueue.setThreadId(threadId);
    sendingQueue.setUniqueId(uniqueId);
    sendingQueue.setMessage(description);
    sendingQueue.setMetadata(metaData);
    ChatMessage chatMessage = new ChatMessage();
    chatMessage.setContent(description);
    chatMessage.setType(Constants.MESSAGE);
    chatMessage.setTokenIssuer("1");
    chatMessage.setToken(getToken());
    chatMessage.setMetadata(metaData);
    chatMessage.setSystemMetadata(systemMetadata);
    chatMessage.setMessageType(messageType);
    chatMessage.setUniqueId(uniqueId);
    chatMessage.setSubjectId(threadId);
    chatMessage.setTypeCode(typeCode != null ? typeCode : getTypeCode());
    JsonObject jsonObject = (JsonObject) gson.toJsonTree(chatMessage);
    if (Util.isNullOrEmpty(systemMetadata)) {
        jsonObject.remove("systemMetadata");
    }
    if (chatMessage.getRepliedTo() == 0)
        jsonObject.remove("repliedTo");
    if (chatMessage.getTime() == 0)
        jsonObject.remove("time");
    jsonObject.remove("contentCount");
    String asyncContent = jsonObject.toString();
    sendingQueue.setAsyncContent(asyncContent);
    insertToSendQueue(uniqueId, sendingQueue);
    if (chatReady) {
        setThreadCallbacks(threadId, uniqueId);
        moveFromSendingQueueToWaitQueue(uniqueId, sendingQueue);
        sendAsyncMessage(asyncContent, AsyncAckType.Constants.WITHOUT_ACK, "SEND_TXT_MSG_WITH_FILE");
        stopTyping();
    } else {
        captureError(ChatConstant.ERROR_CHAT_READY, ChatConstant.ERROR_CODE_CHAT_READY, uniqueId);
    }
}
Also used : SendingQueueCache(com.fanap.podchat.cachemodel.queue.SendingQueueCache) ChatMessage(com.fanap.podchat.mainmodel.ChatMessage) JsonObject(com.google.gson.JsonObject)

Aggregations

ChatMessage (com.fanap.podchat.mainmodel.ChatMessage)56 JsonObject (com.google.gson.JsonObject)33 AsyncMessage (com.fanap.podchat.mainmodel.AsyncMessage)20 RoomIntegrityException (com.fanap.podchat.persistance.RoomIntegrityException)9 PodChatException (com.fanap.podchat.util.PodChatException)9 JsonSyntaxException (com.google.gson.JsonSyntaxException)9 SentryException (io.sentry.core.protocol.SentryException)9 IOException (java.io.IOException)9 JSONException (org.json.JSONException)9 ArrayList (java.util.ArrayList)5 ChatResponse (com.fanap.podchat.model.ChatResponse)4 JsonArray (com.google.gson.JsonArray)4 NonNull (android.support.annotation.NonNull)3 CacheMessageVO (com.fanap.podchat.cachemodel.CacheMessageVO)3 GapMessageVO (com.fanap.podchat.cachemodel.GapMessageVO)3 MessageVO (com.fanap.podchat.mainmodel.MessageVO)3 ResultNewMessage (com.fanap.podchat.model.ResultNewMessage)3 JsonElement (com.google.gson.JsonElement)3 TypeToken (com.google.gson.reflect.TypeToken)3 SendingQueueCache (com.fanap.podchat.cachemodel.queue.SendingQueueCache)2