Search in sources :

Example 16 with Contact

use of com.fanap.podchat.mainmodel.Contact in project pod-chat-android-sdk by FanapSoft.

the class ChatCore method reformatGetContactResponse.

@NonNull
private ChatResponse<ResultContact> reformatGetContactResponse(ChatMessage chatMessage, Callback callback) {
    ResultContact resultContact = new ResultContact();
    ChatResponse<ResultContact> outPutContact = new ChatResponse<>();
    ArrayList<Contact> contacts = gson.fromJson(chatMessage.getContent(), new TypeToken<ArrayList<Contact>>() {
    }.getType());
    if (cache) {
        // messageDatabaseHelper.saveContacts(contacts, getExpireAmount());
        dataSource.saveContactsResultFromServer(contacts);
    }
    resultContact.setContacts(contacts);
    resultContact.setContentCount(chatMessage.getContentCount());
    resultContact.setHasNext(contacts.size() + callback.getOffset() < chatMessage.getContentCount());
    resultContact.setNextOffset(callback.getOffset() + contacts.size());
    resultContact.setContentCount(chatMessage.getContentCount());
    outPutContact.setResult(resultContact);
    outPutContact.setErrorMessage("");
    outPutContact.setUniqueId(chatMessage.getUniqueId());
    return outPutContact;
}
Also used : ResultContact(com.fanap.podchat.model.ResultContact) TypeToken(com.google.gson.reflect.TypeToken) ChatResponse(com.fanap.podchat.model.ChatResponse) RequestAddContact(com.fanap.podchat.requestobject.RequestAddContact) ResultRemoveContact(com.fanap.podchat.model.ResultRemoveContact) ResultAddContact(com.fanap.podchat.model.ResultAddContact) UpdateContact(com.fanap.podchat.mainmodel.UpdateContact) RequestGetContact(com.fanap.podchat.requestobject.RequestGetContact) RequestUpdateContact(com.fanap.podchat.requestobject.RequestUpdateContact) RequestSearchContact(com.fanap.podchat.mainmodel.RequestSearchContact) Contact(com.fanap.podchat.mainmodel.Contact) ResultContact(com.fanap.podchat.model.ResultContact) RequestRemoveContact(com.fanap.podchat.requestobject.RequestRemoveContact) BlockedContact(com.fanap.podchat.mainmodel.BlockedContact) PhoneContact(com.fanap.podchat.cachemodel.PhoneContact) ResultUpdateContact(com.fanap.podchat.model.ResultUpdateContact) NonNull(android.support.annotation.NonNull)

Example 17 with Contact

use of com.fanap.podchat.mainmodel.Contact in project pod-chat-android-sdk by FanapSoft.

the class ExampleUnitTest method sortContactsWithFullNameTest.

@Test
public void sortContactsWithFullNameTest() {
    ArrayList<Contact> unsorted = new ArrayList<>();
    ArrayList<Contact> expected = new ArrayList<>();
    ArrayList<Contact> sorted;
    Contact contact1 = new Contact();
    contact1.setFirstName("Bahar");
    contact1.setLastName("Bohloli");
    contact1.setHasUser(true);
    unsorted.add(contact1);
    Contact contact2 = new Contact();
    contact2.setFirstName("Ali");
    contact2.setLastName("Alavi");
    contact2.setHasUser(true);
    unsorted.add(contact2);
    expected.add(contact2);
    expected.add(contact1);
    sorted = new ArrayList<>(unsorted);
    Collections.sort(sorted, compareContacts());
    Assert.assertEquals(expected, sorted);
}
Also used : ArrayList(java.util.ArrayList) Contact(com.fanap.podchat.mainmodel.Contact) PhoneContact(com.fanap.podchat.cachemodel.PhoneContact) Test(org.junit.Test)

Example 18 with Contact

use of com.fanap.podchat.mainmodel.Contact in project pod-chat-android-sdk by FanapSoft.

the class CallPresenter method onGetContacts.

