Search in sources :

Example 21 with CacheMessageVO

use of com.fanap.podchat.cachemodel.CacheMessageVO 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)

Example 22 with CacheMessageVO

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

the class MessageDatabaseHelper method getHashTagList.

public void getHashTagList(RequestGetHashTagList request, FunctionalListener listener) {
    worker(() -> {
        List<MessageVO> messageVOS = new ArrayList<>();
        List<CacheMessageVO> cacheMessageVOS = new ArrayList<>();
        String condistion = "'%" + request.getHashtag() + "%'";
        String rawQuery = "SELECT * FROM CacheMessageVO WHERE threadVoId = " + request.getThreadId() + " And hashtags LIKE " + condistion;
        SupportSQLiteQuery sqLiteQuery = new SimpleSQLiteQuery(rawQuery);
        cacheMessageVOS = messageDao.getRawHistory(sqLiteQuery);
        String contentCountQuery = "SELECT count(*) FROM CacheMessageVO WHERE threadVoId = " + request.getThreadId() + " And hashtags LIKE " + condistion;
        long contentCount = messageDao.getHistoryContentCount(new SimpleSQLiteQuery(contentCountQuery));
        prepareMessageVOs(messageVOS, cacheMessageVOS);
        if (messageVOS.size() > 0)
            listener.onWorkDone(messageVOS, contentCount);
    });
}
Also used : SupportSQLiteQuery(android.arch.persistence.db.SupportSQLiteQuery) SimpleSQLiteQuery(android.arch.persistence.db.SimpleSQLiteQuery) ArrayList(java.util.ArrayList) 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)

Aggregations

CacheMessageVO (com.fanap.podchat.cachemodel.CacheMessageVO)22 MessageVO (com.fanap.podchat.mainmodel.MessageVO)15 GapMessageVO (com.fanap.podchat.cachemodel.GapMessageVO)14 PinMessageVO (com.fanap.podchat.mainmodel.PinMessageVO)14 ArrayList (java.util.ArrayList)12 SimpleSQLiteQuery (android.arch.persistence.db.SimpleSQLiteQuery)8 SupportSQLiteQuery (android.arch.persistence.db.SupportSQLiteQuery)7 CacheParticipant (com.fanap.podchat.cachemodel.CacheParticipant)7 CacheReplyInfoVO (com.fanap.podchat.cachemodel.CacheReplyInfoVO)7 ThreadVo (com.fanap.podchat.cachemodel.ThreadVo)6 CacheThreadParticipant (com.fanap.podchat.cachemodel.CacheThreadParticipant)5 CacheCallParticipant (com.fanap.podchat.call.persist.CacheCallParticipant)5 Participant (com.fanap.podchat.mainmodel.Participant)5 Thread (com.fanap.podchat.mainmodel.Thread)5 ReplyInfoVO (com.fanap.podchat.model.ReplyInfoVO)5 Failed (com.fanap.podchat.cachemodel.queue.Failed)3 Sending (com.fanap.podchat.cachemodel.queue.Sending)3 Uploading (com.fanap.podchat.cachemodel.queue.Uploading)3 ChatResponse (com.fanap.podchat.model.ChatResponse)3 ResultHistory (com.fanap.podchat.model.ResultHistory)3