Search in sources :

Example 16 with CacheParticipant

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

the class MessageDatabaseHelper method prepareMessageVOs.

private void prepareMessageVOs(List<MessageVO> messageVOS, List<CacheMessageVO> cacheMessageVOS) {
    for (CacheMessageVO cacheMessageVO : cacheMessageVOS) {
        Participant participant = null;
        ReplyInfoVO replyInfoVO = null;
        ForwardInfo forwardInfo = null;
        ConversationSummery conversationSummery = null;
        if (cacheMessageVO.getForwardInfoId() != null) {
            cacheMessageVO.setForwardInfo(messageDao.getForwardInfo(cacheMessageVO.getForwardInfoId()));
        }
        if (cacheMessageVO.getParticipantId() != null) {
            CacheParticipant cacheParticipant = messageDao.getParticipant(cacheMessageVO.getParticipantId());
            if (cacheParticipant != null) {
                ChatProfileVO profileVO = messageDao.getChatProfileVOById(cacheParticipant.getId());
                cacheParticipant.setChatProfileVO(profileVO);
                participant = cacheToParticipantMapper(cacheParticipant, null, null);
            } else {
                if (cacheMessageVO.getConversationId() > 0)
                    messageDao.deleteParticipant(cacheMessageVO.getConversationId(), cacheMessageVO.getParticipantId());
            }
        }
        ThreadVo thread = messageDao.getThreadById(cacheMessageVO.getConversationId());
        cacheMessageVO.setConversation(thread);
        if (cacheMessageVO.getReplyInfoVOId() != null) {
            CacheReplyInfoVO cacheReplyInfoVO = messageDao.getReplyInfo(cacheMessageVO.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());
                if (cacheReplyInfoVO.getParticipantId() > 0) {
                    CacheParticipant cacheParticipant = messageDao.getParticipant(cacheReplyInfoVO.getParticipantId());
                    if (cacheParticipant != null) {
                        Participant replyParticipant = cacheToParticipantMapper(cacheParticipant, false, null);
                        replyInfoVO.setParticipant(replyParticipant);
                    }
                }
            }
        }
        if (cacheMessageVO.getForwardInfo() != null) {
            CacheForwardInfo cacheForwardInfo = messageDao.getForwardInfo(cacheMessageVO.getForwardInfoId());
            if (cacheForwardInfo != null) {
                if (cacheForwardInfo.getParticipantId() != null) {
                    CacheParticipant cacheParticipant = messageDao.getParticipant(cacheForwardInfo.getParticipantId());
                    if (cacheParticipant != null) {
                        participant = cacheToParticipantMapper(cacheParticipant, null, null);
                    }
                }
                if (Util.isNullOrEmpty(cacheForwardInfo.getConversationId())) {
                    // todo check it again
                    conversationSummery = messageDao.getConversationSummery(cacheForwardInfo.getConversationId());
                }
                forwardInfo = new ForwardInfo(participant, conversationSummery);
            }
        }
        Thread msgThread = threadVoToThreadMapper(cacheMessageVO.getConversation(), null);
        MessageVO messageVO = cacheMessageVoToMessageVoMapper(participant, replyInfoVO, forwardInfo, cacheMessageVO);
        messageVO.setConversation(msgThread);
        messageVOS.add(messageVO);
    }
}
Also used : ChatProfileVO(com.fanap.podchat.chat.user.profile.ChatProfileVO) 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) CacheForwardInfo(com.fanap.podchat.cachemodel.CacheForwardInfo) ConversationSummery(com.fanap.podchat.model.ConversationSummery) ForwardInfo(com.fanap.podchat.mainmodel.ForwardInfo) CacheForwardInfo(com.fanap.podchat.cachemodel.CacheForwardInfo) CacheParticipant(com.fanap.podchat.cachemodel.CacheParticipant) CacheMessageVO(com.fanap.podchat.cachemodel.CacheMessageVO) ReplyInfoVO(com.fanap.podchat.model.ReplyInfoVO) CacheReplyInfoVO(com.fanap.podchat.cachemodel.CacheReplyInfoVO) 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) Thread(com.fanap.podchat.mainmodel.Thread)

Example 17 with CacheParticipant

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

the class MessageDatabaseHelper method updateCashAssistantHistory.

public void updateCashAssistantHistory(OnWorkDone listener, List<AssistantHistoryVo> response) {
    worker(() -> {
        List<CacheAssistantHistoryVo> cashAssitantHistory = new ArrayList<>();
        for (AssistantHistoryVo assistantVo : response) {
            CacheAssistantHistoryVo cashAsisstantHistory = new CacheAssistantHistoryVo();
            if (assistantVo.getParticipantVO() != null) {
                Participant participant = assistantVo.getParticipantVO();
                String participantJson = App.getGson().toJson(participant);
                CacheParticipant cacheParticipant = App.getGson().fromJson(participantJson, CacheParticipant.class);
                messageDao.insertParticipant(cacheParticipant);
                cashAsisstantHistory.setParticipantVOId(assistantVo.getParticipantVO().getId());
            }
            cashAsisstantHistory.setActionTime(assistantVo.getActionTime());
            cashAsisstantHistory.setActionType(assistantVo.getActionType());
            cashAsisstantHistory.setActionName(assistantVo.getActionName());
            cashAssitantHistory.add(cashAsisstantHistory);
        }
        messageDao.insertCacheAssistantHistoryVo(cashAssitantHistory);
        listener.onWorkDone(true);
    });
}
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) ArrayList(java.util.ArrayList) CacheAssistantHistoryVo(com.fanap.podchat.cachemodel.CacheAssistantHistoryVo) CacheAssistantHistoryVo(com.fanap.podchat.cachemodel.CacheAssistantHistoryVo) AssistantHistoryVo(com.fanap.podchat.chat.assistant.model.AssistantHistoryVo) CacheParticipant(com.fanap.podchat.cachemodel.CacheParticipant)

