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);
});
}
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;
}
Aggregations