From 516b9190adcff451efae3464232ef5958d27bc97 Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Sat, 23 Jul 2022 18:27:14 +0200 Subject: [PATCH] fix codacy issues Signed-off-by: Andy Scherzinger --- .../talk/jobs/ShareOperationWorker.java | 3 +- .../talk/jobs/WebsocketConnectionsWorker.java | 20 +- .../talk/utils/database/user/UserUtils.java | 221 ------------------ 3 files changed, 9 insertions(+), 235 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/jobs/ShareOperationWorker.java b/app/src/main/java/com/nextcloud/talk/jobs/ShareOperationWorker.java index 3ef10f3b9..190fd2c33 100644 --- a/app/src/main/java/com/nextcloud/talk/jobs/ShareOperationWorker.java +++ b/app/src/main/java/com/nextcloud/talk/jobs/ShareOperationWorker.java @@ -56,7 +56,6 @@ public class ShareOperationWorker extends Worker { private final String TAG = "ShareOperationWorker"; private long userId; - private User operationsUser; private String roomToken; private List filesArray = new ArrayList<>(); private String credentials; @@ -71,7 +70,7 @@ public class ShareOperationWorker extends Worker { roomToken = data.getString(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN()); metaData = data.getString(BundleKeys.INSTANCE.getKEY_META_DATA()); Collections.addAll(filesArray, data.getStringArray(BundleKeys.INSTANCE.getKEY_FILE_PATHS())); - operationsUser = userManager.getUserWithId(userId).blockingGet(); + User operationsUser = userManager.getUserWithId(userId).blockingGet(); credentials = ApiUtils.getCredentials(operationsUser.getUsername(), operationsUser.getToken()); baseUrl = operationsUser.getBaseUrl(); } diff --git a/app/src/main/java/com/nextcloud/talk/jobs/WebsocketConnectionsWorker.java b/app/src/main/java/com/nextcloud/talk/jobs/WebsocketConnectionsWorker.java index 355e9dc2b..8fec0d025 100644 --- a/app/src/main/java/com/nextcloud/talk/jobs/WebsocketConnectionsWorker.java +++ b/app/src/main/java/com/nextcloud/talk/jobs/WebsocketConnectionsWorker.java @@ -42,8 +42,6 @@ import autodagger.AutoInjector; @AutoInjector(NextcloudTalkApplication.class) public class WebsocketConnectionsWorker extends Worker { - private static final String TAG = "WebsocketConnectionsWorker"; - @Inject UserManager userManager; @@ -58,18 +56,16 @@ public class WebsocketConnectionsWorker extends Worker { NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this); List users = userManager.getUsers().blockingGet(); - ExternalSignalingServer externalSignalingServer; WebSocketConnectionHelper webSocketConnectionHelper = new WebSocketConnectionHelper(); for (User user : users) { - if (user.getExternalSignalingServer() != null) { - if (user.getExternalSignalingServer().getExternalSignalingServer() != null && - !TextUtils.isEmpty(user.getExternalSignalingServer().getExternalSignalingServer()) && - !TextUtils.isEmpty(user.getExternalSignalingServer().getExternalSignalingTicket())) { - webSocketConnectionHelper.getExternalSignalingInstanceForServer( - user.getExternalSignalingServer().getExternalSignalingServer(), - user, user.getExternalSignalingServer().getExternalSignalingTicket(), - false); - } + if (user.getExternalSignalingServer() != null && + user.getExternalSignalingServer().getExternalSignalingServer() != null && + !TextUtils.isEmpty(user.getExternalSignalingServer().getExternalSignalingServer()) && + !TextUtils.isEmpty(user.getExternalSignalingServer().getExternalSignalingTicket())) { + webSocketConnectionHelper.getExternalSignalingInstanceForServer( + user.getExternalSignalingServer().getExternalSignalingServer(), + user, user.getExternalSignalingServer().getExternalSignalingTicket(), + false); } } diff --git a/app/src/main/java/com/nextcloud/talk/utils/database/user/UserUtils.java b/app/src/main/java/com/nextcloud/talk/utils/database/user/UserUtils.java index 4761cab6c..473c75682 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/database/user/UserUtils.java +++ b/app/src/main/java/com/nextcloud/talk/utils/database/user/UserUtils.java @@ -47,225 +47,4 @@ public class UserUtils { UserUtils(ReactiveEntityStore dataStore) { this.dataStore = dataStore; } - - private boolean anyUserExists() { - return (dataStore.count(User.class).where(UserEntity.SCHEDULED_FOR_DELETION.notEqual(Boolean.TRUE)) - .limit(1).get().value() > 0); - } - - private boolean hasMultipleUsers() { - return (dataStore.count(User.class).where(UserEntity.SCHEDULED_FOR_DELETION.notEqual(Boolean.TRUE)) - .get().value() > 1); - } - - private List getUsers() { - Result findUsersQueryResult = dataStore.select(User.class).where - (UserEntity.SCHEDULED_FOR_DELETION.notEqual(Boolean.TRUE)).get(); - - return findUsersQueryResult.toList(); - } - - private List getUsersScheduledForDeletion() { - Result findUsersQueryResult = dataStore.select(User.class) - .where(UserEntity.SCHEDULED_FOR_DELETION.eq(Boolean.TRUE)).get(); - - return findUsersQueryResult.toList(); - } - - - private UserEntity getAnyUserAndSetAsActive() { - Result findUserQueryResult = dataStore.select(User.class) - .where(UserEntity.SCHEDULED_FOR_DELETION.notEqual(Boolean.TRUE)) - .limit(1).get(); - - UserEntity userEntity; - if ((userEntity = (UserEntity) findUserQueryResult.firstOrNull()) != null) { - userEntity.setCurrent(true); - dataStore.update(userEntity).blockingGet(); - return userEntity; - } - - return null; - } - - private Completable deleteUser(long internalId) { - Result findUserQueryResult = dataStore.select(User.class).where(UserEntity.ID.eq(internalId)).limit(1).get(); - - UserEntity user = (UserEntity) findUserQueryResult.firstOrNull(); - - return dataStore.delete(user) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()); - - } - - private Completable deleteUserWithId(long id) { - Result findUserQueryResult = dataStore.select(User.class).where(UserEntity.ID.eq(id)).limit(1).get(); - - UserEntity user = (UserEntity) findUserQueryResult.firstOrNull(); - - return dataStore.delete(user) - .subscribeOn(Schedulers.io()); - - } - - private UserEntity getUserById(String id) { - Result findUserQueryResult = dataStore.select(User.class).where(UserEntity.USER_ID.eq(id)) - .limit(1).get(); - - return (UserEntity) findUserQueryResult.firstOrNull(); - } - - private UserEntity getUserWithId(long id) { - Result findUserQueryResult = dataStore.select(User.class).where(UserEntity.ID.eq(id)) - .limit(1).get(); - - return (UserEntity) findUserQueryResult.firstOrNull(); - } - - - private void disableAllUsersWithoutId(long userId) { - Result findUserQueryResult = dataStore.select(User.class).where(UserEntity.ID.notEqual(userId)).get(); - - for (Object object : findUserQueryResult) { - UserEntity userEntity = (UserEntity) object; - userEntity.setCurrent(false); - dataStore.update(userEntity).blockingGet(); - } - } - - private boolean checkIfUserIsScheduledForDeletion(String username, String server) { - Result findUserQueryResult = dataStore.select(User.class).where(UserEntity.USERNAME.eq(username)) - .and(UserEntity.BASE_URL.eq(server)) - .limit(1).get(); - - UserEntity userEntity; - if ((userEntity = (UserEntity) findUserQueryResult.firstOrNull()) != null) { - return userEntity.getScheduledForDeletion(); - } - - return false; - } - - private UserEntity getUserWithInternalId(long internalId) { - Result findUserQueryResult = dataStore.select(User.class).where(UserEntity.ID.eq(internalId) - .and(UserEntity.SCHEDULED_FOR_DELETION.notEqual(Boolean.TRUE))) - .limit(1).get(); - - return (UserEntity) findUserQueryResult.firstOrNull(); - } - - private boolean getIfUserWithUsernameAndServer(String username, String server) { - Result findUserQueryResult = dataStore.select(User.class).where(UserEntity.USERNAME.eq(username) - .and(UserEntity.BASE_URL.eq(server))) - .limit(1).get(); - - return findUserQueryResult.firstOrNull() != null; - } - - private boolean scheduleUserForDeletionWithId(long id) { - Result findUserQueryResult = dataStore.select(User.class).where(UserEntity.ID.eq(id)) - .limit(1).get(); - - UserEntity userEntity; - if ((userEntity = (UserEntity) findUserQueryResult.firstOrNull()) != null) { - userEntity.setScheduledForDeletion(true); - userEntity.setCurrent(false); - dataStore.update(userEntity).blockingGet(); - } - - return getAnyUserAndSetAsActive() != null; - } - - private Observable createOrUpdateUser(@Nullable String username, @Nullable String token, - @Nullable String serverUrl, - @Nullable String displayName, - @Nullable String pushConfigurationState, - @Nullable Boolean currentUser, - @Nullable String userId, - @Nullable Long internalId, - @Nullable String capabilities, - @Nullable String certificateAlias, - @Nullable String externalSignalingServer) { - Result findUserQueryResult; - if (internalId == null) { - findUserQueryResult = dataStore.select(User.class).where(UserEntity.USERNAME.eq(username). - and(UserEntity.BASE_URL.eq(serverUrl))).limit(1).get(); - } else { - findUserQueryResult = dataStore.select(User.class).where(UserEntity.ID.eq(internalId)).get(); - } - - UserEntity user = (UserEntity) findUserQueryResult.firstOrNull(); - - if (user == null) { - user = new UserEntity(); - user.setBaseUrl(serverUrl); - user.setUsername(username); - user.setToken(token); - - if (!TextUtils.isEmpty(displayName)) { - user.setDisplayName(displayName); - } - - if (pushConfigurationState != null) { - user.setPushConfigurationState(pushConfigurationState); - } - - if (!TextUtils.isEmpty(userId)) { - user.setUserId(userId); - } - - if (!TextUtils.isEmpty(capabilities)) { - user.setCapabilities(capabilities); - } - - if (!TextUtils.isEmpty(certificateAlias)) { - user.setClientCertificate(certificateAlias); - } - - if (!TextUtils.isEmpty(externalSignalingServer)) { - user.setExternalSignalingServer(externalSignalingServer); - } - - user.setCurrent(true); - - } else { - if (userId != null && (user.getUserId() == null || !user.getUserId().equals(userId))) { - user.setUserId(userId); - } - - if (token != null && !token.equals(user.getToken())) { - user.setToken(token); - } - - if ((displayName != null && user.getDisplayName() == null) || (displayName != null && user.getDisplayName() - != null && !displayName.equals(user.getDisplayName()))) { - user.setDisplayName(displayName); - } - - if (pushConfigurationState != null && !pushConfigurationState.equals(user.getPushConfigurationState())) { - user.setPushConfigurationState(pushConfigurationState); - } - - if (capabilities != null && !capabilities.equals(user.getCapabilities())) { - user.setCapabilities(capabilities); - } - - if (certificateAlias != null && !certificateAlias.equals(user.getClientCertificate())) { - user.setClientCertificate(certificateAlias); - } - - if (externalSignalingServer != null && !externalSignalingServer.equals(user.getExternalSignalingServer())) { - user.setExternalSignalingServer(externalSignalingServer); - } - - if (currentUser != null) { - user.setCurrent(currentUser); - } - } - - return dataStore.upsert(user) - .toObservable() - .subscribeOn(Schedulers.io()); - } }