Search in sources :

Example 6 with ResultNewMessage

use of com.fanap.podchat.model.ResultNewMessage in project pod-chat-android-sdk by FanapSoft.

the class ChatCore method publishNewMessages.

private void publishNewMessages(List<MessageVO> newMessages, long threadId, String uniqueId) {
    for (MessageVO messageVO : newMessages) {
        try {
            // gson.toJson(chatResponse);
            ChatResponse<ResultNewMessage> chatResponse = MessageManager.preparepublishNewMessagesResponse(messageVO, threadId);
            String json = gson.toJson(chatResponse);
            listenerManager.callOnNewMessage(json, chatResponse);
            long ownerId = 0;
            if (messageVO.getParticipant() != null) {
                ownerId = messageVO.getParticipant().getId();
            }
            showLog("RECEIVED_NEW_MESSAGE", json);
            if (ownerId > 0 && ownerId != getUserId()) {
                ChatMessage message = getChatMessage(messageVO);
                String asyncContent = gson.toJson(message);
                async.sendMessage(asyncContent, AsyncAckType.Constants.WITHOUT_ACK);
                setThreadCallbacks(threadId, uniqueId);
                showLog("SEND_DELIVERY_MESSAGE", asyncContent);
            }
        } catch (Exception e) {
            showErrorLog(e.getMessage());
            onUnknownException(uniqueId, e);
        }
    }
}
Also used : ResultNewMessage(com.fanap.podchat.model.ResultNewMessage) ChatMessage(com.fanap.podchat.mainmodel.ChatMessage) 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 7 with ResultNewMessage

use of com.fanap.podchat.model.ResultNewMessage 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 8 with ResultNewMessage

use of com.fanap.podchat.model.ResultNewMessage in project pod-chat-android-sdk by FanapSoft.

the class ChatCore method findEditedMessages.

private List<MessageVO> findEditedMessages(List<MessageVO> oldMessages, List<MessageVO> newMessages, String uniqueId, long threadId) {
    Set<MessageVO> editedMessages = new HashSet<>();
    for (MessageVO newMessage : newMessages) {
        for (MessageVO oldMessage : oldMessages) {
            if (oldMessage.isEdited(newMessage)) {
                editedMessages.add(newMessage);
                // gson.toJson(chatResponse);
                ChatResponse<ResultNewMessage> chatResponse = MessageManager.prepareNewMessageResponse(newMessage, threadId, uniqueId);
                showLog("RECEIVE_EDIT_MESSAGE", chatResponse.toString());
                listenerManager.callOnEditedMessage(chatResponse.toString(), chatResponse);
                messageCallbacks.remove(newMessage.getUniqueId());
            }
        }
    }
    return new ArrayList<>(editedMessages);
}
Also used : ResultNewMessage(com.fanap.podchat.model.ResultNewMessage) ArrayList(java.util.ArrayList) GapMessageVO(com.fanap.podchat.cachemodel.GapMessageVO) CacheMessageVO(com.fanap.podchat.cachemodel.CacheMessageVO) MessageVO(com.fanap.podchat.mainmodel.MessageVO) HashSet(java.util.HashSet)

Example 9 with ResultNewMessage

use of com.fanap.podchat.model.ResultNewMessage in project pod-chat-android-sdk by FanapSoft.

the class ChatCore method handleEditMessage.

private void handleEditMessage(ChatMessage chatMessage, String messageUniqueId) {
    if (sentryResponseLog) {
        showLog("RECEIVE_EDIT_MESSAGE", gson.toJson(chatMessage));
    } else {
        showLog("RECEIVE_EDIT_MESSAGE");
    }
    ChatResponse<ResultNewMessage> chatResponse = new ChatResponse<>();
    ResultNewMessage newMessage = new ResultNewMessage();
    MessageVO messageVO = gson.fromJson(chatMessage.getContent(), MessageVO.class);
    if (messageVO.getMessage().startsWith("#")) {
        Log.e(TAG, "hashtag: " + "hello");
        String hashtag = messageVO.getMessage().substring(0, messageVO.getMessage().indexOf(' '));
        Log.e(TAG, "hashtag: " + hashtag);
    }
    if (cache) {
        dataSource.updateMessageResultFromServer(messageVO, chatMessage.getSubjectId());
    }
    newMessage.setMessageVO(messageVO);
    newMessage.setThreadId(chatMessage.getSubjectId());
    chatResponse.setResult(newMessage);
    chatResponse.setUniqueId(chatMessage.getUniqueId());
    chatResponse.setSubjectId(chatMessage.getSubjectId());
    String content = gson.toJson(chatResponse);
    messageCallbacks.remove(messageUniqueId);
    listenerManager.callOnEditedMessage(content, chatResponse);
}
Also used : ResultNewMessage(com.fanap.podchat.model.ResultNewMessage) 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 10 with ResultNewMessage

use of com.fanap.podchat.model.ResultNewMessage 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)

Aggregations

ResultNewMessage (com.fanap.podchat.model.ResultNewMessage)17 ChatListener (com.fanap.podchat.chat.ChatListener)10 MessageVO (com.fanap.podchat.mainmodel.MessageVO)8 Thread (com.fanap.podchat.mainmodel.Thread)8 RequestMessage (com.fanap.podchat.requestobject.RequestMessage)8 RequestThread (com.fanap.podchat.requestobject.RequestThread)8 Test (org.junit.Test)6 CacheMessageVO (com.fanap.podchat.cachemodel.CacheMessageVO)5 GapMessageVO (com.fanap.podchat.cachemodel.GapMessageVO)5 ChatResponse (com.fanap.podchat.model.ChatResponse)5 ArrayList (java.util.ArrayList)5 Date (java.util.Date)5 ChatMessage (com.fanap.podchat.mainmodel.ChatMessage)3 ErrorOutPut (com.fanap.podchat.model.ErrorOutPut)3 ResultHistory (com.fanap.podchat.model.ResultHistory)3 ResultThread (com.fanap.podchat.model.ResultThread)3 RequestGetHistory (com.fanap.podchat.requestobject.RequestGetHistory)3 LargeTest (android.support.test.filters.LargeTest)2 RoomIntegrityException (com.fanap.podchat.persistance.RoomIntegrityException)2 PodChatException (com.fanap.podchat.util.PodChatException)2