Search in sources :

Example 1 with ChatProfileVO

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

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

the class MessageDatabaseHelper method saveParticipant.

public void saveParticipant(@NonNull CacheParticipant participant, long threadId, int expireSecond) {
    worker(() -> {
        participant.setThreadId(threadId);
        SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss", Locale.getDefault());
        Calendar c = Calendar.getInstance();
        c.setTime(new Date());
        c.add(Calendar.SECOND, expireSecond);
        String expireDate = format.format(c.getTime());
        messageDao.insertParticipant(participant);
        CacheThreadParticipant ctp = new CacheThreadParticipant();
        ctp.setExpireDate(expireDate);
        ctp.setParticipantId(participant.getId());
        ctp.setThreadId(threadId);
        messageDao.insertThreadParticipant(ctp);
        if (!Util.isNullOrEmpty(participant.getRoles())) {
            CacheParticipantRoles cpr = new CacheParticipantRoles();
            cpr.setId(participant.getId());
            cpr.setThreadId(threadId);
            cpr.setRoles(participant.getRoles());
            Log.d("MTAG", "SAVE CPR: " + cpr);
            messageDao.insertRoles(cpr);
        }
        if (participant.getChatProfileVO() != null) {
            ChatProfileVO chatProfileVO = participant.getChatProfileVO();
            chatProfileVO.setId(participant.getId());
            messageDao.insertChatProfile(chatProfileVO);
        }
    });
}
Also used : CacheThreadParticipant(com.fanap.podchat.cachemodel.CacheThreadParticipant) ChatProfileVO(com.fanap.podchat.chat.user.profile.ChatProfileVO) CacheParticipantRoles(com.fanap.podchat.cachemodel.CacheParticipantRoles) Calendar(java.util.Calendar) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 3 with ChatProfileVO

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

the class MessageDatabaseHelper method saveParticipants.

/**
 * Cache participant
 */
public void saveParticipants(@NonNull List<CacheParticipant> participants, long threadId, int expireSecond) {
    worker(() -> {
        for (CacheParticipant participant : participants) {
            participant.setThreadId(threadId);
            SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss", Locale.getDefault());
            Calendar c = Calendar.getInstance();
            c.setTime(new Date());
            c.add(Calendar.SECOND, expireSecond);
            String expireDate = format.format(c.getTime());
            messageDao.insertParticipant(participant);
            CacheThreadParticipant ctp = new CacheThreadParticipant();
            ctp.setExpireDate(expireDate);
            ctp.setParticipantId(participant.getId());
            ctp.setThreadId(threadId);
            messageDao.insertThreadParticipant(ctp);
            if (!Util.isNullOrEmpty(participant.getRoles())) {
                CacheParticipantRoles cpr = new CacheParticipantRoles();
                cpr.setId(participant.getId());
                cpr.setThreadId(threadId);
                cpr.setRoles(participant.getRoles());
                Log.d("MTAG", "SAVE CPR: " + cpr);
                messageDao.insertRoles(cpr);
            }
            if (participant.getChatProfileVO() != null) {
                ChatProfileVO chatProfileVO = participant.getChatProfileVO();
                chatProfileVO.setId(participant.getId());
                messageDao.insertChatProfile(chatProfileVO);
            }
        }
    });
}
Also used : CacheThreadParticipant(com.fanap.podchat.cachemodel.CacheThreadParticipant) ChatProfileVO(com.fanap.podchat.chat.user.profile.ChatProfileVO) CacheParticipantRoles(com.fanap.podchat.cachemodel.CacheParticipantRoles) Calendar(java.util.Calendar) CacheParticipant(com.fanap.podchat.cachemodel.CacheParticipant) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 4 with ChatProfileVO

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

the class MessageDatabaseHelper method updateChatProfile.

public void updateChatProfile(ResultUpdateProfile result) {
    worker(() -> {
        UserInfo userInfo = getUserInfo();
        ChatProfileVO chatProfileVO = new ChatProfileVO();
        chatProfileVO.setId(userInfo.getId());
        chatProfileVO.setBio(result.getBio());
        userInfo.setChatProfileVO(chatProfileVO);
        messageDao.insertChatProfile(chatProfileVO);
        messageDao.insertUserInfo(userInfo);
    });
}
Also used : ChatProfileVO(com.fanap.podchat.chat.user.profile.ChatProfileVO) UserInfo(com.fanap.podchat.mainmodel.UserInfo)

Example 5 with ChatProfileVO

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

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