Skip to content

Commit

Permalink
fix: v3 consent works
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Sep 30, 2024
1 parent c8b3180 commit e13c1bf
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, Any> {
val consentString = when (group.consentState()) {
ConsentState.ALLOWED -> "allowed"
ConsentState.DENIED -> "denied"
ConsentState.UNKNOWN -> "unknown"
}
return mapOf(
"clientAddress" to client.address,
"id" to group.id,
Expand All @@ -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
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 12 additions & 12 deletions example/src/tests/v3OnlyTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
Expand All @@ -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}`
Expand All @@ -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}`
Expand All @@ -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(
Expand All @@ -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)
Expand All @@ -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(
Expand All @@ -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])
Expand All @@ -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
Expand Down
10 changes: 1 addition & 9 deletions ios/Wrappers/GroupWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
]
}
Expand Down
11 changes: 1 addition & 10 deletions ios/Wrappers/MemberWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -32,7 +23,7 @@ struct MemberWrapper {
"inboxId": member.inboxId,
"addresses": member.addresses,
"permissionLevel": permissionString,
"consentString": consentString
"consentState": ConsentWrapper.consentStateToString(state: member.consentState)
]
}

Expand Down
4 changes: 2 additions & 2 deletions ios/XMTPModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1660,7 +1660,7 @@ public class XMTPModule: Module {
case "denied":
return .denied
default:
throw .unknown
return .unknown
}
}

Expand Down
8 changes: 6 additions & 2 deletions src/lib/Group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class Group<
addedByInboxId: InboxId
imageUrlSquare: string
description: string
consentState: ConsentState
state: ConsentState
// pinnedFrameUrl: string

constructor(
Expand All @@ -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
}

Expand Down Expand Up @@ -613,6 +613,10 @@ export class Group<
}
}

async consentState(): Promise<ConsentState> {
return await XMTP.groupConsentState(this.client.inboxId, this.id)
}

async updateConsent(state: ConsentState): Promise<void> {
return await XMTP.updateGroupConsent(this.client.inboxId, this.id, state)
}
Expand Down

0 comments on commit e13c1bf

Please sign in to comment.