Search in sources :

Example 56 with Thread

use of com.fanap.podchat.mainmodel.Thread in project pod-chat-android-sdk by FanapSoft.

the class ChatTest method sendMessageToThreadMessage.

@Test
@LargeTest
public void sendMessageToThreadMessage() {
    populateThreadsListFromServerOrCache();
    long threadID = 0;
    for (Thread thread : new ArrayList<>(threads)) {
        if (!thread.isClosed() && thread.isGroup() && thread.getAdmin()) {
            threadID = thread.getId();
        }
    }
    if (threadID > 0)
        sendTestMessageOnSeen(threadID);
}
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 57 with Thread

use of com.fanap.podchat.mainmodel.Thread in project pod-chat-android-sdk by FanapSoft.

the class ChatTest method getAllThreadsHistories.

@Test
@LargeTest
public // performance should be acceptable
void getAllThreadsHistories() {
    // get 25 thread from server
    populateThreadsListFromServerOrCache();
    long startTime = System.currentTimeMillis();
    for (Thread thread : new ArrayList<>(threads)) {
        System.out.println("NEXT: " + thread.getTitle());
        System.out.println(thread.getId());
        getThreadFullHistory(thread);
    }
    long endTime = System.currentTimeMillis();
    Assert.assertTrue(true);
    System.out.println(">>> >>> >>>");
    System.out.println(">>> >>> >>>");
    System.out.println(">>> >>> >>>");
    System.out.println("TEST IS DONE FOR ");
    System.out.println(threads.size());
    System.out.println("THREADS IN");
    System.out.println(endTime - startTime + " MILLISECONDS");
    System.out.println(">>> >>> >>>");
    System.out.println(">>> >>> >>>");
    System.out.println(">>> >>> >>>");
}
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 58 with Thread

use of com.fanap.podchat.mainmodel.Thread in project pod-chat-android-sdk by FanapSoft.

the class MessageDatabaseHelper method retrieveAndUpdateThreadOnLastMessageEdited.

public void retrieveAndUpdateThreadOnLastMessageEdited(Thread thread, ThreadManager.ILastMessageChanged callback) {
    worker(() -> {
        long threadId = thread.getId();
        ArrayList<Integer> tIds = new ArrayList<>();
        tIds.add((int) threadId);
        try {
            getThreadRaw(1, (long) 0, tIds, null, false, threads -> {
                List<Thread> threadList = (List<Thread>) threads;
                if (!Util.isNullOrEmpty(threadList) && threadList.get(0).getId() > 0) {
                    Thread threadFromCache = threadList.get(0);
                    threadFromCache.setLastMessage(thread.getLastMessage());
                    threadFromCache.setLastMessageVO(thread.getLastMessageVO());
                    callback.onThreadExistInCache(threadFromCache);
                    saveNewThread(threadFromCache);
                } else {
                    callback.threadNotFoundInCache();
                }
            });
        } catch (RoomIntegrityException e) {
            e.printStackTrace();
            callback.threadNotFoundInCache();
        }
    });
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) RequestGetHashTagList(com.fanap.podchat.chat.hashtag.model.RequestGetHashTagList) List(java.util.List) RequestGetMentionList(com.fanap.podchat.chat.mention.model.RequestGetMentionList) Thread(com.fanap.podchat.mainmodel.Thread)

Example 59 with Thread

use of com.fanap.podchat.mainmodel.Thread in project pod-chat-android-sdk by FanapSoft.

the class ChatTestSandbox method getUserRolesInThread.

@Test
@LargeTest
public void getUserRolesInThread() {
    populateThreadsListFromServerOrCache();
    for (Thread t : threads) {
        if (t.getAdmin()) {
            System.out.println("Get roles in " + t.getId());
            getCurrentUserRoles(t.getId());
            break;
        }
    }
    System.out.println("** Get roles in " + threads.get(0).getId());
    getCurrentUserRoles(threads.get(0).getId());
}
Also used : 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 60 with Thread

use of com.fanap.podchat.mainmodel.Thread 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)

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