Search in sources :

Example 6 with Thread

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

the class MessageDatabaseHelper method retrieveAndUpdateThreadOnLastMessageDeleted.

public void retrieveAndUpdateThreadOnLastMessageDeleted(Thread thread, ThreadManager.ILastMessageChanged callback) {
    worker(() -> {
        long threadId = thread.getId();
        ArrayList<Integer> tIds = new ArrayList<>();
        tIds.add((int) threadId);
        try {
            getThreadRaw(1, (long) 0, tIds, null, false, threads -> {
                List<Thread> threadList = (List<Thread>) threads;
                if (!Util.isNullOrEmpty(threadList) && threadList.get(0).getId() > 0) {
                    Thread threadFromCache = threadList.get(0);
                    threadFromCache.setLastMessage(thread.getLastMessage());
                    threadFromCache.setLastMessageVO(thread.getLastMessageVO());
                    threadFromCache.setTime(thread.getTime());
                    threadFromCache.setUnreadCount(thread.getUnreadCount());
                    callback.onThreadExistInCache(threadFromCache);
                    saveNewThread(threadFromCache);
                } else {
                    callback.threadNotFoundInCache();
                }
            });
        } catch (RoomIntegrityException e) {
            e.printStackTrace();
            callback.threadNotFoundInCache();
        }
    });
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) RequestGetHashTagList(com.fanap.podchat.chat.hashtag.model.RequestGetHashTagList) List(java.util.List) RequestGetMentionList(com.fanap.podchat.chat.mention.model.RequestGetMentionList) Thread(com.fanap.podchat.mainmodel.Thread)

Example 7 with Thread

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

the class MessageDatabaseHelper method prepareTagList.

private List<TagVo> prepareTagList() {
    List<CacheTagVo> tags = messageDao.getCacheTagVos();
    List<TagVo> tagVos = new ArrayList<>();
    for (CacheTagVo item : tags) {
        TagVo tag = CacheTagVoToTagVoMapper(item);
        long allUnreadCount = 0;
        List<CacheTagParticipantVO> cacheTagParticipants = messageDao.getCacheTagParticipantVosByTagId(item.getTagId());
        List<TagParticipantVO> tagParticipants = new ArrayList<>();
        for (CacheTagParticipantVO cacheTagParticipantVO : cacheTagParticipants) {
            TagParticipantVO cache = cacheTagParticipantVOToTagParticipantVOMapper(cacheTagParticipantVO);
            if (messageDao.getThreadById(cacheTagParticipantVO.getThreadId()) != null) {
                Thread thread = threadVoToThreadMapper(messageDao.getThreadById(cacheTagParticipantVO.getThreadId()), null);
                cache.setConversationVO(thread);
                // TODO it should be save in db. can save it when save tags on db
                if (thread.getUnreadCount() > 0)
                    allUnreadCount = allUnreadCount + thread.getUnreadCount();
            }
            tagParticipants.add(cache);
        }
        tag.setTagParticipants(tagParticipants);
        tag.setAllUnreadCount(allUnreadCount);
        tagVos.add(tag);
    }
    return tagVos;
}
Also used : CacheTagParticipantVO(com.fanap.podchat.cachemodel.CacheTagParticipantVO) CacheTagVo(com.fanap.podchat.cachemodel.CacheTagVo) ArrayList(java.util.ArrayList) CacheTagParticipantVO(com.fanap.podchat.cachemodel.CacheTagParticipantVO) TagParticipantVO(com.fanap.podchat.model.TagParticipantVO) TagVo(com.fanap.podchat.model.TagVo) CacheTagVo(com.fanap.podchat.cachemodel.CacheTagVo) Thread(com.fanap.podchat.mainmodel.Thread)

Example 8 with Thread

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

the class MessageDatabaseHelper method retrieveAndUpdateThreadOnThreadInfoUpdated.

