Search in sources :

Example 1 with ThreadVo

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

the class MessageDatabaseHelper method getThreadRaw.

public void getThreadRaw(Integer count, Long offset, @Nullable ArrayList<Integer> threadIds, @Nullable String threadName, boolean isNew, OnWorkDone listener) throws RoomIntegrityException {
    if (!canUseDatabase())
        throw new RoomIntegrityException();
    worker(() -> {
        String sQuery;
        final String ORDER = "order by pin desc,time desc";
        sQuery = "select * from ThreadVo " + ORDER;
        if (threadName != null && !isNew) {
            sQuery = "select * from ThreadVo where title LIKE '%" + threadName + "%' " + ORDER;
        }
        if (threadIds != null && threadIds.size() > 0 && !isNew) {
            StringBuilder stringBuilder = new StringBuilder();
            for (int id : threadIds) {
                stringBuilder.append(id).append(",");
            }
            String stringIds = stringBuilder.toString();
            String lastString = stringIds.replaceAll(",$", "");
            if (threadName != null) {
                sQuery = "select * from ThreadVo where id IN " + "(" + lastString + ")" + "AND title LIKE  '%" + threadName + "%' " + ORDER;
            } else {
                sQuery = "select * from ThreadVo where id IN " + "(" + lastString + ")" + " " + ORDER;
            }
        }
        // only threads with unreadCount > 0 if isNew == true
        if (isNew) {
            sQuery = "select * from ThreadVo where unreadCount > 0 " + ORDER;
        }
        long contentCount = 0;
        SimpleSQLiteQuery countQuery = new SimpleSQLiteQuery(sQuery.replaceFirst("select \\* ", "select count(id) "));
        contentCount = messageDao.getThreadContentCount(countQuery);
        sQuery += getPaging(count, offset);
        SimpleSQLiteQuery query = new SimpleSQLiteQuery(sQuery);
        List<ThreadVo> threadVos = messageDao.getThreadRaw(query);
        List<Thread> threads = new ArrayList<>();
        if (threadVos != null) {
            for (ThreadVo threadVo : threadVos) {
                if (threadVo.getId() == 0)
                    continue;
                CacheParticipant cacheParticipant;
                CacheReplyInfoVO cacheReplyInfoVO;
                Participant participant = null;
                ReplyInfoVO replyInfoVO = null;
                @Nullable MessageVO lastMessageVO = null;
                if (threadVo.getInviterId() > 0) {
                    threadVo.setInviter(messageDao.getInviter(threadVo.getInviterId()));
                }
                if (threadVo.getLastMessageVOId() > 0) {
                    threadVo.setLastMessageVO(messageDao.getLastMessageVO(threadVo.getLastMessageVOId()));
                    CacheMessageVO cacheLastMessageVO = threadVo.getLastMessageVO();
                    if (cacheLastMessageVO != null) {
                        if (cacheLastMessageVO.getParticipantId() != null) {
                            cacheParticipant = messageDao.getParticipant(cacheLastMessageVO.getParticipantId());
                            if (cacheParticipant != null) {
                                participant = cacheToParticipantMapper(cacheParticipant, null, null);
                            }
                        }
                        if (cacheLastMessageVO.getReplyInfoVOId() != null) {
                            cacheReplyInfoVO = messageDao.getReplyInfo(cacheLastMessageVO.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());
                        }
                        lastMessageVO = cacheMessageVoToMessageVoMapper(participant, replyInfoVO, null, cacheLastMessageVO);
                    }
                }
                // adding pinned message of thread if exist
                addPinnedMessageOfThread(threadVo);
                Thread thread = threadVoToThreadMapper(threadVo, lastMessageVO);
                threads.add(thread);
            }
        }
        listener.onWorkDone(threads);
        listener.onWorkDone(contentCount, threads);
    });
}
Also used : ArrayList(java.util.ArrayList) 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) SimpleSQLiteQuery(android.arch.persistence.db.SimpleSQLiteQuery) CacheParticipant(com.fanap.podchat.cachemodel.CacheParticipant) CacheReplyInfoVO(com.fanap.podchat.cachemodel.CacheReplyInfoVO) ReplyInfoVO(com.fanap.podchat.model.ReplyInfoVO) 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) CacheMessageVO(com.fanap.podchat.cachemodel.CacheMessageVO) Nullable(android.support.annotation.Nullable)

