Search in sources :

Example 6 with ChatProfileVO

use of com.fanap.podchat.chat.user.profile.ChatProfileVO in project pod-chat-android-sdk by FanapSoft.

the class MessageDatabaseHelper method getCallHistory.

public void getCallHistory(GetCallHistoryRequest request, FunctionalListener callback) throws RoomIntegrityException {
    if (!canUseDatabase())
        throw new RoomIntegrityException();
    worker(() -> {
        request.setCount(request.getCount() > 0 ? request.getCount() : 50);
        List<CacheCall> cacheCalls = new ArrayList<>();
        long contentCount = 0;
        if (request.getCreatorCoreUserId() > 0) {
            cacheCalls = messageDao.getCachedCallByUserId(request.getCount(), request.getOffset(), request.getCreatorCoreUserId(), request.getType());
            contentCount = messageDao.getCountOfCachedCallByUserId(request.getCreatorCoreUserId(), request.getType());
        } else if (!Util.isNullOrEmpty(request.getCallIds())) {
            if (request.getCallIds().size() > 1) {
                String ids = "";
                for (Long callId : request.getCallIds()) {
                    ids = ids.concat("" + callId + ", ");
                }
                ids = ids.substring(0, ids.lastIndexOf(","));
                cacheCalls = messageDao.getCachedCallByIds(request.getCount(), request.getOffset(), ids);
                contentCount = messageDao.getCountOfCachedCallByIds(ids);
            } else {
                CacheCall cacheCall = messageDao.getCachedCallById(request.getCallIds().get(0));
                contentCount = 1;
                cacheCalls.add(cacheCall);
            }
        } else if (request.getThreadId() != null && request.getThreadId() > 0) {
            cacheCalls = messageDao.getCachedCallByTypeAndThreadId(request.getCount(), request.getOffset(), request.getType(), request.getThreadId());
            contentCount = messageDao.getCountOfCachedCallByTypeAndThreadId(request.getType(), request.getThreadId());
        } else {
            cacheCalls = messageDao.getCachedCallByType(request.getCount(), request.getOffset(), request.getType());
            contentCount = messageDao.getCountOfCachedCallByType(request.getType());
        }
        ArrayList<CallVO> callVOList = new ArrayList<>();
        for (CacheCall cacheCall : cacheCalls) {
            @Nullable CacheCallParticipant callPartnerParticipant = messageDao.getCachedCallParticipant(cacheCall.getPartnerParticipantId());
            if (callPartnerParticipant != null) {
                Participant partnerParticipant = callPartnerParticipant.toParticipant();
                ChatProfileVO chatProfileVO = messageDao.getChatProfileVOById(partnerParticipant.getId());
                partnerParticipant.setChatProfileVO(chatProfileVO);
                cacheCall.setPartnerParticipantVO(partnerParticipant);
            }
            if (cacheCall.isGroup()) {
                List<CacheCallParticipant> cacheCallParticipants = messageDao.getCachedCallParticipants(cacheCall.getId());
                if (!Util.isNullOrEmpty(cacheCallParticipants)) {
                    List<Participant> callParticipantsList = new ArrayList<>();
                    for (CacheCallParticipant cacheCll : cacheCallParticipants) {
                        Participant callParticipant = cacheCll.toParticipant();
                        ChatProfileVO profileVO = messageDao.getChatProfileVOById(callParticipant.getId());
                        callParticipant.setChatProfileVO(profileVO);
                        callParticipantsList.add(callParticipant);
                    }
                    cacheCall.setCallParticipants(callParticipantsList);
                }
            }
            CallVO call = cacheCall.toCallVo();
            if (cacheCall.getThreadId() > 0) {
                ThreadVo threadVo = messageDao.getThreadById(cacheCall.getThreadId());
                Thread thread;
                if (threadVo != null) {
                    thread = threadVoToThreadMapper(threadVo, null);
                } else {
                    thread = new Thread();
                    thread.setId(cacheCall.getThreadId());
                }
                call.setConversationVO(thread);
            }
            callVOList.add(call);
        }
        callback.onWorkDone(contentCount, callVOList);
    });
}
Also used : ChatProfileVO(com.fanap.podchat.chat.user.profile.ChatProfileVO) ArrayList(java.util.ArrayList) CallVO(com.fanap.podchat.call.model.CallVO) CacheCallParticipant(com.fanap.podchat.call.persist.CacheCallParticipant) CacheCall(com.fanap.podchat.call.persist.CacheCall) 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) Nullable(android.support.annotation.Nullable)

Example 7 with ChatProfileVO

use of com.fanap.podchat.chat.user.profile.ChatProfileVO 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 8 with ChatProfileVO

use of com.fanap.podchat.chat.user.profile.ChatProfileVO in project pod-chat-android-sdk by FanapSoft.

the class MessageDatabaseHelper method getCacheAssistantVos.

