use of com.fanap.podchat.mainmodel.Thread in project pod-chat-android-sdk by FanapSoft.
the class ChatTest method getThreadHistoryIns.
@Test
@LargeTest
public void getThreadHistoryIns() {
populateThreadsListFromServerOrCache();
System.out.println("** Get history of " + threads.get(0).getId());
for (Thread thread : new ArrayList<>(threads)) {
getThreadHistory(thread.getId());
}
// getThreadHistory(threads.get(0).getId());
}
use of com.fanap.podchat.mainmodel.Thread 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.mainmodel.Thread 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.mainmodel.Thread in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method handleRemoveFromThread.
private void handleRemoveFromThread(ChatMessage chatMessage) {
ChatResponse<ResultThread> chatResponse = new ChatResponse<>();
ResultThread resultThread = new ResultThread();
Thread thread = new Thread();
thread.setId(chatMessage.getSubjectId());
resultThread.setThread(thread);
String content = gson.toJson(chatResponse);
if (cache) {
messageDatabaseHelper.deleteThread(chatMessage.getSubjectId());
}
if (sentryResponseLog) {
showLog("RECEIVED_REMOVED_FROM_THREAD", content);
} else {
showLog("RECEIVED_REMOVED_FROM_THREAD");
}
listenerManager.callOnRemovedFromThread(content, chatResponse);
}
use of com.fanap.podchat.mainmodel.Thread 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