diff --git a/src/index.ts b/src/index.ts index db28d689f..765ccd0e1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -18,6 +18,7 @@ import { } from './lib/ConversationContainer' import { DecodedMessage, MessageDeliveryStatus } from './lib/DecodedMessage' import { Group } from './lib/Group' +import { Member } from './lib/Member' import type { Query } from './lib/Query' import { ConversationSendPayload } from './lib/types' import { DefaultContentTypes } from './lib/types/DefaultContentType' @@ -147,6 +148,17 @@ export async function listMemberInboxIds< return XMTPModule.listMemberInboxIds(client.address, id) } +export async function listGroupMembers( + clientAddress: string, + id: string +): Promise { + const members = await XMTPModule.listGroupMembers(clientAddress, id) + + return members.map((json: string) => { + return Member.from(json) + }) +} + export async function sendMessageToGroup( clientAddress: string, groupId: string, @@ -893,3 +905,4 @@ export { Query } from './lib/Query' export { XMTPPush } from './lib/XMTPPush' export { ConsentListEntry, DecodedMessage, MessageDeliveryStatus } export { Group } from './lib/Group' +export { Member } from './lib/Member' diff --git a/src/lib/Group.ts b/src/lib/Group.ts index 1870871af..69e600080 100644 --- a/src/lib/Group.ts +++ b/src/lib/Group.ts @@ -3,6 +3,7 @@ import { ConversationContainer, } from './ConversationContainer' import { DecodedMessage, MessageDeliveryStatus } from './DecodedMessage' +import { Member } from './Member' import { ConversationSendPayload } from './types/ConversationCodecs' import { DefaultContentTypes } from './types/DefaultContentType' import { EventTypes } from './types/EventTypes' @@ -295,4 +296,8 @@ export class Group< async isDenied(): Promise { return await XMTP.isGroupDenied(this.client.address, this.id) } + + async members(): Promise { + return await XMTP.listGroupMembers(this.client.address, this.id) + } } diff --git a/src/lib/Member.ts b/src/lib/Member.ts new file mode 100644 index 000000000..10aa2db1a --- /dev/null +++ b/src/lib/Member.ts @@ -0,0 +1,20 @@ +export class Member { + inboxId: string + addresses: string[] + permissionLevel: 'member' | 'admin' | 'super_admin' + + constructor( + inboxId: string, + addresses: string[], + permissionLevel: 'member' | 'admin' | 'super_admin' + ) { + this.inboxId = inboxId + this.addresses = addresses + this.permissionLevel = permissionLevel + } + + static from(json: string): Member { + const entry = JSON.parse(json) + return new Member(entry.inboxId, entry.addresses, entry.permissionLevel) + } +}