Skip to content

Commit

Permalink
add consent state for groups as well
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Apr 18, 2024
1 parent 716c0ac commit 81322d3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,14 @@ class XMTPModule : Module() {
}
}

AsyncFunction("groupConsentState") Coroutine { clientAddress: String, groupId: String ->
withContext(Dispatchers.IO) {
val group = findGroup(clientAddress, groupId)
?: throw XMTPException("no group found for $groupId")
consentStateToString(Conversation.Group(group).consentState())
}
}

AsyncFunction("consentList") { clientAddress: String ->
val client = clients[clientAddress] ?: throw XMTPException("No client")
client.contacts.consentList.entries.map { ConsentWrapper.encode(it.value) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class GroupWrapper {
"createdAt" to group.createdAt.time,
"peerAddresses" to Conversation.Group(group).peerAddresses,
"version" to "GROUP",
"topic" to group.id.toHex(),
"topic" to group.topic,
"permissionLevel" to permissionString,
"adminAddress" to group.adminAddress()
)
Expand Down
7 changes: 7 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,13 @@ export async function conversationConsentState(
)
}

export async function groupConsentState(
clientAddress: string,
groupId: string
): Promise<ConsentState> {
return await XMTPModule.groupConsentState(clientAddress, groupId)
}

export async function isAllowed(
clientAddress: string,
address: string
Expand Down
7 changes: 6 additions & 1 deletion src/lib/Group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ export class Group<
peerAddresses: string[]
adminAddress: string
permissionLevel: 'everyone_admin' | 'creator_admin'
topic: string
}
) {
this.client = client
this.id = params.id
this.createdAt = params.createdAt
this.peerAddresses = params.peerAddresses
this.topic = params.id
this.topic = params.topic
this.adminAddress = params.adminAddress
this.permissionLevel = params.permissionLevel
}
Expand Down Expand Up @@ -225,4 +226,8 @@ export class Group<
throw e
}
}

async consentState(): Promise<'allowed' | 'denied' | 'unknown'> {
return await XMTP.groupConsentState(this.clientAddress, this.id)
}
}

0 comments on commit 81322d3

Please sign in to comment.