use of com.fanap.podchat.model.ResultHistory in project pod-chat-android-sdk by FanapSoft.
the class IntegrationTest method searchHistoryWithMetadata_OR_Test.
@Test
@LargeTest
public void searchHistoryWithMetadata_OR_Test() {
populateThreadsListFromServerOnly();
ChatListener mTestListener = Mockito.mock(ChatListener.class);
chat.setListener(mTestListener);
assert threads.size() > 0;
Thread thread = threads.get(0);
DummyMetadataVO dummyMetadataVO = new DummyMetadataVO();
int random1 = Math.abs(new Random().nextInt());
dummyMetadataVO.count = random1;
String meta = App.getGson().toJson(dummyMetadataVO);
RequestMessage sendMessageWithMetadataRequest = new RequestMessage.Builder("Android Test " + new Date(), thread.getId()).messageType(TextMessageType.Constants.TEXT).jsonMetaData(meta).build();
chat.sendTextMessage(sendMessageWithMetadataRequest, null);
sleep(6000);
int random2 = Math.abs(new Random().nextInt());
dummyMetadataVO.count = random2;
meta = App.getGson().toJson(dummyMetadataVO);
sendMessageWithMetadataRequest.setJsonMetaData(meta);
chat.sendTextMessage(sendMessageWithMetadataRequest, null);
sleep(6000);
// NosqlSearchMetadataCriteria
// metadataCriteriaLB =
// new NosqlSearchMetadataCriteria.Builder("count")
// .is(String.valueOf(random1))
// .build();
NosqlSearchMetadataCriteria metadataCriteriaUB = new NosqlSearchMetadataCriteria.Builder("count").is(String.valueOf(random2)).build();
List<NosqlSearchMetadataCriteria> criteriaList = new ArrayList<>();
// criteriaList.add(metadataCriteriaLB);
criteriaList.add(metadataCriteriaUB);
NosqlSearchMetadataCriteria metadataCriteria = new NosqlSearchMetadataCriteria.Builder("count").is(String.valueOf(random1)).or(criteriaList).build();
SearchSystemMetadataRequest request = new SearchSystemMetadataRequest.Builder(thread.getId()).metadataCriteria(metadataCriteria).count(50).build();
chat.searchHistory(request, null);
Mockito.verify(mTestListener, Mockito.after(5000).atLeastOnce()).onGetHistory(Mockito.any(String.class), Mockito.argThat((ChatResponse<ResultHistory> resp) -> resp.getResult().getHistory().stream().anyMatch(messageVO -> messageVO.getSystemMetadata().contains(String.valueOf(dummyMetadataVO.count)))));
}
use of com.fanap.podchat.model.ResultHistory in project pod-chat-android-sdk by FanapSoft.
the class MessageDatabaseHelper method getHistories.
public void getHistories(@NonNull History history, long threadId, OnWorkDone listener) {
List<MessageVO> messageVOS = new ArrayList<>();
List<CacheMessageVO> cacheMessageVOS;
long fromTime = history.getFromTime();
long fromTimeNanos = history.getFromTimeNanos();
long toTime = history.getToTime();
long toTimeNanos = history.getToTimeNanos();
long messageId = history.getId();
long offset = history.getOffset();
long count = history.getCount();
int messageType = history.getMessageType();
String query = history.getQuery();
String order = history.getOrder();
offset = offset >= 0 ? offset : 0;
count = count > 0 ? count : 50;
if (Util.isNullOrEmpty(order)) {
order = "desc";
}
String rawQuery = "SELECT * FROM CacheMessageVO WHERE threadVoId =" + threadId;
rawQuery = addMessageIdIfExist(messageId, rawQuery);
rawQuery = addFromTimeIfExist(fromTime, fromTimeNanos, rawQuery);
rawQuery = addToTimeIfExist(toTime, toTimeNanos, rawQuery);
rawQuery = addQueryIfExist(query, rawQuery);
rawQuery = addMessageTypeIfExist(messageType, rawQuery);
long contentCount = messageDao.getHistoryContentCount(new SimpleSQLiteQuery(rawQuery.replaceFirst("SELECT \\* ", "SELECT COUNT(ID) ")));
rawQuery = addOrderAndLimitAndOffset(offset, count, order, rawQuery);
SupportSQLiteQuery sqLiteQuery = new SimpleSQLiteQuery(rawQuery);
cacheMessageVOS = messageDao.getRawHistory(sqLiteQuery);
prepareMessageVOs(messageVOS, cacheMessageVOS);
List<Sending> sendingList = getAllSendingQueueByThreadId(threadId);
List<Uploading> uploadingList = getAllUploadingQueueByThreadId(threadId);
List<Failed> failedList = getAllWaitQueueCacheByThreadId(threadId);
ChatResponse<ResultHistory> chatResponse = new ChatResponse<>();
chatResponse.setCache(true);
ResultHistory resultHistory = new ResultHistory();
resultHistory.setHistory(messageVOS);
resultHistory.setNextOffset(history.getOffset() + messageVOS.size());
resultHistory.setContentCount(contentCount);
if (messageVOS.size() + history.getOffset() < contentCount) {
resultHistory.setHasNext(true);
} else {
resultHistory.setHasNext(false);
}
resultHistory.setHistory(messageVOS);
resultHistory.setSending(sendingList);
resultHistory.setUploadingQueue(uploadingList);
resultHistory.setFailed(failedList);
chatResponse.setErrorCode(0);
chatResponse.setHasError(false);
chatResponse.setErrorMessage("");
chatResponse.setResult(resultHistory);
chatResponse.setCache(true);
chatResponse.setSubjectId(threadId);
listener.onWorkDone(chatResponse);
}
Aggregations