Example 2 with ThreadVo

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

the class MessageDatabaseHelper method getThreadsByThreadName.

public List<Thread> getThreadsByThreadName(String threadName) {
    List<Thread> threads;
    List<ThreadVo> listThreadVo = messageDao.getThreadByName(50, 0, threadName);
    if (listThreadVo != null) {
        threads = new ArrayList<>();
        for (ThreadVo threadVo : listThreadVo) {
            CacheParticipant cacheParticipant;
            CacheReplyInfoVO cacheReplyInfoVO;
            Participant participant = null;
            ReplyInfoVO replyInfoVO = null;
            MessageVO lastMessageVO = null;
            if (threadVo.getInviterId() > 0) {
                threadVo.setInviter(messageDao.getInviter(threadVo.getInviterId()));
            }
            if (threadVo.getLastMessageVOId() > 0) {
                threadVo.setLastMessageVO(messageDao.getLastMessageVO(threadVo.getLastMessageVOId()));
                CacheMessageVO cacheLastMessageVO = threadVo.getLastMessageVO();
                if (cacheLastMessageVO != null) {
                    if (cacheLastMessageVO.getParticipantId() != null) {
                        cacheParticipant = messageDao.getParticipant(cacheLastMessageVO.getParticipantId());
                        participant = cacheToParticipantMapper(cacheParticipant, null, null);
                    }
                    if (cacheLastMessageVO.getReplyInfoVOId() != null) {
                        cacheReplyInfoVO = messageDao.getReplyInfo(cacheLastMessageVO.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());
                    }
                    lastMessageVO = cacheMessageVoToMessageVoMapper(participant, replyInfoVO, null, cacheLastMessageVO);
                }
            }
            // adding pinned message of thread if exist
            addPinnedMessageOfThread(threadVo);
            Thread thread = threadVoToThreadMapper(threadVo, lastMessageVO);
            threads.add(thread);
        }
    } else {
        return new ArrayList<>();
    }
    return threads;
}
Also used : 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) ArrayList(java.util.ArrayList) CacheParticipant(com.fanap.podchat.cachemodel.CacheParticipant) CacheReplyInfoVO(com.fanap.podchat.cachemodel.CacheReplyInfoVO) ReplyInfoVO(com.fanap.podchat.model.ReplyInfoVO) 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) CacheMessageVO(com.fanap.podchat.cachemodel.CacheMessageVO) Thread(com.fanap.podchat.mainmodel.Thread)

Example 3 with ThreadVo

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

the class MessageDatabaseHelper method prepareThreadVOAndSaveIt.

private void prepareThreadVOAndSaveIt(Thread thread) {
    String threadJson = App.getGson().toJson(thread);
    ThreadVo threadVo = App.getGson().fromJson(threadJson, ThreadVo.class);
    if (threadVo.getInviter() != null) {
        insertInviter(threadVo);
    }
    if (thread.getPinMessageVO() != null) {
        insertPinnedMessage(thread);
    }
    if (thread.getLastMessageVO() != null) {
        updateThreadLastMessage(thread, threadVo);
    }
    messageDao.insertThread(threadVo);
}
Also used : ThreadVo(com.fanap.podchat.cachemodel.ThreadVo)

Example 4 with ThreadVo

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

the class MessageDatabaseHelper method getThreads.

