Skip to content

Commit f255441

Browse files
committed
Added refresh to init
1 parent 547571a commit f255441

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ await fula.init(
4141
bloxAddr: string, //leave empty for testing without a backend node
4242
exchange: 'noop'|'', //add noop for testing without a backend
4343
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
44-
useRelay: boolean //default to true. If true it forces the connection through relay
44+
useRelay: boolean, //default to true. If true it forces the connection through relay
45+
refresh: boolean //forces the fula object to be recreated. default is false
4546
);
4647
```
4748

android/src/main/java/land/fx/fula/FulaModule.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,15 +212,15 @@ public void isReady(boolean filesystemCheck, Promise promise) {
212212
}
213213

214214
@ReactMethod
215-
public void init(String identityString, String storePath, String bloxAddr, String exchange, boolean autoFlush, String rootConfig, boolean useRelay, Promise promise) {
215+
public void init(String identityString, String storePath, String bloxAddr, String exchange, boolean autoFlush, String rootConfig, boolean useRelay, boolean refresh, Promise promise) {
216216
Log.d("ReactNative", "init started");
217217
ThreadUtils.runOnExecutor(() -> {
218218
try {
219219
WritableMap resultData = new WritableNativeMap();
220220
Log.d("ReactNative", "init storePath= " + storePath);
221221
byte[] identity = toByte(identityString);
222222
Log.d("ReactNative", "init identity= " + identityString);
223-
String[] obj = this.initInternal(identity, storePath, bloxAddr, exchange, autoFlush, rootConfig, useRelay);
223+
String[] obj = this.initInternal(identity, storePath, bloxAddr, exchange, autoFlush, rootConfig, useRelay, refresh);
224224
Log.d("ReactNative", "init object created: [ " + obj[0] + ", " + obj[1] + ", " + obj[2] + " ]");
225225
resultData.putString("peerId", obj[0]);
226226
resultData.putString("rootCid", obj[1]);
@@ -251,7 +251,7 @@ public void logout(String identityString, String storePath, Promise promise) {
251251

252252
private boolean checkConnectionInternal() throws Exception {
253253
try {
254-
Log.d("ReactNative", "checkConnectionInternal fstarted");
254+
Log.d("ReactNative", "checkConnectionInternal started");
255255
if (this.fula != null) {
256256
try {
257257
Log.d("ReactNative", "connectToBlox started");
@@ -510,12 +510,12 @@ private byte[] newClientInternal(byte[] identity, String storePath, String bloxA
510510
}
511511

512512
@NonNull
513-
private String[] initInternal(byte[] identity, String storePath, String bloxAddr, String exchange, boolean autoFlush, String rootCid, boolean useRelay) throws Exception {
513+
private String[] initInternal(byte[] identity, String storePath, String bloxAddr, String exchange, boolean autoFlush, String rootCid, boolean useRelay, boolean refresh) throws Exception {
514514
try {
515-
if (this.fula == null) {
515+
if (this.fula == null || refresh) {
516516
this.newClientInternal(identity, storePath, bloxAddr, exchange, autoFlush, useRelay);
517517
}
518-
if(this.client == null) {
518+
if(this.client == null || refresh) {
519519
this.client = new Client(this.fula);
520520
Log.d("ReactNative", "fula initialized: " + this.fula.id());
521521
}

src/interfaces/fulaNativeModule.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ interface FulaNativeModule {
88
exchange: string, //set to 'noope' for testing
99
autoFlush: boolean, //set to false always unless you know what you are doing. This is to write actions to disk explicitly after each write
1010
rootCid: string | null, //if you have the latest rootCid you can send it and it generates the private_ref for filesystem
11-
useRelay: boolean | null // if true it forces the use of relay
11+
useRelay: boolean | null, // if true it forces the use of relay
12+
refresh: boolean // if true it forces to refresh the fula object
1213
) => Promise<{ peerId: string; rootCid: string; private_ref: string }>;
1314
newClient: (
1415
identity: string, //Private key of did identity

src/protocols/fula.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ export const init = (
1414
exchange: string,
1515
autoFlush: boolean = false,
1616
rootCid: string | null = null,
17-
useRelay: boolean = true
17+
useRelay: boolean = true,
18+
refresh: boolean = false
1819
): Promise<{ peerId: string; rootCid: string; private_ref: string }> => {
1920
console.log(
2021
'init in react-native started',
@@ -25,7 +26,7 @@ export const init = (
2526
autoFlush,
2627
useRelay
2728
);
28-
return Fula.init(identity, storePath, bloxAddr, exchange, autoFlush, rootCid, useRelay);
29+
return Fula.init(identity, storePath, bloxAddr, exchange, autoFlush, rootCid, useRelay, refresh);
2930
};
3031

3132
/**

0 commit comments

Comments
 (0)