mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-28 08:00:19 +01:00
Do some more work on deleting accounts
Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
parent
45f07f6118
commit
97589da58e
@ -21,6 +21,7 @@
|
||||
package com.nextcloud.talk.api;
|
||||
|
||||
import com.nextcloud.talk.api.models.json.call.CallOverall;
|
||||
import com.nextcloud.talk.api.models.json.generic.GenericOverall;
|
||||
import com.nextcloud.talk.api.models.json.generic.Status;
|
||||
import com.nextcloud.talk.api.models.json.participants.AddParticipantOverall;
|
||||
import com.nextcloud.talk.api.models.json.participants.ParticipantsOverall;
|
||||
@ -199,10 +200,27 @@ public interface NcApi {
|
||||
@QueryMap Map<String,
|
||||
String> options);
|
||||
|
||||
@DELETE
|
||||
Observable<GenericOverall> unregisterDeviceForNotificationsWithNextcloud(@Header("Authorization")
|
||||
String authorization,
|
||||
@Url String url);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST
|
||||
Observable<Void> registerDeviceForNotificationsWithProxy(@Header("Authorization") String authorization,
|
||||
@Url String url,
|
||||
@FieldMap Map<String, String> fields);
|
||||
|
||||
|
||||
/*
|
||||
QueryMap items are as follows:
|
||||
- "deviceIdentifier": "{{deviceIdentifier}}",
|
||||
- "deviceIdentifierSignature": "{{signature}}",
|
||||
- "userPublicKey": "{{userPublicKey}}"
|
||||
*/
|
||||
@DELETE
|
||||
Observable<Void> unregisterDeviceForNotificationsWithProxy(@Header("Authorization") String authorization,
|
||||
@Url String url,
|
||||
@QueryMap Map<String, String> fields);
|
||||
|
||||
}
|
||||
|
@ -145,7 +145,7 @@ public class ApiHelper {
|
||||
return baseUrl + ocsApiVersion + "/apps/notifications/api/v2/push";
|
||||
}
|
||||
|
||||
public static String getUrlPushProxy(String baseUrl) {
|
||||
public static String getUrlPushProxy() {
|
||||
return NextcloudTalkApplication.getSharedApplication().
|
||||
getApplicationContext().getResources().getString(R.string.nc_push_server_url) + "/devices";
|
||||
}
|
||||
|
@ -43,9 +43,6 @@ public class PushConfigurationState {
|
||||
@JsonField(name = "userPublicKey")
|
||||
public String userPublicKey;
|
||||
|
||||
@JsonField(name = "shouldBeDeleted")
|
||||
public boolean shouldBeDeleted;
|
||||
|
||||
@JsonField(name = "usesRegularPass")
|
||||
public boolean usesRegularPass;
|
||||
}
|
||||
|
@ -22,14 +22,26 @@ package com.nextcloud.talk.jobs;
|
||||
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.util.Log;
|
||||
|
||||
import com.bluelinelabs.logansquare.LoganSquare;
|
||||
import com.evernote.android.job.Job;
|
||||
import com.nextcloud.talk.api.NcApi;
|
||||
import com.nextcloud.talk.api.helpers.api.ApiHelper;
|
||||
import com.nextcloud.talk.api.models.json.generic.GenericOverall;
|
||||
import com.nextcloud.talk.api.models.json.push.PushConfigurationState;
|
||||
import com.nextcloud.talk.application.NextcloudTalkApplication;
|
||||
import com.nextcloud.talk.persistence.entities.UserEntity;
|
||||
import com.nextcloud.talk.utils.database.user.UserUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import autodagger.AutoInjector;
|
||||
import io.reactivex.Observer;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
|
||||
@AutoInjector(NextcloudTalkApplication.class)
|
||||
public class AccountRemovalJob extends Job {
|
||||
@ -38,10 +50,82 @@ public class AccountRemovalJob extends Job {
|
||||
@Inject
|
||||
UserUtils userUtils;
|
||||
|
||||
@Inject
|
||||
NcApi ncApi;
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
protected Result onRunJob(Params params) {
|
||||
NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this);
|
||||
|
||||
PushConfigurationState pushConfigurationState;
|
||||
for(Object userEntityObject : userUtils.getUsersScheduledForDeletion()) {
|
||||
UserEntity userEntity = (UserEntity) userEntityObject;
|
||||
try {
|
||||
pushConfigurationState = LoganSquare.parse(userEntity.getPushConfigurationState(),
|
||||
PushConfigurationState.class);
|
||||
PushConfigurationState finalPushConfigurationState = pushConfigurationState;
|
||||
ncApi.unregisterDeviceForNotificationsWithNextcloud(ApiHelper.getCredentials(userEntity.getUsername(),
|
||||
userEntity.getToken()), ApiHelper.getUrlNextcloudPush(userEntity.getBaseUrl()))
|
||||
.subscribe(new Observer<GenericOverall>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(GenericOverall genericOverall) {
|
||||
if (genericOverall.getOcs().getMeta().getStatusCode().equals("200")
|
||||
|| genericOverall.getOcs().getMeta().getStatusCode().equals("202")) {
|
||||
HashMap<String, String> queryMap = new HashMap<>();
|
||||
queryMap.put("deviceIdentifier", finalPushConfigurationState.deviceIdentifier);
|
||||
queryMap.put("userPublicKey", finalPushConfigurationState.getUserPublicKey());
|
||||
queryMap.put("deviceIdentifierSignature",
|
||||
finalPushConfigurationState.getDeviceIdentifierSignature());
|
||||
|
||||
ncApi.unregisterDeviceForNotificationsWithProxy
|
||||
(ApiHelper.getCredentials(userEntity.getUsername(),
|
||||
userEntity.getToken()), ApiHelper.getUrlPushProxy(), queryMap)
|
||||
.subscribe(new Observer<Void>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(Void aVoid) {
|
||||
userUtils.deleteUser(userEntity.getUsername(),
|
||||
userEntity.getBaseUrl());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
|
||||
}
|
||||
});
|
||||
} catch (IOException e) {
|
||||
Log.d(TAG, "Something went wrong while removing job at parsing PushConfigurationState");
|
||||
}
|
||||
|
||||
}
|
||||
return Result.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
@ -178,9 +178,6 @@ public class PushUtils {
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
private void deleteRegistrationForAccount(UserEntity userEntity) {
|
||||
}
|
||||
|
||||
public int generateRsa2048KeyPair() {
|
||||
if (!publicKeyFile.exists() && !privateKeyFile.exists()) {
|
||||
if (!keysFile.exists()) {
|
||||
@ -246,8 +243,8 @@ public class PushUtils {
|
||||
}
|
||||
|
||||
if (accountPushData != null && !accountPushData.getPushToken().equals(token) &&
|
||||
!accountPushData.isShouldBeDeleted() ||
|
||||
TextUtils.isEmpty(providerValue)) {
|
||||
!userEntity.getScheduledForDeletion() ||
|
||||
TextUtils.isEmpty(providerValue) && !userEntity.getScheduledForDeletion()) {
|
||||
|
||||
|
||||
Map<String, String> queryMap = new HashMap<>();
|
||||
@ -273,7 +270,7 @@ public class PushUtils {
|
||||
|
||||
ncApi.registerDeviceForNotificationsWithProxy(ApiHelper.getCredentials
|
||||
(userEntity.getUsername(), userEntity.getToken()),
|
||||
ApiHelper.getUrlPushProxy(userEntity.getBaseUrl()), proxyMap)
|
||||
ApiHelper.getUrlPushProxy(), proxyMap)
|
||||
.subscribeOn(Schedulers.newThread())
|
||||
.subscribe(new Consumer<Void>() {
|
||||
@Override
|
||||
@ -291,7 +288,6 @@ public class PushUtils {
|
||||
pushConfigurationState.setUserPublicKey(
|
||||
pushRegistrationOverall.getOcs()
|
||||
.getData().getPublicKey());
|
||||
pushConfigurationState.setShouldBeDeleted(false);
|
||||
pushConfigurationState.setUsesRegularPass(false);
|
||||
|
||||
userUtils.createOrUpdateUser(userEntity.getUsername(),
|
||||
|
@ -57,6 +57,14 @@ public class UserUtils {
|
||||
return findUsersQueryResult.toList();
|
||||
}
|
||||
|
||||
public List getUsersScheduledForDeletion() {
|
||||
Result findUsersQueryResult = dataStore.select(User.class).where(UserEntity.SCHEDULED_FOR_DELETION.eq(true))
|
||||
.get();
|
||||
|
||||
return findUsersQueryResult.toList();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public UserEntity getAnyUserAndSetAsActive() {
|
||||
Result findUserQueryResult = dataStore.select(User.class)
|
||||
|
Loading…
Reference in New Issue
Block a user