public List<Thread> getThreads(long count, long offset) {
    List<Thread> threads;
    if (messageDao.getThreads(count, offset) != null) {
        List<ThreadVo> threadVos = messageDao.getThreads(count, offset);
        threads = new ArrayList<>();
        CacheParticipant cacheParticipant;
        CacheReplyInfoVO cacheReplyInfoVO;
        Participant participant = null;
        ReplyInfoVO replyInfoVO = null;
        for (ThreadVo threadVo : threadVos) {
            MessageVO lastMessageVO = null;
            if (threadVo.getInviterId() > 0) {
                threadVo.setInviter(messageDao.getInviter(threadVo.getInviterId()));
            }
            if (threadVo.getLastMessageVOId() > 0) {
                threadVo.setLastMessageVO(messageDao.getLastMessageVO(threadVo.getLastMessageVOId()));
                CacheMessageVO cacheLastMessageVO = threadVo.getLastMessageVO();
                if (cacheLastMessageVO != null) {
                    if (cacheLastMessageVO.getParticipantId() != null) {
                        cacheParticipant = messageDao.getParticipant(cacheLastMessageVO.getParticipantId());
                        if (cacheParticipant != null) {
                            participant = cacheToParticipantMapper(cacheParticipant, null, null);
                        }
                    }
                    if (cacheLastMessageVO.getReplyInfoVOId() != null) {
                        cacheReplyInfoVO = messageDao.getReplyInfo(cacheLastMessageVO.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());
                    }
                    lastMessageVO = cacheMessageVoToMessageVoMapper(participant, replyInfoVO, null, cacheLastMessageVO);
                }
            }
            // adding pinned message of thread if exist
            addPinnedMessageOfThread(threadVo);
            Thread thread = threadVoToThreadMapper(threadVo, lastMessageVO);
            threads.add(thread);
        }
        // sort threads by last message time
        Collections.sort(new ArrayList<>(threads), (o1, o2) -> Long.compare(o1.getLastMessageVO().getTime(), o2.getLastMessageVO().getTime()));
        return threads;
    } else {
        threads = new ArrayList<>();
    }
    return threads;
}
Also used : 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) CacheParticipant(com.fanap.podchat.cachemodel.CacheParticipant) CacheReplyInfoVO(com.fanap.podchat.cachemodel.CacheReplyInfoVO) ReplyInfoVO(com.fanap.podchat.model.ReplyInfoVO) 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) CacheMessageVO(com.fanap.podchat.cachemodel.CacheMessageVO) Thread(com.fanap.podchat.mainmodel.Thread)

Example 5 with ThreadVo

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

the class MessageDatabaseHelper method getThreadsByThreadIds.

@NonNull
public List<Thread> getThreadsByThreadIds(@NonNull ArrayList<Integer> threadIds) {
    List<Thread> threads = new ArrayList<>();
    for (int id : threadIds) {
        if (messageDao.getThreadById(id) != null) {
            ThreadVo threadVo = messageDao.getThreadById(id);
            CacheParticipant cacheParticipant;
            CacheReplyInfoVO cacheReplyInfoVO;
            Participant participant = null;
            ReplyInfoVO replyInfoVO = null;
            MessageVO lastMessageVO = null;
            if (threadVo.getInviterId() > 0) {
                threadVo.setInviter(messageDao.getInviter(threadVo.getInviterId()));
            }
            if (threadVo.getLastMessageVOId() > 0) {
                threadVo.setLastMessageVO(messageDao.getLastMessageVO(threadVo.getLastMessageVOId()));
                CacheMessageVO cacheLastMessageVO = threadVo.getLastMessageVO();
                if (cacheLastMessageVO != null) {
                    if (cacheLastMessageVO.getParticipantId() != null) {
                        cacheParticipant = messageDao.getParticipant(cacheLastMessageVO.getParticipantId());
                        participant = cacheToParticipantMapper(cacheParticipant, null, null);
                    }
                    if (cacheLastMessageVO.getReplyInfoVOId() != null) {
                        cacheReplyInfoVO = messageDao.getReplyInfo(cacheLastMessageVO.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());
                    }
                    lastMessageVO = cacheMessageVoToMessageVoMapper(participant, replyInfoVO, null, cacheLastMessageVO);
                }
            }
            // adding pinned message of thread if exist
            addPinnedMessageOfThread(threadVo);
            Thread thread = threadVoToThreadMapper(threadVo, lastMessageVO);
            threads.add(thread);
        }
    }
    return threads;
}
Also used : 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) ArrayList(java.util.ArrayList) CacheParticipant(com.fanap.podchat.cachemodel.CacheParticipant) CacheReplyInfoVO(com.fanap.podchat.cachemodel.CacheReplyInfoVO) ReplyInfoVO(com.fanap.podchat.model.ReplyInfoVO) 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) CacheMessageVO(com.fanap.podchat.cachemodel.CacheMessageVO) Thread(com.fanap.podchat.mainmodel.Thread) NonNull(android.support.annotation.NonNull)

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