use of com.fanap.podchat.model.ResultThreads in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method publishMutualThreadsList.
private String publishMutualThreadsList(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);
if (threadList.size() + finalOffset < contentCount) {
resultThreads.setHasNext(true);
} else {
resultThreads.setHasNext(false);
}
resultThreads.setNextOffset(finalOffset + threadList.size());
chatResponse.setResult(resultThreads);
chatResponse.setUniqueId(uniqueId);
String result = gson.toJson(chatResponse);
listenerManager.callOnGetMutualGroup(result, chatResponse);
return result;
}
use of com.fanap.podchat.model.ResultThreads in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method reformatGetThreadsResponseForMutual.
/**
* Reformat the get thread response
*/
private ChatResponse<ResultThreads> reformatGetThreadsResponseForMutual(ChatMessage chatMessage, long userId) {
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);
dataSource.saveMutualThreadResultFromServer(threads, userId);
}
}
ResultThreads resultThreads = new ResultThreads();
resultThreads.setThreads(threads);
resultThreads.setContentCount(chatMessage.getContentCount());
outPutThreads.setErrorCode(0);
outPutThreads.setErrorMessage("");
outPutThreads.setHasError(false);
outPutThreads.setUniqueId(chatMessage.getUniqueId());
outPutThreads.setResult(resultThreads);
return outPutThreads;
}
use of com.fanap.podchat.model.ResultThreads in project pod-chat-android-sdk by FanapSoft.
the class MessagesCacheTest method populateThreadsListFromServerOnly.
// requests for list of threads from server
public void populateThreadsListFromServerOnly() {
chatListeners = new ChatListener() {
@Override
public void onGetThread(String content, ChatResponse<ResultThreads> response) {
if (!response.isCache()) {
System.out.println("Received List: " + content);
threads.addAll(response.getResult().getThreads().stream().filter(thread -> thread.getTitle() != null && thread.getId() > 0 && !thread.isClosed() && thread.getLastMessageVO() != null).collect(Collectors.toList()));
chat.removeListener(chatListeners);
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 MessagesCacheTest method populateThreadsListFromServerOrCache.
// requests for list of threads
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.removeListener(chatListeners);
}
};
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 MentionCacheTest method populateMessageFromServer.
public void populateMessageFromServer() {
chatListeners = new ChatListener() {
@Override
public void onGetMentionList(ChatResponse<ResultHistory> response) {
ChatListener.super.onGetMentionList(response);
}
@Override
public void onGetThread(String content, ChatResponse<ResultThreads> response) {
if (!response.isCache()) {
System.out.println("Received List: " + content);
for (Thread thread : response.getResult().getThreads()) {
if (thread.isGroup()) {
threads.add(thread);
}
}
chat.removeListener(chatListeners);
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());
}
Aggregations