use of com.fanap.podchat.model.ResultAddContact in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method addContact.
/**
* Add one contact to the contact list
* <p>
* firstName and cellphoneNumber or email or username are required
*
* @param username username of contact
* @param firstName Notice: if just put fistName without lastName its ok.
* @param lastName last name of the contact
* @param cellphoneNumber Notice: If you just put the cellPhoneNumber doesn't necessary to add email
* @param email email of the contact
*/
@Deprecated
public String addContact(String firstName, String lastName, String cellphoneNumber, String email, String typeCode, String username) {
if (Util.isNullOrEmpty(firstName)) {
firstName = "";
}
if (Util.isNullOrEmpty(lastName)) {
lastName = "";
}
if (Util.isNullOrEmpty(email)) {
email = "";
}
if (Util.isNullOrEmpty(cellphoneNumber)) {
cellphoneNumber = "";
}
if (Util.isNullOrEmpty(username)) {
username = "";
}
String uniqueId = generateUniqueId();
typeCode = Util.isNullOrEmpty(typeCode) ? getTypeCode() : typeCode;
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("uniqueId", uniqueId);
jsonObject.addProperty("tokenIssuer", 1);
jsonObject.addProperty("firstName", firstName);
jsonObject.addProperty("lastName", lastName);
if (!Util.isNullOrEmpty(cellphoneNumber))
jsonObject.addProperty("cellphoneNumber", cellphoneNumber);
if (!Util.isNullOrEmpty(email))
jsonObject.addProperty("email", email);
if (!Util.isNullOrEmpty(typeCode))
jsonObject.addProperty("typeCode", typeCode);
if (!Util.isNullOrEmpty(username))
jsonObject.addProperty("username", username);
showLog("SEND_ADD_CONTACT", getJsonForLog(jsonObject));
Observable<Response<Contacts>> addContactObservable;
if (chatReady) {
if (!Util.isNullOrEmpty(username)) {
addContactObservable = contactApi.addContactWithUserName(getToken(), 1, firstName, lastName, username, uniqueId, typeCode, "", "");
} else if (Util.isNullOrEmpty(typeCode)) {
addContactObservable = contactApi.addContact(getToken(), 1, firstName, lastName, email, uniqueId, cellphoneNumber);
} else {
addContactObservable = contactApi.addContact(getToken(), 1, firstName, lastName, email, uniqueId, cellphoneNumber, typeCode);
}
addContactObservable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(addContactResponse -> {
if (addContactResponse.isSuccessful()) {
Contacts contacts = addContactResponse.body();
if (contacts != null) {
if (!contacts.getHasError()) {
ChatResponse<ResultAddContact> chatResponse = Util.getReformatOutPutAddContact(contacts, uniqueId);
String contactsJson = gson.toJson(chatResponse);
listenerManager.callOnAddContact(contactsJson, chatResponse);
showLog("RECEIVED_ADD_CONTACT", contactsJson);
if (cache) {
// messageDatabaseHelper.saveContact(chatResponse.getResult().getContact(), getExpireAmount());
dataSource.saveContactResultFromServer(chatResponse.getResult().getContact());
}
} else {
captureError(contacts.getMessage(), contacts.getErrorCode(), uniqueId);
}
}
}
}, (Throwable throwable) -> {
captureError(throwable.getMessage(), ChatConstant.ERROR_CODE_UNKNOWN_EXCEPTION, uniqueId, throwable);
Log.e(TAG, throwable.getMessage());
});
} else {
captureError(ChatConstant.ERROR_CHAT_READY, ChatConstant.ERROR_CODE_CHAT_READY, uniqueId);
}
return uniqueId;
}
use of com.fanap.podchat.model.ResultAddContact in project pod-chat-android-sdk by FanapSoft.
the class CallPresenter method onContactAdded.
@Override
public void onContactAdded(String content, ChatResponse<ResultAddContact> chatResponse) {
super.onContactAdded(content, chatResponse);
Contact c = chatResponse.getResult().getContact();
view.showMessage(c.getFirstName() + " " + c.getLastName() + " " + c.getCellphoneNumber() + " " + c.getEmail() + " " + (c.getLinkedUser() != null ? c.getLinkedUser().getName() + " " + c.getLinkedUser().getUsername() : "") + " اضافه شد");
}
use of com.fanap.podchat.model.ResultAddContact in project pod-chat-android-sdk by FanapSoft.
the class IntegrationTest method addContact.
@Test
public void addContact() {
chatListeners = new ChatListener() {
@Override
public void onContactAdded(String content, ChatResponse<ResultAddContact> response) {
System.out.println("Contact Removed: " + content);
contactContent = content;
resumeProcess();
}
};
chat.addListener(chatListeners);
RequestAddContact request = new RequestAddContact.Builder().firstName("Nadia").lastName("Anvari").username("nadia.anvari").email("nadia.anvari@fanap.ir").build();
chat.addContact(request);
pauseProcess();
System.out.println("Received contact: " + contactContent);
}
use of com.fanap.podchat.model.ResultAddContact in project pod-chat-android-sdk by FanapSoft.
the class ContactManager method prepareAddContactResponse.
public static ChatResponse<ResultAddContact> prepareAddContactResponse(ChatMessage chatMessage) {
Contacts contacts = App.getGson().fromJson(chatMessage.getContent(), Contacts.class);
ChatResponse<ResultAddContact> chatResponse = new ChatResponse<>();
chatResponse.setUniqueId(chatMessage.getUniqueId());
ResultAddContact resultAddContact = new ResultAddContact();
resultAddContact.setContentCount(1);
Contact contact = new Contact();
contact.setCellphoneNumber(contacts.getResult().get(0).getCellphoneNumber());
contact.setEmail(contacts.getResult().get(0).getEmail());
contact.setFirstName(contacts.getResult().get(0).getFirstName());
contact.setId(contacts.getResult().get(0).getId());
contact.setLastName(contacts.getResult().get(0).getLastName());
contact.setUniqueId(contacts.getResult().get(0).getUniqueId());
// add linked user
LinkedUser linkedUser = contacts.getResult().get(0).getLinkedUser();
if (linkedUser != null)
contact.setLinkedUser(linkedUser);
resultAddContact.setContact(contact);
chatResponse.setResult(resultAddContact);
return chatResponse;
}
use of com.fanap.podchat.model.ResultAddContact in project pod-chat-android-sdk by FanapSoft.
the class Util method getReformatOutPutAddContact.
@NonNull
public static ChatResponse<ResultAddContact> getReformatOutPutAddContact(Contacts contacts, String uniqueId) {
ChatResponse<ResultAddContact> chatResponse = new ChatResponse<>();
chatResponse.setUniqueId(uniqueId);
ResultAddContact resultAddContact = new ResultAddContact();
resultAddContact.setContentCount(1);
Contact contact = new Contact();
contact.setCellphoneNumber(contacts.getResult().get(0).getCellphoneNumber());
contact.setEmail(contacts.getResult().get(0).getEmail());
contact.setFirstName(contacts.getResult().get(0).getFirstName());
contact.setId(contacts.getResult().get(0).getId());
contact.setLastName(contacts.getResult().get(0).getLastName());
contact.setUniqueId(contacts.getResult().get(0).getUniqueId());
// add linked user
LinkedUser linkedUser = contacts.getResult().get(0).getLinkedUser();
if (linkedUser != null)
contact.setLinkedUser(linkedUser);
resultAddContact.setContact(contact);
chatResponse.setResult(resultAddContact);
return chatResponse;
}
Aggregations