use of com.fanap.podchat.model.ResultUpdateContact 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;
}
Aggregations