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/
tmp/
android/libs/gowaku-sources.jar
android/libs/gowaku.aar
gowaku-sources.jar
gowaku.aar
ios/Gowaku.xcframework

View File

@ -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

View File

@ -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()) {

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
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

View File

@ -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'

View File

@ -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
package-lock.json generated
View File

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

View File

@ -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": [

View File

@ -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();
@ -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(
@ -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);