Search in sources :

Example 1 with MessageVO

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

the class ChatCore method findDeletedMessages.

private void findDeletedMessages(List<MessageVO> messagesFromCache, List<MessageVO> newMessagesFromServer, String uniqueId, long threadId) {
    for (MessageVO msg : messagesFromCache) {
        if (!newMessagesFromServer.contains(msg)) {
            ChatResponse<ResultDeleteMessage> chatResponse = MessageManager.prepareDeleteMessageResponseForFind(msg, uniqueId, threadId);
            String jsonDeleteMsg = gson.toJson(chatResponse);
            listenerManager.callOnDeleteMessage(jsonDeleteMsg, chatResponse);
            showLog("RECEIVE_DELETE_MESSAGE", jsonDeleteMsg);
            if (cache) {
                dataSource.deleteMessage(msg, threadId);
                messageDatabaseHelper.deleteMessage(msg.getId(), threadId);
                showLog("Delete message from database with this messageId" + " " + msg.getId(), "");
            }
        }
    }
}
Also used : GapMessageVO(com.fanap.podchat.cachemodel.GapMessageVO) CacheMessageVO(com.fanap.podchat.cachemodel.CacheMessageVO) MessageVO(com.fanap.podchat.mainmodel.MessageVO) ResultDeleteMessage(com.fanap.podchat.mainmodel.ResultDeleteMessage)

Example 2 with MessageVO

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

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

the class MessageManager method generateSendingQueueCache.

public static SendingQueueCache generateSendingQueueCache(long threadId, long messageId, String uniqueId, String typecode, String token) {
    SendingQueueCache sendingQueue = new SendingQueueCache();
    sendingQueue.setUniqueId(uniqueId);
    MessageVO messageVO = new MessageVO();
    messageVO.setId(messageId);
    messageVO.setUniqueId(uniqueId);
    sendingQueue.setThreadId(threadId);
    String queueAsyncContent = CreateAsyncContentForQueue(threadId, messageId, uniqueId, typecode, token);
    sendingQueue.setAsyncContent(queueAsyncContent);
    return sendingQueue;
}
Also used : SendingQueueCache(com.fanap.podchat.cachemodel.queue.SendingQueueCache) MessageVO(com.fanap.podchat.mainmodel.MessageVO)

Example 4 with MessageVO

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

the class MessageDatabaseHelper method getThreadRaw.

public void getThreadRaw(Integer count, Long offset, @Nullable ArrayList<Integer> threadIds, @Nullable String threadName, boolean isNew, OnWorkDone listener) throws RoomIntegrityException {
    if (!canUseDatabase())
        throw new RoomIntegrityException();
    worker(() -> {
        String sQuery;
        final String ORDER = "order by pin desc,time desc";
        sQuery = "select * from ThreadVo " + ORDER;
        if (threadName != null && !isNew) {
            sQuery = "select * from ThreadVo where title LIKE '%" + threadName + "%' " + ORDER;
        }
        if (threadIds != null && threadIds.size() > 0 && !isNew) {
            StringBuilder stringBuilder = new StringBuilder();
            for (int id : threadIds) {
                stringBuilder.append(id).append(",");
            }
            String stringIds = stringBuilder.toString();
            String lastString = stringIds.replaceAll(",$", "");
            if (threadName != null) {
                sQuery = "select * from ThreadVo where id IN " + "(" + lastString + ")" + "AND title LIKE  '%" + threadName + "%' " + ORDER;
            } else {
                sQuery = "select * from ThreadVo where id IN " + "(" + lastString + ")" + " " + ORDER;
            }
        }
        // only threads with unreadCount > 0 if isNew == true
        if (isNew) {
            sQuery = "select * from ThreadVo where unreadCount > 0 " + ORDER;
        }
        long contentCount = 0;
        SimpleSQLiteQuery countQuery = new SimpleSQLiteQuery(sQuery.replaceFirst("select \\* ", "select count(id) "));
        contentCount = messageDao.getThreadContentCount(countQuery);
        sQuery += getPaging(count, offset);
        SimpleSQLiteQuery query = new SimpleSQLiteQuery(sQuery);
        List<ThreadVo> threadVos = messageDao.getThreadRaw(query);
        List<Thread> threads = new ArrayList<>();
        if (threadVos != null) {
            for (ThreadVo threadVo : threadVos) {
                if (threadVo.getId() == 0)
                    continue;
                CacheParticipant cacheParticipant;
                CacheReplyInfoVO cacheReplyInfoVO;
                Participant participant = null;
                ReplyInfoVO replyInfoVO = null;
                @Nullable MessageVO lastMessageVO = null;
                if (threadVo.getInviterId() > 0) {
                    threadVo.setInviter(messageDao.getInviter(threadVo.getInviterId()));
                }
                if (threadVo.getLastMessageVOId() > 0) {
                    threadVo.setLastMessageVO(messageDao.getLastMessageVO(threadVo.getLastMessageVOId()));
                    CacheMessageVO cacheLastMessageVO = threadVo.getLastMessageVO();
                    if (cacheLastMessageVO != null) {
                        if (cacheLastMessageVO.getParticipantId() != null) {
                            cacheParticipant = messageDao.getParticipant(cacheLastMessageVO.getParticipantId());
                            if (cacheParticipant != null) {
                                participant = cacheToParticipantMapper(cacheParticipant, null, null);
                            }
                        }
                        if (cacheLastMessageVO.getReplyInfoVOId() != null) {
                            cacheReplyInfoVO = messageDao.getReplyInfo(cacheLastMessageVO.getReplyInfoVOId());
                            if (cacheReplyInfoVO != null)
                                replyInfoVO = new ReplyInfoVO(cacheReplyInfoVO.getRepliedToMessageId(), cacheReplyInfoVO.getMessageType(), cacheReplyInfoVO.isDeleted(), cacheReplyInfoVO.getRepliedToMessage(), cacheReplyInfoVO.getSystemMetadata(), cacheReplyInfoVO.getMetadata(), cacheReplyInfoVO.getMessage(), cacheReplyInfoVO.getRepliedToMessageTime(), cacheReplyInfoVO.getRepliedToMessageNanos());
                        }
                        lastMessageVO = cacheMessageVoToMessageVoMapper(participant, replyInfoVO, null, cacheLastMessageVO);
                    }
                }
                // adding pinned message of thread if exist
                addPinnedMessageOfThread(threadVo);
                Thread thread = threadVoToThreadMapper(threadVo, lastMessageVO);
                threads.add(thread);
            }
        }
        listener.onWorkDone(threads);
        listener.onWorkDone(contentCount, threads);
    });
}
Also used : ArrayList(java.util.ArrayList) Thread(com.fanap.podchat.mainmodel.Thread) ThreadVo(com.fanap.podchat.cachemodel.ThreadVo) CacheThreadParticipant(com.fanap.podchat.cachemodel.CacheThreadParticipant) CacheParticipant(com.fanap.podchat.cachemodel.CacheParticipant) Participant(com.fanap.podchat.mainmodel.Participant) CacheCallParticipant(com.fanap.podchat.call.persist.CacheCallParticipant) SimpleSQLiteQuery(android.arch.persistence.db.SimpleSQLiteQuery) CacheParticipant(com.fanap.podchat.cachemodel.CacheParticipant) CacheReplyInfoVO(com.fanap.podchat.cachemodel.CacheReplyInfoVO) ReplyInfoVO(com.fanap.podchat.model.ReplyInfoVO) CacheReplyInfoVO(com.fanap.podchat.cachemodel.CacheReplyInfoVO) 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) Nullable(android.support.annotation.Nullable)

Example 5 with MessageVO

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

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