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) + } }