Search in sources :

Example 1 with CacheCallParticipant

use of com.fanap.podchat.call.persist.CacheCallParticipant in project pod-chat-android-sdk by FanapSoft.

the class MessageDatabaseHelper method saveCallParticipant.

private void saveCallParticipant(Participant participant, long callId) {
    CacheCallParticipant callParticipant = new CacheCallParticipant().fromParticipant(participant, callId);
    messageDao.insertCallParticipant(callParticipant);
    if (callParticipant.getChatProfileVO() != null) {
        ChatProfileVO chatProfileVO = callParticipant.getChatProfileVO();
        chatProfileVO.setId(callParticipant.getId());
        messageDao.insertChatProfile(chatProfileVO);
    }
// CacheParticipantRoles cpr = new CacheParticipantRoles();
// 
// cpr.setId(participant.getId());
// 
// cpr.setThreadId(callId);
// 
// cpr.setRoles(participant.getRoles());
// 
// messageDao.insertRoles(cpr);
}
Also used : ChatProfileVO(com.fanap.podchat.chat.user.profile.ChatProfileVO) CacheCallParticipant(com.fanap.podchat.call.persist.CacheCallParticipant)

Example 2 with CacheCallParticipant

use of com.fanap.podchat.call.persist.CacheCallParticipant in project pod-chat-android-sdk by FanapSoft.

the class ExampleUnitTest method testCallParticipant.

@Test
public void testCallParticipant() {
    Participant participant = new Participant();
    participant.setName("John");
    participant.setLastName("Doe");
    participant.setImage("mmm");
    CacheCallParticipant callParticipant = new CacheCallParticipant().fromParticipant(participant, 1000);
    assertEquals(participant.getFirstName(), callParticipant.getFirstName());
}
Also used : Participant(com.fanap.podchat.mainmodel.Participant) CacheCallParticipant(com.fanap.podchat.call.persist.CacheCallParticipant) CacheCallParticipant(com.fanap.podchat.call.persist.CacheCallParticipant) Test(org.junit.Test)

Example 3 with CacheCallParticipant

use of com.fanap.podchat.call.persist.CacheCallParticipant 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)

Aggregations

CacheCallParticipant (com.fanap.podchat.call.persist.CacheCallParticipant)3 ChatProfileVO (com.fanap.podchat.chat.user.profile.ChatProfileVO)2 Participant (com.fanap.podchat.mainmodel.Participant)2 Nullable (android.support.annotation.Nullable)1 CacheParticipant (com.fanap.podchat.cachemodel.CacheParticipant)1 CacheThreadParticipant (com.fanap.podchat.cachemodel.CacheThreadParticipant)1 ThreadVo (com.fanap.podchat.cachemodel.ThreadVo)1 CallVO (com.fanap.podchat.call.model.CallVO)1 CacheCall (com.fanap.podchat.call.persist.CacheCall)1 Thread (com.fanap.podchat.mainmodel.Thread)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1