Search in sources :

Example 1 with WaitQueueCache

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

the class MessageDatabaseHelper method insertWaitMessageQueue.

/*
     *
     * Failed Queue
     *
     * */
public void insertWaitMessageQueue(@NonNull SendingQueueCache sendingQueue) {
    WaitQueueCache waitMessageQueue = MessageManager.getWaitingFromSendingMessage(sendingQueue);
    worker(() -> messageQueueDao.insertWaitMessageQueue(waitMessageQueue));
}
Also used : WaitQueueCache(com.fanap.podchat.cachemodel.queue.WaitQueueCache)

Example 2 with WaitQueueCache

use of com.fanap.podchat.cachemodel.queue.WaitQueueCache 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 3 with WaitQueueCache

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

the class ChatCore method getWaitQueueCacheFromSendQueue.

private WaitQueueCache getWaitQueueCacheFromSendQueue(SendingQueueCache sendingQueue, String uniqueId2) {
    WaitQueueCache waitMessageQueue = new WaitQueueCache();
    waitMessageQueue.setUniqueId(uniqueId2);
    waitMessageQueue.setId(sendingQueue.getId());
    waitMessageQueue.setAsyncContent(sendingQueue.getAsyncContent());
    waitMessageQueue.setMessage(sendingQueue.getMessage());
    waitMessageQueue.setThreadId(sendingQueue.getThreadId());
    waitMessageQueue.setMessageType(sendingQueue.getMessageType());
    waitMessageQueue.setSystemMetadata(sendingQueue.getSystemMetadata());
    waitMessageQueue.setMetadata(sendingQueue.getMetadata());
    return waitMessageQueue;
}
Also used : WaitQueueCache(com.fanap.podchat.cachemodel.queue.WaitQueueCache)

Example 4 with WaitQueueCache

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

the class ChatCore method moveFromSendingQueueToWaitQueue.

private void moveFromSendingQueueToWaitQueue(String uniqueId, SendingQueueCache sendingQueue) {
    if (cache) {
        // messageDatabaseHelper.deleteSendingMessageQueue(uniqueId);
        // messageDatabaseHelper.insertWaitMessageQueue(sendingQueue);
        dataSource.moveFromSendingToWaitingQueue(uniqueId);
    } else {
        sendingQList.remove(uniqueId);
        WaitQueueCache waitMessageQueue = getWaitQueueCacheFromSendQueue(sendingQueue, sendingQueue.getUniqueId());
        waitQList.put(uniqueId, waitMessageQueue);
    }
}
Also used : WaitQueueCache(com.fanap.podchat.cachemodel.queue.WaitQueueCache)

Example 5 with WaitQueueCache

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

the class ChatCore method checkMessageQueue.

/**
 * When chat is ready its checking the message that was stored in the Sending Queue and if there is any,
 * it's sent them to async
 */
