Search in sources :

Example 26 with MessageVO

use of com.fanap.podchat.mainmodel.MessageVO 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 27 with MessageVO

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

the class ChatCore method handleEditMessage.

private void handleEditMessage(ChatMessage chatMessage, String messageUniqueId) {
    if (sentryResponseLog) {
        showLog("RECEIVE_EDIT_MESSAGE", gson.toJson(chatMessage));
    } else {
        showLog("RECEIVE_EDIT_MESSAGE");
    }
    ChatResponse<ResultNewMessage> chatResponse = new ChatResponse<>();
    ResultNewMessage newMessage = new ResultNewMessage();
    MessageVO messageVO = gson.fromJson(chatMessage.getContent(), MessageVO.class);
    if (messageVO.getMessage().startsWith("#")) {
        Log.e(TAG, "hashtag: " + "hello");
        String hashtag = messageVO.getMessage().substring(0, messageVO.getMessage().indexOf(' '));
        Log.e(TAG, "hashtag: " + hashtag);
    }
    if (cache) {
        dataSource.updateMessageResultFromServer(messageVO, chatMessage.getSubjectId());
    }
    newMessage.setMessageVO(messageVO);
    newMessage.setThreadId(chatMessage.getSubjectId());
    chatResponse.setResult(newMessage);
    chatResponse.setUniqueId(chatMessage.getUniqueId());
    chatResponse.setSubjectId(chatMessage.getSubjectId());
    String content = gson.toJson(chatResponse);
    messageCallbacks.remove(messageUniqueId);
    listenerManager.callOnEditedMessage(content, chatResponse);
}
Also used : ResultNewMessage(com.fanap.podchat.model.ResultNewMessage) ChatResponse(com.fanap.podchat.model.ChatResponse) GapMessageVO(com.fanap.podchat.cachemodel.GapMessageVO) CacheMessageVO(com.fanap.podchat.cachemodel.CacheMessageVO) MessageVO(com.fanap.podchat.mainmodel.MessageVO)

Example 28 with MessageVO

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

the class ChatCore method handleForwardMessage.

private void handleForwardMessage(ChatMessage chatMessage) {
    MessageVO messageVO = gson.fromJson(chatMessage.getContent(), MessageVO.class);
    ChatResponse<ResultNewMessage> chatResponse = new ChatResponse<>();
    ResultNewMessage resultMessage = new ResultNewMessage();
    resultMessage.setThreadId(chatMessage.getSubjectId());
    resultMessage.setMessageVO(messageVO);
    chatResponse.setResult(resultMessage);
    String json = gson.toJson(chatResponse);
    long ownerId = 0;
    if (messageVO != null) {
        ownerId = messageVO.getParticipant().getId();
    }
    if (sentryResponseLog) {
        showLog("RECEIVED_FORWARD_MESSAGE", json);
    } else {
        showLog("RECEIVED_FORWARD_MESSAGE");
    }
    if (ownerId != getUserId()) {
        ChatMessage message = null;
        if (messageVO != null) {
            message = getChatMessage(messageVO);
        }
        String asyncContent = gson.toJson(message);
        showLog("SEND_DELIVERY_MESSAGE", asyncContent);
        async.sendMessage(asyncContent, AsyncAckType.Constants.WITHOUT_ACK);
    }
    if (cache) {
        dataSource.saveMessageResultFromServer(messageVO, chatMessage.getSubjectId());
    }
    listenerManager.callOnNewMessage(json, chatResponse);
}
Also used : ResultNewMessage(com.fanap.podchat.model.ResultNewMessage) ChatMessage(com.fanap.podchat.mainmodel.ChatMessage) ChatResponse(com.fanap.podchat.model.ChatResponse) GapMessageVO(com.fanap.podchat.cachemodel.GapMessageVO) CacheMessageVO(com.fanap.podchat.cachemodel.CacheMessageVO) MessageVO(com.fanap.podchat.mainmodel.MessageVO)

