Search in sources :

Example 1 with CacheThreadParticipant

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

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

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

the class MessageDatabaseHelper method getThreadAdmins.

public void getThreadAdmins(long offset, long count, long threadId, FunctionalListener listener) throws RoomIntegrityException {
    if (!canUseDatabase())
        throw new RoomIntegrityException();
    worker(() -> {
        List<Participant> participants = new ArrayList<>();
        List<CacheThreadParticipant> listCtp = messageDao.getAllThreadParticipants(offset, count, threadId);
        long participantCount = messageDao.getParticipantCount(threadId);
        if (listCtp == null) {
            listener.onWorkDone(participantCount, participants);
        } else {
            SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss", Locale.getDefault());
            Calendar c = Calendar.getInstance();
            c.setTime(new Date());
            Date nowDate = c.getTime();
            for (CacheThreadParticipant threadParticipant : listCtp) {
                try {
                    Date expireDate = format.parse(threadParticipant.getExpireDate());
                    long participantId = threadParticipant.getParticipantId();
                    if (expireDate != null) {
                        if (expireDate.compareTo(nowDate) < 0) {
                            messageDao.deleteCacheThreadParticipant(participantId);
                        } else {
                            CacheParticipant cParticipant = messageDao.getParticipant(participantId);
                            ChatProfileVO chatProfileVO = messageDao.getChatProfileVOById(cParticipant.getId());
                            if (chatProfileVO != null) {
                                cParticipant.setChatProfileVO(chatProfileVO);
                            }
                            List<String> roles = new ArrayList<>();
                            CacheParticipantRoles cachedRoles = messageDao.getParticipantRoles(participantId, threadId);
                            if (cachedRoles != null) {
                                if (cachedRoles.getRoles().size() > 0)
                                    roles = cachedRoles.getRoles();
                            }
                            if (roles.size() > 0) {
                                Participant participant = cacheToParticipantMapper(cParticipant, true, roles);
                                participants.add(participant);
                            }
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
        listener.onWorkDone(participantCount, participants);
    });
}
Also used : ChatProfileVO(com.fanap.podchat.chat.user.profile.ChatProfileVO) CacheParticipantRoles(com.fanap.podchat.cachemodel.CacheParticipantRoles) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) Date(java.util.Date) IOException(java.io.IOException) ParseException(java.text.ParseException) CacheThreadParticipant(com.fanap.podchat.cachemodel.CacheThreadParticipant) 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) CacheParticipant(com.fanap.podchat.cachemodel.CacheParticipant) SimpleDateFormat(java.text.SimpleDateFormat)

Example 4 with CacheThreadParticipant

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

the class MessageDatabaseHelper method getThreadParticipant.

public void getThreadParticipant(long offset, long count, long threadId, FunctionalListener listener) throws RoomIntegrityException {
    if (!canUseDatabase())
        throw new RoomIntegrityException();
    worker(() -> {
        List<Participant> participants = new ArrayList<>();
        List<CacheThreadParticipant> listCtp = messageDao.getAllThreadParticipants(offset, count, threadId);
        long participantCount = messageDao.getParticipantCount(threadId);
        if (listCtp == null) {
            listener.onWorkDone(participantCount, participants);
        } else {
            SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss", Locale.getDefault());
            Calendar c = Calendar.getInstance();
            c.setTime(new Date());
            Date nowDate = c.getTime();
            for (CacheThreadParticipant threadParticipant : listCtp) {
                try {
                    Date expireDate = format.parse(threadParticipant.getExpireDate());
                    long participantId = threadParticipant.getParticipantId();
                    if (expireDate != null) {
                        if (expireDate.compareTo(nowDate) < 0) {
                            messageDao.deleteCacheThreadParticipant(participantId);
                        } else {
                            CacheParticipant cParticipant = messageDao.getParticipant(participantId);
                            ChatProfileVO chatProfileVO = messageDao.getChatProfileVOById(cParticipant.getId());
                            if (chatProfileVO != null) {
                                cParticipant.setChatProfileVO(chatProfileVO);
                            }
                            List<String> roles = new ArrayList<>();
                            Participant participant = cacheToParticipantMapper(cParticipant, false, roles);
                            participants.add(participant);
                        }
                    }
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }
        }
        listener.onWorkDone(participantCount, participants);
    });
}
Also used : ChatProfileVO(com.fanap.podchat.chat.user.profile.ChatProfileVO) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) Date(java.util.Date) CacheThreadParticipant(com.fanap.podchat.cachemodel.CacheThreadParticipant) 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) ParseException(java.text.ParseException) CacheParticipant(com.fanap.podchat.cachemodel.CacheParticipant) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

CacheThreadParticipant (com.fanap.podchat.cachemodel.CacheThreadParticipant)4 ChatProfileVO (com.fanap.podchat.chat.user.profile.ChatProfileVO)4 SimpleDateFormat (java.text.SimpleDateFormat)4 Calendar (java.util.Calendar)4 Date (java.util.Date)4 CacheParticipant (com.fanap.podchat.cachemodel.CacheParticipant)3 CacheParticipantRoles (com.fanap.podchat.cachemodel.CacheParticipantRoles)3 CacheCallParticipant (com.fanap.podchat.call.persist.CacheCallParticipant)2 Participant (com.fanap.podchat.mainmodel.Participant)2 ParseException (java.text.ParseException)2 ArrayList (java.util.ArrayList)2 IOException (java.io.IOException)1