private void checkMessageQueue() {
    try {
        if (log)
            showLog("checkMessageQueue");
        if (cache) {
            dataSource.getAllSendingQueue().doOnError(exception -> {
                handleException(exception);
                captureError(ChatConstant.ERROR_UNKNOWN_EXCEPTION, ChatConstant.ERROR_CODE_UNKNOWN_EXCEPTION, "", exception);
            }).onErrorResumeNext(Observable.empty()).subscribe(sendingQueueCaches -> {
                if (!Util.isNullOrEmpty(sendingQueueCaches)) {
                    for (SendingQueueCache sendingQueue : sendingQueueCaches) {
                        String uniqueId = sendingQueue.getUniqueId();
                        long threadId = sendingQueue.getThreadId();
                        setThreadCallbacks(threadId, uniqueId);
                        dataSource.moveFromSendingToWaitingQueue(uniqueId);
                        JsonObject jsonObject = (new JsonParser()).parse(sendingQueue.getAsyncContent()).getAsJsonObject();
                        jsonObject.remove("token");
                        jsonObject.addProperty("token", getToken());
                        if (log)
                            Log.i(TAG, "checkMessageQueue");
                        String async = jsonObject.toString();
                        sendAsyncMessage(async, AsyncAckType.Constants.WITHOUT_ACK, "SEND_TEXT_MESSAGE_FROM_MESSAGE_QUEUE");
                    }
                }
            });
        // new PodThreadManager().doThisAndGo(() -> {
        // 
        // //                    List<SendingQueueCache> sendingQueueCaches = messageDatabaseHelper.getAllSendingQueue();
        // List<SendingQueueCache> sendingQueueCaches = dataSource.getAllSendingQueue();
        // 
        // if (!Util.isNullOrEmpty(sendingQueueCaches)) {
        // for (SendingQueueCache sendingQueue : sendingQueueCaches) {
        // String uniqueId = sendingQueue.getUniqueId();
        // long threadId = sendingQueue.getThreadId();
        // setThreadCallbacks(threadId, uniqueId);
        // 
        // //                            messageDatabaseHelper.insertWaitMessageQueue(sendingQueue);
        // //                            messageDatabaseHelper.deleteSendingMessageQueue(uniqueId);
        // 
        // dataSource.moveFromSendingToWaitingQueue(uniqueId);
        // 
        // JsonObject jsonObject = (new JsonParser()).parse(sendingQueue.getAsyncContent()).getAsJsonObject();
        // 
        // jsonObject.remove("token");
        // jsonObject.addProperty("token", getToken());
        // 
        // if (log) Log.i(TAG, "checkMessageQueue");
        // String async = jsonObject.toString();
        // sendAsyncMessage(async, AsyncAckType.Constants.WITHOUT_ACK, "SEND_TEXT_MESSAGE_FROM_MESSAGE_QUEUE");
        // }
        // }
        // });
        } else {
            if (!sendingQList.isEmpty()) {
                for (SendingQueueCache sendingQueue : sendingQList.values()) {
                    String uniqueId = sendingQueue.getUniqueId();
                    long threadId = sendingQueue.getThreadId();
                    setThreadCallbacks(threadId, uniqueId);
                    WaitQueueCache waitMessageQueue = getWaitQueueCacheFromSendQueue(sendingQueue, uniqueId);
                    waitQList.put(uniqueId, waitMessageQueue);
                    // sendingQList.remove(uniqueId);
                    JsonObject jsonObject = (new JsonParser()).parse(sendingQueue.getAsyncContent()).getAsJsonObject();
                    jsonObject.remove("token");
                    jsonObject.addProperty("token", getToken());
                    sendAsyncMessage(jsonObject.toString(), AsyncAckType.Constants.WITHOUT_ACK, "SEND_TEXT_MESSAGE_FROM_MESSAGE_QUEUE");
                }
                sendingQList.clear();
            }
        }
    } catch (Throwable throwable) {
        showErrorLog(throwable.getMessage());
        onUnknownException("", throwable);
    }
}
Also used : SendingQueueCache(com.fanap.podchat.cachemodel.queue.SendingQueueCache) JsonObject(com.google.gson.JsonObject) WaitQueueCache(com.fanap.podchat.cachemodel.queue.WaitQueueCache) JsonParser(com.google.gson.JsonParser)

Aggregations

WaitQueueCache (com.fanap.podchat.cachemodel.queue.WaitQueueCache)12 SendingQueueCache (com.fanap.podchat.cachemodel.queue.SendingQueueCache)5 ChatListener (com.fanap.podchat.chat.ChatListener)3 MessageVO (com.fanap.podchat.mainmodel.MessageVO)3 ResultNewMessage (com.fanap.podchat.model.ResultNewMessage)3 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 Activity (android.app.Activity)2 Context (android.content.Context)2 Looper (android.os.Looper)2 InstrumentationRegistry (android.support.test.InstrumentationRegistry)2 ActivityTestRule (android.support.test.rule.ActivityTestRule)2 AndroidJUnit4 (android.support.test.runner.AndroidJUnit4)2 BaseApplication (com.example.chat.application.chatexample.BaseApplication)2 ChatActivity (com.example.chat.application.chatexample.ChatActivity)2 APP_ID (com.example.chat.application.chatexample.ChatActivity.APP_ID)2 ChatContract (com.example.chat.application.chatexample.ChatContract)2 ChatPresenter (com.example.chat.application.chatexample.ChatPresenter)2 Chat (com.fanap.podchat.chat.Chat)2 R (com.fanap.podchat.example.R)2