Example 18 with CacheParticipant

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

the class MessageDatabaseHelper method getThreadAdmins.

public void getThreadAdmins(long offset, long count, long threadId, FunctionalListener listener) throws RoomIntegrityException {
    if (!canUseDatabase())
        throw new RoomIntegrityException();
    worker(() -> {
        List<Participant> participants = new ArrayList<>();
        List<CacheThreadParticipant> listCtp = messageDao.getAllThreadParticipants(offset, count, threadId);
        long participantCount = messageDao.getParticipantCount(threadId);
        if (listCtp == null) {
            listener.onWorkDone(participantCount, participants);
        } else {
            SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss", Locale.getDefault());
            Calendar c = Calendar.getInstance();
            c.setTime(new Date());
            Date nowDate = c.getTime();
            for (CacheThreadParticipant threadParticipant : listCtp) {
                try {
                    Date expireDate = format.parse(threadParticipant.getExpireDate());
                    long participantId = threadParticipant.getParticipantId();
                    if (expireDate != null) {
                        if (expireDate.compareTo(nowDate) < 0) {
                            messageDao.deleteCacheThreadParticipant(participantId);
                        } else {
                            CacheParticipant cParticipant = messageDao.getParticipant(participantId);
                            ChatProfileVO chatProfileVO = messageDao.getChatProfileVOById(cParticipant.getId());
                            if (chatProfileVO != null) {
                                cParticipant.setChatProfileVO(chatProfileVO);
                            }
                            List<String> roles = new ArrayList<>();
                            CacheParticipantRoles cachedRoles = messageDao.getParticipantRoles(participantId, threadId);
                            if (cachedRoles != null) {
                                if (cachedRoles.getRoles().size() > 0)
                                    roles = cachedRoles.getRoles();
                            }
                            if (roles.size() > 0) {
                                Participant participant = cacheToParticipantMapper(cParticipant, true, roles);
                                participants.add(participant);
                            }
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
        listener.onWorkDone(participantCount, participants);
    });
}
Also used : ChatProfileVO(com.fanap.podchat.chat.user.profile.ChatProfileVO) CacheParticipantRoles(com.fanap.podchat.cachemodel.CacheParticipantRoles) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) Date(java.util.Date) IOException(java.io.IOException) ParseException(java.text.ParseException) CacheThreadParticipant(com.fanap.podchat.cachemodel.CacheThreadParticipant) 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) SimpleDateFormat(java.text.SimpleDateFormat)

Example 19 with CacheParticipant

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

the class MessageDatabaseHelper method getThreadParticipant.

public void getThreadParticipant(long offset, long count, long threadId, FunctionalListener listener) throws RoomIntegrityException {
    if (!canUseDatabase())
        throw new RoomIntegrityException();
    worker(() -> {
        List<Participant> participants = new ArrayList<>();
        List<CacheThreadParticipant> listCtp = messageDao.getAllThreadParticipants(offset, count, threadId);
        long participantCount = messageDao.getParticipantCount(threadId);
        if (listCtp == null) {
            listener.onWorkDone(participantCount, participants);
        } else {
            SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss", Locale.getDefault());
            Calendar c = Calendar.getInstance();
            c.setTime(new Date());
            Date nowDate = c.getTime();
            for (CacheThreadParticipant threadParticipant : listCtp) {
                try {
                    Date expireDate = format.parse(threadParticipant.getExpireDate());
                    long participantId = threadParticipant.getParticipantId();
                    if (expireDate != null) {
                        if (expireDate.compareTo(nowDate) < 0) {
                            messageDao.deleteCacheThreadParticipant(participantId);
                        } else {
                            CacheParticipant cParticipant = messageDao.getParticipant(participantId);
                            ChatProfileVO chatProfileVO = messageDao.getChatProfileVOById(cParticipant.getId());
                            if (chatProfileVO != null) {
                                cParticipant.setChatProfileVO(chatProfileVO);
                            }
                            List<String> roles = new ArrayList<>();
                            Participant participant = cacheToParticipantMapper(cParticipant, false, roles);
                            participants.add(participant);
                        }
                    }
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }
        }
        listener.onWorkDone(participantCount, participants);
    });
}
Also used : ChatProfileVO(com.fanap.podchat.chat.user.profile.ChatProfileVO) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) Date(java.util.Date) CacheThreadParticipant(com.fanap.podchat.cachemodel.CacheThreadParticipant) 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) ParseException(java.text.ParseException) CacheParticipant(com.fanap.podchat.cachemodel.CacheParticipant) SimpleDateFormat(java.text.SimpleDateFormat)

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