Search in sources :

Example 11 with CacheMessageVO

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

the class MessageDatabaseHelper method insertLastMessage.

@Nullable
private CacheMessageVO insertLastMessage(Thread thread, ThreadVo threadVo) {
    CacheMessageVO cacheMessageVO;
    try {
        MessageVO messageVO = thread.getLastMessageVO();
        messageVO.setConversation(thread);
        cacheMessageVO = new CacheMessageVO(messageVO);
        threadVo.setLastMessageVO(cacheMessageVO);
        threadVo.setLastMessageVOId(cacheMessageVO.getId());
        messageDao.insertLastMessageVO(cacheMessageVO);
        // to avoid infinite message-thread loop
        messageVO.setConversation(null);
    } catch (Exception e) {
        captureException(e);
        return null;
    }
    return cacheMessageVO;
}
Also used : CacheMessageVO(com.fanap.podchat.cachemodel.CacheMessageVO) CacheMessageVO(com.fanap.podchat.cachemodel.CacheMessageVO) PinMessageVO(com.fanap.podchat.mainmodel.PinMessageVO) MessageVO(com.fanap.podchat.mainmodel.MessageVO) GapMessageVO(com.fanap.podchat.cachemodel.GapMessageVO) IOException(java.io.IOException) ParseException(java.text.ParseException) Nullable(android.support.annotation.Nullable)

Example 12 with CacheMessageVO

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

the class DbTest method updateCacheFirstMsgIdAndLastMsgIdConditional2.

// first messsage and last message
// Conditional 2
// cache siz more than one but server size is 1
@Test
public void updateCacheFirstMsgIdAndLastMsgIdConditional2() {
    long threadId = 2;
    Callback callback = new Callback();
    List<MessageVO> messageVOS = new ArrayList<>();
    // MessageVO messageVO = new MessageVO(
    // 5653,
    // false,
    // false,
    // false,
    // false,
    // false,
    // "91efe7da-547f-4c5f-c34b-0442951ffbbc",
    // 0,
    // 5652,
    // "",
    // null,
    // 13354321,
    // 321000000,
    // "",
    // null,
    // null,
    // null,
    // null
    // 
    // );
    List<CacheMessageVO> cacheMessageVOS = new ArrayList<>();
    CacheMessageVO cacheMessageVO = new CacheMessageVO();
    cacheMessageVO.setId(5878);
    cacheMessageVO.setThreadVoId(2L);
    cacheMessageVOS.add(cacheMessageVO);
    // messageVOS.add(messageVO);
    callback.setOffset(0);
    callback.setOffset(0);
    callback.setCount(50);
    callback.setOrder("asc");
    callback.setFirstMessageId(5652);
    callback.setLastMessageId(5878);
    messageDatabaseHelper.updateGetHistoryResponse(callback, messageVOS, threadId, cacheMessageVOS);
}
Also used : Callback(com.fanap.podchat.util.Callback) ArrayList(java.util.ArrayList) MessageVO(com.fanap.podchat.mainmodel.MessageVO) CacheMessageVO(com.fanap.podchat.cachemodel.CacheMessageVO) CacheMessageVO(com.fanap.podchat.cachemodel.CacheMessageVO) Test(org.junit.Test)

Example 13 with CacheMessageVO

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

the class ChatCore method findAndUpdateGaps.

