Search in sources :

Example 1 with ResultAddContact

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;
}
Also used : ChatResponse(com.fanap.podchat.model.ChatResponse) Response(retrofit2.Response) Contacts(com.fanap.podchat.model.Contacts) JsonObject(com.google.gson.JsonObject) ResultAddContact(com.fanap.podchat.model.ResultAddContact)

Example 2 with ResultAddContact

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() : "") + " اضافه شد");
}
Also used : ResultContact(com.fanap.podchat.model.ResultContact) ResultAddContact(com.fanap.podchat.model.ResultAddContact) RequestGetContact(com.fanap.podchat.requestobject.RequestGetContact) Contact(com.fanap.podchat.mainmodel.Contact)

Example 3 with ResultAddContact

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);
}
Also used : ChatListener(com.fanap.podchat.chat.ChatListener) ResultAddContact(com.fanap.podchat.model.ResultAddContact) RequestAddContact(com.fanap.podchat.requestobject.RequestAddContact) Test(org.junit.Test) LargeTest(android.support.test.filters.LargeTest)

Example 4 with ResultAddContact

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;
}
Also used : Contacts(com.fanap.podchat.model.Contacts) ChatResponse(com.fanap.podchat.model.ChatResponse) ResultAddContact(com.fanap.podchat.model.ResultAddContact) LinkedUser(com.fanap.podchat.mainmodel.LinkedUser) BlockedContact(com.fanap.podchat.mainmodel.BlockedContact) ResultRemoveContact(com.fanap.podchat.model.ResultRemoveContact) Contact(com.fanap.podchat.mainmodel.Contact) ResultAddContact(com.fanap.podchat.model.ResultAddContact) RequestAddContact(com.fanap.podchat.requestobject.RequestAddContact)

Example 5 with ResultAddContact

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;
}
Also used : ChatResponse(com.fanap.podchat.model.ChatResponse) ResultAddContact(com.fanap.podchat.model.ResultAddContact) LinkedUser(com.fanap.podchat.mainmodel.LinkedUser) Contact(com.fanap.podchat.mainmodel.Contact) ResultAddContact(com.fanap.podchat.model.ResultAddContact) NonNull(android.support.annotation.NonNull)

Aggregations

ResultAddContact (com.fanap.podchat.model.ResultAddContact)5 Contact (com.fanap.podchat.mainmodel.Contact)3 ChatResponse (com.fanap.podchat.model.ChatResponse)3 LinkedUser (com.fanap.podchat.mainmodel.LinkedUser)2 Contacts (com.fanap.podchat.model.Contacts)2 RequestAddContact (com.fanap.podchat.requestobject.RequestAddContact)2 NonNull (android.support.annotation.NonNull)1 LargeTest (android.support.test.filters.LargeTest)1 ChatListener (com.fanap.podchat.chat.ChatListener)1 BlockedContact (com.fanap.podchat.mainmodel.BlockedContact)1 ResultContact (com.fanap.podchat.model.ResultContact)1 ResultRemoveContact (com.fanap.podchat.model.ResultRemoveContact)1 RequestGetContact (com.fanap.podchat.requestobject.RequestGetContact)1 JsonObject (com.google.gson.JsonObject)1 Test (org.junit.Test)1 Response (retrofit2.Response)1