use of com.fanap.podchat.model.ChatResponse in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method syncContact.
/**
* First we get the contact from server then at the respond of that
*
* @param activity its for check the permission of reading the phone contact
* {@link #getPhoneContact(Context, String, OnContactLoaded)}
*/
public String syncContact(Activity activity) {
showLog(">>> Start Syncing... " + new Date());
String uniqueId = generateUniqueId();
if (Permission.Check_READ_CONTACTS(activity)) {
if (chatReady) {
getPhoneContact(getContext(), uniqueId, phoneContacts -> {
if (phoneContacts.size() > 0) {
if (sentryResponseLog) {
showLog(">>> Synchronizing " + phoneContacts.size() + " with server at " + new Date());
} else {
showLog(">>> Synchronizing");
}
handleAddContacts(uniqueId, phoneContacts);
} else {
showLog(">>> No New Contact Found. Everything is synced ");
ChatResponse<Contacts> chatResponse = new ChatResponse<>();
chatResponse.setUniqueId(uniqueId);
Contacts contacts = new Contacts();
contacts.setCount(0);
contacts.setResult(new ArrayList<>());
chatResponse.setResult(contacts);
listenerManager.callOnSyncContact(gson.toJson(chatResponse), chatResponse);
if (log)
showLog("SYNC_CONTACT_COMPLETED");
}
});
} else {
onChatNotReady(uniqueId);
}
} else {
String jsonError = captureError(ChatConstant.ERROR_READ_CONTACT_PERMISSION, ChatConstant.ERROR_CODE_READ_CONTACT_PERMISSION, uniqueId);
Permission.Request_READ_CONTACTS(activity, READ_CONTACTS_CODE);
if (log)
Log.e(TAG, jsonError);
}
return uniqueId;
}
use of com.fanap.podchat.model.ChatResponse in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method updateContact.
/**
* Update contacts
* all of the params all required to update
*/
public String updateContact(long userId, String firstName, String lastName, String cellphoneNumber, String email) {
String uniqueId = generateUniqueId();
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("uniqueId", uniqueId);
jsonObject.addProperty("id", userId);
jsonObject.addProperty("tokenIssuer", 1);
jsonObject.addProperty("firstName", firstName);
jsonObject.addProperty("lastName", lastName);
jsonObject.addProperty("cellphoneNumber", cellphoneNumber);
jsonObject.addProperty("email", email);
showLog("SEND_UPDATE_CONTACT", getJsonForLog(jsonObject));
if (Util.isNullOrEmpty(firstName)) {
firstName = "";
}
if (Util.isNullOrEmpty(lastName)) {
lastName = "";
}
if (Util.isNullOrEmpty(cellphoneNumber)) {
cellphoneNumber = "";
}
if (Util.isNullOrEmpty(email)) {
email = "";
}
if (chatReady) {
Observable<Response<UpdateContact>> updateContactObservable;
if (Util.isNullOrEmpty(getTypeCode())) {
updateContactObservable = contactApi.updateContact(getToken(), 1, userId, firstName, lastName, email, uniqueId, cellphoneNumber);
} else {
updateContactObservable = contactApi.updateContact(getToken(), 1, userId, firstName, lastName, email, uniqueId, cellphoneNumber, getTypeCode());
}
updateContactObservable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(response -> {
UpdateContact updateContact = response.body();
if (updateContact != null && response.isSuccessful()) {
if (response.body() != null) {
if (!response.body().getHasError()) {
ChatResponse<ResultUpdateContact> chatResponse = new ChatResponse<>();
chatResponse.setUniqueId(uniqueId);
ResultUpdateContact resultUpdateContact = new ResultUpdateContact();
if (!Util.isNullOrEmpty(updateContact.getCount())) {
resultUpdateContact.setContentCount(updateContact.getCount());
}
resultUpdateContact.setContacts(updateContact.getResult());
chatResponse.setResult(resultUpdateContact);
String json = gson.toJson(chatResponse);
listenerManager.callOnUpdateContact(json, chatResponse);
if (cache) {
// messageDatabaseHelper.saveContact(updateContact.getResult().get(0), getExpireAmount());
dataSource.saveContactsResultFromServer(updateContact.getResult());
}
showLog("RECEIVE_UPDATE_CONTACT", json);
} else {
String errorMsg = response.body().getMessage();
int errorCodeMsg = response.body().getErrorCode();
errorMsg = errorMsg != null ? errorMsg : "";
captureError(errorMsg, errorCodeMsg, uniqueId);
}
}
}
}, (Throwable throwable) -> {
if (throwable != null) {
captureError(throwable.getMessage(), ChatConstant.ERROR_CODE_UNKNOWN_EXCEPTION, uniqueId, throwable);
}
});
} else {
captureError(ChatConstant.ERROR_CHAT_READY, ChatConstant.ERROR_CODE_CHAT_READY, uniqueId);
}
return uniqueId;
}
use of com.fanap.podchat.model.ChatResponse in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method onThreadLastMessageUpdated.
private void onThreadLastMessageUpdated(Thread thread, String uniqueId) {
ResultThread resultThread = new ResultThread();
resultThread.setThread(thread);
ChatResponse<ResultThread> chatResponse = new ChatResponse<>();
chatResponse.setResult(resultThread);
chatResponse.setUniqueId(uniqueId);
chatResponse.setSubjectId(thread.getId());
if (sentryResponseLog) {
showLog("THREAD_INFO_UPDATED", chatResponse.getJson());
} else {
showLog("THREAD_INFO_UPDATED");
}
if (cache) {
dataSource.saveThreadResultFromCache(thread);
}
listenerManager.callOnThreadInfoUpdated(chatResponse.getJson(), chatResponse);
}
use of com.fanap.podchat.model.ChatResponse in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method handleDelivery.
private void handleDelivery(ChatMessage chatMessage, String messageUniqueId, long threadId) {
try {
if (threadCallbacks.containsKey(threadId)) {
ArrayList<Callback> callbacks = threadCallbacks.get(threadId);
if (callbacks != null) {
for (Callback callback : callbacks) {
if (messageUniqueId.equals(callback.getUniqueId())) {
int indexUnique = callbacks.indexOf(callback);
while (indexUnique > -1) {
if (callbacks.get(indexUnique).isDelivery()) {
ChatResponse<ResultMessage> chatResponse = new ChatResponse<>();
ResultMessage resultMessage = gson.fromJson(chatMessage.getContent(), ResultMessage.class);
chatResponse.setErrorMessage("");
chatResponse.setErrorCode(0);
chatResponse.setHasError(false);
chatResponse.setUniqueId(callback.getUniqueId());
chatResponse.setResult(resultMessage);
String json = gson.toJson(chatResponse);
listenerManager.callOnDeliveryMessage(json, chatResponse);
Callback callbackUpdateSent = new Callback();
callbackUpdateSent.setSent(callback.isSent());
callbackUpdateSent.setDelivery(false);
callbackUpdateSent.setSeen(callback.isSeen());
callbackUpdateSent.setUniqueId(callback.getUniqueId());
callbacks.set(indexUnique, callbackUpdateSent);
threadCallbacks.put(threadId, callbacks);
if (sentryResponseLog) {
showLog("RECEIVED_DELIVERED_MESSAGE", json);
} else {
showLog("RECEIVED_DELIVERED_MESSAGE");
}
}
indexUnique--;
}
break;
}
}
}
}
} catch (Exception e) {
showErrorLog(e.getMessage());
onUnknownException(chatMessage.getUniqueId(), e);
}
}
use of com.fanap.podchat.model.ChatResponse in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method handleOnGetUserInfo.
/**
* Its check the Failed Queue {@link #checkMessageQueue()} to send all the message that is waiting to be send.
*/
private void handleOnGetUserInfo(ChatMessage chatMessage, String messageUniqueId, Callback callback) {
if (callback.isResult()) {
// if there is a key its ok if not it will go for the key and then chat ready
ChatResponse<ResultUserInfo> chatResponse = new ChatResponse<>();
UserInfo userInfo = gson.fromJson(chatMessage.getContent(), UserInfo.class);
setUserId(userInfo.getId());
setChatReady("CHAT_READY", true);
userInfoResponse = true;
// add user info for sentry
setSentryUser(userInfo);
String userInfoJson = reformatUserInfo(chatMessage, chatResponse, userInfo);
if (sentryResponseLog) {
showLog("RECEIVE_USER_INFO", userInfoJson);
} else {
showLog("RECEIVE_USER_INFO");
}
pingWithDelay();
messageCallbacks.remove(messageUniqueId);
listenerManager.callOnUserInfo(userInfoJson, chatResponse);
}
}
Aggregations