Search in sources :

Example 1 with AssistantHistoryVo

use of com.fanap.podchat.chat.assistant.model.AssistantHistoryVo in project pod-chat-android-sdk by FanapSoft.

the class AssistantCacheTest method getAndValidateAssistantHistoriesCache.

@Test
public void getAndValidateAssistantHistoriesCache() {
    ArrayList<AssistantVo> assistantVoArrayList = new ArrayList<>();
    chat.addListener(new ChatListener() {

        @Override
        public void onGetAssistants(ChatResponse<List<AssistantVo>> response) {
            assistantVoArrayList.addAll(response.getResult());
            chat.removeListener(this);
            resumeProcess();
        }
    });
    GetAssistantRequest request = new GetAssistantRequest.Builder().setCount(25).setOffset(0).build();
    chat.getAssistants(request);
    pauseProcess();
    Collections.shuffle(assistantVoArrayList);
    ArrayList<AssistantHistoryVo> assistantHistoryVos = new ArrayList<>();
    ArrayList<AssistantHistoryVo> assistantHistoryVosCache = new ArrayList<>();
    chat.addListener(new ChatListener() {

        @Override
        public void onGetAssistantHistory(ChatResponse<List<AssistantHistoryVo>> response) {
            print("Received Assistant Histories cache: " + response.isCache());
            prettyLog(App.getGson().toJson(response.getResult()));
            if (response.isCache()) {
                assistantHistoryVosCache.addAll(response.getResult());
            } else {
                assistantHistoryVos.addAll(response.getResult());
            }
            if (assistantHistoryVos.size() == assistantHistoryVosCache.size()) {
                chat.removeListener(this);
                resumeProcess();
            }
        }
    });
    GetAssistantHistoryRequest getAssistantHistoryRequest = new GetAssistantHistoryRequest.Builder().setCount(50).build();
    chat.getAssistantHistory(getAssistantHistoryRequest);
    pauseProcess();
    Assert.assertTrue(true);
}
Also used : AssistantVo(com.fanap.podchat.chat.assistant.model.AssistantVo) ArrayList(java.util.ArrayList) AssistantHistoryVo(com.fanap.podchat.chat.assistant.model.AssistantHistoryVo) ChatListener(com.fanap.podchat.chat.ChatListener) List(java.util.List) ArrayList(java.util.ArrayList) GetAssistantHistoryRequest(com.fanap.podchat.chat.assistant.request_model.GetAssistantHistoryRequest) GetAssistantRequest(com.fanap.podchat.chat.assistant.request_model.GetAssistantRequest) Test(org.junit.Test) LargeTest(android.support.test.filters.LargeTest)

Example 2 with AssistantHistoryVo

use of com.fanap.podchat.chat.assistant.model.AssistantHistoryVo in project pod-chat-android-sdk by FanapSoft.

the class AssistantManager method handleAssistantHistoryResponse.

public static ChatResponse<List<AssistantHistoryVo>> handleAssistantHistoryResponse(ChatMessage chatMessage) {
    ChatResponse<List<AssistantHistoryVo>> response = new ChatResponse<>();
    List<AssistantHistoryVo> result = App.getGson().fromJson(chatMessage.getContent(), new TypeToken<ArrayList<AssistantHistoryVo>>() {
    }.getType());
    for (AssistantHistoryVo history : result) {
        switch(history.getActionType()) {
            case AssistantActionType.REGISTER_ASSISTANT:
                history.setActionName("REGISTER_ASSISTANT");
                break;
            case AssistantActionType.ACTIVATE_ASSISTANT:
                history.setActionName("ACTIVATE_ASSISTANT");
                break;
            case AssistantActionType.DEACTIVE_ASSISTANT:
                history.setActionName("DEACTIVE_ASSISTANT");
                break;
            case AssistantActionType.BLOCK_ASSISTANT:
                history.setActionName("BLOCK_ASSISTANT");
                break;
            case AssistantActionType.UNBLOCK_ASSISTANT:
                history.setActionName("UNBLOCK_ASSISTANT");
                break;
        }
    }
    response.setResult(result);
    response.setUniqueId(chatMessage.getUniqueId());
    response.setCache(false);
    return response;
}
Also used : TypeToken(com.google.gson.reflect.TypeToken) ChatResponse(com.fanap.podchat.model.ChatResponse) ArrayList(java.util.ArrayList) List(java.util.List) AssistantHistoryVo(com.fanap.podchat.chat.assistant.model.AssistantHistoryVo)

Example 3 with AssistantHistoryVo

use of com.fanap.podchat.chat.assistant.model.AssistantHistoryVo in project pod-chat-android-sdk by FanapSoft.

the class MessageDatabaseHelper method updateCashAssistantHistory.

