use of com.fanap.podchat.model.ResultThreads in project pod-chat-android-sdk by FanapSoft.
the class ChatTest method populateThreadsListFromCacheOnly.
// requests for list of threads from cache
@Test
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());
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.model.ResultThreads in project pod-chat-android-sdk by FanapSoft.
the class ChatTest method populateThreadsListFromServerOrCache.
// requests for list of threads
@Test
public void populateThreadsListFromServerOrCache() {
chatListeners = new ChatListener() {
@Override
public void onGetThread(String content, ChatResponse<ResultThreads> thread) {
System.out.println("Received List: " + content);
threads.addAll(thread.getResult().getThreads());
}
};
chat.addListener(chatListeners);
RequestThread requestThread = new RequestThread.Builder().count(25).build();
presenter.getThreads(requestThread, null);
long t1 = System.currentTimeMillis();
Mockito.verify(view, Mockito.after(10000).atLeastOnce()).onGetThreadList(Mockito.any(), Mockito.any());
long t2 = System.currentTimeMillis();
System.out.println("Received List: " + threads.size() + " after: " + (t2 - t1) + " ms");
}
use of com.fanap.podchat.model.ResultThreads in project pod-chat-android-sdk by FanapSoft.
the class ChatTest method populateThreadsListFromServerOnly.
// requests for list of threads from server
@Test
public void populateThreadsListFromServerOnly() {
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());
resumeProcess();
}
}
};
chat.setListener(chatListeners);
RequestThread requestThread = new RequestThread.Builder().count(25).withNoCache().build();
presenter.getThreads(requestThread, null);
pauseProcess();
System.out.println("Received List: " + threads.size());
}
use of com.fanap.podchat.model.ResultThreads in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method reformatGetThreadsResponse.
/**
* Reformat the get thread response
*/
private ChatResponse<ResultThreads> reformatGetThreadsResponse(ChatMessage chatMessage, Callback callback) {
ChatResponse<ResultThreads> outPutThreads = new ChatResponse<>();
ArrayList<Thread> threads = gson.fromJson(chatMessage.getContent(), new TypeToken<ArrayList<Thread>>() {
}.getType());
if (cache) {
// get threads summary shouldn't update cache
if (!handlerSend.containsKey(chatMessage.getUniqueId())) {
// messageDatabaseHelper.saveThreads(threads);
dataSource.saveThreadResultFromServer(threads);
}
}
ResultThreads resultThreads = new ResultThreads();
resultThreads.setThreads(threads);
resultThreads.setContentCount(chatMessage.getContentCount());
outPutThreads.setErrorCode(0);
outPutThreads.setErrorMessage("");
outPutThreads.setHasError(false);
outPutThreads.setUniqueId(chatMessage.getUniqueId());
if (callback != null) {
resultThreads.setHasNext(threads.size() + callback.getOffset() < chatMessage.getContentCount());
resultThreads.setNextOffset(callback.getOffset() + threads.size());
}
outPutThreads.setResult(resultThreads);
return outPutThreads;
}
use of com.fanap.podchat.model.ResultThreads in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method publishThreadsList.
private String publishThreadsList(String uniqueId, Long finalOffset, ThreadManager.ThreadResponse cacheThreadResponse) {
ChatResponse<ResultThreads> chatResponse = new ChatResponse<>();
List<Thread> threadList = cacheThreadResponse.getThreadList();
chatResponse.setCache(true);
long contentCount = cacheThreadResponse.getContentCount();
ResultThreads resultThreads = new ResultThreads();
resultThreads.setThreads(threadList);
resultThreads.setContentCount(contentCount);
chatResponse.setCache(true);
resultThreads.setHasNext(threadList.size() + finalOffset < contentCount);
resultThreads.setNextOffset(finalOffset + threadList.size());
chatResponse.setResult(resultThreads);
chatResponse.setUniqueId(uniqueId);
String result = gson.toJson(chatResponse);
listenerManager.callOnGetThread(result, chatResponse);
return result;
}
Aggregations