public void getCacheAssistantVos(GetAssistantRequest request, FunctionalListener callback) throws RoomIntegrityException {
    if (!canUseDatabase())
        throw new RoomIntegrityException();
    worker(() -> {
        List<CacheAssistantVo> list = messageDao.getCacheAssistantVos(request.getCount() > 0 ? request.getCount() : 25, request.getOffset());
        List<AssistantVo> cachResponseList = new ArrayList<>();
        for (CacheAssistantVo item : list) {
            AssistantVo assistantVo = new AssistantVo();
            assistantVo.setRoles((ArrayList<String>) item.getRoles());
            assistantVo.setBlock(item.isBlock());
            assistantVo.setContactType(item.getContactType());
            Participant participant = cacheToParticipantMapper(messageDao.getParticipant(item.getParticipantVOId()), false, null);
            ChatProfileVO profileVO = messageDao.getChatProfileVOById(participant.getId());
            participant.setChatProfileVO(profileVO);
            assistantVo.setParticipantVO(participant);
            cachResponseList.add(assistantVo);
        }
        callback.onWorkDone(list.size(), cachResponseList);
    });
}
Also used : ChatProfileVO(com.fanap.podchat.chat.user.profile.ChatProfileVO) 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) AssistantVo(com.fanap.podchat.chat.assistant.model.AssistantVo) CacheAssistantVo(com.fanap.podchat.cachemodel.CacheAssistantVo) ArrayList(java.util.ArrayList) CacheAssistantVo(com.fanap.podchat.cachemodel.CacheAssistantVo)

Example 9 with ChatProfileVO

use of com.fanap.podchat.chat.user.profile.ChatProfileVO in project pod-chat-android-sdk by FanapSoft.

the class MessageDatabaseHelper method getCacheBlockedAssistantVos.

public void getCacheBlockedAssistantVos(GetBlockedAssistantsRequest request, FunctionalListener callback) throws RoomIntegrityException {
    if (!canUseDatabase())
        throw new RoomIntegrityException();
    worker(() -> {
        List<CacheAssistantVo> list = messageDao.getCacheBlockedAssistantVos(request.getCount() > 0 ? request.getCount() : 25, request.getOffset());
        List<AssistantVo> cacheResponseList = new ArrayList<>();
        for (CacheAssistantVo item : list) {
            AssistantVo assistantVo = new AssistantVo();
            assistantVo.setRoles((ArrayList<String>) item.getRoles());
            assistantVo.setBlock(item.isBlock());
            assistantVo.setContactType(item.getContactType());
            Participant participant = cacheToParticipantMapper(messageDao.getParticipant(item.getParticipantVOId()), false, null);
            ChatProfileVO profileVO = messageDao.getChatProfileVOById(participant.getId());
            participant.setChatProfileVO(profileVO);
            assistantVo.setParticipantVO(participant);
            cacheResponseList.add(assistantVo);
        }
        callback.onWorkDone(list.size(), cacheResponseList);
    });
}
Also used : ChatProfileVO(com.fanap.podchat.chat.user.profile.ChatProfileVO) 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) AssistantVo(com.fanap.podchat.chat.assistant.model.AssistantVo) CacheAssistantVo(com.fanap.podchat.cachemodel.CacheAssistantVo) ArrayList(java.util.ArrayList) CacheAssistantVo(com.fanap.podchat.cachemodel.CacheAssistantVo)

Example 10 with ChatProfileVO

use of com.fanap.podchat.chat.user.profile.ChatProfileVO 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

ChatProfileVO (com.fanap.podchat.chat.user.profile.ChatProfileVO)11 CacheThreadParticipant (com.fanap.podchat.cachemodel.CacheThreadParticipant)8 CacheParticipant (com.fanap.podchat.cachemodel.CacheParticipant)7 CacheCallParticipant (com.fanap.podchat.call.persist.CacheCallParticipant)7 Participant (com.fanap.podchat.mainmodel.Participant)6 ArrayList (java.util.ArrayList)5 SimpleDateFormat (java.text.SimpleDateFormat)4 Calendar (java.util.Calendar)4 Date (java.util.Date)4 CacheParticipantRoles (com.fanap.podchat.cachemodel.CacheParticipantRoles)3 CacheAssistantVo (com.fanap.podchat.cachemodel.CacheAssistantVo)2 ThreadVo (com.fanap.podchat.cachemodel.ThreadVo)2 AssistantVo (com.fanap.podchat.chat.assistant.model.AssistantVo)2 Thread (com.fanap.podchat.mainmodel.Thread)2 UserInfo (com.fanap.podchat.mainmodel.UserInfo)2 ParseException (java.text.ParseException)2 Nullable (android.support.annotation.Nullable)1 CacheForwardInfo (com.fanap.podchat.cachemodel.CacheForwardInfo)1 CacheMessageVO (com.fanap.podchat.cachemodel.CacheMessageVO)1 CacheReplyInfoVO (com.fanap.podchat.cachemodel.CacheReplyInfoVO)1