Skip to content

Commit

Permalink
Merge pull request #366 from xmtp/em/beta/who-added-me
Browse files Browse the repository at this point in the history
Who Added Me Feature Implementation
  • Loading branch information
zombieobject authored Apr 18, 2024
2 parents 1918078 + 4ec9fe9 commit 716c0ac
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,15 @@ class XMTPModule : Module() {
}
}

AsyncFunction("addedByAddress") Coroutine { clientAddress: String, id: String ->
withContext(Dispatchers.IO) {
logV("addedByAddress")
val group = findGroup(clientAddress, id) ?: throw XMTPException("No group found")

group.addedByAddress()
}
}

AsyncFunction("isGroupAdmin") Coroutine { clientAddress: String, id: String ->
withContext(Dispatchers.IO) {
logV("isGroupAdmin")
Expand Down
16 changes: 16 additions & 0 deletions example/src/tests/groupTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 9 additions & 1 deletion ios/XMTPModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,15 @@ public class XMTPModule: Module {

return try group.isActive()
}


AsyncFunction("addedByAddress") { (clientAddress: String, id: String) -> String in
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
Expand Down
7 changes: 7 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,13 @@ export async function isGroupActive(
return XMTPModule.isGroupActive(clientAddress, id)
}

export async function addedByAddress(
clientAddress: string,
id: string
): Promise<string> {
return XMTPModule.addedByAddress(clientAddress, id)
}

export async function isGroupAdmin(
clientAddress: string,
id: string
Expand Down
4 changes: 4 additions & 0 deletions src/lib/Group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ export class Group<
return XMTP.isGroupActive(this.client.address, this.id)
}

addedByAddress(): Promise<string> {
return XMTP.addedByAddress(this.client.address, this.id)
}

async isAdmin(): Promise<boolean> {
return XMTP.isGroupAdmin(this.client.address, this.id)
}
Expand Down

0 comments on commit 716c0ac

Please sign in to comment.