use of com.fanap.podchat.model.ChatResponse in project pod-chat-android-sdk by FanapSoft.
the class CallAsyncRequestsManager method handleMuteUnMuteCallParticipant.
public static ChatResponse<MuteUnMuteCallParticipantResult> handleMuteUnMuteCallParticipant(ChatMessage chatMessage) {
ChatResponse<MuteUnMuteCallParticipantResult> response = new ChatResponse<>();
try {
ArrayList<CallParticipantVO> mutedParticipants = App.getGson().fromJson(chatMessage.getContent(), new TypeToken<ArrayList<CallParticipantVO>>() {
}.getType());
MuteUnMuteCallParticipantResult result = new MuteUnMuteCallParticipantResult(mutedParticipants);
result.setCallId(chatMessage.getSubjectId());
response.setResult(result);
response.setCache(false);
response.setSubjectId(chatMessage.getSubjectId());
response.setUniqueId(chatMessage.getUniqueId());
response.setHasError(false);
return response;
} catch (Exception e) {
response.setCache(false);
response.setSubjectId(chatMessage.getSubjectId());
response.setUniqueId(chatMessage.getUniqueId());
response.setHasError(true);
response.setErrorMessage(e.getMessage());
response.setErrorCode(ChatConstant.ERROR_CODE_INVALID_DATA);
return response;
}
}
use of com.fanap.podchat.model.ChatResponse in project pod-chat-android-sdk by FanapSoft.
the class CallAsyncRequestsManager method reformatActiveCallParticipant.
public static ChatResponse<GetCallParticipantResult> reformatActiveCallParticipant(ChatMessage chatMessage) {
try {
ArrayList<CallParticipantVO> callParticipantVOS = App.getGson().fromJson(chatMessage.getContent(), new TypeToken<ArrayList<CallParticipantVO>>() {
}.getType());
ChatResponse<GetCallParticipantResult> response = new ChatResponse<>();
GetCallParticipantResult result = new GetCallParticipantResult(callParticipantVOS);
result.setThreadId(chatMessage.getSubjectId());
response.setResult(result);
response.setSubjectId(chatMessage.getSubjectId());
response.setUniqueId(chatMessage.getUniqueId());
response.setCache(false);
response.setHasError(false);
return response;
} catch (Exception e) {
e.printStackTrace();
ChatResponse<GetCallParticipantResult> response = new ChatResponse<>();
response.setErrorMessage(e.getMessage());
response.setErrorCode(ChatConstant.ERROR_CODE_UNKNOWN_EXCEPTION);
response.setHasError(true);
return response;
}
}
use of com.fanap.podchat.model.ChatResponse in project pod-chat-android-sdk by FanapSoft.
the class CallAsyncRequestsManager method handleOnGetCallHistory.
public static ChatResponse<GetCallHistoryResult> handleOnGetCallHistory(ChatMessage chatMessage, Callback callback) {
ChatResponse<GetCallHistoryResult> response = new ChatResponse<>();
response.setUniqueId(chatMessage.getUniqueId());
ArrayList<CallVO> calls = new ArrayList<>();
long offset = callback != null ? callback.getOffset() : 0;
try {
calls = App.getGson().fromJson(chatMessage.getContent(), new TypeToken<ArrayList<CallVO>>() {
}.getType());
} catch (JsonSyntaxException ignored) {
}
response.setResult(new GetCallHistoryResult(calls, chatMessage.getContentCount(), (calls.size() + offset < chatMessage.getContentCount()), (calls.size() + offset)));
return response;
}
use of com.fanap.podchat.model.ChatResponse in project pod-chat-android-sdk by FanapSoft.
the class CallAsyncRequestsManager method handleOnGetCallHistoryFromCache.
public static ChatResponse<GetCallHistoryResult> handleOnGetCallHistoryFromCache(String uniqueId, ArrayList<CallVO> calls, long contentCount, long offset) {
ChatResponse<GetCallHistoryResult> response = new ChatResponse<>();
response.setUniqueId(uniqueId);
response.setResult(new GetCallHistoryResult(calls, contentCount, (calls.size() + offset < contentCount), (calls.size() + offset)));
response.setCache(true);
return response;
}
use of com.fanap.podchat.model.ChatResponse in project pod-chat-android-sdk by FanapSoft.
the class AssistantCacheTest method blockAssistantAndCheckCache.
@Test
public void blockAssistantAndCheckCache() {
populateContactsFromServer();
List<AssistantVo> assistantVos = new ArrayList<>();
chat.addListener(new ChatListener() {
@Override
public void onGetAssistants(ChatResponse<List<AssistantVo>> response) {
if (!response.isCache()) {
prettyLog(response.getJson());
assistantVos.addAll(response.getResult());
chat.removeListener(this);
resumeProcess();
}
}
});
GetAssistantRequest request = new GetAssistantRequest.Builder().setCount(25).withNoCache().setOffset(0).build();
chat.getAssistants(request);
pauseProcess();
// the block assistant method accepts only Invitee
Collections.shuffle(assistantVos);
List<AssistantVo> notBlockedAssistants = assistantVos.stream().filter(assistantVo -> !assistantVo.getBlock()).collect(Collectors.toList());
Contact assistantContactToBlock = contacts.stream().filter(contact -> contact.getLinkedUser() != null && Objects.equals(contact.getLinkedUser().getUsername(), notBlockedAssistants.get(0).getParticipantVO().getUsername())).findFirst().get();
print("Going to block " + assistantContactToBlock.getFirstName());
prettyLog(App.getGson().toJson(assistantContactToBlock));
Invitee invitee = new Invitee(assistantContactToBlock.getId(), InviteType.Constants.TO_BE_USER_CONTACT_ID);
AssistantVo assistantToBlock = new AssistantVo();
assistantToBlock.setInvitees(invitee);
List<AssistantVo> toBlockAssistantList = new ArrayList<>();
toBlockAssistantList.add(assistantToBlock);
chat.addListener(new ChatListener() {
@Override
public void onAssistantBlocked(ChatResponse<List<AssistantVo>> response) {
prettyLog(response.getJson());
toBlockAssistantList.clear();
toBlockAssistantList.addAll(response.getResult());
chat.removeListener(this);
resumeProcess();
}
});
BlockUnblockAssistantRequest requestBlock = new BlockUnblockAssistantRequest.Builder(toBlockAssistantList, true).build();
chat.blockAssistant(requestBlock);
pauseProcess();
ArrayList<AssistantVo> inCache = new ArrayList<>();
chat.addListener(new ChatListener() {
@Override
public void onGetAssistants(ChatResponse<List<AssistantVo>> response) {
if (response.isCache()) {
prettyLog(response.getJson());
inCache.addAll(response.getResult());
chat.removeListener(this);
resumeProcess();
}
}
});
GetAssistantRequest requestGetAssistantFromCache = new GetAssistantRequest.Builder().setCount(25).setOffset(0).build();
chat.getAssistants(requestGetAssistantFromCache);
pauseProcess();
assert inCache.size() > 0;
Assert.assertTrue(inCache.stream().filter(anAssistantInCache -> toBlockAssistantList.stream().anyMatch(blockListAssistant -> anAssistantInCache.getParticipantVO().getId() == blockListAssistant.getParticipantVO().getId())).findFirst().get().getBlock());
}
Aggregations