private void findAndUpdateGaps(List<MessageVO> newMessagesFromServer, long threadId) {
    Runnable jobFindAndInsertGap = () -> {
        if (newMessagesFromServer.size() == 0)
            return;
        MessageVO lastMessage = newMessagesFromServer.get(newMessagesFromServer.size() - 1);
        if (lastMessage.getPreviousId() == 0)
            return;
        List<CacheMessageVO> messages = messageDatabaseHelper.getMessageById(lastMessage.getPreviousId());
        if (Util.isNullOrEmpty(messages)) {
            GapMessageVO gapMessageVO = new GapMessageVO();
            gapMessageVO.setId(lastMessage.getId());
            gapMessageVO.setPreviousId(lastMessage.getPreviousId());
            gapMessageVO.setThreadId(threadId);
            gapMessageVO.setTime(lastMessage.getTime());
            gapMessageVO.setUniqueId(lastMessage.getUniqueId());
            messageDatabaseHelper.insertGap(gapMessageVO);
            lastMessage.setHasGap(true);
            dataSource.updateMessage(lastMessage, threadId);
        // messageDatabaseHelper.updateMessage(lastMessage, threadId);
        }
    };
    Runnable jobUpdateGaps = () -> {
        List<GapMessageVO> gaps = messageDatabaseHelper.getAllGaps(threadId);
        if (!Util.isNullOrEmpty(gaps)) {
            Map<Long, Long> msgIdAndPreviousId = new HashMap<>();
            for (GapMessageVO gapMessage : gaps) {
                msgIdAndPreviousId.put(gapMessage.getPreviousId(), gapMessage.getId());
            }
            for (MessageVO newMessage : newMessagesFromServer) {
                if (msgIdAndPreviousId.containsKey(newMessage.getId())) {
                    // delete gap that produced by this message
                    messageDatabaseHelper.deleteGapForMessageId(msgIdAndPreviousId.get(newMessage.getId()));
                    // set message gap field to false
                    messageDatabaseHelper.updateMessageGapState(msgIdAndPreviousId.get(newMessage.getId()), false);
                }
            }
        }
    };
    PodThreadManager podThreadManager = new PodThreadManager();
    podThreadManager.addTask(jobFindAndInsertGap);
    podThreadManager.addTask(jobUpdateGaps);
    podThreadManager.runTasksSynced();
}
Also used : GapMessageVO(com.fanap.podchat.cachemodel.GapMessageVO) PodThreadManager(com.fanap.podchat.util.PodThreadManager) ResultBlockList(com.fanap.podchat.model.ResultBlockList) RequestGetMentionList(com.fanap.podchat.chat.mention.model.RequestGetMentionList) RequestDeliveredMessageList(com.fanap.podchat.requestobject.RequestDeliveredMessageList) ArrayList(java.util.ArrayList) RequestBlockList(com.fanap.podchat.requestobject.RequestBlockList) RequestGetHashTagList(com.fanap.podchat.chat.hashtag.model.RequestGetHashTagList) RequestSeenMessageList(com.fanap.podchat.requestobject.RequestSeenMessageList) List(java.util.List) GapMessageVO(com.fanap.podchat.cachemodel.GapMessageVO) CacheMessageVO(com.fanap.podchat.cachemodel.CacheMessageVO) MessageVO(com.fanap.podchat.mainmodel.MessageVO) Map(java.util.Map) RetrofitHelperMap(com.fanap.podchat.networking.retrofithelper.RetrofitHelperMap) HashMap(java.util.HashMap) MimeTypeMap(android.webkit.MimeTypeMap)

Example 14 with CacheMessageVO

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

the class MessageDatabaseHelper method updateMessageGapState.

public void updateMessageGapState(Long msgId, boolean hasGap) {
    worker(() -> {
        List<CacheMessageVO> cacheMessageVO = messageDao.getMessage(msgId);
        if (!Util.isNullOrEmpty(cacheMessageVO)) {
            for (CacheMessageVO msg : cacheMessageVO) {
                msg.setHasGap(hasGap);
                messageDao.updateMessage(msg);
            }
        }
    });
}
Also used : CacheMessageVO(com.fanap.podchat.cachemodel.CacheMessageVO)

Example 15 with CacheMessageVO

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

the class MessageDatabaseHelper method getHistories.

@NonNull
public List<MessageVO> getHistories(@NonNull History history, long threadId) {
    List<MessageVO> messageVOS = new ArrayList<>();
    List<CacheMessageVO> cacheMessageVOS;
    long fromTime = history.getFromTime();
    long fromTimeNanos = history.getFromTimeNanos();
    long toTime = history.getToTime();
    long toTimeNanos = history.getToTimeNanos();
    long messageId = history.getId();
    long offset = history.getOffset();
    long count = history.getCount();
    String query = history.getQuery();
    String order = history.getOrder();
    offset = offset >= 0 ? offset : 0;
    count = count > 0 ? count : 50;
    if (Util.isNullOrEmpty(order)) {
        order = "desc";
    }
    String rawQuery = "SELECT * FROM CacheMessageVO WHERE threadVoId =" + threadId;
    rawQuery = addMessageIdIfExist(messageId, rawQuery);
    rawQuery = addFromTimeIfExist(fromTime, fromTimeNanos, rawQuery);
    rawQuery = addToTimeIfExist(toTime, toTimeNanos, rawQuery);
    rawQuery = addQueryIfExist(query, rawQuery);
    rawQuery = addOrderAndLimitAndOffset(offset, count, order, rawQuery);
    SupportSQLiteQuery sqLiteQuery = new SimpleSQLiteQuery(rawQuery);
    cacheMessageVOS = messageDao.getRawHistory(sqLiteQuery);
    prepareMessageVOs(messageVOS, cacheMessageVOS);
    return messageVOS;
}
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) NonNull(android.support.annotation.NonNull)

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