use of com.fanap.podchat.chat.ChatListener 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()));
}
use of com.fanap.podchat.chat.ChatListener in project pod-chat-android-sdk by FanapSoft.
the class AssistantCacheTest method populateParticipantList.
@Test
public void populateParticipantList() {
populateThreadsListFromServerOnly();
assert threads.size() > 0;
Thread thread = getValidGroupThread();
chatListeners = new ChatListener() {
@Override
public void onGetThreadParticipant(String content, ChatResponse<ResultParticipant> response) {
System.out.println("Received Participant, Cache: " + response.isCache() + " Content: " + content);
if (response.getResult().getParticipants().size() > 1) {
threadParticipant.addAll(response.getResult().getParticipants());
chat.removeListener(chatListeners);
resumeProcess();
} else {
threads.remove(thread);
Thread t2 = getValidGroupThread();
print("try again changing thread...");
RequestThreadParticipant request = new RequestThreadParticipant.Builder().threadId(t2.getId()).build();
chat.getThreadParticipants(request, null);
}
}
};
chat.addListener(chatListeners);
RequestThreadParticipant request = new RequestThreadParticipant.Builder().threadId(thread.getId()).build();
chat.getThreadParticipants(request, null);
pauseProcess();
}
use of com.fanap.podchat.chat.ChatListener in project pod-chat-android-sdk by FanapSoft.
the class AssistantCacheTest method getBlockedAssistantsList.
@Test
public void getBlockedAssistantsList() {
ArrayList<AssistantVo> blockedListFromServer = new ArrayList<>();
ArrayList<AssistantVo> blockedListInCache = new ArrayList<>();
chat.addListener(new ChatListener() {
@Override
public void onAssistantBlocks(ChatResponse<List<AssistantVo>> response) {
print("Blocked assistants list cache: " + response.isCache());
prettyLog(response.getJson());
if (response.isCache()) {
blockedListInCache.addAll(response.getResult());
} else {
blockedListFromServer.addAll(response.getResult());
}
if (blockedListFromServer.size() == blockedListInCache.size()) {
print("Cache and Server data are filled now");
chat.removeListener(this);
resumeProcess();
}
}
});
GetBlockedAssistantsRequest getBlockedAssistantsRequest = new GetBlockedAssistantsRequest.Builder().build();
chat.getBlocksAssistant(getBlockedAssistantsRequest);
pauseProcess();
for (AssistantVo assistantCache : blockedListInCache) {
AssistantVo assistantServer = blockedListFromServer.stream().filter(assistantVo -> assistantVo.getParticipantVO().getId() == assistantCache.getParticipantVO().getId()).findFirst().get();
if (!assistantCache.getRoles().containsAll(assistantServer.getRoles())) {
Assert.fail("Roles are not same => " + assistantCache.getRoles() + " != " + assistantServer.getRoles());
}
}
Assert.assertTrue(true);
}
use of com.fanap.podchat.chat.ChatListener in project pod-chat-android-sdk by FanapSoft.
the class AssistantCacheTest method populateMessagesFromServerOrCache.
public void populateMessagesFromServerOrCache() {
populateThreadsListFromServerOnly();
assert threads.size() > 0;
Thread thread = threads.get(0);
chatListeners = new ChatListener() {
@Override
public void onGetHistory(String content, ChatResponse<ResultHistory> history) {
System.out.println("Received Message List, Cache: " + history.isCache() + " Content: " + content);
threadMessagesList.addAll(history.getResult().getHistory());
chat.removeListener(chatListeners);
resumeProcess();
}
};
chat.addListener(chatListeners);
RequestGetHistory requestGetHistory = new RequestGetHistory.Builder(thread.getId()).build();
chat.getHistory(requestGetHistory, null);
pauseProcess();
}
use of com.fanap.podchat.chat.ChatListener in project pod-chat-android-sdk by FanapSoft.
the class AssistantCacheTest method populateThreadsListFromCacheOnly.
// requests for list of threads from cache
public void populateThreadsListFromCacheOnly() {
chatListeners = new ChatListener() {
@Override
public void onGetThread(String content, ChatResponse<ResultThreads> thread) {
if (thread.isCache()) {
print("Received List: " + content);
threads.addAll(thread.getResult().getThreads());
chat.removeListener(chatListeners);
resumeProcess();
}
}
};
chat.addListener(chatListeners);
RequestThread requestThread = new RequestThread.Builder().count(25).build();
presenter.getThreads(requestThread, null);
pauseProcess();
print("Received List: " + threads.size());
}
Aggregations