Example 29 with MessageVO

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

the class MessageManager method getFailedFromWaiting.

public static List<Failed> getFailedFromWaiting(List<WaitQueueCache> listCaches) {
    List<Failed> listQueues = new ArrayList<>();
    for (WaitQueueCache queueCache : listCaches) {
        Failed failed = new Failed();
        MessageVO messageVO = new MessageVO();
        messageVO.setId(queueCache.getId());
        messageVO.setMessage(queueCache.getMessage());
        messageVO.setMessageType(queueCache.getMessageType());
        messageVO.setMetadata(queueCache.getMetadata());
        messageVO.setSystemMetadata(queueCache.getSystemMetadata());
        failed.setMessageVo(messageVO);
        failed.setThreadId(queueCache.getThreadId());
        failed.setUniqueId(queueCache.getUniqueId());
        listQueues.add(failed);
    }
    return listQueues;
}
Also used : Failed(com.fanap.podchat.cachemodel.queue.Failed) ArrayList(java.util.ArrayList) WaitQueueCache(com.fanap.podchat.cachemodel.queue.WaitQueueCache) MessageVO(com.fanap.podchat.mainmodel.MessageVO)

Example 30 with MessageVO

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

the class MessageManager method getUploadingFromUploadCache.

public static List<Uploading> getUploadingFromUploadCache(List<UploadingQueueCache> uploadingQueueCaches) {
    List<Uploading> uploadingQueues = new ArrayList<>();
    for (UploadingQueueCache queueCache : uploadingQueueCaches) {
        Uploading uploadingQueue = new Uploading();
        MessageVO messageVO = new MessageVO();
        messageVO.setId(queueCache.getId());
        messageVO.setMessage(queueCache.getMessage());
        messageVO.setMessageType(queueCache.getMessageType());
        messageVO.setMetadata(queueCache.getMetadata());
        messageVO.setSystemMetadata(queueCache.getSystemMetadata());
        uploadingQueue.setMessageVo(messageVO);
        uploadingQueue.setThreadId(queueCache.getThreadId());
        uploadingQueue.setUniqueId(queueCache.getUniqueId());
        uploadingQueues.add(uploadingQueue);
    }
    return uploadingQueues;
}
Also used : UploadingQueueCache(com.fanap.podchat.cachemodel.queue.UploadingQueueCache) ArrayList(java.util.ArrayList) Uploading(com.fanap.podchat.cachemodel.queue.Uploading) MessageVO(com.fanap.podchat.mainmodel.MessageVO)

Aggregations

MessageVO (com.fanap.podchat.mainmodel.MessageVO)48 ArrayList (java.util.ArrayList)34 CacheMessageVO (com.fanap.podchat.cachemodel.CacheMessageVO)25 GapMessageVO (com.fanap.podchat.cachemodel.GapMessageVO)20 Thread (com.fanap.podchat.mainmodel.Thread)20 Test (org.junit.Test)20 ChatResponse (com.fanap.podchat.model.ChatResponse)18 ResultHistory (com.fanap.podchat.model.ResultHistory)18 ChatListener (com.fanap.podchat.chat.ChatListener)15 ResultNewMessage (com.fanap.podchat.model.ResultNewMessage)15 RequestThread (com.fanap.podchat.requestobject.RequestThread)15 PinMessageVO (com.fanap.podchat.mainmodel.PinMessageVO)13 Activity (android.app.Activity)10 Context (android.content.Context)10 Looper (android.os.Looper)10 InstrumentationRegistry (android.support.test.InstrumentationRegistry)10 ActivityTestRule (android.support.test.rule.ActivityTestRule)10 AndroidJUnit4 (android.support.test.runner.AndroidJUnit4)10 BaseApplication (com.example.chat.application.chatexample.BaseApplication)10 ChatActivity (com.example.chat.application.chatexample.ChatActivity)10