Search in sources :

Example 1 with GenericOverall

use of com.nextcloud.talk.models.json.generic.GenericOverall in project talk-android by nextcloud.

the class AccountRemovalJob method onRunJob.

@NonNull
@Override
protected Result onRunJob(Params params) {
    NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this);
    PushConfigurationState pushConfigurationState;
    for (Object userEntityObject : userUtils.getUsersScheduledForDeletion()) {
        UserEntity userEntity = (UserEntity) userEntityObject;
        try {
            if (!TextUtils.isEmpty(userEntity.getPushConfigurationState())) {
                pushConfigurationState = LoganSquare.parse(userEntity.getPushConfigurationState(), PushConfigurationState.class);
                PushConfigurationState finalPushConfigurationState = pushConfigurationState;
                ncApi = retrofit.newBuilder().client(okHttpClient.newBuilder().cookieJar(new JavaNetCookieJar(new CookieManager())).build()).build().create(NcApi.class);
                ncApi.unregisterDeviceForNotificationsWithNextcloud(ApiUtils.getCredentials(userEntity.getUsername(), userEntity.getToken()), ApiUtils.getUrlNextcloudPush(userEntity.getBaseUrl())).subscribe(new Observer<GenericOverall>() {

                    @Override
                    public void onSubscribe(Disposable d) {
                    }

                    @Override
                    public void onNext(GenericOverall genericOverall) {
                        if (genericOverall.getOcs().getMeta().getStatusCode() == 200 || genericOverall.getOcs().getMeta().getStatusCode() == 202) {
                            HashMap<String, String> queryMap = new HashMap<>();
                            queryMap.put("deviceIdentifier", finalPushConfigurationState.deviceIdentifier);
                            queryMap.put("userPublicKey", finalPushConfigurationState.getUserPublicKey());
                            queryMap.put("deviceIdentifierSignature", finalPushConfigurationState.getDeviceIdentifierSignature());
                            ncApi.unregisterDeviceForNotificationsWithProxy(ApiUtils.getCredentials(userEntity.getUsername(), userEntity.getToken()), ApiUtils.getUrlPushProxy(), queryMap).subscribe(new Observer<Void>() {

                                @Override
                                public void onSubscribe(Disposable d) {
                                }

                                @Override
                                public void onNext(Void aVoid) {
                                    userUtils.deleteUser(userEntity.getUsername(), userEntity.getBaseUrl()).subscribe(new CompletableObserver() {

                                        @Override
                                        public void onSubscribe(Disposable d) {
                                        }

                                        @Override
                                        public void onComplete() {
                                        }

                                        @Override
                                        public void onError(Throwable e) {
                                        }
                                    });
                                }

                                @Override
                                public void onError(Throwable e) {
                                }

                                @Override
                                public void onComplete() {
                                }
                            });
                        }
                    }

                    @Override
                    public void onError(Throwable e) {
                    }

                    @Override
                    public void onComplete() {
                    }
                });
            } else {
                userUtils.deleteUser(userEntity.getUsername(), userEntity.getBaseUrl()).subscribe(new CompletableObserver() {

                    @Override
                    public void onSubscribe(Disposable d) {
                    }

                    @Override
                    public void onComplete() {
                    }

                    @Override
                    public void onError(Throwable e) {
                    }
                });
            }
        } catch (IOException e) {
            Log.d(TAG, "Something went wrong while removing job at parsing PushConfigurationState");
            userUtils.deleteUser(userEntity.getUsername(), userEntity.getBaseUrl()).subscribe(new CompletableObserver() {

                @Override
                public void onSubscribe(Disposable d) {
                }

                @Override
                public void onComplete() {
                }

                @Override
                public void onError(Throwable e) {
                }
            });
        }
    }
    return Result.SUCCESS;
}
Also used : JavaNetCookieJar(okhttp3.JavaNetCookieJar) Disposable(io.reactivex.disposables.Disposable) HashMap(java.util.HashMap) IOException(java.io.IOException) UserEntity(com.nextcloud.talk.models.database.UserEntity) PushConfigurationState(com.nextcloud.talk.models.json.push.PushConfigurationState) CompletableObserver(io.reactivex.CompletableObserver) Observer(io.reactivex.Observer) CompletableObserver(io.reactivex.CompletableObserver) NcApi(com.nextcloud.talk.api.NcApi) GenericOverall(com.nextcloud.talk.models.json.generic.GenericOverall) CookieManager(java.net.CookieManager) NonNull(android.support.annotation.NonNull)

Aggregations

NonNull (android.support.annotation.NonNull)1 NcApi (com.nextcloud.talk.api.NcApi)1 UserEntity (com.nextcloud.talk.models.database.UserEntity)1 GenericOverall (com.nextcloud.talk.models.json.generic.GenericOverall)1 PushConfigurationState (com.nextcloud.talk.models.json.push.PushConfigurationState)1 CompletableObserver (io.reactivex.CompletableObserver)1 Observer (io.reactivex.Observer)1 Disposable (io.reactivex.disposables.Disposable)1 IOException (java.io.IOException)1 CookieManager (java.net.CookieManager)1 HashMap (java.util.HashMap)1 JavaNetCookieJar (okhttp3.JavaNetCookieJar)1