Search in sources :

Example 1 with PinMessageVO

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

the class MessageDatabaseHelper method addPinnedMessageOfThread.

private void addPinnedMessageOfThread(ThreadVo threadVo) {
    worker(() -> {
        PinMessageVO pinnedMessage = messageDao.getThreadPinnedMessage(threadVo.getId());
        if (pinnedMessage != null) {
            // get cached participant
            if (pinnedMessage.getParticipantId() > 0) {
                CacheParticipant cacheParticipant = messageDao.getParticipant(pinnedMessage.getParticipantId());
                if (cacheParticipant != null) {
                    // convert cached participant to participant
                    Participant participant = cacheToParticipantMapper(cacheParticipant, false, null);
                    pinnedMessage.setParticipant(participant);
                }
            }
            threadVo.setPinMessageVO(pinnedMessage);
        }
    });
}
Also used : 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) PinMessageVO(com.fanap.podchat.mainmodel.PinMessageVO) CacheParticipant(com.fanap.podchat.cachemodel.CacheParticipant)

Example 2 with PinMessageVO

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

the class MessageDatabaseHelper method insertPinnedMessage.

private void insertPinnedMessage(Thread thread) {
    PinMessageVO pinMessageVO = thread.getPinMessageVO();
    pinMessageVO.setThreadId(thread.getId());
    try {
        Participant participant = pinMessageVO.getParticipant();
        if (participant != null) {
            String participantJson = App.getGson().toJson(participant);
            CacheParticipant cacheParticipant = App.getGson().fromJson(participantJson, CacheParticipant.class);
            messageDao.insertParticipant(cacheParticipant);
            pinMessageVO.setParticipantId(cacheParticipant.getId());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    messageDao.insertPinnedMessage(pinMessageVO);
}
Also used : 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) PinMessageVO(com.fanap.podchat.mainmodel.PinMessageVO) CacheParticipant(com.fanap.podchat.cachemodel.CacheParticipant) IOException(java.io.IOException) ParseException(java.text.ParseException)

Example 3 with PinMessageVO

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

the class MessageDatabaseHelper method savePinMessage.

public void savePinMessage(ChatResponse<ResultPinMessage> response, long subjectId) {
    worker(() -> {
        ResultPinMessage result = response.getResult();
        PinMessageVO pinMessageVO = new PinMessageVO();
        pinMessageVO.setThreadId(subjectId);
        pinMessageVO.setMessageId(result.getMessageId());
        pinMessageVO.setNotifyAll(result.isNotifyAll());
        pinMessageVO.setText(result.getText());
        pinMessageVO.setTime(result.getTime());
        if (result.getParticipant() != null) {
            Participant participant = result.getParticipant();
            String participantJson = App.getGson().toJson(participant);
            CacheParticipant cacheParticipant = App.getGson().fromJson(participantJson, CacheParticipant.class);
            messageDao.insertParticipant(cacheParticipant);
            pinMessageVO.setParticipantId(cacheParticipant.getId());
        }
        messageDao.insertPinnedMessage(pinMessageVO);
    });
}
Also used : 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) ResultPinMessage(com.fanap.podchat.chat.pin.pin_message.model.ResultPinMessage) PinMessageVO(com.fanap.podchat.mainmodel.PinMessageVO) CacheParticipant(com.fanap.podchat.cachemodel.CacheParticipant)

Example 4 with PinMessageVO

use of com.fanap.podchat.mainmodel.PinMessageVO 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

PinMessageVO (com.fanap.podchat.mainmodel.PinMessageVO)4 CacheParticipant (com.fanap.podchat.cachemodel.CacheParticipant)3 CacheThreadParticipant (com.fanap.podchat.cachemodel.CacheThreadParticipant)3 CacheCallParticipant (com.fanap.podchat.call.persist.CacheCallParticipant)3 Participant (com.fanap.podchat.mainmodel.Participant)3 CacheMessageVO (com.fanap.podchat.cachemodel.CacheMessageVO)1 ThreadVo (com.fanap.podchat.cachemodel.ThreadVo)1 ResultPinMessage (com.fanap.podchat.chat.pin.pin_message.model.ResultPinMessage)1 IOException (java.io.IOException)1 ParseException (java.text.ParseException)1