use of com.fanap.podchat.model.ResultNewMessage in project pod-chat-android-sdk by FanapSoft.
the class MessageManager method prepareNewMessageResponse.
public static ChatResponse<ResultNewMessage> prepareNewMessageResponse(MessageVO newMessage, long threadId, String uniqueId) {
ChatResponse<ResultNewMessage> chatResponse = new ChatResponse<>();
ResultNewMessage editMessage = new ResultNewMessage();
editMessage.setMessageVO(newMessage);
editMessage.setThreadId(threadId);
chatResponse.setResult(editMessage);
chatResponse.setUniqueId(uniqueId);
chatResponse.setSubjectId(threadId);
return chatResponse;
}
use of com.fanap.podchat.model.ResultNewMessage in project pod-chat-android-sdk by FanapSoft.
the class MessageManager method preparepublishNewMessagesResponse.
public static ChatResponse<ResultNewMessage> preparepublishNewMessagesResponse(MessageVO messageVO, long threadId) {
ChatResponse<ResultNewMessage> chatResponse = new ChatResponse<>();
chatResponse.setUniqueId(messageVO.getUniqueId());
chatResponse.setHasError(false);
chatResponse.setErrorCode(0);
chatResponse.setErrorMessage("");
ResultNewMessage resultNewMessage = new ResultNewMessage();
resultNewMessage.setMessageVO(messageVO);
resultNewMessage.setThreadId(threadId);
chatResponse.setResult(resultNewMessage);
chatResponse.setSubjectId(threadId);
return chatResponse;
}
use of com.fanap.podchat.model.ResultNewMessage in project pod-chat-android-sdk by FanapSoft.
the class MessagesCacheTest method testIfParticipantsAreSame.
@Test
public void testIfParticipantsAreSame() {
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.getParticipant() != null, msgInCache.getParticipant() != null);
if (msg.getParticipant() != null) {
Assert.assertEquals(msg.getParticipant().getId(), msgInCache.getParticipant().getId());
Assert.assertEquals(msg.getParticipant().getName(), msgInCache.getParticipant().getName());
Assert.assertEquals(msg.getParticipant().getChatProfileVO() != null, msgInCache.getParticipant().getChatProfileVO() != null);
}
}
}
use of com.fanap.podchat.model.ResultNewMessage in project pod-chat-android-sdk by FanapSoft.
the class IntegrationTest method sendMessageWithMetadataTest.
@Test
@LargeTest
public void sendMessageWithMetadataTest() {
populateThreadsListFromServerOnly();
assert threads.size() > 0;
Thread thread = threads.get(0);
ChatListener mTestListener = Mockito.mock(ChatListener.class);
chat.setListener(mTestListener);
DummyMetadataVO dummyMetadataVO = new DummyMetadataVO();
dummyMetadataVO.count = new Random().nextInt();
dummyMetadataVO.desc = dummyMetadataVO.desc + "" + dummyMetadataVO.count;
String meta = App.getGson().toJson(dummyMetadataVO);
RequestMessage request = new RequestMessage.Builder("Android Test " + new Date(), thread.getId()).messageType(TextMessageType.Constants.TEXT).jsonMetaData(meta).build();
chat.sendTextMessage(request, null);
sleep(2000);
for (int i = 0; i < 16; i++) {
dummyMetadataVO.count++;
dummyMetadataVO.desc = String.format("%s%d", dummyMetadataVO.desc, dummyMetadataVO.count);
String meta2 = App.getGson().toJson(dummyMetadataVO);
request = new RequestMessage.Builder("Android Test " + new Date(), thread.getId()).messageType(TextMessageType.Constants.TEXT).jsonMetaData(meta2).build();
chat.sendTextMessage(request, null);
sleep(6000);
}
Mockito.verify(mTestListener, Mockito.after(2000).atLeastOnce()).onNewMessage(Mockito.any(), Mockito.argThat((ChatResponse<ResultNewMessage> resp) -> resp.getResult().getMessageVO().getSystemMetadata().equals(meta)));
Mockito.verify(mTestListener, Mockito.after(2000).atLeastOnce()).onNewMessage(Mockito.any(), Mockito.argThat((ChatResponse<ResultNewMessage> resp) -> !resp.getResult().getMessageVO().getSystemMetadata().equals("I'm something else!")));
}
use of com.fanap.podchat.model.ResultNewMessage in project pod-chat-android-sdk by FanapSoft.
the class ThreadCacheTest method sendMessage.
public void sendMessage() {
populateThreadsFromServer();
Collections.shuffle(threadsInServer);
Thread thread = threadsInServer.get(0);
System.out.println("Thread : " + thread.getTitle());
Assert.assertNotNull(thread);
chatListeners = new ChatListener() {
@Override
public void onNewMessage(String content, ChatResponse<ResultNewMessage> response) {
resumeProcess();
chat.removeListener(chatListeners);
}
@Override
public void onError(String content, ErrorOutPut error) {
resumeProcess();
System.out.println("Error: " + content);
Assert.assertEquals(0, 1);
chat.removeListener(chatListeners);
}
};
chat.addListener(chatListeners);
RequestMessage request = new RequestMessage.Builder("Android Test " + new Date(), thread.getId()).messageType(TextMessageType.Constants.TEXT).build();
chat.sendTextMessage(request, null);
}
Aggregations