Search in sources :

Example 6 with Callback

use of com.fanap.podchat.util.Callback in project pod-chat-android-sdk by FanapSoft.

the class DbTest method justFirstMsgIdC3.

@Test
public void justFirstMsgIdC3() {
    Callback callback = new Callback();
    long threadId = 2;
    callback.setOffset(0);
    callback.setCount(2);
    callback.setOrder("asc");
    callback.setFirstMessageId(9236);
// MessageVO messageVO = new MessageVO(
// 5653,
// false,
// false,
// false,
// false,
// false,
// "91efe7da-547f-4c5f-c34b-0442951ffbbc",
// 0,
// 5652,
// "",
// null,
// 13354321,
// 321000000,
// "",
// null,
// null,
// null,
// null
// );
// messageDatabaseHelper.updateGetHistoryResponse(callback);
}
Also used : Callback(com.fanap.podchat.util.Callback) Test(org.junit.Test)

Example 7 with Callback

use of com.fanap.podchat.util.Callback 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 8 with Callback

use of com.fanap.podchat.util.Callback in project pod-chat-android-sdk by FanapSoft.

the class DbTest method justFirstMsgIdsetConditional1.

// first message id conditional 1
// cache siz more than one but server size is 1
@Test
public void justFirstMsgIdsetConditional1() {
    Callback callback = new Callback();
    long threadId = 2;
    // MessageVO messageVO = new MessageVO(
    // 5653,
    // false,
    // false,
    // false,
    // false,
    // false,
    // "91efe7da-547f-4c5f-c34b-0442951ffbbc",
    // 0,
    // 5652,
    // "",
    // null,
    // 13354321,
    // 321000000,
    // "",
    // null,
    // null,
    // null,
    // null
    // );
    callback.setOffset(0);
    callback.setCount(2);
    callback.setOrder("asc");
    callback.setFirstMessageId(9261);
    messageDatabaseHelper.updateGetHistoryResponse(callback, null, threadId, null);
}
Also used : Callback(com.fanap.podchat.util.Callback) Test(org.junit.Test)

Example 9 with Callback

use of com.fanap.podchat.util.Callback in project pod-chat-android-sdk by FanapSoft.

the class ChatCore method handleDelivery.

private void handleDelivery(ChatMessage chatMessage, String messageUniqueId, long threadId) {
    try {
        if (threadCallbacks.containsKey(threadId)) {
            ArrayList<Callback> callbacks = threadCallbacks.get(threadId);
            if (callbacks != null) {
                for (Callback callback : callbacks) {
                    if (messageUniqueId.equals(callback.getUniqueId())) {
                        int indexUnique = callbacks.indexOf(callback);
                        while (indexUnique > -1) {
                            if (callbacks.get(indexUnique).isDelivery()) {
                                ChatResponse<ResultMessage> chatResponse = new ChatResponse<>();
                                ResultMessage resultMessage = gson.fromJson(chatMessage.getContent(), ResultMessage.class);
                                chatResponse.setErrorMessage("");
                                chatResponse.setErrorCode(0);
                                chatResponse.setHasError(false);
                                chatResponse.setUniqueId(callback.getUniqueId());
                                chatResponse.setResult(resultMessage);
                                String json = gson.toJson(chatResponse);
                                listenerManager.callOnDeliveryMessage(json, chatResponse);
                                Callback callbackUpdateSent = new Callback();
                                callbackUpdateSent.setSent(callback.isSent());
                                callbackUpdateSent.setDelivery(false);
                                callbackUpdateSent.setSeen(callback.isSeen());
                                callbackUpdateSent.setUniqueId(callback.getUniqueId());
                                callbacks.set(indexUnique, callbackUpdateSent);
                                threadCallbacks.put(threadId, callbacks);
                                if (sentryResponseLog) {
                                    showLog("RECEIVED_DELIVERED_MESSAGE", json);
                                } else {
                                    showLog("RECEIVED_DELIVERED_MESSAGE");
                                }
                            }
                            indexUnique--;
                        }
                        break;
                    }
                }
            }
        }
    } catch (Exception e) {
        showErrorLog(e.getMessage());
        onUnknownException(chatMessage.getUniqueId(), e);
    }
}
Also used : Callback(com.fanap.podchat.util.Callback) ChatResponse(com.fanap.podchat.model.ChatResponse) ResultMessage(com.fanap.podchat.model.ResultMessage) JSONException(org.json.JSONException) SentryException(io.sentry.core.protocol.SentryException) IOException(java.io.IOException) JsonSyntaxException(com.google.gson.JsonSyntaxException) PodChatException(com.fanap.podchat.util.PodChatException) RoomIntegrityException(com.fanap.podchat.persistance.RoomIntegrityException)

Example 10 with Callback

use of com.fanap.podchat.util.Callback in project pod-chat-android-sdk by FanapSoft.

the class ChatCore method setCallBacks.

private void setCallBacks(long firstMessageId, long lastMessageId, String order, long count, Long offset, String uniqueId, long msgId, boolean messageCriteriaVO, String query) {
    try {
        if (chatReady || asyncReady) {
            offset = offset != null ? offset : 0;
            Callback callback = new Callback();
            callback.setFirstMessageId(firstMessageId);
            callback.setLastMessageId(lastMessageId);
            callback.setOffset(offset);
            callback.setCount(count);
            callback.setOrder(order);
            callback.setMessageId(msgId);
            callback.setResult(true);
            callback.setQuery(query);
            callback.setMetadataCriteria(messageCriteriaVO);
            callback.setRequestType(Constants.GET_HISTORY);
            messageCallbacks.put(uniqueId, callback);
        }
    } catch (Exception e) {
        showErrorLog(e.getMessage());
        onUnknownException(uniqueId, e);
    }
}
Also used : Callback(com.fanap.podchat.util.Callback) JSONException(org.json.JSONException) SentryException(io.sentry.core.protocol.SentryException) IOException(java.io.IOException) JsonSyntaxException(com.google.gson.JsonSyntaxException) PodChatException(com.fanap.podchat.util.PodChatException) RoomIntegrityException(com.fanap.podchat.persistance.RoomIntegrityException)

Aggregations

Callback (com.fanap.podchat.util.Callback)18 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)7 CacheMessageVO (com.fanap.podchat.cachemodel.CacheMessageVO)5 MessageVO (com.fanap.podchat.mainmodel.MessageVO)5 PodChatException (com.fanap.podchat.util.PodChatException)5 RoomIntegrityException (com.fanap.podchat.persistance.RoomIntegrityException)4 JsonSyntaxException (com.google.gson.JsonSyntaxException)4 SentryException (io.sentry.core.protocol.SentryException)4 IOException (java.io.IOException)4 JSONException (org.json.JSONException)4 ChatResponse (com.fanap.podchat.model.ChatResponse)3 ResultMessage (com.fanap.podchat.model.ResultMessage)3 SendingQueueCache (com.fanap.podchat.cachemodel.queue.SendingQueueCache)1 ChatMessage (com.fanap.podchat.mainmodel.ChatMessage)1 Constants (com.fanap.podchat.util.ChatMessageType.Constants)1