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);
}
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;
}
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);
});
}
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);
});
}
Aggregations