Search in sources :

Example 1 with Failed

use of com.fanap.podchat.cachemodel.queue.Failed 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 2 with Failed

use of com.fanap.podchat.cachemodel.queue.Failed 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 3 with Failed

use of com.fanap.podchat.cachemodel.queue.Failed in project pod-chat-android-sdk by FanapSoft.

the class MessageManager method getFailedFromWaiting.

public static List<Failed> getFailedFromWaiting(List<WaitQueueCache> listCaches) {
    List<Failed> listQueues = new ArrayList<>();
    for (WaitQueueCache queueCache : listCaches) {
        Failed failed = new Failed();
        MessageVO messageVO = new MessageVO();
        messageVO.setId(queueCache.getId());
        messageVO.setMessage(queueCache.getMessage());
        messageVO.setMessageType(queueCache.getMessageType());
        messageVO.setMetadata(queueCache.getMetadata());
        messageVO.setSystemMetadata(queueCache.getSystemMetadata());
        failed.setMessageVo(messageVO);
        failed.setThreadId(queueCache.getThreadId());
        failed.setUniqueId(queueCache.getUniqueId());
        listQueues.add(failed);
    }
    return listQueues;
}
Also used : Failed(com.fanap.podchat.cachemodel.queue.Failed) ArrayList(java.util.ArrayList) WaitQueueCache(com.fanap.podchat.cachemodel.queue.WaitQueueCache) MessageVO(com.fanap.podchat.mainmodel.MessageVO)

Example 4 with Failed

use of com.fanap.podchat.cachemodel.queue.Failed in project pod-chat-android-sdk by FanapSoft.

the class MessageDatabaseHelper method getHistories.

public void getHistories(@NonNull History history, long threadId, OnWorkDone listener) {
    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);
    listener.onWorkDone(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)

Aggregations

Failed (com.fanap.podchat.cachemodel.queue.Failed)4 MessageVO (com.fanap.podchat.mainmodel.MessageVO)4 ArrayList (java.util.ArrayList)4 SimpleSQLiteQuery (android.arch.persistence.db.SimpleSQLiteQuery)3 SupportSQLiteQuery (android.arch.persistence.db.SupportSQLiteQuery)3 CacheMessageVO (com.fanap.podchat.cachemodel.CacheMessageVO)3 GapMessageVO (com.fanap.podchat.cachemodel.GapMessageVO)3 Sending (com.fanap.podchat.cachemodel.queue.Sending)3 Uploading (com.fanap.podchat.cachemodel.queue.Uploading)3 PinMessageVO (com.fanap.podchat.mainmodel.PinMessageVO)3 ChatResponse (com.fanap.podchat.model.ChatResponse)3 ResultHistory (com.fanap.podchat.model.ResultHistory)3 WaitQueueCache (com.fanap.podchat.cachemodel.queue.WaitQueueCache)1