From 59056e9a85442e9c5c5a172c701bcda11cefaf80 Mon Sep 17 00:00:00 2001 From: Ethan Mateja Date: Wed, 17 Apr 2024 18:02:46 -0700 Subject: [PATCH 1/3] added_by_address implementation + test --- example/src/tests/groupTests.ts | 16 ++++++++++++++++ src/lib/Group.ts | 7 +++++++ 2 files changed, 23 insertions(+) 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/src/lib/Group.ts b/src/lib/Group.ts index 28a90a957..9b9cbdf6f 100644 --- a/src/lib/Group.ts +++ b/src/lib/Group.ts @@ -203,6 +203,13 @@ export class Group< return XMTP.isGroupActive(this.client.address, this.id) } + async addedByAddress(skipSync = false): Promise { + if (!skipSync) { + await this.sync() + } + return XMTP.addedByAddress(this.client.address, this.id) + } + async isAdmin(): Promise { return XMTP.isGroupAdmin(this.client.address, this.id) } From a04ec82d85103d73764b805c37b2d549581119f6 Mon Sep 17 00:00:00 2001 From: Ethan Mateja Date: Thu, 18 Apr 2024 11:08:16 -0700 Subject: [PATCH 2/3] Update Bridges + Index --- .../expo/modules/xmtpreactnativesdk/XMTPModule.kt | 10 ++++++++++ ios/XMTPModule.swift | 13 ++++++++++++- src/index.ts | 7 +++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt index 856716b28..63f3016ae 100644 --- a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt +++ b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt @@ -804,6 +804,16 @@ class XMTPModule : Module() { } } + AsyncFunction("addedByAddress") Coroutine { clientAddress: String, id: String -> + withContext(Dispatchers.IO) { + logV("addedByAddress") + val client = clients[clientAddress] ?: throw XMTPException("No client") + val group = findGroup(clientAddress, id) + + group?.addedByAddress() + } + } + AsyncFunction("isGroupAdmin") Coroutine { clientAddress: String, id: String -> withContext(Dispatchers.IO) { logV("isGroupAdmin") diff --git a/ios/XMTPModule.swift b/ios/XMTPModule.swift index 222ebf773..2fbaec56c 100644 --- a/ios/XMTPModule.swift +++ b/ios/XMTPModule.swift @@ -703,7 +703,18 @@ public class XMTPModule: Module { return try group.isActive() } - + + AsyncFunction("addedByAddress") { (clientAddress: String, id: String) -> String in + guard let client = await clientsManager.getClient(key: clientAddress) else { + throw Error.noClient + } + 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 From 4ec9fe99550f0d7861da8a855b0f1a9fcd34c03d Mon Sep 17 00:00:00 2001 From: Ethan Mateja Date: Thu, 18 Apr 2024 13:56:47 -0700 Subject: [PATCH 3/3] Adress PR Feedback --- .../main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt | 5 ++--- ios/XMTPModule.swift | 3 --- src/lib/Group.ts | 5 +---- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt index 63f3016ae..2c5be7b18 100644 --- a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt +++ b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt @@ -807,10 +807,9 @@ class XMTPModule : Module() { AsyncFunction("addedByAddress") Coroutine { clientAddress: String, id: String -> withContext(Dispatchers.IO) { logV("addedByAddress") - val client = clients[clientAddress] ?: throw XMTPException("No client") - val group = findGroup(clientAddress, id) + val group = findGroup(clientAddress, id) ?: throw XMTPException("No group found") - group?.addedByAddress() + group.addedByAddress() } } diff --git a/ios/XMTPModule.swift b/ios/XMTPModule.swift index 2fbaec56c..01331862d 100644 --- a/ios/XMTPModule.swift +++ b/ios/XMTPModule.swift @@ -705,9 +705,6 @@ public class XMTPModule: Module { } AsyncFunction("addedByAddress") { (clientAddress: String, id: String) -> String in - guard let client = await clientsManager.getClient(key: clientAddress) else { - throw Error.noClient - } guard let group = try await findGroup(clientAddress: clientAddress, id: id) else { throw Error.conversationNotFound("no group found for \(id)") } diff --git a/src/lib/Group.ts b/src/lib/Group.ts index 9b9cbdf6f..c34f172e8 100644 --- a/src/lib/Group.ts +++ b/src/lib/Group.ts @@ -203,10 +203,7 @@ export class Group< return XMTP.isGroupActive(this.client.address, this.id) } - async addedByAddress(skipSync = false): Promise { - if (!skipSync) { - await this.sync() - } + addedByAddress(): Promise { return XMTP.addedByAddress(this.client.address, this.id) }