Skip to content

Commit

Permalink
Added refresh to init
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsan6sha committed Apr 29, 2023
1 parent 547571a commit f255441
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
```

Expand Down
12 changes: 6 additions & 6 deletions android/src/main/java/land/fx/fula/FulaModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,15 @@ 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 {
WritableMap resultData = new WritableNativeMap();
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]);
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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());
}
Expand Down
3 changes: 2 additions & 1 deletion src/interfaces/fulaNativeModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/protocols/fula.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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);
};

/**
Expand Down

0 comments on commit f255441

Please sign in to comment.