@Override
public void onGetContacts(String content, ChatResponse<ResultContact> outPutContact) {
    super.onGetContacts(content, outPutContact);
    ArrayList<ContactsWrapper> contactsWrappers = new ArrayList<>();
    for (Contact c : outPutContact.getResult().getContacts()) {
        ContactsWrapper contactsWrapper = new ContactsWrapper(c);
        contactsWrappers.add(contactsWrapper);
    }
    ContactsFragment fragment = new ContactsFragment();
    Bundle v = new Bundle();
    v.putParcelableArrayList("CONTACTS", contactsWrappers);
    fragment.setArguments(v);
    if (!outPutContact.isCache())
        view.showContactsFragment(fragment);
    else
        view.updateContactsFragment(contactsWrappers);
}
Also used : Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) ContactsWrapper(com.fanap.podchat.call.contacts.ContactsWrapper) ContactsFragment(com.fanap.podchat.call.contacts.ContactsFragment) 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 19 with Contact

use of com.fanap.podchat.mainmodel.Contact in project pod-chat-android-sdk by FanapSoft.

the class AssistantCacheTest method unBlockAssistantAndCheckAssistantListInCache.

@Test
public void unBlockAssistantAndCheckAssistantListInCache() {
    populateContactsFromServer();
    ArrayList<AssistantVo> blockedListFromServer = new ArrayList<>();
    chat.addListener(new ChatListener() {

        @Override
        public void onAssistantBlocks(ChatResponse<List<AssistantVo>> response) {
            print("Blocked assistants list cache: " + response.isCache());
            prettyLog(response.getJson());
            blockedListFromServer.addAll(response.getResult());
            chat.removeListener(this);
            resumeProcess();
        }
    });
    GetBlockedAssistantsRequest getBlockedAssistantsRequest = new GetBlockedAssistantsRequest.Builder().withNoCache().build();
    chat.getBlocksAssistant(getBlockedAssistantsRequest);
    pauseProcess();
    Contact assistantContactToUnBlock = contacts.stream().filter(contact -> contact.getLinkedUser() != null && Objects.equals(contact.getLinkedUser().getUsername(), blockedListFromServer.get(0).getParticipantVO().getUsername())).findFirst().get();
    print("Going to unblock " + assistantContactToUnBlock.getFirstName());
    prettyLog(App.getGson().toJson(assistantContactToUnBlock));
    Invitee invitee = new Invitee(assistantContactToUnBlock.getId(), InviteType.Constants.TO_BE_USER_CONTACT_ID);
    AssistantVo assistantToUnBlock = new AssistantVo();
    assistantToUnBlock.setInvitees(invitee);
    List<AssistantVo> toUnBlockAssistantList = new ArrayList<>();
    toUnBlockAssistantList.add(assistantToUnBlock);
    chat.addListener(new ChatListener() {

        @Override
        public void onAssistantUnBlocked(ChatResponse<List<AssistantVo>> response) {
            print("Assistant unblocked");
            prettyLog(response.getJson());
            toUnBlockAssistantList.clear();
            toUnBlockAssistantList.addAll(response.getResult());
            chat.removeListener(this);
            resumeProcess();
        }
    });
    ChatListener mMockedListener = Mockito.mock(ChatListener.class);
    chat.addListener(mMockedListener);
    BlockUnblockAssistantRequest requestBlock = new BlockUnblockAssistantRequest.Builder(toUnBlockAssistantList, false).build();
    chat.unBlockAssistant(requestBlock);
    pauseProcess();
    ArrayList<AssistantVo> assistantListInCache = new ArrayList<>();
    chat.addListener(new ChatListener() {

        @Override
        public void onGetAssistants(ChatResponse<List<AssistantVo>> response) {
            print("Receive assistants list cache: " + response.isCache());
            prettyLog(response.getJson());
            if (response.isCache()) {
                assistantListInCache.addAll(response.getResult());
                chat.removeListener(this);
                resumeProcess();
            }
        }
    });
    GetAssistantRequest getAssistantRequest = new GetAssistantRequest.Builder().build();
    chat.getAssistants(getAssistantRequest);
    pauseProcess();
    Assert.assertTrue(assistantListInCache.stream().anyMatch(assistantInCache -> assistantInCache.getParticipantVO().getId() == toUnBlockAssistantList.get(0).getParticipantVO().getId() && !assistantInCache.getBlock()));
}
Also used : ResultContact(com.fanap.podchat.model.ResultContact) ResultThreads(com.fanap.podchat.model.ResultThreads) RoleType(com.fanap.podchat.chat.RoleType) ChatPresenter(com.example.chat.application.chatexample.ChatPresenter) ResultHistory(com.fanap.podchat.model.ResultHistory) RequestGetContact(com.fanap.podchat.requestobject.RequestGetContact) Looper(android.os.Looper) App(com.fanap.podchat.chat.App) Invitee(com.fanap.podchat.mainmodel.Invitee) InviteType(com.fanap.podchat.util.InviteType) Participant(com.fanap.podchat.mainmodel.Participant) Logger(com.orhanobut.logger.Logger) InstrumentationRegistry(android.support.test.InstrumentationRegistry) ChatListener(com.fanap.podchat.chat.ChatListener) MessageVO(com.fanap.podchat.mainmodel.MessageVO) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) AssistantHistoryVo(com.fanap.podchat.chat.assistant.model.AssistantHistoryVo) APP_ID(com.example.chat.application.chatexample.ChatActivity.APP_ID) List(java.util.List) GetBlockedAssistantsRequest(com.fanap.podchat.chat.assistant.request_model.GetBlockedAssistantsRequest) GetAssistantRequest(com.fanap.podchat.chat.assistant.request_model.GetAssistantRequest) Chat(com.fanap.podchat.chat.Chat) Context(android.content.Context) GetAssistantHistoryRequest(com.fanap.podchat.chat.assistant.request_model.GetAssistantHistoryRequest) RequestConnect(com.fanap.podchat.requestobject.RequestConnect) AssistantVo(com.fanap.podchat.chat.assistant.model.AssistantVo) BeforeClass(org.junit.BeforeClass) Mock(org.mockito.Mock) Thread(com.fanap.podchat.mainmodel.Thread) RunWith(org.junit.runner.RunWith) ChatContract(com.example.chat.application.chatexample.ChatContract) RegisterAssistantRequest(com.fanap.podchat.chat.assistant.request_model.RegisterAssistantRequest) ChatResponse(com.fanap.podchat.model.ChatResponse) ResultParticipant(com.fanap.podchat.model.ResultParticipant) ArrayList(java.util.ArrayList) R(com.fanap.podchat.example.R) RequestThreadParticipant(com.fanap.podchat.requestobject.RequestThreadParticipant) BaseApplication(com.example.chat.application.chatexample.BaseApplication) ChatActivity(com.example.chat.application.chatexample.ChatActivity) Contact(com.fanap.podchat.mainmodel.Contact) RequestThread(com.fanap.podchat.requestobject.RequestThread) Before(org.junit.Before) RequestGetHistory(com.fanap.podchat.requestobject.RequestGetHistory) CHAT_READY(com.fanap.podchat.util.ChatStateType.ChatSateConstant.CHAT_READY) ActivityTestRule(android.support.test.rule.ActivityTestRule) Test(org.junit.Test) AndroidJUnit4(android.support.test.runner.AndroidJUnit4) LargeTest(android.support.test.filters.LargeTest) Mockito(org.mockito.Mockito) Rule(org.junit.Rule) BlockUnblockAssistantRequest(com.fanap.podchat.chat.assistant.request_model.BlockUnblockAssistantRequest) Assert(org.junit.Assert) Activity(android.app.Activity) Collections(java.util.Collections) AssistantVo(com.fanap.podchat.chat.assistant.model.AssistantVo) ArrayList(java.util.ArrayList) ResultContact(com.fanap.podchat.model.ResultContact) RequestGetContact(com.fanap.podchat.requestobject.RequestGetContact) Contact(com.fanap.podchat.mainmodel.Contact) Invitee(com.fanap.podchat.mainmodel.Invitee) ChatListener(com.fanap.podchat.chat.ChatListener) List(java.util.List) ArrayList(java.util.ArrayList) GetBlockedAssistantsRequest(com.fanap.podchat.chat.assistant.request_model.GetBlockedAssistantsRequest) GetAssistantRequest(com.fanap.podchat.chat.assistant.request_model.GetAssistantRequest) BlockUnblockAssistantRequest(com.fanap.podchat.chat.assistant.request_model.BlockUnblockAssistantRequest) Test(org.junit.Test) LargeTest(android.support.test.filters.LargeTest)

