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