Search in sources :

Example 11 with Contact

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

the class AssistantCacheTest method blockAssistantAndCheckCache.

@Test
public void blockAssistantAndCheckCache() {
    populateContactsFromServer();
    List<AssistantVo> assistantVos = new ArrayList<>();
    chat.addListener(new ChatListener() {

        @Override
        public void onGetAssistants(ChatResponse<List<AssistantVo>> response) {
            if (!response.isCache()) {
                prettyLog(response.getJson());
                assistantVos.addAll(response.getResult());
                chat.removeListener(this);
                resumeProcess();
            }
        }
    });
    GetAssistantRequest request = new GetAssistantRequest.Builder().setCount(25).withNoCache().setOffset(0).build();
    chat.getAssistants(request);
    pauseProcess();
    // the block assistant method accepts only Invitee
    Collections.shuffle(assistantVos);
    List<AssistantVo> notBlockedAssistants = assistantVos.stream().filter(assistantVo -> !assistantVo.getBlock()).collect(Collectors.toList());
    Contact assistantContactToBlock = contacts.stream().filter(contact -> contact.getLinkedUser() != null && Objects.equals(contact.getLinkedUser().getUsername(), notBlockedAssistants.get(0).getParticipantVO().getUsername())).findFirst().get();
    print("Going to block " + assistantContactToBlock.getFirstName());
    prettyLog(App.getGson().toJson(assistantContactToBlock));
    Invitee invitee = new Invitee(assistantContactToBlock.getId(), InviteType.Constants.TO_BE_USER_CONTACT_ID);
    AssistantVo assistantToBlock = new AssistantVo();
    assistantToBlock.setInvitees(invitee);
    List<AssistantVo> toBlockAssistantList = new ArrayList<>();
    toBlockAssistantList.add(assistantToBlock);
    chat.addListener(new ChatListener() {

        @Override
        public void onAssistantBlocked(ChatResponse<List<AssistantVo>> response) {
            prettyLog(response.getJson());
            toBlockAssistantList.clear();
            toBlockAssistantList.addAll(response.getResult());
            chat.removeListener(this);
            resumeProcess();
        }
    });
    BlockUnblockAssistantRequest requestBlock = new BlockUnblockAssistantRequest.Builder(toBlockAssistantList, true).build();
    chat.blockAssistant(requestBlock);
    pauseProcess();
    ArrayList<AssistantVo> inCache = new ArrayList<>();
    chat.addListener(new ChatListener() {

        @Override
        public void onGetAssistants(ChatResponse<List<AssistantVo>> response) {
            if (response.isCache()) {
                prettyLog(response.getJson());
                inCache.addAll(response.getResult());
                chat.removeListener(this);
                resumeProcess();
            }
        }
    });
    GetAssistantRequest requestGetAssistantFromCache = new GetAssistantRequest.Builder().setCount(25).setOffset(0).build();
    chat.getAssistants(requestGetAssistantFromCache);
    pauseProcess();
    assert inCache.size() > 0;
    Assert.assertTrue(inCache.stream().filter(anAssistantInCache -> toBlockAssistantList.stream().anyMatch(blockListAssistant -> anAssistantInCache.getParticipantVO().getId() == blockListAssistant.getParticipantVO().getId())).findFirst().get().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) 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 12 with Contact

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

the class ChatTestSandbox method createThreadWithMetaData.

@Test
@MediumTest
public void createThreadWithMetaData() {
    sleep(7000);
    Invitee[] invite = new Invitee[] { new Invitee("589", 2), new Invitee("1162", 2), new Invitee("2404", 2) // , new Invitee(824, 2)
    };
    Contact contac = new Contact();
    contac.setLastName("mamadi");
// String  metaData =
// JsonUtil.getJson(contac);
// presenter.createThread(0,invite,null,null,null,metaData,null);
}
Also used : Invitee(com.fanap.podchat.mainmodel.Invitee) RequestSearchContact(com.fanap.podchat.mainmodel.RequestSearchContact) Contact(com.fanap.podchat.mainmodel.Contact) FlakyTest(android.support.test.filters.FlakyTest) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test) LargeTest(android.support.test.filters.LargeTest) MediumTest(android.support.test.filters.MediumTest)

Example 13 with Contact

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

the class ContactCacheTest method testIfContactsAreSame.

@Test
public void testIfContactsAreSame() {
    populateContactsFromServer();
    populateContactsFromCache();
    assert serverContacts.size() > 0;
    assert cacheContacts.size() > 0;
    assert cacheContacts.size() == serverContacts.size();
    for (Contact serverContact : serverContacts) {
        if (serverContact == null)
            continue;
        System.out.println(">>>>>>>>>>> Server Contact " + serverContact.getCellphoneNumber());
        Contact contactInCache = cacheContacts.stream().filter(cachContact -> cachContact.getId() == serverContact.getId()).findFirst().get();
        System.out.println(">>>>>>>>>>> Cache Contact " + contactInCache.getCellphoneNumber());
        Assert.assertEquals(serverContact.getCellphoneNumber() != null, contactInCache.getCellphoneNumber() != null);
        Assert.assertEquals(serverContact.getFirstName(), contactInCache.getFirstName());
        Assert.assertEquals(serverContact.getId(), contactInCache.getId());
        if (serverContact.getLinkedUser() == null) {
            System.out.println(">>>>>>>>>>> linked user is null ");
            System.out.println(">>>>>>>>>>> linked user in cache " + contactInCache.getLinkedUser());
            continue;
        }
        Assert.assertEquals(serverContact.getLinkedUser().getName(), contactInCache.getLinkedUser().getName());
        Assert.assertEquals(serverContact.getLinkedUser().getUsername(), contactInCache.getLinkedUser().getUsername());
        Assert.assertEquals(serverContact.getLinkedUser().getNickname(), contactInCache.getLinkedUser().getNickname());
        System.out.println(">>>>>>>>>>> Server Contact linked " + serverContact.getLinkedUser().getName());
        System.out.println(">>>>>>>>>>> Cache Contact linked" + contactInCache.getLinkedUser().getName());
        System.out.println(">>>>>>>>>>>Contacts are same");
    }
}
Also used : ResultContact(com.fanap.podchat.model.ResultContact) RequestGetContact(com.fanap.podchat.requestobject.RequestGetContact) Contact(com.fanap.podchat.mainmodel.Contact) Test(org.junit.Test)

Example 14 with Contact

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

the class ChatTest method createThreadWithMetaData.

@Test
@MediumTest
public void createThreadWithMetaData() {
    sleep(7000);
    Invitee[] invite = new Invitee[] { new Invitee("589", 2), new Invitee("1162", 2), new Invitee("2404", 2) // , new Invitee(824, 2)
    };
    Contact contac = new Contact();
    contac.setLastName("mamadi");
// String  metaData =
// JsonUtil.getJson(contac);
// presenter.createThread(0,invite,null,null,null,metaData,null);
}
Also used : Invitee(com.fanap.podchat.mainmodel.Invitee) RequestSearchContact(com.fanap.podchat.mainmodel.RequestSearchContact) Contact(com.fanap.podchat.mainmodel.Contact) FlakyTest(android.support.test.filters.FlakyTest) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test) LargeTest(android.support.test.filters.LargeTest) MediumTest(android.support.test.filters.MediumTest)

Example 15 with Contact

use of com.fanap.podchat.mainmodel.Contact 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)

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