Search in sources :

Example 6 with BlockedContact

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

the class MessageDatabaseHelper method saveBlockedContact.

/**
 * Blocked Contacts in Cache
 *
 * @param blockedContact blocked contact
 * @param expireSecond   validation second
 */
public void saveBlockedContact(@NonNull BlockedContact blockedContact, int expireSecond) {
    worker(() -> {
        SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss", Locale.getDefault());
        Calendar c = Calendar.getInstance();
        c.setTime(new Date());
        c.add(Calendar.DATE, expireSecond);
        String expireDate = dateFormat.format(c.getTime());
        Contact contact = blockedContact.getContactVO();
        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);
        }
        messageDao.insertBlockedContact(cacheBlockedContact);
    });
}
Also used : CacheBlockedContact(com.fanap.podchat.cachemodel.CacheBlockedContact) Calendar(java.util.Calendar) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) 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 7 with BlockedContact

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

the class MessageDatabaseHelper method getBlockedContacts.

@NonNull
public List<BlockedContact> getBlockedContacts(Long count, Long offset) {
    List<BlockedContact> contacts = new ArrayList<>();
    List<CacheBlockedContact> cacheBlockedContacts = messageDao.getBlockedContacts(count, offset);
    if (cacheBlockedContacts != null && cacheBlockedContacts.size() > 0) {
        SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss", Locale.getDefault());
        Calendar c = Calendar.getInstance();
        c.setTime(new Date());
        Date nowDate = c.getTime();
        for (CacheBlockedContact blockedContact : cacheBlockedContacts) {
            try {
                Date expireDate = format.parse(blockedContact.getExpireDate());
                if (expireDate != null && expireDate.compareTo(nowDate) < 0) {
                    deleteBlockedContact(blockedContact);
                } else {
                    Contact contactVO = null;
                    if (blockedContact.getContactId() > 0) {
                        CacheContact cacheContact = messageDao.getContactById(blockedContact.getContactId());
                        blockedContact.setCacheContact(cacheContact);
                    }
                    if (blockedContact.getCacheContact() != null) {
                        try {
                            contactVO = new Contact(blockedContact.getCacheContact().getId(), blockedContact.getCacheContact().getFirstName(), blockedContact.getCacheContact().getUserId(), blockedContact.getCacheContact().getLastName(), blockedContact.getCacheContact().getBlocked(), blockedContact.getCacheContact().getCreationDate(), blockedContact.getCacheContact().getLinkedUser(), blockedContact.getCacheContact().getCellphoneNumber(), blockedContact.getCacheContact().getEmail(), blockedContact.getCacheContact().getUniqueId(), blockedContact.getCacheContact().getNotSeenDuration(), blockedContact.getCacheContact().isHasUser(), true, blockedContact.getCacheContact().getProfileImage());
                        } catch (Exception e) {
                            captureException("GET BLOCK LIST", e);
                        }
                    }
                    BlockedContact blocked = new BlockedContact(blockedContact.getBlockId(), blockedContact.getFirstName(), blockedContact.getLastName(), blockedContact.getNickName(), blockedContact.getProfileImage(), blockedContact.getCoreUserId(), contactVO);
                    contacts.add(blocked);
                }
            } catch (ParseException e) {
                captureException("GET BLOCK LIST", e);
            }
        }
    }
    return contacts;
}
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) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) CacheContact(com.fanap.podchat.cachemodel.CacheContact) IOException(java.io.IOException) ParseException(java.text.ParseException) 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) NonNull(android.support.annotation.NonNull)

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