Search in sources :

Example 1 with ResultRemoveContact

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

the class ChatCore method removeContact.

/**
 * Remove contact with the user id
 *
 * @param userId id of the user that we want to remove from contact list
 */
@Deprecated
public String removeContact(long userId) {
    String uniqueId = generateUniqueId();
    JsonObject jsonObject = new JsonObject();
    jsonObject.addProperty("uniqueId", uniqueId);
    jsonObject.addProperty("id", userId);
    jsonObject.addProperty("tokenIssuer", 1);
    showLog("SEND_REMOVE_CONTACT", getJsonForLog(jsonObject));
    Observable<Response<ContactRemove>> removeContactObservable;
    if (chatReady) {
        if (Util.isNullOrEmpty(getTypeCode())) {
            removeContactObservable = contactApi.removeContact(getToken(), 1, userId);
        } else {
            removeContactObservable = contactApi.removeContact(getToken(), 1, userId, getTypeCode());
        }
        removeContactObservable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(response -> {
            Log.d("MTAG", response.raw().toString());
            if (response.body() != null && response.isSuccessful()) {
                ContactRemove contactRemove = response.body();
                if (!contactRemove.getHasError()) {
                    ChatResponse<ResultRemoveContact> chatResponse = new ChatResponse<>();
                    chatResponse.setUniqueId(uniqueId);
                    ResultRemoveContact resultRemoveContact = new ResultRemoveContact();
                    resultRemoveContact.setResult(contactRemove.isResult());
                    chatResponse.setResult(resultRemoveContact);
                    String json = gson.toJson(chatResponse);
                    if (cache) {
                        dataSource.deleteContactById(userId);
                    // messageDatabaseHelper.deleteContactById(userId);
                    }
                    listenerManager.callOnRemoveContact(json, chatResponse);
                    showLog("RECEIVED_REMOVE_CONTACT", json);
                } else {
                    captureError(contactRemove.getErrorMessage(), contactRemove.getErrorCode(), uniqueId);
                }
            }
        }, (Throwable throwable) -> captureError(throwable.getMessage(), ChatConstant.ERROR_CODE_UNKNOWN_EXCEPTION, uniqueId, throwable));
    } else {
        captureError(ChatConstant.ERROR_CHAT_READY, ChatConstant.ERROR_CODE_CHAT_READY, uniqueId);
    }
    return uniqueId;
}
Also used : ChatResponse(com.fanap.podchat.model.ChatResponse) Response(retrofit2.Response) ContactRemove(com.fanap.podchat.model.ContactRemove) ChatResponse(com.fanap.podchat.model.ChatResponse) JsonObject(com.google.gson.JsonObject) ResultRemoveContact(com.fanap.podchat.model.ResultRemoveContact)

Example 2 with ResultRemoveContact

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

the class ContactManager method prepareRemoveContactResponse.

public static ChatResponse<ResultRemoveContact> prepareRemoveContactResponse(ChatMessage chatMessage) {
    ChatResponse<ResultRemoveContact> response = new ChatResponse<>();
    ResultRemoveContact result = App.getGson().fromJson(chatMessage.getContent(), ResultRemoveContact.class);
    response.setResult(result);
    response.setUniqueId(chatMessage.getUniqueId());
    return response;
}
Also used : ChatResponse(com.fanap.podchat.model.ChatResponse) ResultRemoveContact(com.fanap.podchat.model.ResultRemoveContact)

Example 3 with ResultRemoveContact

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

the class IntegrationTest method removeContact.

@Test
public void removeContact() {
    chatListeners = new ChatListener() {

        @Override
        public void onRemoveContact(String content, ChatResponse<ResultRemoveContact> response) {
            System.out.println("Contact Removed: " + content);
            contactContent = content;
            resumeProcess();
        }

        @Override
        public void onError(String content, ErrorOutPut error) {
            System.out.println("onError: " + content);
            contactContent = content;
            resumeProcess();
        }
    };
    chat.addListener(chatListeners);
    chat.removeContact(18479);
    pauseProcess();
    System.out.println("Received contact: " + contactContent);
}
Also used : ChatListener(com.fanap.podchat.chat.ChatListener) ErrorOutPut(com.fanap.podchat.model.ErrorOutPut) ResultRemoveContact(com.fanap.podchat.model.ResultRemoveContact) Test(org.junit.Test) LargeTest(android.support.test.filters.LargeTest)

Aggregations

ResultRemoveContact (com.fanap.podchat.model.ResultRemoveContact)3 ChatResponse (com.fanap.podchat.model.ChatResponse)2 LargeTest (android.support.test.filters.LargeTest)1 ChatListener (com.fanap.podchat.chat.ChatListener)1 ContactRemove (com.fanap.podchat.model.ContactRemove)1 ErrorOutPut (com.fanap.podchat.model.ErrorOutPut)1 JsonObject (com.google.gson.JsonObject)1 Test (org.junit.Test)1 Response (retrofit2.Response)1