Search in sources :

Example 41 with Thread

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());
}
Also used : ArrayList(java.util.ArrayList) Thread(com.fanap.podchat.mainmodel.Thread) RequestThread(com.fanap.podchat.requestobject.RequestThread) FlakyTest(android.support.test.filters.FlakyTest) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test) LargeTest(android.support.test.filters.LargeTest) LargeTest(android.support.test.filters.LargeTest)

Example 42 with Thread

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());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RequestGetHistory(com.fanap.podchat.requestobject.RequestGetHistory) ChatResponse(com.fanap.podchat.model.ChatResponse) ChatListener(com.fanap.podchat.chat.ChatListener) Thread(com.fanap.podchat.mainmodel.Thread) RequestThread(com.fanap.podchat.requestobject.RequestThread) FlakyTest(android.support.test.filters.FlakyTest) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test) LargeTest(android.support.test.filters.LargeTest) LargeTest(android.support.test.filters.LargeTest)

Example 43 with Thread

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;
}
Also used : TypeToken(com.google.gson.reflect.TypeToken) ResultThreads(com.fanap.podchat.model.ResultThreads) ChatResponse(com.fanap.podchat.model.ChatResponse) RequestCreateThread(com.fanap.podchat.requestobject.RequestCreateThread) ResultPinThread(com.fanap.podchat.chat.pin.pin_thread.model.ResultPinThread) Thread(com.fanap.podchat.mainmodel.Thread) RequestLeaveThread(com.fanap.podchat.requestobject.RequestLeaveThread) HandlerThread(android.os.HandlerThread) PinThread(com.fanap.podchat.chat.pin.pin_thread.PinThread) ResultLeaveThread(com.fanap.podchat.model.ResultLeaveThread) RequestMuteThread(com.fanap.podchat.requestobject.RequestMuteThread) ResultJoinPublicThread(com.fanap.podchat.chat.thread.public_thread.ResultJoinPublicThread) RequestJoinPublicThread(com.fanap.podchat.chat.thread.public_thread.RequestJoinPublicThread) PublicThread(com.fanap.podchat.chat.thread.public_thread.PublicThread) RequestThread(com.fanap.podchat.requestobject.RequestThread) ResultThread(com.fanap.podchat.model.ResultThread) RequestPinThread(com.fanap.podchat.chat.pin.pin_thread.model.RequestPinThread)

Example 44 with Thread

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);
}
Also used : ChatResponse(com.fanap.podchat.model.ChatResponse) ResultThread(com.fanap.podchat.model.ResultThread) RequestCreateThread(com.fanap.podchat.requestobject.RequestCreateThread) ResultPinThread(com.fanap.podchat.chat.pin.pin_thread.model.ResultPinThread) Thread(com.fanap.podchat.mainmodel.Thread) RequestLeaveThread(com.fanap.podchat.requestobject.RequestLeaveThread) HandlerThread(android.os.HandlerThread) PinThread(com.fanap.podchat.chat.pin.pin_thread.PinThread) ResultLeaveThread(com.fanap.podchat.model.ResultLeaveThread) RequestMuteThread(com.fanap.podchat.requestobject.RequestMuteThread) ResultJoinPublicThread(com.fanap.podchat.chat.thread.public_thread.ResultJoinPublicThread) RequestJoinPublicThread(com.fanap.podchat.chat.thread.public_thread.RequestJoinPublicThread) PublicThread(com.fanap.podchat.chat.thread.public_thread.PublicThread) RequestThread(com.fanap.podchat.requestobject.RequestThread) ResultThread(com.fanap.podchat.model.ResultThread) RequestPinThread(com.fanap.podchat.chat.pin.pin_thread.model.RequestPinThread)

Example 45 with Thread

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;
}
Also used : ResultThreads(com.fanap.podchat.model.ResultThreads) ChatResponse(com.fanap.podchat.model.ChatResponse) RequestCreateThread(com.fanap.podchat.requestobject.RequestCreateThread) ResultPinThread(com.fanap.podchat.chat.pin.pin_thread.model.ResultPinThread) Thread(com.fanap.podchat.mainmodel.Thread) RequestLeaveThread(com.fanap.podchat.requestobject.RequestLeaveThread) HandlerThread(android.os.HandlerThread) PinThread(com.fanap.podchat.chat.pin.pin_thread.PinThread) ResultLeaveThread(com.fanap.podchat.model.ResultLeaveThread) RequestMuteThread(com.fanap.podchat.requestobject.RequestMuteThread) ResultJoinPublicThread(com.fanap.podchat.chat.thread.public_thread.ResultJoinPublicThread) RequestJoinPublicThread(com.fanap.podchat.chat.thread.public_thread.RequestJoinPublicThread) PublicThread(com.fanap.podchat.chat.thread.public_thread.PublicThread) RequestThread(com.fanap.podchat.requestobject.RequestThread) ResultThread(com.fanap.podchat.model.ResultThread) RequestPinThread(com.fanap.podchat.chat.pin.pin_thread.model.RequestPinThread)

Aggregations

Thread (com.fanap.podchat.mainmodel.Thread)95 RequestThread (com.fanap.podchat.requestobject.RequestThread)79 Test (org.junit.Test)55 ChatListener (com.fanap.podchat.chat.ChatListener)53 ArrayList (java.util.ArrayList)42 ResultHistory (com.fanap.podchat.model.ResultHistory)36 LargeTest (android.support.test.filters.LargeTest)35 RequestMessage (com.fanap.podchat.requestobject.RequestMessage)33 Date (java.util.Date)30 ChatResponse (com.fanap.podchat.model.ChatResponse)22 RequestGetHistory (com.fanap.podchat.requestobject.RequestGetHistory)22 MessageVO (com.fanap.podchat.mainmodel.MessageVO)20 SearchSystemMetadataRequest (com.fanap.podchat.chat.messge.SearchSystemMetadataRequest)16 NosqlSearchMetadataCriteria (com.fanap.podchat.mainmodel.NosqlSearchMetadataCriteria)16 ResultNewMessage (com.fanap.podchat.model.ResultNewMessage)16 ResultThreads (com.fanap.podchat.model.ResultThreads)16 FlakyTest (android.support.test.filters.FlakyTest)14 MediumTest (android.support.test.filters.MediumTest)14 Activity (android.app.Activity)10 Context (android.content.Context)10