Fix TokenMismatchException after deleting and readding an account

This commit is contained in:
Stefan Niedermann 2020-04-16 08:11:39 +02:00
parent 4df11459d5
commit 027f787003
2 changed files with 34 additions and 2 deletions

View file

@ -810,10 +810,10 @@ public class NotesDatabase extends AbstractNotesDatabase {
}
try {
NotesClient.invalidateAPICache(AccountImporter.getSingleSignOnAccount(getContext(), localAccount.getAccountName()));
SSOClient.invalidateAPICache(AccountImporter.getSingleSignOnAccount(getContext(), localAccount.getAccountName()));
} catch (NextcloudFilesAppAccountNotFoundException e) {
e.printStackTrace();
NotesClient.invalidateAPICache();
SSOClient.invalidateAPICache();
}
final int deletedNotes = db.delete(table_notes, key_account_id + " = ?", new String[]{String.valueOf(localAccount.getId())});

View file

@ -47,4 +47,36 @@ public class SSOClient {
return nextcloudAPI;
}
}
/**
* Invalidates thes API cache for the given ssoAccount
*
* @param ssoAccount the ssoAccount for which the API cache should be cleared.
*/
public static void invalidateAPICache(@NonNull SingleSignOnAccount ssoAccount) {
Log.v(TAG, "Invalidating API cache for " + ssoAccount.name);
if (mNextcloudAPIs.containsKey(ssoAccount.name)) {
final NextcloudAPI nextcloudAPI = mNextcloudAPIs.get(ssoAccount.name);
if (nextcloudAPI != null) {
nextcloudAPI.stop();
}
mNextcloudAPIs.remove(ssoAccount.name);
}
}
/**
* Invalidates the whole API cache for all accounts
*/
public static void invalidateAPICache() {
for (String key : mNextcloudAPIs.keySet()) {
Log.v(TAG, "Invalidating API cache for " + key);
if (mNextcloudAPIs.containsKey(key)) {
final NextcloudAPI nextcloudAPI = mNextcloudAPIs.get(key);
if (nextcloudAPI != null) {
nextcloudAPI.stop();
}
mNextcloudAPIs.remove(key);
}
}
}
}