Dont start account creation if user is anonymous in fetchExternalLinks function

Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2024-08-23 10:23:26 +02:00
parent 1bbbb95493
commit 96058c7072
No known key found for this signature in database
GPG key ID: 4E577DC593B59BDF

View file

@ -1233,47 +1233,48 @@ public abstract class DrawerActivity extends ToolbarActivity
return; return;
} }
User user = accountManager.getUser();
if (user.isAnonymous()) {
Log_OC.d(TAG, "Trying to execute a sync operation with a storage manager for an anonymous account");
return;
}
Thread t = new Thread(() -> { Thread t = new Thread(() -> {
User user = accountManager.getUser(); if ((getCapabilities() == null || getCapabilities().getAccountName() != null && getCapabilities().getAccountName().isEmpty()) && getStorageManager() != null) {
if (user.isAnonymous()) { GetCapabilitiesOperation getCapabilities = new GetCapabilitiesOperation(getStorageManager());
accountManager.startAccountCreation(this); getCapabilities.execute(getBaseContext());
} else { }
if ((getCapabilities() == null || getCapabilities().getAccountName() != null && getCapabilities().getAccountName().isEmpty()) && getStorageManager() != null) {
GetCapabilitiesOperation getCapabilities = new GetCapabilitiesOperation(getStorageManager());
getCapabilities.execute(getBaseContext());
}
if (getStorageManager() != null && CapabilityUtils.getCapability(user, this).getExternalLinks().isTrue()) { if (getStorageManager() != null && CapabilityUtils.getCapability(user, this).getExternalLinks().isTrue()) {
int count = arbitraryDataProvider.getIntegerValue(FilesSyncHelper.GLOBAL, FileActivity.APP_OPENED_COUNT); int count = arbitraryDataProvider.getIntegerValue(FilesSyncHelper.GLOBAL, FileActivity.APP_OPENED_COUNT);
if (count > 10 || count == -1 || force) { if (count > 10 || count == -1 || force) {
if (force) { if (force) {
Log_OC.d("ExternalLinks", "force update"); Log_OC.d("ExternalLinks", "force update");
}
arbitraryDataProvider.storeOrUpdateKeyValue(FilesSyncHelper.GLOBAL, FileActivity.APP_OPENED_COUNT, "0");
Log_OC.d("ExternalLinks", "update via api");
RemoteOperation getExternalLinksOperation = new ExternalLinksOperation();
RemoteOperationResult result = getExternalLinksOperation.execute(user, this);
if (result.isSuccess() && result.getData() != null) {
externalLinksProvider.deleteAllExternalLinks();
ArrayList<ExternalLink> externalLinks = (ArrayList<ExternalLink>) result.getData();
for (ExternalLink link : externalLinks) {
externalLinksProvider.storeExternalLink(link);
} }
arbitraryDataProvider.storeOrUpdateKeyValue(FilesSyncHelper.GLOBAL, FileActivity.APP_OPENED_COUNT, "0");
Log_OC.d("ExternalLinks", "update via api");
RemoteOperation getExternalLinksOperation = new ExternalLinksOperation();
RemoteOperationResult result = getExternalLinksOperation.execute(user, this);
if (result.isSuccess() && result.getData() != null) {
externalLinksProvider.deleteAllExternalLinks();
ArrayList<ExternalLink> externalLinks = (ArrayList<ExternalLink>) result.getData();
for (ExternalLink link : externalLinks) {
externalLinksProvider.storeExternalLink(link);
}
}
} else {
arbitraryDataProvider.storeOrUpdateKeyValue(FilesSyncHelper.GLOBAL, FileActivity.APP_OPENED_COUNT, String.valueOf(count + 1));
} }
} else { } else {
externalLinksProvider.deleteAllExternalLinks(); arbitraryDataProvider.storeOrUpdateKeyValue(FilesSyncHelper.GLOBAL, FileActivity.APP_OPENED_COUNT, String.valueOf(count + 1));
Log_OC.d("ExternalLinks", "links disabled");
} }
} else {
runOnUiThread(this::updateExternalLinksInDrawer); externalLinksProvider.deleteAllExternalLinks();
Log_OC.d("ExternalLinks", "links disabled");
} }
runOnUiThread(this::updateExternalLinksInDrawer);
}); });
t.start(); t.start();
} }