Search in sources :

Example 1 with CacheBlockedContact

use of com.fanap.podchat.cachemodel.CacheBlockedContact 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 2 with CacheBlockedContact

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

use of com.fanap.podchat.cachemodel.CacheBlockedContact 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)

Example 4 with CacheBlockedContact

use of com.fanap.podchat.cachemodel.CacheBlockedContact in project pod-chat-android-sdk by FanapSoft.

the class MessageDatabaseHelper method deleteBlockedContactById.

public void deleteBlockedContactById(long id) {
    // updated blocked field in CacheContact
    worker(() -> {
        try {
            CacheBlockedContact cacheBlockedContact = messageDao.getBlockedContactByBlockId(id);
            long contactId = cacheBlockedContact.getContactId();
            if (contactId > 0) {
                messageDao.updateContactBlockedState(false, contactId);
            }
        } catch (Exception e) {
            Log.wtf(TAG, e);
        }
        messageDao.deleteBlockedContactById(id);
    });
}
Also used : CacheBlockedContact(com.fanap.podchat.cachemodel.CacheBlockedContact) IOException(java.io.IOException) ParseException(java.text.ParseException)

Aggregations

CacheBlockedContact (com.fanap.podchat.cachemodel.CacheBlockedContact)4 CacheContact (com.fanap.podchat.cachemodel.CacheContact)3 BlockedContact (com.fanap.podchat.mainmodel.BlockedContact)3 Contact (com.fanap.podchat.mainmodel.Contact)3 RequestSearchContact (com.fanap.podchat.mainmodel.RequestSearchContact)3 ResultContact (com.fanap.podchat.model.ResultContact)3 SimpleDateFormat (java.text.SimpleDateFormat)3 Calendar (java.util.Calendar)3 Date (java.util.Date)3 IOException (java.io.IOException)2 ParseException (java.text.ParseException)2 ArrayList (java.util.ArrayList)2 NonNull (android.support.annotation.NonNull)1 Nullable (android.support.annotation.Nullable)1