Search in sources :

Example 16 with RequestGetHistory

use of com.fanap.podchat.requestobject.RequestGetHistory in project pod-chat-android-sdk by FanapSoft.

the class AssistantCacheTest method populateMessagesFromServerOrCache.

public void populateMessagesFromServerOrCache() {
    populateThreadsListFromServerOnly();
    assert threads.size() > 0;
    Thread thread = threads.get(0);
    chatListeners = new ChatListener() {

        @Override
        public void onGetHistory(String content, ChatResponse<ResultHistory> history) {
            System.out.println("Received Message List, Cache: " + history.isCache() + " Content: " + content);
            threadMessagesList.addAll(history.getResult().getHistory());
            chat.removeListener(chatListeners);
            resumeProcess();
        }
    };
    chat.addListener(chatListeners);
    RequestGetHistory requestGetHistory = new RequestGetHistory.Builder(thread.getId()).build();
    chat.getHistory(requestGetHistory, null);
    pauseProcess();
}
Also used : RequestGetHistory(com.fanap.podchat.requestobject.RequestGetHistory) ChatListener(com.fanap.podchat.chat.ChatListener) ResultHistory(com.fanap.podchat.model.ResultHistory) Thread(com.fanap.podchat.mainmodel.Thread) RequestThread(com.fanap.podchat.requestobject.RequestThread)

Example 17 with RequestGetHistory

use of com.fanap.podchat.requestobject.RequestGetHistory in project pod-chat-android-sdk by FanapSoft.

the class ChatTestSandbox 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 18 with RequestGetHistory

use of com.fanap.podchat.requestobject.RequestGetHistory in project pod-chat-android-sdk by FanapSoft.

the class ChatTestSandbox method getThreadFullHistory.

private void getThreadFullHistory(Thread thread) {
    long startTime = System.currentTimeMillis();
    AtomicBoolean hasNext = new AtomicBoolean(true);
    int count = 25;
    int offset = 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());
            resumeProcess();
        }
    };
    chat.addListener(historyListeners);
    while (hasNext.get()) {
        RequestGetHistory requestGetHistory = new RequestGetHistory.Builder(thread.getId()).offset(offset).count(count).order("desc").build();
        String uniqueId = presenter.getHistory(requestGetHistory, null);
        offset = offset + count;
        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());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicLong(java.util.concurrent.atomic.AtomicLong) RequestGetHistory(com.fanap.podchat.requestobject.RequestGetHistory) ChatResponse(com.fanap.podchat.model.ChatResponse) ChatListener(com.fanap.podchat.chat.ChatListener)

Example 19 with RequestGetHistory

use of com.fanap.podchat.requestobject.RequestGetHistory in project pod-chat-android-sdk by FanapSoft.

the class MessagesCacheTest method forwardMessageAndCheckCache.

