Skip to content

Commit

Permalink
write the typescript RN side
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Dec 6, 2023
1 parent 134e468 commit 0a7d80b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
21 changes: 21 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,27 @@ export function refreshConsentList(clientAddress: string) {
XMTPModule.refreshConsentList(clientAddress)
}

export async function consentList(
clientAddress: string
): Promise<Map<string, 'allowed' | 'denied' | 'unknown'>> {
return jsonArrayToMap(await XMTPModule.consentList(clientAddress))
}

function jsonArrayToMap(jsonArray: string[]): Map<string, any> {
const result = new Map<string, any>()

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'
Expand Down
10 changes: 6 additions & 4 deletions src/lib/Contacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ export default class Contacts {
}

async isAllowed(address: string): Promise<boolean> {
const result = await XMTPModule.isAllowed(this.client.address, address)
return result
return await XMTPModule.isAllowed(this.client.address, address)
}

async isDenied(address: string): Promise<boolean> {
const result = await XMTPModule.isDenied(this.client.address, address)
return result
return await XMTPModule.isDenied(this.client.address, address)
}

deny(addresses: string[]) {
Expand All @@ -29,4 +27,8 @@ export default class Contacts {
refreshConsentList() {
XMTPModule.refreshConsentList(this.client.address)
}

async consentList(): Promise<Map<string, 'allowed' | 'denied' | 'unknown'>> {
return await XMTPModule.consentList(this.client.address)
}
}

0 comments on commit 0a7d80b

Please sign in to comment.