fix: timestamp to date, and building .aar

This commit is contained in:
Richard Ramos 2023-01-23 13:28:17 -04:00
parent b2624f4db1
commit 98ef3d59f8
No known key found for this signature in database
GPG Key ID: 1CE87DB518195760
12 changed files with 40 additions and 16 deletions

4
.gitignore vendored
View File

@ -67,6 +67,6 @@ android/keystores/debug.keystore
lib/ lib/
tmp/ tmp/
android/libs/gowaku-sources.jar gowaku-sources.jar
android/libs/gowaku.aar gowaku.aar
ios/Gowaku.xcframework ios/Gowaku.xcframework

View File

@ -6,6 +6,12 @@ Waku React Native
npm install @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 ## Usage
```js ```js

View File

@ -133,7 +133,7 @@ dependencies {
//noinspection GradleDynamicVersion //noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+" implementation "com.facebook.react:react-native:+"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation files('libs/gowaku.aar') implementation project(":gowaku")
// From node_modules // From node_modules
} }

View File

@ -0,0 +1,2 @@
configurations.maybeCreate("default")
artifacts.add("default", file('gowaku.aar'))

View File

1
android/settings.gradle Normal file
View File

@ -0,0 +1 @@
include ':gowaku'

View File

@ -41,8 +41,8 @@ if [ "$DOWNLOAD_ANDROID" = true ]; then
exit 1 exit 1
fi fi
rm -f ../android/libs/gowaku* rm -f ../android/gowaku/gowaku*
tar xvfz ${ANDROID_TAR} -C ../android/libs tar xvfz ${ANDROID_TAR} -C ../android/gowaku
fi fi
if [ "$DOWNLOAD_IOS" = true ]; then if [ "$DOWNLOAD_IOS" = true ]; then

View File

@ -92,7 +92,7 @@ export default function App() {
// TO RETRIEVE HISTORIC MESSAGES: // TO RETRIEVE HISTORIC MESSAGES:
console.log('Retrieving messages from store node'); console.log('Retrieving messages from store node');
const query = new StoreQuery(); const query = new StoreQuery();
query.contentFilters.push(new ContentFilter('test-rramos')); query.contentFilters.push(new ContentFilter('ABC'));
const queryResult = await storeQuery( const queryResult = await storeQuery(
query, query,
'16Uiu2HAkvWiyFsgRhuJEb9JfjYxEkoHLgnUQmr1N5mKWnYjxYRVm' '16Uiu2HAkvWiyFsgRhuJEb9JfjYxEkoHLgnUQmr1N5mKWnYjxYRVm'

View File

@ -15,3 +15,6 @@ if (settings.hasProperty("newArchEnabled") && settings.newArchEnabled == "true")
include(":ReactAndroid:hermes-engine") 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"); 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
package-lock.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "@waku/react-native", "name": "@waku/react-native",
"version": "0.0.12", "version": "0.1.0",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "@waku/react-native", "name": "@waku/react-native",
"version": "0.0.12", "version": "0.1.0",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"base-64": "^1.0.0", "base-64": "^1.0.0",

View File

@ -1,6 +1,6 @@
{ {
"name": "@waku/react-native", "name": "@waku/react-native",
"version": "0.0.12", "version": "0.1.0",
"description": "Waku React Native", "description": "Waku React Native",
"author": "Status Research & Development GMBH", "author": "Status Research & Development GMBH",
"authors": [ "authors": [

View File

@ -19,7 +19,7 @@ const ReactNative = NativeModules.ReactNative
} }
); );
const OneMillion = bigInt(1_000_000); const OneMillion = bigInt(1000000);
export class WakuMessage { export class WakuMessage {
payload: Uint8Array = new Uint8Array(); payload: Uint8Array = new Uint8Array();
@ -51,7 +51,10 @@ export function onMessage(cb: (arg0: any) => void) {
let signal = JSON.parse(event.signal); let signal = JSON.parse(event.signal);
let msg = signal.event.wakuMessage; let msg = signal.event.wakuMessage;
signal.event.wakuMessage = new 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.version = msg.version || 0;
signal.event.wakuMessage.contentTopic = msg.contentTopic; signal.event.wakuMessage.contentTopic = msg.contentTopic;
signal.event.wakuMessage.payload = new Uint8Array( signal.event.wakuMessage.payload = new Uint8Array(
@ -736,7 +739,16 @@ export function storeQuery(
} else { } else {
if (response.result.messages) { if (response.result.messages) {
for (let i = 0; i < response.result.messages.length; i++) { 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))); 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); resolve(response.result);