package peergos.shared.login;

import peergos.shared.crypto.asymmetric.*;
import peergos.shared.user.*;

import java.util.*;
import java.util.concurrent.*;

public class OfflineAccountStore implements Account {

    private final Account target;
    private final LoginCache local;

    public OfflineAccountStore(Account target, LoginCache local) {
        this.target = target;
        this.local = local;
    }

    @Override
    public CompletableFuture<Boolean> setLoginData(LoginData login, byte[] auth) {
        return target.setLoginData(login, auth).thenApply(r -> {
            if (r)
                local.setLoginData(login);
            return r;
        });
    }

    @Override
    public CompletableFuture<UserStaticData> getLoginData(String username, PublicSigningKey authorisedReader, byte[] auth) {
        return target.getLoginData(username, authorisedReader, auth)
                .thenApply(entryPoints -> {
                    local.setLoginData(new LoginData(username, entryPoints, authorisedReader, Optional.empty()));
                    return entryPoints;
                }).exceptionally(t -> local.getEntryData(username, authorisedReader).join());
    }
}

@@ -96,16 +96,46 @@
 .user.*;
+%0Aimport peergos.shared.util.*;
 %0A%0Aimport
@@ -848,32 +848,65 @@
 %7B%0A        return
+ Futures.asyncExceptionally(() -%3E
  target.getLogin
@@ -960,16 +960,24 @@
         
+       
+ 
 .thenApp
@@ -992,24 +992,32 @@
 Points -%3E %7B%0A
+        
             
@@ -1134,24 +1134,32 @@
             
+    
+    
 return entry
@@ -1186,25 +1186,36 @@
     
-%7D).exceptionally(
+        %7D),%0A                
 t -%3E
@@ -1265,15 +1265,8 @@
 der)
-.join()
 );%0A 

Remove join in offline account cache