@Test
public void forwardMessageAndCheckCache() {
    populateThreadsListFromServerOnly();
    populateMessagesFromServer();
    assert threads.size() > 1;
    assert threadMessagesList.size() > 0;
    Collections.shuffle(threads);
    Thread thread2 = threads.get(1);
    MessageVO message = threadMessagesList.get(0);
    ChatListener mTestListener = Mockito.mock(ChatListener.class);
    chat.setListener(mTestListener);
    RequestForwardMessage forRequest = new RequestForwardMessage.Builder(thread2.getId(), new ArrayList<>(Collections.singletonList(message.getId()))).build();
    chat.forwardMessage(forRequest);
    sleep(2000);
    RequestGetHistory requestGetHistory = new RequestGetHistory.Builder(thread2.getId()).build();
    chat.getHistory(requestGetHistory, null);
    Mockito.verify(mTestListener, Mockito.after(2000).atLeastOnce()).onGetHistory(Mockito.any(), Mockito.argThat((ChatResponse<ResultHistory> response) -> response.isCache() && response.getResult().getHistory().stream().anyMatch(messageVO -> messageVO.getForwardInfo() != null)));
}
Also used : ResultThreads(com.fanap.podchat.model.ResultThreads) Context(android.content.Context) ResultNewMessage(com.fanap.podchat.model.ResultNewMessage) RequestConnect(com.fanap.podchat.requestobject.RequestConnect) BeforeClass(org.junit.BeforeClass) RequestForwardMessage(com.fanap.podchat.requestobject.RequestForwardMessage) Mock(org.mockito.Mock) Date(java.util.Date) Thread(com.fanap.podchat.mainmodel.Thread) RunWith(org.junit.runner.RunWith) ChatPresenter(com.example.chat.application.chatexample.ChatPresenter) ChatContract(com.example.chat.application.chatexample.ChatContract) ChatResponse(com.fanap.podchat.model.ChatResponse) ArrayList(java.util.ArrayList) R(com.fanap.podchat.example.R) ResultHistory(com.fanap.podchat.model.ResultHistory) Looper(android.os.Looper) BaseApplication(com.example.chat.application.chatexample.BaseApplication) ChatActivity(com.example.chat.application.chatexample.ChatActivity) RequestThread(com.fanap.podchat.requestobject.RequestThread) RequestMessage(com.fanap.podchat.requestobject.RequestMessage) Before(org.junit.Before) RequestGetHistory(com.fanap.podchat.requestobject.RequestGetHistory) CHAT_READY(com.fanap.podchat.util.ChatStateType.ChatSateConstant.CHAT_READY) ActivityTestRule(android.support.test.rule.ActivityTestRule) Test(org.junit.Test) InstrumentationRegistry(android.support.test.InstrumentationRegistry) AndroidJUnit4(android.support.test.runner.AndroidJUnit4) ChatListener(com.fanap.podchat.chat.ChatListener) MessageVO(com.fanap.podchat.mainmodel.MessageVO) Collectors(java.util.stream.Collectors) Mockito(org.mockito.Mockito) APP_ID(com.example.chat.application.chatexample.ChatActivity.APP_ID) Rule(org.junit.Rule) TextMessageType(com.fanap.podchat.util.TextMessageType) Assert(org.junit.Assert) Activity(android.app.Activity) Chat(com.fanap.podchat.chat.Chat) Collections(java.util.Collections) RequestReplyMessage(com.fanap.podchat.requestobject.RequestReplyMessage) RequestForwardMessage(com.fanap.podchat.requestobject.RequestForwardMessage) RequestGetHistory(com.fanap.podchat.requestobject.RequestGetHistory) ChatListener(com.fanap.podchat.chat.ChatListener) ArrayList(java.util.ArrayList) MessageVO(com.fanap.podchat.mainmodel.MessageVO) ResultHistory(com.fanap.podchat.model.ResultHistory) Thread(com.fanap.podchat.mainmodel.Thread) RequestThread(com.fanap.podchat.requestobject.RequestThread) Test(org.junit.Test)

Example 20 with RequestGetHistory

use of com.fanap.podchat.requestobject.RequestGetHistory in project pod-chat-android-sdk by FanapSoft.

the class MessagesCacheTest method populateMessagesFromCache.

public void populateMessagesFromCache() {
    populateThreadsListFromServerOnly();
    assert threads.size() > 0;
    Thread thread = threads.get(0);
    chatListeners = new ChatListener() {

        @Override
        public void onGetHistory(String content, ChatResponse<ResultHistory> history) {
            if (history.isCache()) {
                System.out.println("Received Message List Cache: " + content);
                threadMessagesList.addAll(history.getResult().getHistory());
                chat.removeListener(chatListeners);
                resumeProcess();
            }
        }
    };
    chat.addListener(chatListeners);
    RequestGetHistory requestGetHistory = new RequestGetHistory.Builder(thread.getId()).build();
    chat.getHistory(requestGetHistory, null);
    pauseProcess();
}
Also used : RequestGetHistory(com.fanap.podchat.requestobject.RequestGetHistory) ChatListener(com.fanap.podchat.chat.ChatListener) ResultHistory(com.fanap.podchat.model.ResultHistory) Thread(com.fanap.podchat.mainmodel.Thread) RequestThread(com.fanap.podchat.requestobject.RequestThread)

Aggregations

RequestGetHistory (com.fanap.podchat.requestobject.RequestGetHistory)27 ChatListener (com.fanap.podchat.chat.ChatListener)23 Thread (com.fanap.podchat.mainmodel.Thread)18 RequestThread (com.fanap.podchat.requestobject.RequestThread)18 ResultHistory (com.fanap.podchat.model.ResultHistory)15 ChatResponse (com.fanap.podchat.model.ChatResponse)14 Test (org.junit.Test)14 MessageVO (com.fanap.podchat.mainmodel.MessageVO)9 ArrayList (java.util.ArrayList)9 ResultNewMessage (com.fanap.podchat.model.ResultNewMessage)8 RequestMessage (com.fanap.podchat.requestobject.RequestMessage)7 Date (java.util.Date)7 Activity (android.app.Activity)6 Context (android.content.Context)6 Looper (android.os.Looper)6 InstrumentationRegistry (android.support.test.InstrumentationRegistry)6 LargeTest (android.support.test.filters.LargeTest)6 ActivityTestRule (android.support.test.rule.ActivityTestRule)6 AndroidJUnit4 (android.support.test.runner.AndroidJUnit4)6 BaseApplication (com.example.chat.application.chatexample.BaseApplication)6