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));
}
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();
});
}
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;
}
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);
}
}
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);
}
}
Aggregations