Example 20 with Contact

use of com.fanap.podchat.mainmodel.Contact in project pod-chat-android-sdk by FanapSoft.

the class AssistantCacheTest method checkRegisteredAssistantInCache.

// Register new assistant and check if it is in cache
@LargeTest
@Test
public void checkRegisteredAssistantInCache() {
    populateContactsFromServer();
    assert contacts.size() > 0;
    Collections.shuffle(contacts);
    Contact contact = getValidContact();
    print("Selected contact for register as assistant " + App.getGson().toJson(contact));
    ArrayList<String> typeRoles = new ArrayList<>();
    typeRoles.add(RoleType.Constants.ADD_ROLE_TO_USER);
    typeRoles.add(RoleType.Constants.READ_THREAD);
    typeRoles.add(RoleType.Constants.EDIT_THREAD);
    List<AssistantVo> assistantVos = new ArrayList<>();
    AssistantVo assistantVo = new AssistantVo();
    Invitee invite = new Invitee(contact.getId(), InviteType.Constants.TO_BE_USER_CONTACT_ID);
    assistantVo.setInvitees(invite);
    assistantVo.setContactType("default");
    assistantVo.setRoles(typeRoles);
    assistantVos.add(assistantVo);
    final AssistantVo[] registeredAssistant = new AssistantVo[1];
    ChatListener mListener = new ChatListener() {

        @Override
        public void onRegisterAssistant(ChatResponse<List<AssistantVo>> response) {
            registeredAssistant[0] = response.getResult().get(0);
            chat.removeListener(this);
            resumeProcess();
        }
    };
    chat.setListener(mListener);
    RegisterAssistantRequest request = new RegisterAssistantRequest.Builder(assistantVos).build();
    chat.registerAssistant(request);
    pauseProcess();
    ChatListener mTestListener = Mockito.mock(ChatListener.class);
    chat.addListener(mTestListener);
    GetAssistantRequest requestGet = new GetAssistantRequest.Builder().setCount(25).setOffset(0).build();
    chat.getAssistants(requestGet);
    Mockito.verify(mTestListener, Mockito.after(2000).atLeastOnce()).onGetAssistants(Mockito.argThat((ChatResponse<List<AssistantVo>> response) -> (response.isCache() && validateAssistantsAreSame(registeredAssistant[0], response.getResult()))));
}
Also used : AssistantVo(com.fanap.podchat.chat.assistant.model.AssistantVo) ArrayList(java.util.ArrayList) ResultContact(com.fanap.podchat.model.ResultContact) RequestGetContact(com.fanap.podchat.requestobject.RequestGetContact) Contact(com.fanap.podchat.mainmodel.Contact) Invitee(com.fanap.podchat.mainmodel.Invitee) ChatResponse(com.fanap.podchat.model.ChatResponse) ChatListener(com.fanap.podchat.chat.ChatListener) List(java.util.List) ArrayList(java.util.ArrayList) RegisterAssistantRequest(com.fanap.podchat.chat.assistant.request_model.RegisterAssistantRequest) GetAssistantRequest(com.fanap.podchat.chat.assistant.request_model.GetAssistantRequest) Test(org.junit.Test) LargeTest(android.support.test.filters.LargeTest) LargeTest(android.support.test.filters.LargeTest)

