Search in sources :

Example 36 with ChatResponse

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;
    }
}
Also used : CallParticipantVO(com.fanap.podchat.call.model.CallParticipantVO) TypeToken(com.google.gson.reflect.TypeToken) ChatResponse(com.fanap.podchat.model.ChatResponse) MuteUnMuteCallParticipantResult(com.fanap.podchat.call.result_model.MuteUnMuteCallParticipantResult) PodChatException(com.fanap.podchat.util.PodChatException) JsonSyntaxException(com.google.gson.JsonSyntaxException)

Example 37 with ChatResponse

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;
    }
}
Also used : CallParticipantVO(com.fanap.podchat.call.model.CallParticipantVO) TypeToken(com.google.gson.reflect.TypeToken) ChatResponse(com.fanap.podchat.model.ChatResponse) PodChatException(com.fanap.podchat.util.PodChatException) JsonSyntaxException(com.google.gson.JsonSyntaxException) GetCallParticipantResult(com.fanap.podchat.call.result_model.GetCallParticipantResult)

Example 38 with ChatResponse

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;
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) ChatResponse(com.fanap.podchat.model.ChatResponse) ArrayList(java.util.ArrayList) CreateCallVO(com.fanap.podchat.call.model.CreateCallVO) CallVO(com.fanap.podchat.call.model.CallVO) GetCallHistoryResult(com.fanap.podchat.call.result_model.GetCallHistoryResult)

Example 39 with ChatResponse

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;
}
Also used : ChatResponse(com.fanap.podchat.model.ChatResponse) GetCallHistoryResult(com.fanap.podchat.call.result_model.GetCallHistoryResult)

Example 40 with ChatResponse

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());
}
Also used : ResultContact(com.fanap.podchat.model.ResultContact) ResultThreads(com.fanap.podchat.model.ResultThreads) RoleType(com.fanap.podchat.chat.RoleType) ChatPresenter(com.example.chat.application.chatexample.ChatPresenter) ResultHistory(com.fanap.podchat.model.ResultHistory) RequestGetContact(com.fanap.podchat.requestobject.RequestGetContact) Looper(android.os.Looper) App(com.fanap.podchat.chat.App) Invitee(com.fanap.podchat.mainmodel.Invitee) InviteType(com.fanap.podchat.util.InviteType) Participant(com.fanap.podchat.mainmodel.Participant) Logger(com.orhanobut.logger.Logger) InstrumentationRegistry(android.support.test.InstrumentationRegistry) ChatListener(com.fanap.podchat.chat.ChatListener) MessageVO(com.fanap.podchat.mainmodel.MessageVO) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) AssistantHistoryVo(com.fanap.podchat.chat.assistant.model.AssistantHistoryVo) APP_ID(com.example.chat.application.chatexample.ChatActivity.APP_ID) List(java.util.List) GetBlockedAssistantsRequest(com.fanap.podchat.chat.assistant.request_model.GetBlockedAssistantsRequest) GetAssistantRequest(com.fanap.podchat.chat.assistant.request_model.GetAssistantRequest) Chat(com.fanap.podchat.chat.Chat) Context(android.content.Context) GetAssistantHistoryRequest(com.fanap.podchat.chat.assistant.request_model.GetAssistantHistoryRequest) RequestConnect(com.fanap.podchat.requestobject.RequestConnect) AssistantVo(com.fanap.podchat.chat.assistant.model.AssistantVo) BeforeClass(org.junit.BeforeClass) Mock(org.mockito.Mock) Thread(com.fanap.podchat.mainmodel.Thread) RunWith(org.junit.runner.RunWith) ChatContract(com.example.chat.application.chatexample.ChatContract) RegisterAssistantRequest(com.fanap.podchat.chat.assistant.request_model.RegisterAssistantRequest) ChatResponse(com.fanap.podchat.model.ChatResponse) ResultParticipant(com.fanap.podchat.model.ResultParticipant) ArrayList(java.util.ArrayList) R(com.fanap.podchat.example.R) RequestThreadParticipant(com.fanap.podchat.requestobject.RequestThreadParticipant) BaseApplication(com.example.chat.application.chatexample.BaseApplication) ChatActivity(com.example.chat.application.chatexample.ChatActivity) Contact(com.fanap.podchat.mainmodel.Contact) RequestThread(com.fanap.podchat.requestobject.RequestThread) 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) AndroidJUnit4(android.support.test.runner.AndroidJUnit4) LargeTest(android.support.test.filters.LargeTest) Mockito(org.mockito.Mockito) Rule(org.junit.Rule) BlockUnblockAssistantRequest(com.fanap.podchat.chat.assistant.request_model.BlockUnblockAssistantRequest) Assert(org.junit.Assert) Activity(android.app.Activity) Collections(java.util.Collections) AssistantVo(com.fanap.podchat.chat.assistant.model.AssistantVo) ArrayList(java.util.ArrayList) ResultContact(com.fanap.podchat.model.ResultContact) RequestGetContact(com.fanap.podchat.requestobject.RequestGetContact) Contact(com.fanap.podchat.mainmodel.Contact) Invitee(com.fanap.podchat.mainmodel.Invitee) ChatListener(com.fanap.podchat.chat.ChatListener) List(java.util.List) ArrayList(java.util.ArrayList) GetAssistantRequest(com.fanap.podchat.chat.assistant.request_model.GetAssistantRequest) BlockUnblockAssistantRequest(com.fanap.podchat.chat.assistant.request_model.BlockUnblockAssistantRequest) Test(org.junit.Test) LargeTest(android.support.test.filters.LargeTest)

Aggregations

ChatResponse (com.fanap.podchat.model.ChatResponse)162 ChatListener (com.fanap.podchat.chat.ChatListener)38 Test (org.junit.Test)38 ArrayList (java.util.ArrayList)35 Thread (com.fanap.podchat.mainmodel.Thread)29 JsonSyntaxException (com.google.gson.JsonSyntaxException)29 ResultHistory (com.fanap.podchat.model.ResultHistory)28 LargeTest (android.support.test.filters.LargeTest)27 RequestThread (com.fanap.podchat.requestobject.RequestThread)27 PodChatException (com.fanap.podchat.util.PodChatException)26 MessageVO (com.fanap.podchat.mainmodel.MessageVO)25 RoomIntegrityException (com.fanap.podchat.persistance.RoomIntegrityException)23 IOException (java.io.IOException)23 JSONException (org.json.JSONException)22 ResultThreads (com.fanap.podchat.model.ResultThreads)21 RequestGetHistory (com.fanap.podchat.requestobject.RequestGetHistory)21 SentryException (io.sentry.core.protocol.SentryException)21 FlakyTest (android.support.test.filters.FlakyTest)19 MediumTest (android.support.test.filters.MediumTest)19 Activity (android.app.Activity)17