diff --git a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt index 856716b28..2c5be7b18 100644 --- a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt +++ b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt @@ -804,6 +804,15 @@ class XMTPModule : Module() { } } + AsyncFunction("addedByAddress") Coroutine { clientAddress: String, id: String -> + withContext(Dispatchers.IO) { + logV("addedByAddress") + val group = findGroup(clientAddress, id) ?: throw XMTPException("No group found") + + group.addedByAddress() + } + } + AsyncFunction("isGroupAdmin") Coroutine { clientAddress: String, id: String -> withContext(Dispatchers.IO) { logV("isGroupAdmin") diff --git a/example/src/tests/groupTests.ts b/example/src/tests/groupTests.ts index e83e4ce67..5544f1c95 100644 --- a/example/src/tests/groupTests.ts +++ b/example/src/tests/groupTests.ts @@ -205,6 +205,22 @@ test('production MLS V3 client creation throws error', async () => { ) }) +test('who added me to a group', async () => { + const [alixClient, boClient] = await createClients(2) + const alixGroup = await alixClient.conversations.newGroup([ + boClient.address, + ]) + + const boGroup = (await boClient.conversations.listGroups())[0] + const addedByAddress = await boGroup.addedByAddress() + + assert( + addedByAddress.toLocaleLowerCase === alixClient.address.toLocaleLowerCase, + `addedByAddress ${addedByAddress} does not match ${alixClient.address}` + ) + return true +}) + test('can message in a group', async () => { // Create three MLS enabled Clients const [alixClient, boClient, caroClient] = await createClients(3) diff --git a/ios/XMTPModule.swift b/ios/XMTPModule.swift index 222ebf773..01331862d 100644 --- a/ios/XMTPModule.swift +++ b/ios/XMTPModule.swift @@ -703,7 +703,15 @@ public class XMTPModule: Module { return try group.isActive() } - + + AsyncFunction("addedByAddress") { (clientAddress: String, id: String) -> String in + guard let group = try await findGroup(clientAddress: clientAddress, id: id) else { + throw Error.conversationNotFound("no group found for \(id)") + } + + return try group.addedByAddress() + } + AsyncFunction("isGroupAdmin") { (clientAddress: String, id: String) -> Bool in guard let client = await clientsManager.getClient(key: clientAddress) else { throw Error.noClient diff --git a/src/index.ts b/src/index.ts index 7fcb861f4..8cd7d959f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -665,6 +665,13 @@ export async function isGroupActive( return XMTPModule.isGroupActive(clientAddress, id) } +export async function addedByAddress( + clientAddress: string, + id: string +): Promise { + return XMTPModule.addedByAddress(clientAddress, id) +} + export async function isGroupAdmin( clientAddress: string, id: string diff --git a/src/lib/Group.ts b/src/lib/Group.ts index 28a90a957..c34f172e8 100644 --- a/src/lib/Group.ts +++ b/src/lib/Group.ts @@ -203,6 +203,10 @@ export class Group< return XMTP.isGroupActive(this.client.address, this.id) } + addedByAddress(): Promise { + return XMTP.addedByAddress(this.client.address, this.id) + } + async isAdmin(): Promise { return XMTP.isGroupAdmin(this.client.address, this.id) }