From f2554410485ec70c3554f837cc20142a790cb544 Mon Sep 17 00:00:00 2001 From: ehsan shariati Date: Sat, 29 Apr 2023 09:25:45 -0400 Subject: [PATCH] Added refresh to init --- README.md | 3 ++- android/src/main/java/land/fx/fula/FulaModule.java | 12 ++++++------ src/interfaces/fulaNativeModule.ts | 3 ++- src/protocols/fula.ts | 5 +++-- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 50f9d08..b313bbc 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,8 @@ await fula.init( bloxAddr: string, //leave empty for testing without a backend node exchange: 'noop'|'', //add noop for testing without a backend autoFlush: boolean, //Default to false. Always set to false unless you know what you are doing. explicitly write data to disk after each operation if set to true - useRelay: boolean //default to true. If true it forces the connection through relay + useRelay: boolean, //default to true. If true it forces the connection through relay + refresh: boolean //forces the fula object to be recreated. default is false ); ``` diff --git a/android/src/main/java/land/fx/fula/FulaModule.java b/android/src/main/java/land/fx/fula/FulaModule.java index 20ddeb1..d4d77fd 100755 --- a/android/src/main/java/land/fx/fula/FulaModule.java +++ b/android/src/main/java/land/fx/fula/FulaModule.java @@ -212,7 +212,7 @@ public void isReady(boolean filesystemCheck, Promise promise) { } @ReactMethod - public void init(String identityString, String storePath, String bloxAddr, String exchange, boolean autoFlush, String rootConfig, boolean useRelay, Promise promise) { + public void init(String identityString, String storePath, String bloxAddr, String exchange, boolean autoFlush, String rootConfig, boolean useRelay, boolean refresh, Promise promise) { Log.d("ReactNative", "init started"); ThreadUtils.runOnExecutor(() -> { try { @@ -220,7 +220,7 @@ public void init(String identityString, String storePath, String bloxAddr, Strin Log.d("ReactNative", "init storePath= " + storePath); byte[] identity = toByte(identityString); Log.d("ReactNative", "init identity= " + identityString); - String[] obj = this.initInternal(identity, storePath, bloxAddr, exchange, autoFlush, rootConfig, useRelay); + String[] obj = this.initInternal(identity, storePath, bloxAddr, exchange, autoFlush, rootConfig, useRelay, refresh); Log.d("ReactNative", "init object created: [ " + obj[0] + ", " + obj[1] + ", " + obj[2] + " ]"); resultData.putString("peerId", obj[0]); resultData.putString("rootCid", obj[1]); @@ -251,7 +251,7 @@ public void logout(String identityString, String storePath, Promise promise) { private boolean checkConnectionInternal() throws Exception { try { - Log.d("ReactNative", "checkConnectionInternal fstarted"); + Log.d("ReactNative", "checkConnectionInternal started"); if (this.fula != null) { try { Log.d("ReactNative", "connectToBlox started"); @@ -510,12 +510,12 @@ private byte[] newClientInternal(byte[] identity, String storePath, String bloxA } @NonNull - private String[] initInternal(byte[] identity, String storePath, String bloxAddr, String exchange, boolean autoFlush, String rootCid, boolean useRelay) throws Exception { + private String[] initInternal(byte[] identity, String storePath, String bloxAddr, String exchange, boolean autoFlush, String rootCid, boolean useRelay, boolean refresh) throws Exception { try { - if (this.fula == null) { + if (this.fula == null || refresh) { this.newClientInternal(identity, storePath, bloxAddr, exchange, autoFlush, useRelay); } - if(this.client == null) { + if(this.client == null || refresh) { this.client = new Client(this.fula); Log.d("ReactNative", "fula initialized: " + this.fula.id()); } diff --git a/src/interfaces/fulaNativeModule.ts b/src/interfaces/fulaNativeModule.ts index eba3ea4..8827fb5 100644 --- a/src/interfaces/fulaNativeModule.ts +++ b/src/interfaces/fulaNativeModule.ts @@ -8,7 +8,8 @@ interface FulaNativeModule { exchange: string, //set to 'noope' for testing autoFlush: boolean, //set to false always unless you know what you are doing. This is to write actions to disk explicitly after each write rootCid: string | null, //if you have the latest rootCid you can send it and it generates the private_ref for filesystem - useRelay: boolean | null // if true it forces the use of relay + useRelay: boolean | null, // if true it forces the use of relay + refresh: boolean // if true it forces to refresh the fula object ) => Promise<{ peerId: string; rootCid: string; private_ref: string }>; newClient: ( identity: string, //Private key of did identity diff --git a/src/protocols/fula.ts b/src/protocols/fula.ts index b53864d..f16f677 100644 --- a/src/protocols/fula.ts +++ b/src/protocols/fula.ts @@ -14,7 +14,8 @@ export const init = ( exchange: string, autoFlush: boolean = false, rootCid: string | null = null, - useRelay: boolean = true + useRelay: boolean = true, + refresh: boolean = false ): Promise<{ peerId: string; rootCid: string; private_ref: string }> => { console.log( 'init in react-native started', @@ -25,7 +26,7 @@ export const init = ( autoFlush, useRelay ); - return Fula.init(identity, storePath, bloxAddr, exchange, autoFlush, rootCid, useRelay); + return Fula.init(identity, storePath, bloxAddr, exchange, autoFlush, rootCid, useRelay, refresh); }; /**