Search in sources :

Example 1 with GapMessageVO

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

the class ChatCore method findAndUpdateGaps.

private void findAndUpdateGaps(List<MessageVO> newMessagesFromServer, long threadId) {
    Runnable jobFindAndInsertGap = () -> {
        if (newMessagesFromServer.size() == 0)
            return;
        MessageVO lastMessage = newMessagesFromServer.get(newMessagesFromServer.size() - 1);
        if (lastMessage.getPreviousId() == 0)
            return;
        List<CacheMessageVO> messages = messageDatabaseHelper.getMessageById(lastMessage.getPreviousId());
        if (Util.isNullOrEmpty(messages)) {
            GapMessageVO gapMessageVO = new GapMessageVO();
            gapMessageVO.setId(lastMessage.getId());
            gapMessageVO.setPreviousId(lastMessage.getPreviousId());
            gapMessageVO.setThreadId(threadId);
            gapMessageVO.setTime(lastMessage.getTime());
            gapMessageVO.setUniqueId(lastMessage.getUniqueId());
            messageDatabaseHelper.insertGap(gapMessageVO);
            lastMessage.setHasGap(true);
            dataSource.updateMessage(lastMessage, threadId);
        // messageDatabaseHelper.updateMessage(lastMessage, threadId);
        }
    };
    Runnable jobUpdateGaps = () -> {
        List<GapMessageVO> gaps = messageDatabaseHelper.getAllGaps(threadId);
        if (!Util.isNullOrEmpty(gaps)) {
            Map<Long, Long> msgIdAndPreviousId = new HashMap<>();
            for (GapMessageVO gapMessage : gaps) {
                msgIdAndPreviousId.put(gapMessage.getPreviousId(), gapMessage.getId());
            }
            for (MessageVO newMessage : newMessagesFromServer) {
                if (msgIdAndPreviousId.containsKey(newMessage.getId())) {
                    // delete gap that produced by this message
                    messageDatabaseHelper.deleteGapForMessageId(msgIdAndPreviousId.get(newMessage.getId()));
                    // set message gap field to false
                    messageDatabaseHelper.updateMessageGapState(msgIdAndPreviousId.get(newMessage.getId()), false);
                }
            }
        }
    };
    PodThreadManager podThreadManager = new PodThreadManager();
    podThreadManager.addTask(jobFindAndInsertGap);
    podThreadManager.addTask(jobUpdateGaps);
    podThreadManager.runTasksSynced();
}
Also used : GapMessageVO(com.fanap.podchat.cachemodel.GapMessageVO) PodThreadManager(com.fanap.podchat.util.PodThreadManager) ResultBlockList(com.fanap.podchat.model.ResultBlockList) RequestGetMentionList(com.fanap.podchat.chat.mention.model.RequestGetMentionList) RequestDeliveredMessageList(com.fanap.podchat.requestobject.RequestDeliveredMessageList) ArrayList(java.util.ArrayList) RequestBlockList(com.fanap.podchat.requestobject.RequestBlockList) RequestGetHashTagList(com.fanap.podchat.chat.hashtag.model.RequestGetHashTagList) RequestSeenMessageList(com.fanap.podchat.requestobject.RequestSeenMessageList) List(java.util.List) GapMessageVO(com.fanap.podchat.cachemodel.GapMessageVO) CacheMessageVO(com.fanap.podchat.cachemodel.CacheMessageVO) MessageVO(com.fanap.podchat.mainmodel.MessageVO) Map(java.util.Map) RetrofitHelperMap(com.fanap.podchat.networking.retrofithelper.RetrofitHelperMap) HashMap(java.util.HashMap) MimeTypeMap(android.webkit.MimeTypeMap)

Aggregations

MimeTypeMap (android.webkit.MimeTypeMap)1 CacheMessageVO (com.fanap.podchat.cachemodel.CacheMessageVO)1 GapMessageVO (com.fanap.podchat.cachemodel.GapMessageVO)1 RequestGetHashTagList (com.fanap.podchat.chat.hashtag.model.RequestGetHashTagList)1 RequestGetMentionList (com.fanap.podchat.chat.mention.model.RequestGetMentionList)1 MessageVO (com.fanap.podchat.mainmodel.MessageVO)1 ResultBlockList (com.fanap.podchat.model.ResultBlockList)1 RetrofitHelperMap (com.fanap.podchat.networking.retrofithelper.RetrofitHelperMap)1 RequestBlockList (com.fanap.podchat.requestobject.RequestBlockList)1 RequestDeliveredMessageList (com.fanap.podchat.requestobject.RequestDeliveredMessageList)1 RequestSeenMessageList (com.fanap.podchat.requestobject.RequestSeenMessageList)1 PodThreadManager (com.fanap.podchat.util.PodThreadManager)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1