Search in sources :

Example 1 with ContactRemove

use of com.fanap.podchat.model.ContactRemove 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)

Aggregations

ChatResponse (com.fanap.podchat.model.ChatResponse)1 ContactRemove (com.fanap.podchat.model.ContactRemove)1 ResultRemoveContact (com.fanap.podchat.model.ResultRemoveContact)1 JsonObject (com.google.gson.JsonObject)1 Response (retrofit2.Response)1