Search in sources :

Example 1 with ResultHistory

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

the class Mention 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 2 with ResultHistory

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

the class MessageDatabaseHelper method getThreadHistory.

public Observable<ChatResponse<ResultHistory>> getThreadHistory(@NonNull SearchSystemMetadataRequest request) {
    return rx.Observable.create(subscriber -> {
        List<MessageVO> messageVOS = new ArrayList<>();
        List<CacheMessageVO> cacheMessageVOS;
        long offset = request.getOffset();
        long count = request.getCount();
        String order = request.getOrder();
        offset = offset >= 0 ? offset : 0;
        count = count > 0 ? count : 50;
        if (Util.isNullOrEmpty(order)) {
            order = "desc";
        }
        String rawQuery = "SELECT * FROM CacheMessageVO WHERE threadVoId =" + request.getMessageThreadId();
        // rawQuery = rawQuery + " AND system_metadata_" + request.getMetadataCriteria().getField() + " >= " + request.getMetadataCriteria().getGte();
        long contentCount = messageDao.getHistoryContentCount(new SimpleSQLiteQuery(rawQuery.replaceFirst("SELECT \\* ", "SELECT COUNT(ID) ")));
        rawQuery = addOrderAndLimitAndOffset(offset, count, order, rawQuery);
        SupportSQLiteQuery sqLiteQuery = new SimpleSQLiteQuery(rawQuery);
        cacheMessageVOS = messageDao.getRawHistory(sqLiteQuery);
        prepareMessageVOs(messageVOS, cacheMessageVOS);
        List<Sending> sendingList = getAllSendingQueueByThreadId(request.getMessageThreadId());
        List<Uploading> uploadingList = getAllUploadingQueueByThreadId(request.getMessageThreadId());
        List<Failed> failedList = getAllWaitQueueCacheByThreadId(request.getMessageThreadId());
        ChatResponse<ResultHistory> chatResponse = new ChatResponse<>();
        chatResponse.setCache(true);
        ResultHistory resultHistory = new ResultHistory();
        resultHistory.setHistory(messageVOS);
        resultHistory.setNextOffset(request.getOffset() + messageVOS.size());
        resultHistory.setContentCount(contentCount);
        if (messageVOS.size() + request.getOffset() < contentCount) {
            resultHistory.setHasNext(true);
        } else {
            resultHistory.setHasNext(false);
        }
        resultHistory.setHistory(messageVOS);
        resultHistory.setSending(sendingList);
        resultHistory.setUploadingQueue(uploadingList);
        resultHistory.setFailed(failedList);
        chatResponse.setErrorCode(0);
        chatResponse.setHasError(false);
        chatResponse.setErrorMessage("");
        chatResponse.setResult(resultHistory);
        chatResponse.setCache(true);
        chatResponse.setSubjectId(request.getMessageThreadId());
        subscriber.onNext(chatResponse);
    });
}
Also used : Sending(com.fanap.podchat.cachemodel.queue.Sending) SupportSQLiteQuery(android.arch.persistence.db.SupportSQLiteQuery) Failed(com.fanap.podchat.cachemodel.queue.Failed) ArrayList(java.util.ArrayList) Uploading(com.fanap.podchat.cachemodel.queue.Uploading) ResultHistory(com.fanap.podchat.model.ResultHistory) SimpleSQLiteQuery(android.arch.persistence.db.SimpleSQLiteQuery) ChatResponse(com.fanap.podchat.model.ChatResponse) CacheMessageVO(com.fanap.podchat.cachemodel.CacheMessageVO) PinMessageVO(com.fanap.podchat.mainmodel.PinMessageVO) MessageVO(com.fanap.podchat.mainmodel.MessageVO) GapMessageVO(com.fanap.podchat.cachemodel.GapMessageVO) CacheMessageVO(com.fanap.podchat.cachemodel.CacheMessageVO)

Example 3 with ResultHistory

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

the class MessageDatabaseHelper method getThreadHistory.

