Search in sources :

Example 21 with MessageVO

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

the class AssistantCacheTest method populateMessagesFromServer.

public void populateMessagesFromServer() {
    populateThreadsListFromServerOnly();
    assert threads.size() > 0;
    Thread thread = threads.get(0);
    chatListeners = new ChatListener() {

        @Override
        public void onGetHistory(String content, ChatResponse<ResultHistory> history) {
            if (!history.isCache()) {
                print("Received Message List Server: " + content);
                threadMessagesList.addAll(history.getResult().getHistory().stream().filter(messageVO -> messageVO.getMessage() != null).collect(Collectors.toList()));
                chat.removeListener(chatListeners);
                resumeProcess();
            }
        }
    };
    chat.addListener(chatListeners);
    RequestGetHistory requestGetHistory = new RequestGetHistory.Builder(thread.getId()).withNoCache().build();
    chat.getHistory(requestGetHistory, null);
    pauseProcess();
}
Also used : ResultContact(com.fanap.podchat.model.ResultContact) ResultThreads(com.fanap.podchat.model.ResultThreads) RoleType(com.fanap.podchat.chat.RoleType) ChatPresenter(com.example.chat.application.chatexample.ChatPresenter) ResultHistory(com.fanap.podchat.model.ResultHistory) RequestGetContact(com.fanap.podchat.requestobject.RequestGetContact) Looper(android.os.Looper) App(com.fanap.podchat.chat.App) Invitee(com.fanap.podchat.mainmodel.Invitee) InviteType(com.fanap.podchat.util.InviteType) Participant(com.fanap.podchat.mainmodel.Participant) Logger(com.orhanobut.logger.Logger) InstrumentationRegistry(android.support.test.InstrumentationRegistry) ChatListener(com.fanap.podchat.chat.ChatListener) MessageVO(com.fanap.podchat.mainmodel.MessageVO) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) AssistantHistoryVo(com.fanap.podchat.chat.assistant.model.AssistantHistoryVo) APP_ID(com.example.chat.application.chatexample.ChatActivity.APP_ID) List(java.util.List) GetBlockedAssistantsRequest(com.fanap.podchat.chat.assistant.request_model.GetBlockedAssistantsRequest) GetAssistantRequest(com.fanap.podchat.chat.assistant.request_model.GetAssistantRequest) Chat(com.fanap.podchat.chat.Chat) Context(android.content.Context) GetAssistantHistoryRequest(com.fanap.podchat.chat.assistant.request_model.GetAssistantHistoryRequest) RequestConnect(com.fanap.podchat.requestobject.RequestConnect) AssistantVo(com.fanap.podchat.chat.assistant.model.AssistantVo) BeforeClass(org.junit.BeforeClass) Mock(org.mockito.Mock) Thread(com.fanap.podchat.mainmodel.Thread) RunWith(org.junit.runner.RunWith) ChatContract(com.example.chat.application.chatexample.ChatContract) RegisterAssistantRequest(com.fanap.podchat.chat.assistant.request_model.RegisterAssistantRequest) ChatResponse(com.fanap.podchat.model.ChatResponse) ResultParticipant(com.fanap.podchat.model.ResultParticipant) ArrayList(java.util.ArrayList) R(com.fanap.podchat.example.R) RequestThreadParticipant(com.fanap.podchat.requestobject.RequestThreadParticipant) BaseApplication(com.example.chat.application.chatexample.BaseApplication) ChatActivity(com.example.chat.application.chatexample.ChatActivity) Contact(com.fanap.podchat.mainmodel.Contact) RequestThread(com.fanap.podchat.requestobject.RequestThread) Before(org.junit.Before) RequestGetHistory(com.fanap.podchat.requestobject.RequestGetHistory) CHAT_READY(com.fanap.podchat.util.ChatStateType.ChatSateConstant.CHAT_READY) ActivityTestRule(android.support.test.rule.ActivityTestRule) Test(org.junit.Test) AndroidJUnit4(android.support.test.runner.AndroidJUnit4) LargeTest(android.support.test.filters.LargeTest) Mockito(org.mockito.Mockito) Rule(org.junit.Rule) BlockUnblockAssistantRequest(com.fanap.podchat.chat.assistant.request_model.BlockUnblockAssistantRequest) Assert(org.junit.Assert) Activity(android.app.Activity) Collections(java.util.Collections) RequestGetHistory(com.fanap.podchat.requestobject.RequestGetHistory) ChatListener(com.fanap.podchat.chat.ChatListener) ResultHistory(com.fanap.podchat.model.ResultHistory) Thread(com.fanap.podchat.mainmodel.Thread) RequestThread(com.fanap.podchat.requestobject.RequestThread)

Example 22 with MessageVO

use of com.fanap.podchat.mainmodel.MessageVO 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 23 with MessageVO

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

the class HashTagManager method getMentionListResponse.

public static ChatResponse<ResultHistory> getMentionListResponse(ChatMessage chatMessage) {
    List<MessageVO> messageVOS = getMessageVOSFromChatMessage(chatMessage);
    ResultHistory resultHistory = new ResultHistory();
    resultHistory.setContentCount(chatMessage.getContentCount());
    resultHistory.setHistory(messageVOS);
    ChatResponse<ResultHistory> finalResponse = new ChatResponse<>();
    finalResponse.setResult(resultHistory);
    finalResponse.setUniqueId(chatMessage.getUniqueId());
    finalResponse.setSubjectId(chatMessage.getSubjectId());
    return finalResponse;
}
Also used : ChatResponse(com.fanap.podchat.model.ChatResponse) MessageVO(com.fanap.podchat.mainmodel.MessageVO) ResultHistory(com.fanap.podchat.model.ResultHistory)

Example 24 with MessageVO

use of com.fanap.podchat.mainmodel.MessageVO 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 25 with MessageVO

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

Aggregations

MessageVO (com.fanap.podchat.mainmodel.MessageVO)48 ArrayList (java.util.ArrayList)34 CacheMessageVO (com.fanap.podchat.cachemodel.CacheMessageVO)25 GapMessageVO (com.fanap.podchat.cachemodel.GapMessageVO)20 Thread (com.fanap.podchat.mainmodel.Thread)20 Test (org.junit.Test)20 ChatResponse (com.fanap.podchat.model.ChatResponse)18 ResultHistory (com.fanap.podchat.model.ResultHistory)18 ChatListener (com.fanap.podchat.chat.ChatListener)15 ResultNewMessage (com.fanap.podchat.model.ResultNewMessage)15 RequestThread (com.fanap.podchat.requestobject.RequestThread)15 PinMessageVO (com.fanap.podchat.mainmodel.PinMessageVO)13 Activity (android.app.Activity)10 Context (android.content.Context)10 Looper (android.os.Looper)10 InstrumentationRegistry (android.support.test.InstrumentationRegistry)10 ActivityTestRule (android.support.test.rule.ActivityTestRule)10 AndroidJUnit4 (android.support.test.runner.AndroidJUnit4)10 BaseApplication (com.example.chat.application.chatexample.BaseApplication)10 ChatActivity (com.example.chat.application.chatexample.ChatActivity)10