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());
}
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);
}
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");
}
}
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);
}
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;
}
Aggregations