public void retrieveAndUpdateThreadOnThreadInfoUpdated(Thread thread, ThreadManager.ILastMessageChanged callback) {
    worker(() -> {
        long threadId = thread.getId();
        ArrayList<Integer> tIds = new ArrayList<>();
        tIds.add((int) threadId);
        try {
            getThreadRaw(1, (long) 0, tIds, null, false, threads -> {
                List<Thread> threadList = (List<Thread>) threads;
                if (!Util.isNullOrEmpty(threadList) && threadList.get(0).getId() > 0) {
                    Thread threadFromCache = threadList.get(0);
                    if (!Util.isNullOrEmpty(thread.getTitle()))
                        threadFromCache.setTitle(thread.getTitle());
                    if (!Util.isNullOrEmpty(thread.getImage()))
                        threadFromCache.setImage(thread.getImage());
                    if (!Util.isNullOrEmpty(thread.getDescription()))
                        threadFromCache.setDescription(thread.getDescription());
                    if (!Util.isNullOrEmpty(thread.getMetadata()))
                        threadFromCache.setMetadata(thread.getMetadata());
                    threadFromCache.setTime(thread.getTime());
                    threadFromCache.setUserGroupHash(thread.getUserGroupHash());
                    callback.onThreadExistInCache(threadFromCache);
                    saveNewThread(threadFromCache);
                } else {
                    callback.threadNotFoundInCache();
                }
            });
        } catch (RoomIntegrityException e) {
            e.printStackTrace();
            callback.threadNotFoundInCache();
        }
    });
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) RequestGetHashTagList(com.fanap.podchat.chat.hashtag.model.RequestGetHashTagList) List(java.util.List) RequestGetMentionList(com.fanap.podchat.chat.mention.model.RequestGetMentionList) Thread(com.fanap.podchat.mainmodel.Thread)

Example 9 with Thread

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

the class MessageDatabaseHelper method getThreadsByThreadName.

public List<Thread> getThreadsByThreadName(String threadName) {
    List<Thread> threads;
    List<ThreadVo> listThreadVo = messageDao.getThreadByName(50, 0, threadName);
    if (listThreadVo != null) {
        threads = new ArrayList<>();
        for (ThreadVo threadVo : listThreadVo) {
            CacheParticipant cacheParticipant;
            CacheReplyInfoVO cacheReplyInfoVO;
            Participant participant = null;
            ReplyInfoVO replyInfoVO = null;
            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());
                        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);
        }
    } else {
        return new ArrayList<>();
    }
    return threads;
}
Also used : 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) ArrayList(java.util.ArrayList) 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) Thread(com.fanap.podchat.mainmodel.Thread)

Example 10 with Thread

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

the class MessageDatabaseHelper method getThreads.

public List<Thread> getThreads(long count, long offset) {
    List<Thread> threads;
    if (messageDao.getThreads(count, offset) != null) {
        List<ThreadVo> threadVos = messageDao.getThreads(count, offset);
        threads = new ArrayList<>();
        CacheParticipant cacheParticipant;
        CacheReplyInfoVO cacheReplyInfoVO;
        Participant participant = null;
        ReplyInfoVO replyInfoVO = null;
        for (ThreadVo threadVo : threadVos) {
            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);
        }
        // sort threads by last message time
        Collections.sort(new ArrayList<>(threads), (o1, o2) -> Long.compare(o1.getLastMessageVO().getTime(), o2.getLastMessageVO().getTime()));
        return threads;
    } else {
        threads = new ArrayList<>();
    }
    return threads;
}
Also used : 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) 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) Thread(com.fanap.podchat.mainmodel.Thread)

Aggregations

Thread (com.fanap.podchat.mainmodel.Thread)95 RequestThread (com.fanap.podchat.requestobject.RequestThread)79 Test (org.junit.Test)55 ChatListener (com.fanap.podchat.chat.ChatListener)53 ArrayList (java.util.ArrayList)42 ResultHistory (com.fanap.podchat.model.ResultHistory)36 LargeTest (android.support.test.filters.LargeTest)35 RequestMessage (com.fanap.podchat.requestobject.RequestMessage)33 Date (java.util.Date)30 ChatResponse (com.fanap.podchat.model.ChatResponse)22 RequestGetHistory (com.fanap.podchat.requestobject.RequestGetHistory)22 MessageVO (com.fanap.podchat.mainmodel.MessageVO)20 SearchSystemMetadataRequest (com.fanap.podchat.chat.messge.SearchSystemMetadataRequest)16 NosqlSearchMetadataCriteria (com.fanap.podchat.mainmodel.NosqlSearchMetadataCriteria)16 ResultNewMessage (com.fanap.podchat.model.ResultNewMessage)16 ResultThreads (com.fanap.podchat.model.ResultThreads)16 FlakyTest (android.support.test.filters.FlakyTest)14 MediumTest (android.support.test.filters.MediumTest)14 Activity (android.app.Activity)10 Context (android.content.Context)10