use of com.fanap.podchat.requestobject.RequestGetHistory in project pod-chat-android-sdk by FanapSoft.
the class ChatTestSandbox method getHistoryHashtagTest.
@Test
@LargeTest
public void getHistoryHashtagTest() {
long startTime = System.currentTimeMillis();
ChatListener historyListeners = new ChatListener() {
@Override
public void onGetHistory(String content, ChatResponse<ResultHistory> history) {
System.out.println("onGetHistory: ");
Logger.json(history.getJson());
Assert.assertTrue(true);
resumeProcess();
}
};
chat.setListener(historyListeners);
RequestGetHistory request = new RequestGetHistory.Builder(8085).offset(0).count(25).order("desc").build();
presenter.getHistory(request, null);
pauseProcess();
}
use of com.fanap.podchat.requestobject.RequestGetHistory in project pod-chat-android-sdk by FanapSoft.
the class ChatTest method getThreadFullHistory.
private void getThreadFullHistory(Thread thread) {
long startTime = System.currentTimeMillis();
AtomicBoolean hasNext = new AtomicBoolean(true);
int count = 25;
AtomicLong offset = new AtomicLong(0);
AtomicLong threadMessagesCount = new AtomicLong(-1);
AtomicLong threadReceivedHistory = new AtomicLong(0);
ChatListener historyListeners = new ChatListener() {
@Override
public void onGetHistory(String content, ChatResponse<ResultHistory> history) {
threadMessagesCount.set(history.getResult().getContentCount());
long received = threadReceivedHistory.get();
threadReceivedHistory.set(received + history.getResult().getHistory().size());
hasNext.set(history.getResult().isHasNext());
if (hasNext.get()) {
offset.set(offset.get() + history.getResult().getHistory().size());
}
resumeProcess();
}
@Override
public void onError(String content, ErrorOutPut error) {
Assert.fail(content);
}
};
chat.addListener(historyListeners);
while (hasNext.get()) {
RequestGetHistory requestGetHistory = new RequestGetHistory.Builder(thread.getId()).offset(offset.get()).withNoCache().count(count).order("desc").build();
String uniqueId = presenter.getHistory(requestGetHistory, null);
pauseProcess();
}
long endTime = System.currentTimeMillis();
System.out.println(">>> >>> >>>");
System.out.println(">>> >>> >>>");
System.out.println(">>> >>> >>>");
System.out.println("RUNNING TEST ON THREAD:");
System.out.println(thread.getTitle());
System.out.println(thread.getId());
System.out.println("RECEIVED TOTAL " + threadReceivedHistory + " MESSAGES OF HISTORY IN");
System.out.println(endTime - startTime + " MILLISECONDS");
System.out.println(">>> >>> >>>");
System.out.println(">>> >>> >>>");
System.out.println(">>> >>> >>>");
Assert.assertEquals(threadMessagesCount.get(), threadReceivedHistory.get());
}
use of com.fanap.podchat.requestobject.RequestGetHistory in project pod-chat-android-sdk by FanapSoft.
the class ChatTest method getThreadHistoryBeforeAndAfterLastSeenMessage.
@Test
@LargeTest
public // and greater in second case
void getThreadHistoryBeforeAndAfterLastSeenMessage() {
populateThreadsListFromServerOrCache();
System.out.println("** Get history of " + threads.get(0).getTitle());
Thread thread = threads.get(0);
final long lastSeen = thread.getLastSeenMessageTime() + thread.getLastSeenMessageNanos();
AtomicInteger numOfCacheResp = new AtomicInteger(0);
ChatListener historyListeners = new ChatListener() {
@Override
public void onGetHistory(String content, ChatResponse<ResultHistory> history) {
int invokeTimes = 0;
if (history.isCache()) {
invokeTimes = numOfCacheResp.getAndIncrement();
}
checkTimesIsValid(history, invokeTimes, lastSeen);
if (invokeTimes >= 2) {
resumeProcess();
}
}
};
chat.addListener(historyListeners);
RequestGetHistory requestGetHistoryBeforeLastSeenTime = new RequestGetHistory.Builder(thread.getId()).toTimeNanos(lastSeen).offset(0).count(25).order("desc").build();
presenter.getHistory(requestGetHistoryBeforeLastSeenTime, null);
RequestGetHistory requestGetHistoryAfterLastSeenTime = new RequestGetHistory.Builder(thread.getId()).fromTimeNanos(lastSeen).offset(0).count(25).order("asc").build();
presenter.getHistory(requestGetHistoryAfterLastSeenTime, null);
pauseProcess();
sleep(2000);
Mockito.verify(view, Mockito.atLeast(2)).onGetThreadHistory(Mockito.any());
}
use of com.fanap.podchat.requestobject.RequestGetHistory in project pod-chat-android-sdk by FanapSoft.
the class ChatTest method getThreadHistory.
public void getThreadHistory(long threadId) {
RequestGetHistory request = new RequestGetHistory.Builder(threadId).offset(0).count(25).order(// .order("asc")
"desc").build();
presenter.getHistory(request, null);
sleep(2000);
Mockito.verify(view, Mockito.atLeastOnce()).onGetThreadHistory(Mockito.any());
}
use of com.fanap.podchat.requestobject.RequestGetHistory in project pod-chat-android-sdk by FanapSoft.
the class ThreadManager method prepareGetHIstoryWithUniqueIdsRequest.
public static String prepareGetHIstoryWithUniqueIdsRequest(long threadId, String uniqueId, String[] uniqueIds, String typeCode, String token) {
RequestGetHistory request = new RequestGetHistory.Builder(threadId).offset(0).count(uniqueIds.length).uniqueIds(uniqueIds).build();
String content = App.getGson().toJson(request);
ChatMessage chatMessage = new ChatMessage();
chatMessage.setContent(content);
chatMessage.setType(ChatMessageType.Constants.GET_HISTORY);
chatMessage.setToken(token);
chatMessage.setTokenIssuer("1");
chatMessage.setUniqueId(uniqueId);
chatMessage.setSubjectId(threadId);
JsonObject jsonObject = (JsonObject) App.getGson().toJsonTree(chatMessage);
if (Util.isNullOrEmpty(typeCode)) {
jsonObject.remove("typeCode");
} else {
jsonObject.remove("typeCode");
jsonObject.addProperty("typeCode", typeCode);
}
String asyncContent = jsonObject.toString();
return asyncContent;
}
Aggregations