public Observable<ChatResponse<ResultHistory>> getThreadHistory(@NonNull History history, long threadId) {
    return rx.Observable.create(subscriber -> {
        List<MessageVO> messageVOS = new ArrayList<>();
        List<CacheMessageVO> cacheMessageVOS;
        long fromTime = history.getFromTime();
        long fromTimeNanos = history.getFromTimeNanos();
        long toTime = history.getToTime();
        long toTimeNanos = history.getToTimeNanos();
        long messageId = history.getId();
        long offset = history.getOffset();
        long count = history.getCount();
        int messageType = history.getMessageType();
        String query = history.getQuery();
        String order = history.getOrder();
        offset = offset >= 0 ? offset : 0;
        count = count > 0 ? count : 50;
        if (Util.isNullOrEmpty(order)) {
            order = "desc";
        }
        String rawQuery = "SELECT * FROM CacheMessageVO WHERE threadVoId =" + threadId;
        rawQuery = addMessageIdIfExist(messageId, rawQuery);
        rawQuery = addFromTimeIfExist(fromTime, fromTimeNanos, rawQuery);
        rawQuery = addToTimeIfExist(toTime, toTimeNanos, rawQuery);
        rawQuery = addQueryIfExist(query, rawQuery);
        rawQuery = addMessageTypeIfExist(messageType, rawQuery);
        long contentCount = messageDao.getHistoryContentCount(new SimpleSQLiteQuery(rawQuery.replaceFirst("SELECT \\* ", "SELECT COUNT(ID) ")));
        rawQuery = addOrderAndLimitAndOffset(offset, count, order, rawQuery);
        SupportSQLiteQuery sqLiteQuery = new SimpleSQLiteQuery(rawQuery);
        cacheMessageVOS = messageDao.getRawHistory(sqLiteQuery);
        prepareMessageVOs(messageVOS, cacheMessageVOS);
        List<Sending> sendingList = getAllSendingQueueByThreadId(threadId);
        List<Uploading> uploadingList = getAllUploadingQueueByThreadId(threadId);
        List<Failed> failedList = getAllWaitQueueCacheByThreadId(threadId);
        ChatResponse<ResultHistory> chatResponse = new ChatResponse<>();
        chatResponse.setCache(true);
        ResultHistory resultHistory = new ResultHistory();
        resultHistory.setHistory(messageVOS);
        resultHistory.setNextOffset(history.getOffset() + messageVOS.size());
        resultHistory.setContentCount(contentCount);
        if (messageVOS.size() + history.getOffset() < contentCount) {
            resultHistory.setHasNext(true);
        } else {
            resultHistory.setHasNext(false);
        }
        resultHistory.setHistory(messageVOS);
        resultHistory.setSending(sendingList);
        resultHistory.setUploadingQueue(uploadingList);
        resultHistory.setFailed(failedList);
        chatResponse.setErrorCode(0);
        chatResponse.setHasError(false);
        chatResponse.setErrorMessage("");
        chatResponse.setResult(resultHistory);
        chatResponse.setCache(true);
        chatResponse.setSubjectId(threadId);
        subscriber.onNext(chatResponse);
    });
}
Also used : Sending(com.fanap.podchat.cachemodel.queue.Sending) SupportSQLiteQuery(android.arch.persistence.db.SupportSQLiteQuery) Failed(com.fanap.podchat.cachemodel.queue.Failed) ArrayList(java.util.ArrayList) Uploading(com.fanap.podchat.cachemodel.queue.Uploading) ResultHistory(com.fanap.podchat.model.ResultHistory) SimpleSQLiteQuery(android.arch.persistence.db.SimpleSQLiteQuery) ChatResponse(com.fanap.podchat.model.ChatResponse) CacheMessageVO(com.fanap.podchat.cachemodel.CacheMessageVO) PinMessageVO(com.fanap.podchat.mainmodel.PinMessageVO) MessageVO(com.fanap.podchat.mainmodel.MessageVO) GapMessageVO(com.fanap.podchat.cachemodel.GapMessageVO) CacheMessageVO(com.fanap.podchat.cachemodel.CacheMessageVO)

Example 4 with ResultHistory

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

the class MemoryDataSource method createHistoryResponse.

private MessageManager.HistoryResponse createHistoryResponse(List<MessageVO> messageVOS, long threadId) {
    ChatResponse<ResultHistory> response = new ChatResponse<>();
    ResultHistory result = new ResultHistory();
    result.setHistory(messageVOS);
    result.setContentCount(contactContentCount);
    // TODO: 9/14/2020 fix here
    result.setHasNext(messageVOS.size() < contactContentCount);
    result.setNextOffset(messageVOS.size());
    result.setFailed(getThreadFailedMessages(threadId));
    result.setSending(getThreadSendingMessages(threadId));
    result.setUploadingQueue(getThreadUploadingMessage(threadId));
    response.setResult(result);
    return new MessageManager.HistoryResponse(response, MEMORY);
}
Also used : ChatResponse(com.fanap.podchat.model.ChatResponse) ResultHistory(com.fanap.podchat.model.ResultHistory)

Example 5 with ResultHistory

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

the class MessagesCacheTest method testIfParticipantsAreSame.

