Search in sources :

Example 91 with Thread

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

the class MessageDatabaseHelper method saveMutualThreads.

public void saveMutualThreads(@NonNull List<Thread> threads, long userId) {
    worker(() -> {
        List<String> threadids = new ArrayList<>();
        CacheMutualGroupVo cacheMutualGroupVo = new CacheMutualGroupVo();
        cacheMutualGroupVo.setContactId(userId);
        for (Thread thread : threads) {
            if (thread.getId() > 0) {
                threadids.add(String.valueOf(thread.getId()));
            }
        }
        cacheMutualGroupVo.setThreadids(threadids);
        messageDao.insertCacheMutualVo(cacheMutualGroupVo);
    });
}
Also used : CacheMutualGroupVo(com.fanap.podchat.cachemodel.CacheMutualGroupVo) ArrayList(java.util.ArrayList) Thread(com.fanap.podchat.mainmodel.Thread)

Example 92 with Thread

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

the class MessageDatabaseHelper method getTagParticipantsVos.

public Observable<List<TagParticipantVO>> getTagParticipantsVos(long tagId) {
    return Observable.create(emitter -> {
        try {
            List<CacheTagParticipantVO> tagParticipants = messageDao.getCacheTagParticipantVosByTagId(tagId);
            List<TagParticipantVO> cacheTagParticipants = new ArrayList<>();
            for (CacheTagParticipantVO item : tagParticipants) {
                TagParticipantVO cache = cacheTagParticipantVOToTagParticipantVOMapper(item);
                if (messageDao.getThreadById(item.getThreadId()) != null) {
                    Thread thread = threadVoToThreadMapper(messageDao.getThreadById(item.getThreadId()), null);
                    cache.setConversationVO(thread);
                }
                cacheTagParticipants.add(cache);
            }
            emitter.onNext(cacheTagParticipants);
            emitter.onCompleted();
        } catch (Exception e) {
            emitter.onError(e);
        }
    });
}
Also used : CacheTagParticipantVO(com.fanap.podchat.cachemodel.CacheTagParticipantVO) CacheTagParticipantVO(com.fanap.podchat.cachemodel.CacheTagParticipantVO) TagParticipantVO(com.fanap.podchat.model.TagParticipantVO) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ParseException(java.text.ParseException) Thread(com.fanap.podchat.mainmodel.Thread)

Example 93 with Thread

use of com.fanap.podchat.mainmodel.Thread 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 94 with Thread

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

the class MessageDatabaseHelper method retrieveAndUpdateThreadOnLastSeenUpdated.

public void retrieveAndUpdateThreadOnLastSeenUpdated(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.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 95 with Thread

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

the class MessageDatabaseHelper method retrieveAndUpdateThreadOnNewMessageAdded.

public void retrieveAndUpdateThreadOnNewMessageAdded(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.isNotNullOrEmpty(thread.getTitle()))
                        threadFromCache.setTitle(thread.getTitle());
                    threadFromCache.setImage(thread.getImage());
                    threadFromCache.setDescription(thread.getDescription());
                    threadFromCache.setMetadata(thread.getMetadata());
                    threadFromCache.setTime(thread.getTime());
                    threadFromCache.setUserGroupHash(thread.getUserGroupHash());
                    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)

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