From 0a7d80b6908cee5fd5809624c1246f2d698c72ad Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Wed, 6 Dec 2023 12:55:07 -0800 Subject: [PATCH] write the typescript RN side --- src/index.ts | 21 +++++++++++++++++++++ src/lib/Contacts.ts | 10 ++++++---- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index 72f0b1940..349210ca7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -353,6 +353,27 @@ export function refreshConsentList(clientAddress: string) { XMTPModule.refreshConsentList(clientAddress) } +export async function consentList( + clientAddress: string +): Promise> { + return jsonArrayToMap(await XMTPModule.consentList(clientAddress)) +} + +function jsonArrayToMap(jsonArray: string[]): Map { + const result = new Map() + + jsonArray.forEach((jsonString) => { + const parsedObject = JSON.parse(jsonString) + if (parsedObject && parsedObject.key) { + result.set(parsedObject.key, parsedObject) + } else { + console.error('Invalid JSON structure:', jsonString) + } + }) + + return result +} + export const emitter = new EventEmitter(XMTPModule ?? NativeModulesProxy.XMTP) export * from './lib/ContentCodec' diff --git a/src/lib/Contacts.ts b/src/lib/Contacts.ts index 77480048c..c4e809849 100644 --- a/src/lib/Contacts.ts +++ b/src/lib/Contacts.ts @@ -9,13 +9,11 @@ export default class Contacts { } async isAllowed(address: string): Promise { - const result = await XMTPModule.isAllowed(this.client.address, address) - return result + return await XMTPModule.isAllowed(this.client.address, address) } async isDenied(address: string): Promise { - const result = await XMTPModule.isDenied(this.client.address, address) - return result + return await XMTPModule.isDenied(this.client.address, address) } deny(addresses: string[]) { @@ -29,4 +27,8 @@ export default class Contacts { refreshConsentList() { XMTPModule.refreshConsentList(this.client.address) } + + async consentList(): Promise> { + return await XMTPModule.consentList(this.client.address) + } }