Search in sources :

Example 1 with BlockedContact

use of com.fanap.podchat.mainmodel.BlockedContact in project pod-chat-android-sdk by FanapSoft.

the class ChatCore method handleUnBlock.

private void handleUnBlock(ChatMessage chatMessage, String messageUniqueId) {
    BlockedContact contact = gson.fromJson(chatMessage.getContent(), BlockedContact.class);
    ChatResponse<ResultBlock> chatResponse = new ChatResponse<>();
    ResultBlock resultBlock = new ResultBlock();
    resultBlock.setContact(contact);
    chatResponse.setResult(resultBlock);
    chatResponse.setErrorCode(0);
    chatResponse.setHasError(false);
    chatResponse.setUniqueId(chatMessage.getUniqueId());
    String jsonUnBlock = gson.toJson(chatResponse);
    if (sentryResponseLog) {
        showLog("RECEIVE_UN_BLOCK", jsonUnBlock);
    } else {
        showLog("RECEIVE_UN_BLOCK");
    }
    messageCallbacks.remove(messageUniqueId);
    if (cache) {
        dataSource.deleteBlockedContactById(contact.getBlockId());
    }
    listenerManager.callOnUnBlock(jsonUnBlock, chatResponse);
}
Also used : BlockedContact(com.fanap.podchat.mainmodel.BlockedContact) ChatResponse(com.fanap.podchat.model.ChatResponse) ResultBlock(com.fanap.podchat.model.ResultBlock)

Example 2 with BlockedContact

use of com.fanap.podchat.mainmodel.BlockedContact 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 3 with BlockedContact

use of com.fanap.podchat.mainmodel.BlockedContact in project pod-chat-android-sdk by FanapSoft.

the class MessageDatabaseHelper method saveBlockedContacts.

public void saveBlockedContacts(@NonNull List<BlockedContact> contacts, int expireAmount) {
    worker(() -> {
        List<CacheBlockedContact> cacheBlockedContacts = new ArrayList<>();
        for (BlockedContact blockedContact : contacts) {
            SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss", Locale.getDefault());
            Calendar c = Calendar.getInstance();
            c.setTime(new Date());
            c.add(Calendar.SECOND, expireAmount);
            String expireDate = format.format(c.getTime());
            @Nullable Contact contact = blockedContact.getContactVO();
            // BlockedContact to CacheBlockedContact
            CacheBlockedContact cacheBlockedContact;
            if (contact != null) {
                CacheContact cacheContact = getCacheContact(expireDate, contact, true, null);
                cacheBlockedContact = getCacheBlockedContact(blockedContact, expireDate, cacheContact);
                saveContactVoInBlockedContact(cacheContact);
            } else {
                cacheBlockedContact = getCacheBlockedContact(blockedContact, expireDate, null);
            }
            cacheBlockedContacts.add(cacheBlockedContact);
        }
        if (cacheBlockedContacts.size() > 0)
            messageDao.insertBlockedContacts(cacheBlockedContacts);
    });
}
Also used : CacheBlockedContact(com.fanap.podchat.cachemodel.CacheBlockedContact) BlockedContact(com.fanap.podchat.mainmodel.BlockedContact) CacheBlockedContact(com.fanap.podchat.cachemodel.CacheBlockedContact) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Nullable(android.support.annotation.Nullable) CacheContact(com.fanap.podchat.cachemodel.CacheContact) ResultContact(com.fanap.podchat.model.ResultContact) BlockedContact(com.fanap.podchat.mainmodel.BlockedContact) RequestSearchContact(com.fanap.podchat.mainmodel.RequestSearchContact) Contact(com.fanap.podchat.mainmodel.Contact) CacheContact(com.fanap.podchat.cachemodel.CacheContact) CacheBlockedContact(com.fanap.podchat.cachemodel.CacheBlockedContact)

Example 4 with BlockedContact

use of com.fanap.podchat.mainmodel.BlockedContact in project pod-chat-android-sdk by FanapSoft.

the class ChatCore method handleOutPutBlock.

private void handleOutPutBlock(ChatMessage chatMessage, String messageUniqueId) {
    BlockedContact contact = gson.fromJson(chatMessage.getContent(), BlockedContact.class);
    ChatResponse<ResultBlock> chatResponse = new ChatResponse<>();
    ResultBlock resultBlock = new ResultBlock();
    resultBlock.setContact(contact);
    chatResponse.setResult(resultBlock);
    chatResponse.setErrorCode(0);
    chatResponse.setHasError(false);
    chatResponse.setUniqueId(chatMessage.getUniqueId());
    String jsonBlock = gson.toJson(chatResponse);
    if (cache) {
        dataSource.saveBlockedContactResultFromServer(contact);
    }
    if (sentryResponseLog) {
        showLog("RECEIVE_BLOCK", jsonBlock);
    } else {
        showLog("RECEIVE_BLOCK");
    }
    messageCallbacks.remove(messageUniqueId);
    listenerManager.callOnBlock(jsonBlock, chatResponse);
}
Also used : BlockedContact(com.fanap.podchat.mainmodel.BlockedContact) ChatResponse(com.fanap.podchat.model.ChatResponse) ResultBlock(com.fanap.podchat.model.ResultBlock)

Example 5 with BlockedContact

use of com.fanap.podchat.mainmodel.BlockedContact 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

BlockedContact (com.fanap.podchat.mainmodel.BlockedContact)7 CacheBlockedContact (com.fanap.podchat.cachemodel.CacheBlockedContact)3 CacheContact (com.fanap.podchat.cachemodel.CacheContact)3 Contact (com.fanap.podchat.mainmodel.Contact)3 RequestSearchContact (com.fanap.podchat.mainmodel.RequestSearchContact)3 ChatResponse (com.fanap.podchat.model.ChatResponse)3 ResultContact (com.fanap.podchat.model.ResultContact)3 SimpleDateFormat (java.text.SimpleDateFormat)3 Calendar (java.util.Calendar)3 Date (java.util.Date)3 ResultBlock (com.fanap.podchat.model.ResultBlock)2 ResultBlockList (com.fanap.podchat.model.ResultBlockList)2 ArrayList (java.util.ArrayList)2 NonNull (android.support.annotation.NonNull)1 Nullable (android.support.annotation.Nullable)1 PodThreadManager (com.fanap.podchat.util.PodThreadManager)1 TypeToken (com.google.gson.reflect.TypeToken)1 IOException (java.io.IOException)1 ParseException (java.text.ParseException)1