Search in sources :

Example 1 with ResultBlockList

use of com.fanap.podchat.model.ResultBlockList in project pod-chat-android-sdk by FanapSoft.

the class ChatCore method getBlockList.

/**
 * It gets the list of the contacts that is on block list
 */
public String getBlockList(RequestBlockList request, ChatHandler handler) {
    String uniqueId = generateUniqueId();
    PodThreadManager threadManager = new PodThreadManager();
    threadManager.addTask(() -> {
        if (cache && request.useCacheData()) {
            List<BlockedContact> cacheContacts = messageDatabaseHelper.getBlockedContacts(request.getCount(), request.getOffset());
            if (!Util.isNullOrEmpty(cacheContacts)) {
                ChatResponse<ResultBlockList> chatResponse = ContactManager.prepareGetBlockListFromCache(uniqueId, cacheContacts);
                listenerManager.callOnGetBlockList(gson.toJson(chatResponse), chatResponse);
                if (sentryResponseLog) {
                    showLog("RECEIVE_GET_BLOCK_LIST_FROM_CACHE", gson.toJson(chatResponse));
                } else {
                    showLog("RECEIVE_GET_BLOCK_LIST_FROM_CACHE");
                }
            }
        }
    });
    threadManager.addTask(() -> {
        if (chatReady) {
            String asyncContent = ContactManager.prepareGetBlockListRequest(request.getCount(), request.getOffset(), uniqueId, getTypeCode(), getToken());
            setCallBacks(null, null, null, true, Constants.GET_BLOCKED, null, uniqueId);
            sendAsyncMessage(asyncContent, AsyncAckType.Constants.WITHOUT_ACK, "SEND_GET_BLOCK_LIST");
            if (handler != null) {
                handler.onGetBlockList(uniqueId);
            }
        } else {
            captureError(ChatConstant.ERROR_CHAT_READY, ChatConstant.ERROR_CODE_CHAT_READY, uniqueId);
        }
    });
    threadManager.runTasksSynced();
    return uniqueId;
}
Also used : PodThreadManager(com.fanap.podchat.util.PodThreadManager) BlockedContact(com.fanap.podchat.mainmodel.BlockedContact) ResultBlockList(com.fanap.podchat.model.ResultBlockList)

Example 2 with ResultBlockList

use of com.fanap.podchat.model.ResultBlockList in project pod-chat-android-sdk by FanapSoft.

the class ContactManager method prepareGetBlockListFromCache.

public static ChatResponse<ResultBlockList> prepareGetBlockListFromCache(String uniqueId, List<BlockedContact> cacheContacts) {
    ChatResponse<ResultBlockList> chatResponse = new ChatResponse<>();
    chatResponse.setErrorCode(0);
    chatResponse.setHasError(false);
    chatResponse.setUniqueId(uniqueId);
    chatResponse.setCache(true);
    ResultBlockList resultBlockList = new ResultBlockList();
    resultBlockList.setContacts(cacheContacts);
    chatResponse.setResult(resultBlockList);
    return chatResponse;
}
Also used : ChatResponse(com.fanap.podchat.model.ChatResponse) ResultBlockList(com.fanap.podchat.model.ResultBlockList)

Example 3 with ResultBlockList

use of com.fanap.podchat.model.ResultBlockList in project pod-chat-android-sdk by FanapSoft.

the class ContactManager method prepareBlockListResponse.

public static ChatResponse<ResultBlockList> prepareBlockListResponse(ChatMessage chatMessage) {
    ChatResponse<ResultBlockList> chatResponse = new ChatResponse<>();
    chatResponse.setErrorCode(0);
    chatResponse.setHasError(false);
    chatResponse.setUniqueId(chatMessage.getUniqueId());
    ResultBlockList resultBlockList = new ResultBlockList();
    List<BlockedContact> blockedContacts = App.getGson().fromJson(chatMessage.getContent(), new TypeToken<ArrayList<BlockedContact>>() {
    }.getType());
    resultBlockList.setContacts(blockedContacts);
    chatResponse.setResult(resultBlockList);
    return chatResponse;
}
Also used : TypeToken(com.google.gson.reflect.TypeToken) ChatResponse(com.fanap.podchat.model.ChatResponse) BlockedContact(com.fanap.podchat.mainmodel.BlockedContact) ResultBlockList(com.fanap.podchat.model.ResultBlockList)

Aggregations

ResultBlockList (com.fanap.podchat.model.ResultBlockList)3 BlockedContact (com.fanap.podchat.mainmodel.BlockedContact)2 ChatResponse (com.fanap.podchat.model.ChatResponse)2 PodThreadManager (com.fanap.podchat.util.PodThreadManager)1 TypeToken (com.google.gson.reflect.TypeToken)1