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