Skip to content
This repository has been archived by the owner on Nov 21, 2023. It is now read-only.

Commit

Permalink
fix: timestamp to date, and building .aar
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-ramos committed Jan 23, 2023
1 parent b2624f4 commit 98ef3d5
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ android/keystores/debug.keystore
lib/

tmp/
android/libs/gowaku-sources.jar
android/libs/gowaku.aar
gowaku-sources.jar
gowaku.aar
ios/Gowaku.xcframework
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ Waku React Native
npm install @waku/react-native
```

Edit `settings.gradle` from your app and add:
```
include ':gowaku'
project(':gowaku').projectDir = new File(rootProject.projectDir, './../node_modules/@waku/react-native/android/gowaku')
```

## Usage

```js
Expand Down
4 changes: 2 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ dependencies {
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation files('libs/gowaku.aar')
// From node_modules
implementation project(":gowaku")
// From node_modules
}

if (isNewArchitectureEnabled()) {
Expand Down
2 changes: 2 additions & 0 deletions android/gowaku/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
configurations.maybeCreate("default")
artifacts.add("default", file('gowaku.aar'))
Empty file removed android/libs/.gitkeep
Empty file.
1 change: 1 addition & 0 deletions android/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ':gowaku'
4 changes: 2 additions & 2 deletions download-gowaku.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ if [ "$DOWNLOAD_ANDROID" = true ]; then
exit 1
fi

rm -f ../android/libs/gowaku*
tar xvfz ${ANDROID_TAR} -C ../android/libs
rm -f ../android/gowaku/gowaku*
tar xvfz ${ANDROID_TAR} -C ../android/gowaku
fi

if [ "$DOWNLOAD_IOS" = true ]; then
Expand Down
4 changes: 2 additions & 2 deletions example/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default function App() {
}
console.log('The node ID:', await peerID());

await relaySubscribe();
await relaySubscribe();

onMessage((event) => {
setResult(
Expand Down Expand Up @@ -92,7 +92,7 @@ export default function App() {
// TO RETRIEVE HISTORIC MESSAGES:
console.log('Retrieving messages from store node');
const query = new StoreQuery();
query.contentFilters.push(new ContentFilter('test-rramos'));
query.contentFilters.push(new ContentFilter('ABC'));
const queryResult = await storeQuery(
query,
'16Uiu2HAkvWiyFsgRhuJEb9JfjYxEkoHLgnUQmr1N5mKWnYjxYRVm'
Expand Down
3 changes: 3 additions & 0 deletions example/android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ if (settings.hasProperty("newArchEnabled") && settings.newArchEnabled == "true")
include(":ReactAndroid:hermes-engine")
project(":ReactAndroid:hermes-engine").projectDir = new File(["node", "--print", "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim(), "../ReactAndroid/hermes-engine");
}

include ':gowaku'
project(':gowaku').projectDir = new File(rootProject.projectDir, './../node_modules/@waku/react-native/android/gowaku')
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@waku/react-native",
"version": "0.0.12",
"version": "0.1.0",
"description": "Waku React Native",
"author": "Status Research & Development GMBH",
"authors": [
Expand Down
22 changes: 17 additions & 5 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const ReactNative = NativeModules.ReactNative
}
);

const OneMillion = bigInt(1_000_000);
const OneMillion = bigInt(1000000);

export class WakuMessage {
payload: Uint8Array = new Uint8Array();
Expand Down Expand Up @@ -51,7 +51,10 @@ export function onMessage(cb: (arg0: any) => void) {
let signal = JSON.parse(event.signal);
let msg = signal.event.wakuMessage;
signal.event.wakuMessage = new WakuMessage();
signal.event.wakuMessage.timestamp = msg.timestamp;
signal.event.wakuMessage.timestamp =
msg.timestamp != 0
? new Date(bigInt(msg.timestamp).divide(OneMillion).toJSNumber())
: undefined;
signal.event.wakuMessage.version = msg.version || 0;
signal.event.wakuMessage.contentTopic = msg.contentTopic;
signal.event.wakuMessage.payload = new Uint8Array(
Expand Down Expand Up @@ -734,9 +737,18 @@ export function storeQuery(
if (response.error) {
reject(response.error);
} else {
if(response.result.messages){
for(let i = 0; i < response.result.messages.length; i++){
response.result.messages[i].payload = new Uint8Array(decode(response.result.messages[i].payload ?? []).split('').map(c => c.charCodeAt(0)));
if (response.result.messages) {
for (let i = 0; i < response.result.messages.length; i++) {
const t = response.result.messages[i].timestamp;
response.result.messages[i].timestamp =
t != 0
? new Date(bigInt(t).divide(OneMillion).toJSNumber())
: undefined;
response.result.messages[i].payload = new Uint8Array(
decode(response.result.messages[i].payload ?? [])
.split('')
.map((c) => c.charCodeAt(0))
);
}
}
resolve(response.result);
Expand Down

0 comments on commit 98ef3d5

Please sign in to comment.