Search in sources :

Example 1 with SendingQueueCache

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

the class MessageManager method generateSendingQueueCache.

public static SendingQueueCache generateSendingQueueCache(long threadId, long messageId, String uniqueId, String typecode, String token) {
    SendingQueueCache sendingQueue = new SendingQueueCache();
    sendingQueue.setUniqueId(uniqueId);
    MessageVO messageVO = new MessageVO();
    messageVO.setId(messageId);
    messageVO.setUniqueId(uniqueId);
    sendingQueue.setThreadId(threadId);
    String queueAsyncContent = CreateAsyncContentForQueue(threadId, messageId, uniqueId, typecode, token);
    sendingQueue.setAsyncContent(queueAsyncContent);
    return sendingQueue;
}
Also used : SendingQueueCache(com.fanap.podchat.cachemodel.queue.SendingQueueCache) MessageVO(com.fanap.podchat.mainmodel.MessageVO)

Example 2 with SendingQueueCache

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

the class MessageDatabaseHelper method moveFromSendQueueToWaitQueue.

public void moveFromSendQueueToWaitQueue(String uniqueId) {
    getThreadManager().doThisSafe(() -> {
        SendingQueueCache sendingQueue = getSendingQueueCache(uniqueId);
        deleteSendingMessageQueue(uniqueId);
        insertWaitMessageQueue(sendingQueue);
    });
}
Also used : SendingQueueCache(com.fanap.podchat.cachemodel.queue.SendingQueueCache)

Example 3 with SendingQueueCache

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

the class MessageDatabaseHelper method moveFromWaitQueueToSendQueue.

public void moveFromWaitQueueToSendQueue(String uniqueId, OnWorkDone listener) {
    getThreadManager().doThisAndGo(() -> {
        SendingQueueCache sendingQueue = getWaitQueueMsgByUnique(uniqueId);
        deleteWaitQueueMsgs(uniqueId);
        insertSendingMessageQueue(sendingQueue);
        listener.onWorkDone(sendingQueue);
    });
}
Also used : SendingQueueCache(com.fanap.podchat.cachemodel.queue.SendingQueueCache)

Example 4 with SendingQueueCache

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

the class MemoryDataSource method moveFromWaitingQueueToSendingQueue.

public Observable<SendingQueueCache> moveFromWaitingQueueToSendingQueue(String uniqueId) {
    return Observable.create(em -> {
        WaitQueueCache waiting = deleteFromWaitingQueue(uniqueId);
        if (null != waiting) {
            SendingQueueCache sending = MessageManager.getSendingFromWaitingMessage(waiting);
            insertToSendingQueue(sending);
            em.onNext(sending);
        } else
            em.onCompleted();
    });
}
Also used : SendingQueueCache(com.fanap.podchat.cachemodel.queue.SendingQueueCache) WaitQueueCache(com.fanap.podchat.cachemodel.queue.WaitQueueCache)

Example 5 with SendingQueueCache

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

the class ChatCore method mainReplyMessage.

private String mainReplyMessage(String messageContent, long threadId, long messageId, String systemMetaData, Integer messageType, String metaData, String iUniqueId, ChatHandler handler) {
    String uniqueId = iUniqueId;
    if (iUniqueId == null)
        uniqueId = generateUniqueId();
    /* Add to sending Queue*/
    SendingQueueCache sendingQueue = new SendingQueueCache();
    sendingQueue.setSystemMetadata(systemMetaData);
    sendingQueue.setMessageType(messageType);
    sendingQueue.setThreadId(threadId);
    sendingQueue.setUniqueId(uniqueId);
    sendingQueue.setMessage(messageContent);
    sendingQueue.setMetadata(metaData);
    ChatMessage chatMessage = new ChatMessage();
    chatMessage.setUniqueId(uniqueId);
    chatMessage.setRepliedTo(messageId);
    chatMessage.setSubjectId(threadId);
    chatMessage.setTokenIssuer("1");
    chatMessage.setToken(getToken());
    chatMessage.setContent(messageContent);
    chatMessage.setMetadata(metaData);
    chatMessage.setSystemMetadata(systemMetaData);
    chatMessage.setType(Constants.MESSAGE);
    chatMessage.setTypeCode(getTypeCode());
    chatMessage.setMessageType(messageType);
    JsonObject jsonObject = (JsonObject) gson.toJsonTree(chatMessage);
    if (Util.isNullOrEmpty(systemMetaData)) {
        jsonObject.remove("systemMetaData");
    }
    if (Util.isNullOrEmpty(metaData)) {
        jsonObject.remove("metadata");
    }
    jsonObject.remove("time");
    String asyncContent = jsonObject.toString();
    sendingQueue.setAsyncContent(asyncContent);
    insertToSendQueue(uniqueId, sendingQueue);
    if (log)
        Log.i(TAG, "Message with this" + "uniqueId" + uniqueId + "has been added to Message Queue");
    if (chatReady) {
        moveFromSendingQueueToWaitQueue(uniqueId, sendingQueue);
        setThreadCallbacks(threadId, uniqueId);
        sendAsyncMessage(asyncContent, AsyncAckType.Constants.WITHOUT_ACK, "SEND_REPLY_MESSAGE");
        stopTyping();
        if (handler != null) {
            handler.onReplyMessage(uniqueId);
        }
    } else {
        captureError(ChatConstant.ERROR_CHAT_READY, ChatConstant.ERROR_CODE_CHAT_READY, uniqueId);
    }
    return uniqueId;
}
Also used : SendingQueueCache(com.fanap.podchat.cachemodel.queue.SendingQueueCache) ChatMessage(com.fanap.podchat.mainmodel.ChatMessage) JsonObject(com.google.gson.JsonObject)

Aggregations

SendingQueueCache (com.fanap.podchat.cachemodel.queue.SendingQueueCache)14 WaitQueueCache (com.fanap.podchat.cachemodel.queue.WaitQueueCache)4 JsonObject (com.google.gson.JsonObject)4 MessageVO (com.fanap.podchat.mainmodel.MessageVO)3 ArrayList (java.util.ArrayList)3 ChatMessage (com.fanap.podchat.mainmodel.ChatMessage)2 Activity (android.app.Activity)1 Context (android.content.Context)1 Looper (android.os.Looper)1 InstrumentationRegistry (android.support.test.InstrumentationRegistry)1 ActivityTestRule (android.support.test.rule.ActivityTestRule)1 AndroidJUnit4 (android.support.test.runner.AndroidJUnit4)1 BaseApplication (com.example.chat.application.chatexample.BaseApplication)1 ChatActivity (com.example.chat.application.chatexample.ChatActivity)1 APP_ID (com.example.chat.application.chatexample.ChatActivity.APP_ID)1 ChatContract (com.example.chat.application.chatexample.ChatContract)1 ChatPresenter (com.example.chat.application.chatexample.ChatPresenter)1 Sending (com.fanap.podchat.cachemodel.queue.Sending)1 Chat (com.fanap.podchat.chat.Chat)1 ChatListener (com.fanap.podchat.chat.ChatListener)1