Search in sources :

Example 26 with ChatMessage

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

the class AssistantManager method createBlockAssistantsRequest.

public static String createBlockAssistantsRequest(BlockUnblockAssistantRequest request, String uniqueId) {
    String content = App.getGson().toJson(request.getAssistantVos());
    AsyncMessage message = new ChatMessage();
    message.setType(ChatMessageType.Constants.BLOCK_ASSISTANT);
    message.setToken(CoreConfig.token);
    message.setTokenIssuer(CoreConfig.tokenIssuer);
    message.setTypeCode(request.getTypeCode() != null ? request.getTypeCode() : CoreConfig.typeCode);
    message.setContent(content);
    message.setUniqueId(uniqueId);
    return App.getGson().toJson(message);
}
Also used : ChatMessage(com.fanap.podchat.mainmodel.ChatMessage) AsyncMessage(com.fanap.podchat.mainmodel.AsyncMessage)

Example 27 with ChatMessage

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

the class AssistantManager method createGetAssistantHistoryRequest.

public static String createGetAssistantHistoryRequest(GetAssistantHistoryRequest request, String uniqueId) {
    JsonObject content = new JsonObject();
    AsyncMessage message = new ChatMessage();
    message.setType(ChatMessageType.Constants.GET_ASSISTANT_HISTORY);
    message.setToken(CoreConfig.token);
    message.setTokenIssuer(CoreConfig.tokenIssuer);
    message.setTypeCode(request.getTypeCode() != null ? request.getTypeCode() : CoreConfig.typeCode);
    message.setContent(App.getGson().toJson(content));
    message.setUniqueId(uniqueId);
    return App.getGson().toJson(message);
}
Also used : ChatMessage(com.fanap.podchat.mainmodel.ChatMessage) AsyncMessage(com.fanap.podchat.mainmodel.AsyncMessage) JsonObject(com.google.gson.JsonObject)

Example 28 with ChatMessage

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

the class ChatCore method handleNewMessage.

/**
 * When the new message arrived we send the deliver message to the sender user.
 */
private void handleNewMessage(ChatMessage chatMessage) {
    try {
        MessageVO messageVO = gson.fromJson(chatMessage.getContent(), MessageVO.class);
        if (cache) {
            dataSource.saveMessageResultFromServer(messageVO, chatMessage.getSubjectId());
        }
        ChatResponse<ResultNewMessage> chatResponse = new ChatResponse<>();
        chatResponse.setUniqueId(chatMessage.getUniqueId());
        chatResponse.setHasError(false);
        chatResponse.setErrorCode(0);
        chatResponse.setErrorMessage("");
        ResultNewMessage resultNewMessage = new ResultNewMessage();
        resultNewMessage.setMessageVO(messageVO);
        resultNewMessage.setThreadId(chatMessage.getSubjectId());
        chatResponse.setResult(resultNewMessage);
        chatResponse.setSubjectId(chatMessage.getSubjectId());
        String json = gson.toJson(chatResponse);
        long ownerId = 0;
        if (messageVO != null) {
            ownerId = messageVO.getParticipant().getId();
        }
        if (sentryResponseLog) {
            showLog("RECEIVED_NEW_MESSAGE", json);
        } else {
            showLog("RECEIVED_NEW_MESSAGE");
        }
        if (ownerId != getUserId()) {
            if (messageVO != null) {
                ChatMessage message = getChatMessage(messageVO);
                String asyncContent = gson.toJson(message);
                async.sendMessage(asyncContent, AsyncAckType.Constants.WITHOUT_ACK);
                setThreadCallbacks(chatMessage.getSubjectId(), chatMessage.getUniqueId());
                showLog("SEND_DELIVERY_MESSAGE", asyncContent);
            }
        }
        if (messageVO != null) {
            handleOnNewMessageAdded(messageVO.getConversation(), chatMessage.getUniqueId());
        }
        listenerManager.callOnNewMessage(json, chatResponse);
    } catch (Exception e) {
        showErrorLog(e.getMessage());
        onUnknownException(chatMessage.getUniqueId(), e);
    }
}
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) 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 29 with ChatMessage

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

the class ChatCore method deliveredMessageList.

/**
 * The replacement method is getMessageDeliveredList.
 */
private String deliveredMessageList(RequestDeliveredMessageList requestParams) {
    String uniqueId;
    uniqueId = generateUniqueId();
    try {
        if (chatReady) {
            if (Util.isNullOrEmpty(requestParams.getCount())) {
                requestParams.setCount(50);
            }
            JsonObject object = (JsonObject) gson.toJsonTree(requestParams);
            object.remove("typeCode");
            ChatMessage chatMessage = new ChatMessage(uniqueId, Constants.DELIVERED_MESSAGE_LIST, object.toString(), getToken());
            String asyncContent = chatMessage.getJson(requestParams.getTypeCode(), getTypeCode()).toString();
            setCallBacks(null, null, null, true, Constants.DELIVERED_MESSAGE_LIST, requestParams.getOffset(), uniqueId);
            sendAsyncMessage(asyncContent, AsyncAckType.Constants.WITHOUT_ACK, "SEND_DELIVERED_MESSAGE_LIST");
        } else {
            captureError(ChatConstant.ERROR_CHAT_READY, ChatConstant.ERROR_CODE_CHAT_READY, uniqueId);
        }
    } catch (Throwable e) {
        onUnknownException(uniqueId, e);
    }
    return uniqueId;
}
Also used : ChatMessage(com.fanap.podchat.mainmodel.ChatMessage) JsonObject(com.google.gson.JsonObject)

Example 30 with ChatMessage

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

the class ChatCore method editMessage.

/**
 * Message can be edit when you pass the message id and the edited
 * content in order to edit your Message.
 */
public String editMessage(int messageId, String messageContent, String systemMetaData, ChatHandler handler) {
    String uniqueId = generateUniqueId();
    try {
        if (chatReady) {
            ChatMessage chatMessage = new ChatMessage();
            chatMessage.setType(Constants.EDIT_MESSAGE);
            chatMessage.setToken(getToken());
            chatMessage.setUniqueId(uniqueId);
            chatMessage.setSubjectId(messageId);
            chatMessage.setContent(messageContent);
            chatMessage.setSystemMetadata(systemMetaData);
            chatMessage.setTokenIssuer("1");
            // chatMessage.setMessageType(TextMessageType.Constants.TEXT);
            JsonObject jsonObject = (JsonObject) gson.toJsonTree(chatMessage);
            if (Util.isNullOrEmpty(getTypeCode())) {
                jsonObject.remove("typeCode");
            } else {
                jsonObject.remove("typeCode");
                jsonObject.addProperty("typeCode", getTypeCode());
            }
            jsonObject.remove("metadata");
            jsonObject.remove("contentCount");
            jsonObject.remove("repliedTo");
            jsonObject.remove("time");
            jsonObject.remove("messageType");
            String asyncContent = jsonObject.toString();
            setCallBacks(null, null, null, true, Constants.EDIT_MESSAGE, null, uniqueId);
            sendAsyncMessage(asyncContent, AsyncAckType.Constants.WITHOUT_ACK, "SEND_EDIT_MESSAGE");
            stopTyping();
            if (handler != null) {
                handler.onEditMessage(uniqueId);
            }
        } else {
            captureError(ChatConstant.ERROR_CHAT_READY, ChatConstant.ERROR_CODE_CHAT_READY, uniqueId);
        }
    } catch (Throwable e) {
        showErrorLog(e.getMessage());
        onUnknownException(uniqueId, e);
    }
    return uniqueId;
}
Also used : 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