use of com.fanap.podchat.chat.ChatListener in project pod-chat-android-sdk by FanapSoft.
the class MessagesCacheTest method forwardMessageAndCheckCache.
@Test
public void forwardMessageAndCheckCache() {
populateThreadsListFromServerOnly();
populateMessagesFromServer();
assert threads.size() > 1;
assert threadMessagesList.size() > 0;
Collections.shuffle(threads);
Thread thread2 = threads.get(1);
MessageVO message = threadMessagesList.get(0);
ChatListener mTestListener = Mockito.mock(ChatListener.class);
chat.setListener(mTestListener);
RequestForwardMessage forRequest = new RequestForwardMessage.Builder(thread2.getId(), new ArrayList<>(Collections.singletonList(message.getId()))).build();
chat.forwardMessage(forRequest);
sleep(2000);
RequestGetHistory requestGetHistory = new RequestGetHistory.Builder(thread2.getId()).build();
chat.getHistory(requestGetHistory, null);
Mockito.verify(mTestListener, Mockito.after(2000).atLeastOnce()).onGetHistory(Mockito.any(), Mockito.argThat((ChatResponse<ResultHistory> response) -> response.isCache() && response.getResult().getHistory().stream().anyMatch(messageVO -> messageVO.getForwardInfo() != null)));
}
use of com.fanap.podchat.chat.ChatListener in project pod-chat-android-sdk by FanapSoft.
the class MessagesCacheTest method populateMessagesFromCache.
public void populateMessagesFromCache() {
populateThreadsListFromServerOnly();
assert threads.size() > 0;
Thread thread = threads.get(0);
chatListeners = new ChatListener() {
@Override
public void onGetHistory(String content, ChatResponse<ResultHistory> history) {
if (history.isCache()) {
System.out.println("Received Message List Cache: " + 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 MessagesCacheTest 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()) {
System.out.println("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();
System.out.println("Received List: " + threads.size());
}
use of com.fanap.podchat.chat.ChatListener in project pod-chat-android-sdk by FanapSoft.
the class MessagesCacheTest method testIfConversationAreSame.
@Test
public void testIfConversationAreSame() {
populateMessagesFromServer();
assert threadMessagesList.size() > 0;
Collections.shuffle(threadMessagesList);
MessageVO message = threadMessagesList.get(0);
assert message.getConversation() != null;
Thread thread = message.getConversation();
chat.setListener(new ChatListener() {
@Override
public void onNewMessage(String content, ChatResponse<ResultNewMessage> response) {
resumeProcess();
}
});
RequestMessage repRequest = new RequestMessage.Builder("Message at " + new Date(), thread.getId()).messageType(TextMessageType.Constants.TEXT).build();
chat.sendTextMessage(repRequest, null);
pauseProcess();
// Load Server messages
ArrayList<MessageVO> msgFromServer = new ArrayList<>();
chatListeners = new ChatListener() {
@Override
public void onGetHistory(String content, ChatResponse<ResultHistory> history) {
if (!history.isCache()) {
System.out.println("Received Message List Server: " + content);
msgFromServer.addAll(history.getResult().getHistory());
chat.removeListener(chatListeners);
resumeProcess();
}
}
};
chat.addListener(chatListeners);
RequestGetHistory requestGetHistory = new RequestGetHistory.Builder(thread.getId()).withNoCache().build();
chat.getHistory(requestGetHistory, null);
pauseProcess();
// Load cache
ArrayList<MessageVO> msgFromCache = new ArrayList<>();
chatListeners = new ChatListener() {
@Override
public void onGetHistory(String content, ChatResponse<ResultHistory> history) {
if (history.isCache()) {
System.out.println("Received Message List Cache: " + content);
msgFromCache.addAll(history.getResult().getHistory());
chat.removeListener(chatListeners);
resumeProcess();
}
}
};
chat.addListener(chatListeners);
RequestGetHistory requestGetHistoryCache = new RequestGetHistory.Builder(thread.getId()).build();
chat.getHistory(requestGetHistoryCache, null);
pauseProcess();
assert msgFromServer.size() > 0;
assert msgFromCache.size() > 0;
assert msgFromCache.size() == msgFromServer.size();
for (MessageVO msg : msgFromServer) {
if (msg.getMessage() == null)
continue;
System.out.println(">>>>>>>>>>> Server Message " + msg.getMessage() + " Conversation: " + msg.getConversation());
MessageVO msgInCache = msgFromCache.stream().filter(messageVO -> messageVO.getId() == msg.getId()).findFirst().get();
System.out.println(">>>>>>>>>>> Cache Message " + msgInCache.getMessage() + " RepInfo: " + msgInCache.getConversation());
Assert.assertEquals(msg.getConversation() != null, msgInCache.getConversation() != null);
if (msg.getConversation() != null) {
Assert.assertEquals(msg.getConversation().getId(), msgInCache.getConversation().getId());
}
}
}
use of com.fanap.podchat.chat.ChatListener in project pod-chat-android-sdk by FanapSoft.
the class MessagesCacheTest method sendReplyMessage.
@Test
public void sendReplyMessage() {
populateMessagesFromServer();
Collections.shuffle(threadMessagesList);
MessageVO message = threadMessagesList.get(0);
Assert.assertNotNull(message);
Thread thread = message.getConversation();
ChatListener mTestListener = Mockito.mock(ChatListener.class);
chat.setListener(mTestListener);
RequestReplyMessage repRequest = new RequestReplyMessage.Builder("Reply to " + message.getMessage(), thread.getId(), message.getId(), TextMessageType.Constants.TEXT).build();
chat.replyMessage(repRequest, null);
Mockito.verify(mTestListener, Mockito.after(2000).atLeastOnce()).onNewMessage(Mockito.any(), Mockito.any());
sleep(2000);
}
Aggregations