From b013d97a4400bdbbcc182077fc6f8bb62d471fbf Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Thu, 13 Jun 2024 18:09:32 -0700 Subject: [PATCH] fix: inbox id versus client inbox id --- .../modules/xmtpreactnativesdk/XMTPModule.kt | 37 +++++++++---------- example/src/tests/groupPermissionsTests.ts | 15 ++++---- src/index.ts | 33 ++++++++++++----- src/lib/Group.ts | 12 +++--- 4 files changed, 55 insertions(+), 42 deletions(-) diff --git a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt index c1642afe6..aa76efc15 100644 --- a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt +++ b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt @@ -947,21 +947,21 @@ class XMTPModule : Module() { } } - AsyncFunction("isAdmin") Coroutine { id: String, inboxId: String -> + AsyncFunction("isAdmin") Coroutine { clientInboxId: String, id: String, inboxId: String -> withContext(Dispatchers.IO) { logV("isGroupAdmin") - val client = clients[inboxId] ?: throw XMTPException("No client") - val group = findGroup(inboxId, id) + val client = clients[clientInboxId] ?: throw XMTPException("No client") + val group = findGroup(clientInboxId, id) group?.isAdmin(inboxId) } } - AsyncFunction("isSuperAdmin") Coroutine { id: String, inboxId: String -> + AsyncFunction("isSuperAdmin") Coroutine { clientInboxId: String, id: String, inboxId: String -> withContext(Dispatchers.IO) { logV("isSuperAdmin") - val client = clients[inboxId] ?: throw XMTPException("No client") - val group = findGroup(inboxId, id) + val client = clients[clientInboxId] ?: throw XMTPException("No client") + val group = findGroup(clientInboxId, id) group?.isSuperAdmin(inboxId) } @@ -987,41 +987,40 @@ class XMTPModule : Module() { } } - AsyncFunction("addAdmin") Coroutine { id: String, inboxId: String -> + AsyncFunction("addAdmin") Coroutine { clientInboxId: String, id: String, inboxId: String -> withContext(Dispatchers.IO) { logV("addAdmin") - val client = clients[inboxId] ?: throw XMTPException("No client") - val group = findGroup(inboxId, id) - + val client = clients[clientInboxId] ?: throw XMTPException("No client") + val group = findGroup(clientInboxId, id) group?.addAdmin(inboxId) } } - AsyncFunction("addSuperAdmin") Coroutine { id: String, inboxId: String -> + AsyncFunction("addSuperAdmin") Coroutine { clientInboxId: String, id: String, inboxId: String -> withContext(Dispatchers.IO) { logV("addSuperAdmin") - val client = clients[inboxId] ?: throw XMTPException("No client") - val group = findGroup(inboxId, id) + val client = clients[clientInboxId] ?: throw XMTPException("No client") + val group = findGroup(clientInboxId, id) group?.addSuperAdmin(inboxId) } } - AsyncFunction("removeAdmin") Coroutine { id: String, inboxId: String -> + AsyncFunction("removeAdmin") Coroutine { clientInboxId: String, id: String, inboxId: String -> withContext(Dispatchers.IO) { logV("removeAdmin") - val client = clients[inboxId] ?: throw XMTPException("No client") - val group = findGroup(inboxId, id) + val client = clients[clientInboxId] ?: throw XMTPException("No client") + val group = findGroup(clientInboxId, id) group?.removeAdmin(inboxId) } } - AsyncFunction("removeSuperAdmin") Coroutine { id: String, inboxId: String -> + AsyncFunction("removeSuperAdmin") Coroutine { clientInboxId: String, id: String, inboxId: String -> withContext(Dispatchers.IO) { logV("removeSuperAdmin") - val client = clients[inboxId] ?: throw XMTPException("No client") - val group = findGroup(inboxId, id) + val client = clients[clientInboxId] ?: throw XMTPException("No client") + val group = findGroup(clientInboxId, id) group?.removeSuperAdmin(inboxId) } diff --git a/example/src/tests/groupPermissionsTests.ts b/example/src/tests/groupPermissionsTests.ts index 129cf206b..1c865b6b0 100644 --- a/example/src/tests/groupPermissionsTests.ts +++ b/example/src/tests/groupPermissionsTests.ts @@ -85,7 +85,7 @@ test('in admin only group, members can not update group name unless they are an // Alix Create a group const alixGroup = await alix.conversations.newGroup( [bo.address, caro.address], - 'admin_only' + { permissionLevel: 'admin_only' } ) if (alixGroup.permissionLevel !== 'admin_only') { @@ -120,7 +120,7 @@ test('in admin only group, members can update group name once they are an admin' // Alix Create a group const alixGroup = await alix.conversations.newGroup( [bo.address, caro.address], - 'admin_only' + { permissionLevel: 'admin_only' } ) if (alixGroup.permissionLevel !== 'admin_only') { @@ -171,7 +171,7 @@ test('in admin only group, members can not update group name after admin status // Alix Create a group const alixGroup = await alix.conversations.newGroup( [bo.address, caro.address], - 'admin_only' + { permissionLevel: 'admin_only' } ) if (alixGroup.permissionLevel !== 'admin_only') { @@ -235,10 +235,9 @@ test('can not remove a super admin from a group', async () => { const [alix, bo] = await createClients(3) // Alix Create a group - const alixGroup = await alix.conversations.newGroup( - [bo.address], - 'all_members' - ) + const alixGroup = await alix.conversations.newGroup([bo.address], { + permissionLevel: 'all_members', + }) let alixIsSuperAdmin = await alixGroup.isSuperAdmin(alix.inboxId) let boIsSuperAdmin = await alixGroup.isSuperAdmin(bo.inboxId) @@ -323,7 +322,7 @@ test('can commit after invalid permissions commit', async () => { // Bo creates a group with Alix and Caro const boGroup = await bo.conversations.newGroup( [alix.address, caro.address], - 'all_members' + { permissionLevel: 'admin_only' } ) await alix.conversations.syncGroups() const alixGroup = (await alix.conversations.listGroups())[0] diff --git a/src/index.ts b/src/index.ts index 058363456..7ab57618e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -742,15 +742,20 @@ export async function creatorInboxId( return XMTPModule.creatorInboxId(inboxId, id) as InboxId } -export async function isAdmin(id: string, inboxId: string): Promise { - return XMTPModule.isAdmin(id, inboxId) +export async function isAdmin( + clientInboxId: string, + id: string, + inboxId: string +): Promise { + return XMTPModule.isAdmin(clientInboxId, id, inboxId) } export async function isSuperAdmin( + clientInboxId: string, id: string, inboxId: string ): Promise { - return XMTPModule.isSuperAdmin(id, inboxId) + return XMTPModule.isSuperAdmin(clientInboxId, id, inboxId) } export async function listAdmins( @@ -767,26 +772,36 @@ export async function listSuperAdmins( return XMTPModule.listSuperAdmins(inboxId, id) } -export async function addAdmin(id: string, inboxId: string): Promise { - return XMTPModule.addAdmin(id, inboxId) +export async function addAdmin( + clientInboxId: string, + id: string, + inboxId: string +): Promise { + return XMTPModule.addAdmin(clientInboxId, id, inboxId) } export async function addSuperAdmin( + clientInboxId: string, id: string, inboxId: string ): Promise { - return XMTPModule.addSuperAdmin(id, inboxId) + return XMTPModule.addSuperAdmin(clientInboxId, id, inboxId) } -export async function removeAdmin(id: string, inboxId: string): Promise { - return XMTPModule.removeAdmin(id, inboxId) +export async function removeAdmin( + clientInboxId: string, + id: string, + inboxId: string +): Promise { + return XMTPModule.removeAdmin(clientInboxId, id, inboxId) } export async function removeSuperAdmin( + clientInboxId: string, id: string, inboxId: string ): Promise { - return XMTPModule.removeSuperAdmin(id, inboxId) + return XMTPModule.removeSuperAdmin(clientInboxId, id, inboxId) } export async function allowGroups( diff --git a/src/lib/Group.ts b/src/lib/Group.ts index 62824beab..9522699d6 100644 --- a/src/lib/Group.ts +++ b/src/lib/Group.ts @@ -288,7 +288,7 @@ export class Group< * To get the latest admin status from the network, call sync() first. */ async isAdmin(inboxId: InboxId): Promise { - return XMTP.isAdmin(this.id, inboxId) + return XMTP.isAdmin(this.client.inboxId, this.id, inboxId) } /** @@ -298,7 +298,7 @@ export class Group< * To get the latest super admin status from the network, call sync() first. */ async isSuperAdmin(inboxId: InboxId): Promise { - return XMTP.isSuperAdmin(this.id, inboxId) + return XMTP.isSuperAdmin(this.client.inboxId, this.id, inboxId) } /** @@ -326,7 +326,7 @@ export class Group< * Will throw if the user does not have the required permissions. */ async addAdmin(inboxId: InboxId): Promise { - return XMTP.addAdmin(this.id, inboxId) + return XMTP.addAdmin(this.client.inboxId, this.id, inboxId) } /** @@ -336,7 +336,7 @@ export class Group< * Will throw if the user does not have the required permissions. */ async addSuperAdmin(inboxId: InboxId): Promise { - return XMTP.addSuperAdmin(this.id, inboxId) + return XMTP.addSuperAdmin(this.client.inboxId, this.id, inboxId) } /** @@ -346,7 +346,7 @@ export class Group< * Will throw if the user does not have the required permissions. */ async removeAdmin(inboxId: InboxId): Promise { - return XMTP.removeAdmin(this.id, inboxId) + return XMTP.removeAdmin(this.client.inboxId, this.id, inboxId) } /** @@ -356,7 +356,7 @@ export class Group< * Will throw if the user does not have the required permissions. */ async removeSuperAdmin(inboxId: InboxId): Promise { - return XMTP.removeSuperAdmin(this.id, inboxId) + return XMTP.removeSuperAdmin(this.client.inboxId, this.id, inboxId) } async processMessage(