Search in sources :

Example 6 with ThreadVo

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

the class ChatCore method handleAddParticipant.

private void handleAddParticipant(ChatMessage chatMessage, String messageUniqueId) {
    Thread thread = gson.fromJson(chatMessage.getContent(), Thread.class);
    if (cache) {
        ThreadVo threadVo = gson.fromJson(chatMessage.getContent(), ThreadVo.class);
        List<CacheParticipant> cacheParticipants = threadVo.getParticipants();
        if (!Util.isNullOrEmpty(cacheParticipants))
            messageDatabaseHelper.saveParticipants(cacheParticipants, thread.getId(), getExpireAmount());
    }
    ChatResponse<ResultAddParticipant> chatResponse = ParticipantsManager.prepareAddParticipantResponse(chatMessage, thread);
    String jsonAddParticipant = gson.toJson(chatResponse);
    if (sentryResponseLog) {
        showLog("RECEIVE_ADD_PARTICIPANT", jsonAddParticipant);
    } else {
        showLog("RECEIVE_ADD_PARTICIPANT");
    }
    messageCallbacks.remove(messageUniqueId);
    listenerManager.callOnThreadAddParticipant(jsonAddParticipant, chatResponse);
}
Also used : ThreadVo(com.fanap.podchat.cachemodel.ThreadVo) ResultAddParticipant(com.fanap.podchat.model.ResultAddParticipant) CacheParticipant(com.fanap.podchat.cachemodel.CacheParticipant) RequestCreateThread(com.fanap.podchat.requestobject.RequestCreateThread) ResultPinThread(com.fanap.podchat.chat.pin.pin_thread.model.ResultPinThread) Thread(com.fanap.podchat.mainmodel.Thread) RequestLeaveThread(com.fanap.podchat.requestobject.RequestLeaveThread) HandlerThread(android.os.HandlerThread) PinThread(com.fanap.podchat.chat.pin.pin_thread.PinThread) ResultLeaveThread(com.fanap.podchat.model.ResultLeaveThread) RequestMuteThread(com.fanap.podchat.requestobject.RequestMuteThread) ResultJoinPublicThread(com.fanap.podchat.chat.thread.public_thread.ResultJoinPublicThread) RequestJoinPublicThread(com.fanap.podchat.chat.thread.public_thread.RequestJoinPublicThread) PublicThread(com.fanap.podchat.chat.thread.public_thread.PublicThread) RequestThread(com.fanap.podchat.requestobject.RequestThread) ResultThread(com.fanap.podchat.model.ResultThread) RequestPinThread(com.fanap.podchat.chat.pin.pin_thread.model.RequestPinThread)

Example 7 with ThreadVo

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

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

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

the class MessageDatabaseHelper method deleteMessage.

public void deleteMessage(long id, long subjectId) {
    // if this message is thread last message
    // get previous message and then delete this
    // then set previous message as last message
    worker(() -> {
        if (subjectId > 0) {
            ThreadVo threadVo = messageDao.getThreadById(subjectId);
            if (threadVo != null) {
                long threadLastMessageId = threadVo.getLastMessageVOId();
                if (threadLastMessageId == id && threadLastMessageId > 0) {
                    // this is last message
                    List<CacheMessageVO> cacheMessage = messageDao.getMessage(id);
                    if (!Util.isNullOrEmpty(cacheMessage)) {
                        long previousMessageId = cacheMessage.get(0).getPreviousId();
                        // Get previous message
                        List<CacheMessageVO> previousMessage = messageDao.getMessage(previousMessageId);
                        if (!Util.isNullOrEmpty(previousMessage)) {
                            String message = previousMessage.get(0).getMessage();
                            messageDao.updateThreadLastMessageVOId(subjectId, previousMessageId, message);
                        }
                    }
                }
            }
            // delete from pinned message
            PinMessageVO pinnedMessage = messageDao.getThreadPinnedMessage(subjectId);
            if (pinnedMessage != null && pinnedMessage.getMessageId() == id) {
                messageDao.deletePinnedMessageById(id);
            }
        }
        messageDao.deleteMessage(id);
    });
}
Also used : ThreadVo(com.fanap.podchat.cachemodel.ThreadVo) PinMessageVO(com.fanap.podchat.mainmodel.PinMessageVO) CacheMessageVO(com.fanap.podchat.cachemodel.CacheMessageVO)

Aggregations

ThreadVo (com.fanap.podchat.cachemodel.ThreadVo)9 CacheParticipant (com.fanap.podchat.cachemodel.CacheParticipant)7 Thread (com.fanap.podchat.mainmodel.Thread)7 CacheMessageVO (com.fanap.podchat.cachemodel.CacheMessageVO)6 CacheThreadParticipant (com.fanap.podchat.cachemodel.CacheThreadParticipant)6 CacheCallParticipant (com.fanap.podchat.call.persist.CacheCallParticipant)6 Participant (com.fanap.podchat.mainmodel.Participant)6 PinMessageVO (com.fanap.podchat.mainmodel.PinMessageVO)6 CacheReplyInfoVO (com.fanap.podchat.cachemodel.CacheReplyInfoVO)5 GapMessageVO (com.fanap.podchat.cachemodel.GapMessageVO)5 MessageVO (com.fanap.podchat.mainmodel.MessageVO)5 ReplyInfoVO (com.fanap.podchat.model.ReplyInfoVO)5 ArrayList (java.util.ArrayList)4 Nullable (android.support.annotation.Nullable)2 ChatProfileVO (com.fanap.podchat.chat.user.profile.ChatProfileVO)2 SimpleSQLiteQuery (android.arch.persistence.db.SimpleSQLiteQuery)1 HandlerThread (android.os.HandlerThread)1 NonNull (android.support.annotation.NonNull)1 CacheForwardInfo (com.fanap.podchat.cachemodel.CacheForwardInfo)1 CallVO (com.fanap.podchat.call.model.CallVO)1