Aggregations

Contact (com.fanap.podchat.mainmodel.Contact)30 ResultContact (com.fanap.podchat.model.ResultContact)22 ArrayList (java.util.ArrayList)20 RequestSearchContact (com.fanap.podchat.mainmodel.RequestSearchContact)17 BlockedContact (com.fanap.podchat.mainmodel.BlockedContact)15 CacheBlockedContact (com.fanap.podchat.cachemodel.CacheBlockedContact)13 CacheContact (com.fanap.podchat.cachemodel.CacheContact)13 Test (org.junit.Test)12 NonNull (android.support.annotation.NonNull)11 RequestGetContact (com.fanap.podchat.requestobject.RequestGetContact)9 LargeTest (android.support.test.filters.LargeTest)8 Invitee (com.fanap.podchat.mainmodel.Invitee)8 ChatResponse (com.fanap.podchat.model.ChatResponse)8 SimpleDateFormat (java.text.SimpleDateFormat)6 Calendar (java.util.Calendar)6 Date (java.util.Date)6 ChatListener (com.fanap.podchat.chat.ChatListener)5 AssistantVo (com.fanap.podchat.chat.assistant.model.AssistantVo)5 ResultAddContact (com.fanap.podchat.model.ResultAddContact)5 RegisterAssistantRequest (com.fanap.podchat.chat.assistant.request_model.RegisterAssistantRequest)4