From e13c1bfd0972ac406c720c1ff9d62601ec67e3c2 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Mon, 30 Sep 2024 16:20:51 -0600 Subject: [PATCH] fix: v3 consent works --- .../modules/xmtpreactnativesdk/XMTPModule.kt | 2 +- .../wrappers/GroupWrapper.kt | 9 ++----- .../wrappers/MemberWrapper.kt | 8 +------ .../project.pbxproj | 2 ++ example/src/tests/v3OnlyTests.ts | 24 +++++++++---------- ios/Wrappers/GroupWrapper.swift | 10 +------- ios/Wrappers/MemberWrapper.swift | 11 +-------- ios/XMTPModule.swift | 4 ++-- src/lib/Group.ts | 8 +++++-- 9 files changed, 28 insertions(+), 50 deletions(-) diff --git a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt index 157652609..bffa998a1 100644 --- a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt +++ b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt @@ -1614,7 +1614,7 @@ class XMTPModule : Module() { withContext(Dispatchers.IO) { val group = findGroup(inboxId, groupId) ?: throw XMTPException("no group found for $groupId") - consentStateToString(Conversation.Group(group).consentState()) + consentStateToString(group.consentState()) } } diff --git a/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/GroupWrapper.kt b/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/GroupWrapper.kt index 343802809..0336e5f70 100644 --- a/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/GroupWrapper.kt +++ b/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/GroupWrapper.kt @@ -1,19 +1,14 @@ package expo.modules.xmtpreactnativesdk.wrappers import com.google.gson.GsonBuilder +import expo.modules.xmtpreactnativesdk.wrappers.ConsentWrapper.Companion.consentStateToString import org.xmtp.android.library.Client -import org.xmtp.android.library.ConsentState import org.xmtp.android.library.Group class GroupWrapper { companion object { suspend fun encodeToObj(client: Client, group: Group): Map { - val consentString = when (group.consentState()) { - ConsentState.ALLOWED -> "allowed" - ConsentState.DENIED -> "denied" - ConsentState.UNKNOWN -> "unknown" - } return mapOf( "clientAddress" to client.address, "id" to group.id, @@ -27,7 +22,7 @@ class GroupWrapper { "name" to group.name, "imageUrlSquare" to group.imageUrlSquare, "description" to group.description, - "consentState" to consentString + "consentState" to consentStateToString(group.consentState()) // "pinnedFrameUrl" to group.pinnedFrameUrl ) } diff --git a/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/MemberWrapper.kt b/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/MemberWrapper.kt index da5b0e706..b241292d2 100644 --- a/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/MemberWrapper.kt +++ b/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/MemberWrapper.kt @@ -1,7 +1,6 @@ package expo.modules.xmtpreactnativesdk.wrappers import com.google.gson.GsonBuilder -import org.xmtp.android.library.ConsentState import org.xmtp.android.library.libxmtp.Member import org.xmtp.android.library.libxmtp.PermissionLevel @@ -13,16 +12,11 @@ class MemberWrapper { PermissionLevel.ADMIN -> "admin" PermissionLevel.SUPER_ADMIN -> "super_admin" } - val consentString = when (member.consentState) { - ConsentState.ALLOWED -> "allowed" - ConsentState.DENIED -> "denied" - ConsentState.UNKNOWN -> "unknown" - } return mapOf( "inboxId" to member.inboxId, "addresses" to member.addresses, "permissionLevel" to permissionString, - "consentState" to consentString + "consentState" to ConsentWrapper.consentStateToString(member.consentState) ) } diff --git a/example/ios/xmtpreactnativesdkexample.xcodeproj/project.pbxproj b/example/ios/xmtpreactnativesdkexample.xcodeproj/project.pbxproj index 2d41f01a2..3388e7aa2 100644 --- a/example/ios/xmtpreactnativesdkexample.xcodeproj/project.pbxproj +++ b/example/ios/xmtpreactnativesdkexample.xcodeproj/project.pbxproj @@ -294,10 +294,12 @@ inputPaths = ( "${PODS_ROOT}/Target Support Files/Pods-xmtpreactnativesdkexample/Pods-xmtpreactnativesdkexample-frameworks.sh", "${PODS_XCFRAMEWORKS_BUILD_DIR}/OpenSSL-Universal/OpenSSL.framework/OpenSSL", + "${PODS_XCFRAMEWORKS_BUILD_DIR}/hermes-engine/Pre-built/hermes.framework/hermes", ); name = "[CP] Embed Pods Frameworks"; outputPaths = ( "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/OpenSSL.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/hermes.framework", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; diff --git a/example/src/tests/v3OnlyTests.ts b/example/src/tests/v3OnlyTests.ts index 5a6988ae6..9108f6ddf 100644 --- a/example/src/tests/v3OnlyTests.ts +++ b/example/src/tests/v3OnlyTests.ts @@ -99,7 +99,7 @@ test('can group consent', async () => { const isAllowed = await boV3.contacts.isGroupAllowed(group.id) assert(isAllowed === true, `isAllowed should be true but was ${isAllowed}`) - let groupState = await group.consentState + let groupState = await group.state assert( groupState === 'allowed', `group state should be allowed but was ${groupState}` @@ -109,7 +109,7 @@ test('can group consent', async () => { const isDenied = await boV3.contacts.isGroupDenied(group.id) assert(isDenied === true, `isDenied should be true but was ${isDenied}`) - groupState = await group.consentState + groupState = await group.consentState() assert( groupState === 'denied', `group state should be denied but was ${groupState}` @@ -119,7 +119,7 @@ test('can group consent', async () => { const isAllowed2 = await boV3.contacts.isGroupAllowed(group.id) assert(isAllowed2 === true, `isAllowed2 should be true but was ${isAllowed2}`) - groupState = await group.consentState + groupState = await group.consentState() assert( groupState === 'allowed', `group state should be allowed but was ${groupState}` @@ -145,7 +145,7 @@ test('can allow and deny inbox ids', async () => { await boV3.contacts.allowInboxes([caroV2V3.inboxId]) - let caroMember = boGroup.members.find( + let caroMember = (await boGroup.membersList()).find( (member) => member.inboxId === caroV2V3.inboxId ) assert( @@ -157,11 +157,11 @@ test('can allow and deny inbox ids', async () => { isInboxDenied = await boV3.contacts.isInboxDenied(caroV2V3.inboxId) assert( isInboxAllowed === true, - `isInboxAllowed should be true but was ${isInboxAllowed}` + `isInboxAllowed2 should be true but was ${isInboxAllowed}` ) assert( - isInboxDenied === true, - `isInboxDenied should be true but was ${isInboxDenied}` + isInboxDenied === false, + `isInboxDenied2 should be false but was ${isInboxDenied}` ) let isAddressAllowed = await boV3.contacts.isAllowed(caroV2V3.address) @@ -177,7 +177,7 @@ test('can allow and deny inbox ids', async () => { await boV3.contacts.denyInboxes([caroV2V3.inboxId]) - caroMember = boGroup.members.find( + caroMember = (await boGroup.membersList()).find( (member) => member.inboxId === caroV2V3.inboxId ) assert( @@ -189,11 +189,11 @@ test('can allow and deny inbox ids', async () => { isInboxDenied = await boV3.contacts.isInboxDenied(caroV2V3.inboxId) assert( isInboxAllowed === false, - `isInboxAllowed should be false but was ${isInboxAllowed}` + `isInboxAllowed3 should be false but was ${isInboxAllowed}` ) assert( isInboxDenied === true, - `isInboxDenied should be true but was ${isInboxDenied}` + `isInboxDenied3 should be true but was ${isInboxDenied}` ) await boV3.contacts.allow([alixV2.address]) @@ -202,11 +202,11 @@ test('can allow and deny inbox ids', async () => { isAddressDenied = await boV3.contacts.isDenied(alixV2.address) assert( isAddressAllowed === true, - `isAddressAllowed should be true but was ${isAddressAllowed}` + `isAddressAllowed2 should be true but was ${isAddressAllowed}` ) assert( isAddressDenied === false, - `isAddressDenied should be false but was ${isAddressDenied}` + `isAddressDenied2 should be false but was ${isAddressDenied}` ) return true diff --git a/ios/Wrappers/GroupWrapper.swift b/ios/Wrappers/GroupWrapper.swift index 5f8d738ef..3d80b8a70 100644 --- a/ios/Wrappers/GroupWrapper.swift +++ b/ios/Wrappers/GroupWrapper.swift @@ -11,14 +11,6 @@ import XMTP // Wrapper around XMTP.Group to allow passing these objects back into react native. struct GroupWrapper { static func encodeToObj(_ group: XMTP.Group, client: XMTP.Client) async throws -> [String: Any] { - let consentString = switch try group.consentState() { - case .allowed: - "allowed" - case .denied: - "denied" - case .unknown: - "unknown" - } return [ "clientAddress": client.address, "id": group.id, @@ -32,7 +24,7 @@ struct GroupWrapper { "name": try group.groupName(), "imageUrlSquare": try group.groupImageUrlSquare(), "description": try group.groupDescription(), - "consentState": consentString + "consentState": ConsentWrapper.consentStateToString(state: try group.consentState()) // "pinnedFrameUrl": try group.groupPinnedFrameUrl() ] } diff --git a/ios/Wrappers/MemberWrapper.swift b/ios/Wrappers/MemberWrapper.swift index 57de10526..02e29e1ea 100644 --- a/ios/Wrappers/MemberWrapper.swift +++ b/ios/Wrappers/MemberWrapper.swift @@ -11,15 +11,6 @@ import XMTP // Wrapper around XMTP.Member to allow passing these objects back into react native. struct MemberWrapper { static func encodeToObj(_ member: XMTP.Member) throws -> [String: Any] { - let consentString = switch member.consentState { - case .allowed: - "allowed" - case .denied: - "denied" - case .unknown: - "unknown" - } - let permissionString = switch member.permissionLevel { case .Member: "member" @@ -32,7 +23,7 @@ struct MemberWrapper { "inboxId": member.inboxId, "addresses": member.addresses, "permissionLevel": permissionString, - "consentString": consentString + "consentState": ConsentWrapper.consentStateToString(state: member.consentState) ] } diff --git a/ios/XMTPModule.swift b/ios/XMTPModule.swift index 7dba0d4fc..08edd2df5 100644 --- a/ios/XMTPModule.swift +++ b/ios/XMTPModule.swift @@ -1525,7 +1525,7 @@ public class XMTPModule: Module { guard let group = try await findGroup(inboxId: inboxId, id: groupId) else { throw Error.conversationNotFound("no group found for \(groupId)") } - return try ConsentWrapper.consentStateToString(state: await XMTP.Conversation.group(group).consentState()) + return try ConsentWrapper.consentStateToString(state: await group.consentState()) } AsyncFunction("consentList") { (inboxId: String) -> [String] in @@ -1660,7 +1660,7 @@ public class XMTPModule: Module { case "denied": return .denied default: - throw .unknown + return .unknown } } diff --git a/src/lib/Group.ts b/src/lib/Group.ts index 0149ef573..f94fe2e72 100644 --- a/src/lib/Group.ts +++ b/src/lib/Group.ts @@ -46,7 +46,7 @@ export class Group< addedByInboxId: InboxId imageUrlSquare: string description: string - consentState: ConsentState + state: ConsentState // pinnedFrameUrl: string constructor( @@ -65,7 +65,7 @@ export class Group< this.addedByInboxId = params.addedByInboxId this.imageUrlSquare = params.imageUrlSquare this.description = params.description - this.consentState = params.consentState + this.state = params.consentState // this.pinnedFrameUrl = params.pinnedFrameUrl } @@ -613,6 +613,10 @@ export class Group< } } + async consentState(): Promise { + return await XMTP.groupConsentState(this.client.inboxId, this.id) + } + async updateConsent(state: ConsentState): Promise { return await XMTP.updateGroupConsent(this.client.inboxId, this.id, state) }