Skip to content

Commit

Permalink
Merge pull request #397 from xmtp/cv/permissions-admin-super-admin-lists
Browse files Browse the repository at this point in the history
Permissions admin and super admin lists
  • Loading branch information
cameronvoell authored May 30, 2024
2 parents 4ec2a7b + e96160f commit dc6690e
Show file tree
Hide file tree
Showing 9 changed files with 615 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -901,13 +901,93 @@ class XMTPModule : Module() {
}
}

AsyncFunction("isGroupAdmin") Coroutine { clientAddress: String, id: String ->
AsyncFunction("creatorInboxId") Coroutine { clientAddress: String, id: String ->
withContext(Dispatchers.IO) {
logV("creatorInboxId")
val client = clients[clientAddress] ?: throw XMTPException("No client")
val group = findGroup(clientAddress, id)

group?.creatorInboxId()
}
}

AsyncFunction("isAdmin") Coroutine { clientAddress: String, id: String, inboxId: String ->
withContext(Dispatchers.IO) {
logV("isGroupAdmin")
val client = clients[clientAddress] ?: throw XMTPException("No client")
val group = findGroup(clientAddress, id)

group?.isAdmin(client.inboxId)
group?.isAdmin(inboxId)
}
}

AsyncFunction("isSuperAdmin") Coroutine { clientAddress: String, id: String, inboxId: String ->
withContext(Dispatchers.IO) {
logV("isSuperAdmin")
val client = clients[clientAddress] ?: throw XMTPException("No client")
val group = findGroup(clientAddress, id)

group?.isSuperAdmin(inboxId)
}
}

AsyncFunction("listAdmins") Coroutine { clientAddress: String, id: String ->
withContext(Dispatchers.IO) {
logV("listAdmins")
val client = clients[clientAddress] ?: throw XMTPException("No client")
val group = findGroup(clientAddress, id)

group?.listAdmins()
}
}

AsyncFunction("listSuperAdmins") Coroutine { clientAddress: String, id: String ->
withContext(Dispatchers.IO) {
logV("listSuperAdmins")
val client = clients[clientAddress] ?: throw XMTPException("No client")
val group = findGroup(clientAddress, id)

group?.listSuperAdmins()
}
}

AsyncFunction("addAdmin") Coroutine { clientAddress: String, id: String, inboxId: String ->
withContext(Dispatchers.IO) {
logV("addAdmin")
val client = clients[clientAddress] ?: throw XMTPException("No client")
val group = findGroup(clientAddress, id)

group?.addAdmin(inboxId)
}
}

AsyncFunction("addSuperAdmin") Coroutine { clientAddress: String, id: String, inboxId: String ->
withContext(Dispatchers.IO) {
logV("addSuperAdmin")
val client = clients[clientAddress] ?: throw XMTPException("No client")
val group = findGroup(clientAddress, id)

group?.addSuperAdmin(inboxId)
}
}

AsyncFunction("removeAdmin") Coroutine { clientAddress: String, id: String, inboxId: String ->
withContext(Dispatchers.IO) {
logV("removeAdmin")
val client = clients[clientAddress] ?: throw XMTPException("No client")
val group = findGroup(clientAddress, id)

group?.removeAdmin(inboxId)
}
}

AsyncFunction("removeSuperAdmin") Coroutine { clientAddress: String, id: String, inboxId: String ->
withContext(Dispatchers.IO) {
logV("removeSuperAdmin")
val client = clients[clientAddress] ?: throw XMTPException("No client")
val group = findGroup(clientAddress, id)

group?.removeSuperAdmin(inboxId)
}
}

Expand Down
2 changes: 1 addition & 1 deletion example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -769,4 +769,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 95d6ace79946933ecf80684613842ee553dd76a2

COCOAPODS: 1.14.2
COCOAPODS: 1.15.2
7 changes: 7 additions & 0 deletions example/src/TestScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React, { useEffect, useState } from 'react'
import { View, Text, Button, ScrollView } from 'react-native'

import { createdAtTests } from './tests/createdAtTests'
import { groupPermissionsTests } from './tests/groupPermissionsTests'
import { groupTests } from './tests/groupTests'
import { restartStreamTests } from './tests/restartStreamsTests'
import { Test } from './tests/test-utils'
Expand Down Expand Up @@ -108,6 +109,7 @@ export enum TestCategory {
group = 'group',
createdAt = 'createdAt',
restartStreans = 'restartStreams',
groupPermissions = 'groupPermissions',
}

export default function TestScreen(): JSX.Element {
Expand All @@ -121,6 +123,7 @@ export default function TestScreen(): JSX.Element {
...groupTests,
...createdAtTests,
...restartStreamTests,
...groupPermissionsTests,
]
let activeTests, title
switch (params.testSelection) {
Expand All @@ -144,6 +147,10 @@ export default function TestScreen(): JSX.Element {
activeTests = restartStreamTests
title = 'Restart Streams Unit Tests'
break
case TestCategory.groupPermissions:
activeTests = groupPermissionsTests
title = 'Group Permissions Unit Tests'
break
}

return (
Expand Down
Loading

0 comments on commit dc6690e

Please sign in to comment.