public void updateCashAssistantHistory(OnWorkDone listener, List<AssistantHistoryVo> response) {
    worker(() -> {
        List<CacheAssistantHistoryVo> cashAssitantHistory = new ArrayList<>();
        for (AssistantHistoryVo assistantVo : response) {
            CacheAssistantHistoryVo cashAsisstantHistory = new CacheAssistantHistoryVo();
            if (assistantVo.getParticipantVO() != null) {
                Participant participant = assistantVo.getParticipantVO();
                String participantJson = App.getGson().toJson(participant);
                CacheParticipant cacheParticipant = App.getGson().fromJson(participantJson, CacheParticipant.class);
                messageDao.insertParticipant(cacheParticipant);
                cashAsisstantHistory.setParticipantVOId(assistantVo.getParticipantVO().getId());
            }
            cashAsisstantHistory.setActionTime(assistantVo.getActionTime());
            cashAsisstantHistory.setActionType(assistantVo.getActionType());
            cashAsisstantHistory.setActionName(assistantVo.getActionName());
            cashAssitantHistory.add(cashAsisstantHistory);
        }
        messageDao.insertCacheAssistantHistoryVo(cashAssitantHistory);
        listener.onWorkDone(true);
    });
}
Also used : CacheThreadParticipant(com.fanap.podchat.cachemodel.CacheThreadParticipant) CacheParticipant(com.fanap.podchat.cachemodel.CacheParticipant) Participant(com.fanap.podchat.mainmodel.Participant) CacheCallParticipant(com.fanap.podchat.call.persist.CacheCallParticipant) ArrayList(java.util.ArrayList) CacheAssistantHistoryVo(com.fanap.podchat.cachemodel.CacheAssistantHistoryVo) CacheAssistantHistoryVo(com.fanap.podchat.cachemodel.CacheAssistantHistoryVo) AssistantHistoryVo(com.fanap.podchat.chat.assistant.model.AssistantHistoryVo) CacheParticipant(com.fanap.podchat.cachemodel.CacheParticipant)

Example 4 with AssistantHistoryVo

use of com.fanap.podchat.chat.assistant.model.AssistantHistoryVo in project pod-chat-android-sdk by FanapSoft.

the class MessageDatabaseHelper method getCacheAssistantHistoryVos.

public void getCacheAssistantHistoryVos(GetAssistantHistoryRequest request, FunctionalListener callback) throws RoomIntegrityException {
    if (!canUseDatabase())
        throw new RoomIntegrityException();
    worker(() -> {
        List<CacheAssistantHistoryVo> list = messageDao.getCacheAssistantHistory(request.getCount() > 0 ? request.getCount() : 25, request.getOffset());
        List<AssistantHistoryVo> cacheResponseList = new ArrayList<>();
        for (CacheAssistantHistoryVo item : list) {
            AssistantHistoryVo assistantHistoryVo = new AssistantHistoryVo();
            assistantHistoryVo.setActionName(item.getActionName());
            assistantHistoryVo.setActionTime(item.getActionTime());
            assistantHistoryVo.setActionType(item.getActionType());
            Participant participant = cacheToParticipantMapper(messageDao.getParticipant(item.getParticipantVOId()), false, null);
            assistantHistoryVo.setParticipantVO(participant);
            cacheResponseList.add(assistantHistoryVo);
        }
        callback.onWorkDone(list.size(), cacheResponseList);
    });
}
Also used : CacheThreadParticipant(com.fanap.podchat.cachemodel.CacheThreadParticipant) CacheParticipant(com.fanap.podchat.cachemodel.CacheParticipant) Participant(com.fanap.podchat.mainmodel.Participant) CacheCallParticipant(com.fanap.podchat.call.persist.CacheCallParticipant) ArrayList(java.util.ArrayList) CacheAssistantHistoryVo(com.fanap.podchat.cachemodel.CacheAssistantHistoryVo) CacheAssistantHistoryVo(com.fanap.podchat.cachemodel.CacheAssistantHistoryVo) AssistantHistoryVo(com.fanap.podchat.chat.assistant.model.AssistantHistoryVo)

Aggregations

AssistantHistoryVo (com.fanap.podchat.chat.assistant.model.AssistantHistoryVo)4 ArrayList (java.util.ArrayList)4 CacheAssistantHistoryVo (com.fanap.podchat.cachemodel.CacheAssistantHistoryVo)2 CacheParticipant (com.fanap.podchat.cachemodel.CacheParticipant)2 CacheThreadParticipant (com.fanap.podchat.cachemodel.CacheThreadParticipant)2 CacheCallParticipant (com.fanap.podchat.call.persist.CacheCallParticipant)2 Participant (com.fanap.podchat.mainmodel.Participant)2 List (java.util.List)2 LargeTest (android.support.test.filters.LargeTest)1 ChatListener (com.fanap.podchat.chat.ChatListener)1 AssistantVo (com.fanap.podchat.chat.assistant.model.AssistantVo)1 GetAssistantHistoryRequest (com.fanap.podchat.chat.assistant.request_model.GetAssistantHistoryRequest)1 GetAssistantRequest (com.fanap.podchat.chat.assistant.request_model.GetAssistantRequest)1 ChatResponse (com.fanap.podchat.model.ChatResponse)1 TypeToken (com.google.gson.reflect.TypeToken)1 Test (org.junit.Test)1