@Test
public void testIfParticipantsAreSame() {
    populateMessagesFromServer();
    assert threadMessagesList.size() > 0;
    Collections.shuffle(threadMessagesList);
    MessageVO message = threadMessagesList.get(0);
    assert message.getConversation() != null;
    Thread thread = message.getConversation();
    chat.setListener(new ChatListener() {

        @Override
        public void onNewMessage(String content, ChatResponse<ResultNewMessage> response) {
            resumeProcess();
        }
    });
    RequestMessage repRequest = new RequestMessage.Builder("Message at " + new Date(), thread.getId()).messageType(TextMessageType.Constants.TEXT).build();
    chat.sendTextMessage(repRequest, null);
    pauseProcess();
    // Load Server messages
    ArrayList<MessageVO> msgFromServer = new ArrayList<>();
    chatListeners = new ChatListener() {

        @Override
        public void onGetHistory(String content, ChatResponse<ResultHistory> history) {
            if (!history.isCache()) {
                System.out.println("Received Message List Server: " + content);
                msgFromServer.addAll(history.getResult().getHistory());
                chat.removeListener(chatListeners);
                resumeProcess();
            }
        }
    };
    chat.addListener(chatListeners);
    RequestGetHistory requestGetHistory = new RequestGetHistory.Builder(thread.getId()).withNoCache().build();
    chat.getHistory(requestGetHistory, null);
    pauseProcess();
    // Load cache
    ArrayList<MessageVO> msgFromCache = new ArrayList<>();
    chatListeners = new ChatListener() {

        @Override
        public void onGetHistory(String content, ChatResponse<ResultHistory> history) {
            if (history.isCache()) {
                System.out.println("Received Message List Cache: " + content);
                msgFromCache.addAll(history.getResult().getHistory());
                chat.removeListener(chatListeners);
                resumeProcess();
            }
        }
    };
    chat.addListener(chatListeners);
    RequestGetHistory requestGetHistoryCache = new RequestGetHistory.Builder(thread.getId()).build();
    chat.getHistory(requestGetHistoryCache, null);
    pauseProcess();
    assert msgFromServer.size() > 0;
    assert msgFromCache.size() > 0;
    assert msgFromCache.size() == msgFromServer.size();
    for (MessageVO msg : msgFromServer) {
        if (msg.getMessage() == null)
            continue;
        System.out.println(">>>>>>>>>>> Server Message " + msg.getMessage() + " Conversation: " + msg.getConversation());
        MessageVO msgInCache = msgFromCache.stream().filter(messageVO -> messageVO.getId() == msg.getId()).findFirst().get();
        System.out.println(">>>>>>>>>>> Cache Message " + msgInCache.getMessage() + " RepInfo: " + msgInCache.getConversation());
        Assert.assertEquals(msg.getParticipant() != null, msgInCache.getParticipant() != null);
        if (msg.getParticipant() != null) {
            Assert.assertEquals(msg.getParticipant().getId(), msgInCache.getParticipant().getId());
            Assert.assertEquals(msg.getParticipant().getName(), msgInCache.getParticipant().getName());
            Assert.assertEquals(msg.getParticipant().getChatProfileVO() != null, msgInCache.getParticipant().getChatProfileVO() != null);
        }
    }
}
Also used : RequestGetHistory(com.fanap.podchat.requestobject.RequestGetHistory) ArrayList(java.util.ArrayList) ResultHistory(com.fanap.podchat.model.ResultHistory) Date(java.util.Date) Thread(com.fanap.podchat.mainmodel.Thread) RequestThread(com.fanap.podchat.requestobject.RequestThread) ResultNewMessage(com.fanap.podchat.model.ResultNewMessage) RequestMessage(com.fanap.podchat.requestobject.RequestMessage) ChatListener(com.fanap.podchat.chat.ChatListener) MessageVO(com.fanap.podchat.mainmodel.MessageVO) Test(org.junit.Test)

Aggregations

ResultHistory (com.fanap.podchat.model.ResultHistory)47 ChatListener (com.fanap.podchat.chat.ChatListener)36 Thread (com.fanap.podchat.mainmodel.Thread)36 RequestThread (com.fanap.podchat.requestobject.RequestThread)36 Test (org.junit.Test)29 ArrayList (java.util.ArrayList)22 ChatResponse (com.fanap.podchat.model.ChatResponse)21 RequestMessage (com.fanap.podchat.requestobject.RequestMessage)21 Date (java.util.Date)21 MessageVO (com.fanap.podchat.mainmodel.MessageVO)18 LargeTest (android.support.test.filters.LargeTest)17 SearchSystemMetadataRequest (com.fanap.podchat.chat.messge.SearchSystemMetadataRequest)16 NosqlSearchMetadataCriteria (com.fanap.podchat.mainmodel.NosqlSearchMetadataCriteria)16 RequestGetHistory (com.fanap.podchat.requestobject.RequestGetHistory)15 ResultThreads (com.fanap.podchat.model.ResultThreads)11 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