Search in sources :

Example 6 with CacheParticipant

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

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

the class MessageDatabaseHelper method saveMessageHistory.

/**
 * Cache history
 */
public void saveMessageHistory(@NonNull List<MessageVO> messageVOS, long threadId, int expireAmount) {
    worker(() -> {
        List<CacheMessageVO> cacheMessageVOList = new ArrayList<>();
        for (MessageVO messageVO : messageVOS) {
            CacheMessageVO cacheMessageVO = new CacheMessageVO(messageVO);
            cacheMessageVO.setThreadVoId(threadId);
            long time = cacheMessageVO.getTime();
            long timeNanos = cacheMessageVO.getTimeNanos();
            long pow = (long) Math.pow(10, 9);
            long timestamp = ((time / 1000) * pow) + timeNanos;
            cacheMessageVO.setTimeStamp(timestamp);
            if (messageVO.getParticipant() != null) {
                CacheParticipant cacheParticipant = new CacheParticipant(messageVO.getParticipant(), threadId);
                cacheMessageVO.setParticipant(cacheParticipant);
            }
            if (cacheMessageVO.getParticipant() != null) {
                cacheMessageVO.setParticipantId(cacheMessageVO.getParticipant().getId());
                saveParticipant(cacheMessageVO.getParticipant(), threadId, expireAmount);
            }
            if (cacheMessageVO.getConversation() != null) {
                cacheMessageVO.setConversationId(cacheMessageVO.getConversation().getId());
            }
            if (cacheMessageVO.getForwardInfo() != null) {
                cacheMessageVO.setForwardInfoId(cacheMessageVO.getForwardInfo().getId());
                messageDao.insertForwardInfo(cacheMessageVO.getForwardInfo());
                if (cacheMessageVO.getForwardInfo().getParticipant() != null) {
                    cacheMessageVO.getForwardInfo().setParticipantId(cacheMessageVO.getForwardInfo().getParticipant().getId());
                    messageDao.insertParticipant(cacheMessageVO.getForwardInfo().getParticipant());
                }
            }
            if (cacheMessageVO.getReplyInfoVO() != null) {
                cacheMessageVO.setReplyInfoVOId(cacheMessageVO.getReplyInfoVO().getRepliedToMessageId());
                if (cacheMessageVO.getReplyInfoVO().getParticipant() != null) {
                    cacheMessageVO.getReplyInfoVO().setParticipantId(cacheMessageVO.getReplyInfoVO().getParticipant().getId());
                    messageDao.insertParticipant(cacheMessageVO.getReplyInfoVO().getParticipant());
                }
                if (cacheMessageVO.getReplyInfoVO().getParticipant() != null) {
                    cacheMessageVO.getReplyInfoVO().setParticipantId(cacheMessageVO.getReplyInfoVO().getParticipant().getId());
                    messageDao.insertParticipant(cacheMessageVO.getReplyInfoVO().getParticipant());
                }
                messageDao.insertReplyInfoVO(cacheMessageVO.getReplyInfoVO());
            }
            List<String> hashtags = getHashtags(cacheMessageVO.getMessage());
            if (hashtags != null && hashtags.size() > 0)
                cacheMessageVO.setHashtags(hashtags);
            cacheMessageVOList.add(cacheMessageVO);
        }
        messageDao.insertHistories(cacheMessageVOList);
    });
}
Also used : ArrayList(java.util.ArrayList) CacheParticipant(com.fanap.podchat.cachemodel.CacheParticipant) CacheMessageVO(com.fanap.podchat.cachemodel.CacheMessageVO) CacheMessageVO(com.fanap.podchat.cachemodel.CacheMessageVO) PinMessageVO(com.fanap.podchat.mainmodel.PinMessageVO) MessageVO(com.fanap.podchat.mainmodel.MessageVO) GapMessageVO(com.fanap.podchat.cachemodel.GapMessageVO)

Example 8 with CacheParticipant

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

the class MessageDatabaseHelper method addPinnedMessageOfThread.

private void addPinnedMessageOfThread(ThreadVo threadVo) {
    worker(() -> {
        PinMessageVO pinnedMessage = messageDao.getThreadPinnedMessage(threadVo.getId());
        if (pinnedMessage != null) {
            // get cached participant
            if (pinnedMessage.getParticipantId() > 0) {
                CacheParticipant cacheParticipant = messageDao.getParticipant(pinnedMessage.getParticipantId());
                if (cacheParticipant != null) {
                    // convert cached participant to participant
                    Participant participant = cacheToParticipantMapper(cacheParticipant, false, null);
                    pinnedMessage.setParticipant(participant);
                }
            }
            threadVo.setPinMessageVO(pinnedMessage);
        }
    });
}
Also used : 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) PinMessageVO(com.fanap.podchat.mainmodel.PinMessageVO) CacheParticipant(com.fanap.podchat.cachemodel.CacheParticipant)

Example 9 with CacheParticipant

use of com.fanap.podchat.cachemodel.CacheParticipant 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)

Example 10 with CacheParticipant

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

the class MessageDatabaseHelper method getThreadsByThreadIds.

@NonNull
public List<Thread> getThreadsByThreadIds(@NonNull ArrayList<Integer> threadIds) {
    List<Thread> threads = new ArrayList<>();
    for (int id : threadIds) {
        if (messageDao.getThreadById(id) != null) {
            ThreadVo threadVo = messageDao.getThreadById(id);
            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);
        }
    }
    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) NonNull(android.support.annotation.NonNull)

Aggregations

CacheParticipant (com.fanap.podchat.cachemodel.CacheParticipant)19 Participant (com.fanap.podchat.mainmodel.Participant)14 CacheThreadParticipant (com.fanap.podchat.cachemodel.CacheThreadParticipant)13 CacheCallParticipant (com.fanap.podchat.call.persist.CacheCallParticipant)12 PinMessageVO (com.fanap.podchat.mainmodel.PinMessageVO)9 ArrayList (java.util.ArrayList)9 CacheMessageVO (com.fanap.podchat.cachemodel.CacheMessageVO)7 CacheReplyInfoVO (com.fanap.podchat.cachemodel.CacheReplyInfoVO)6 GapMessageVO (com.fanap.podchat.cachemodel.GapMessageVO)6 ThreadVo (com.fanap.podchat.cachemodel.ThreadVo)6 MessageVO (com.fanap.podchat.mainmodel.MessageVO)6 Thread (com.fanap.podchat.mainmodel.Thread)6 ReplyInfoVO (com.fanap.podchat.model.ReplyInfoVO)5 ChatProfileVO (com.fanap.podchat.chat.user.profile.ChatProfileVO)4 IOException (java.io.IOException)4 ResultAddParticipant (com.fanap.podchat.model.ResultAddParticipant)3 CacheParticipantRoles (com.fanap.podchat.cachemodel.CacheParticipantRoles)2 ChatResponse (com.fanap.podchat.model.ChatResponse)2 OutPutParticipant (com.fanap.podchat.model.OutPutParticipant)2 ResultParticipant (com.fanap.podchat.model.ResultParticipant)2