Skip to content

Commit

Permalink
Adding pinned frame metadata field (#269)
Browse files Browse the repository at this point in the history
* added new pinned frame metadata field

* update field name to pinned frame url

* updated bindings from latest libxmtp main

---------

Co-authored-by: cameronvoell <[email protected]>
  • Loading branch information
cameronvoell and cameronvoell authored Jul 3, 2024
1 parent 2d1bbac commit 0429b97
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ class GroupPermissionsTest {

// Verify that alix can NOT update group name
assert(boGroup.name == "")
val exception = assertThrows(uniffi.xmtpv3.GenericException.GroupException::class.java) {
val exception = assertThrows(XMTPException::class.java) {
runBlocking {
alixGroup.updateGroupName("Alix group name")
}
}
assertEquals(exception.message, "Group error: generic: Group intent could not be committed")
assertEquals(exception.message, "Permission denied: Unable to update group name")
runBlocking {
alixGroup.sync()
boGroup.sync()
Expand Down Expand Up @@ -161,12 +161,12 @@ class GroupPermissionsTest {
assert(superAdminList.size == 1)

// Verify that alix can NOT update group name
val exception2 = assertThrows(uniffi.xmtpv3.GenericException.GroupException::class.java) {
val exception2 = assertThrows(XMTPException::class.java) {
runBlocking {
alixGroup.updateGroupName("Alix group name 2")
}
}
assertEquals(exception.message, "Group error: generic: Group intent could not be committed")
assertEquals(exception.message, "Permission denied: Unable to update group name")
}

@Test
Expand Down Expand Up @@ -327,4 +327,42 @@ class GroupPermissionsTest {
assert(boGroup.description == "Alix group description")
assert(alixGroup.description == "Alix group description")
}

@Test
fun testCanUpdatePinnedFrameUrl() {
val boGroup = runBlocking { boClient.conversations.newGroup(listOf(alix.walletAddress, caro.walletAddress), GroupPermissionPreconfiguration.ADMIN_ONLY) }
runBlocking { alixClient.conversations.syncGroups() }
val alixGroup = runBlocking { alixClient.conversations.listGroups().first() }

// Verify that alix can NOT update pinned frame
assert(boGroup.pinnedFrameUrl == "")
val exception = assertThrows(XMTPException::class.java) {
runBlocking {
alixGroup.updateGroupPinnedFrameUrl("new pinned frame url")
}
}
assertEquals(exception.message, "Permission denied: Unable to update pinned frame")
runBlocking {
alixGroup.sync()
boGroup.sync()
}
assertEquals(boGroup.permissionPolicySet().updateGroupPinnedFrameUrlPolicy, PermissionOption.Admin)

// Update group name permissions so Alix can update
runBlocking {
boGroup.updateGroupPinnedFrameUrlPermission(PermissionOption.Allow)
boGroup.sync()
alixGroup.sync()
}
assertEquals(boGroup.permissionPolicySet().updateGroupPinnedFrameUrlPolicy, PermissionOption.Allow)

// Verify that alix can now update group name
runBlocking {
alixGroup.updateGroupPinnedFrameUrl("new pinned frame url 2")
alixGroup.sync()
boGroup.sync()
}
assert(boGroup.pinnedFrameUrl == "new pinned frame url 2")
assert(alixGroup.pinnedFrameUrl == "new pinned frame url 2")
}
}
4 changes: 2 additions & 2 deletions library/src/main/java/libxmtp-version.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Version: e4cfade7
Version: 5c78fbad
Branch: main
Date: 2024-07-01 19:23:57 +0000
Date: 2024-07-03 01:23:38 +0000
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ data class Conversations(
groupName: String = "",
groupImageUrlSquare: String = "",
groupDescription: String = "",
groupPinnedFrameUrl: String = ""
): Group {
if (accountAddresses.size == 1 &&
accountAddresses.first().lowercase() == client.address.lowercase()
Expand All @@ -133,7 +134,8 @@ data class Conversations(
permissions = GroupPermissionPreconfiguration.toFfiGroupPermissionOptions(permissions),
groupName = groupName,
groupImageUrlSquare = groupImageUrlSquare,
groupDescription = groupDescription
groupDescription = groupDescription,
groupPinnedFrameUrl = groupPinnedFrameUrl
)
) ?: throw XMTPException("Client does not support Groups")
client.contacts.allowGroups(groupIds = listOf(group.id()))
Expand Down
15 changes: 15 additions & 0 deletions library/src/main/java/org/xmtp/android/library/Group.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ class Group(val client: Client, private val libXMTPGroup: FfiGroup) {
val description: String
get() = libXMTPGroup.groupDescription()

val pinnedFrameUrl: String
get() = libXMTPGroup.groupPinnedFrameUrl()

suspend fun send(text: String): String {
return send(prepareMessage(content = text, options = null))
}
Expand Down Expand Up @@ -249,6 +252,14 @@ class Group(val client: Client, private val libXMTPGroup: FfiGroup) {
}
}

suspend fun updateGroupPinnedFrameUrl(pinnedFrameUrl: String) {
try {
return libXMTPGroup.updateGroupPinnedFrameUrl(pinnedFrameUrl)
} catch (e: Exception) {
throw XMTPException("Permission denied: Unable to update pinned frame", e)
}
}

suspend fun updateAddMemberPermission(newPermissionOption: PermissionOption) {
return libXMTPGroup.updatePermissionPolicy(FfiPermissionUpdateType.ADD_MEMBER, PermissionOption.toFfiPermissionPolicy(newPermissionOption), null)
}
Expand Down Expand Up @@ -277,6 +288,10 @@ class Group(val client: Client, private val libXMTPGroup: FfiGroup) {
return libXMTPGroup.updatePermissionPolicy(FfiPermissionUpdateType.UPDATE_METADATA, PermissionOption.toFfiPermissionPolicy(newPermissionOption), FfiMetadataField.IMAGE_URL_SQUARE)
}

suspend fun updateGroupPinnedFrameUrlPermission(newPermissionOption: PermissionOption) {
return libXMTPGroup.updatePermissionPolicy(FfiPermissionUpdateType.UPDATE_METADATA, PermissionOption.toFfiPermissionPolicy(newPermissionOption), FfiMetadataField.PINNED_FRAME_URL)
}

fun isAdmin(inboxId: String): Boolean {
return libXMTPGroup.isAdmin(inboxId)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,6 @@ class PermissionPolicySet(private val ffiPermissionPolicySet: FfiPermissionPolic
get() = PermissionOption.fromFfiPermissionPolicy(ffiPermissionPolicySet.updateGroupDescriptionPolicy)
val updateGroupImagePolicy: PermissionOption
get() = PermissionOption.fromFfiPermissionPolicy(ffiPermissionPolicySet.updateGroupImageUrlSquarePolicy)
val updateGroupPinnedFrameUrlPolicy: PermissionOption
get() = PermissionOption.fromFfiPermissionPolicy(ffiPermissionPolicySet.updateGroupPinnedFrameUrlPolicy)
}
Loading

0 comments on commit 0429b97

Please sign in to comment.