From 2b0532c254236aa494acf9d7d2f60f05df30562a Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Wed, 25 Sep 2024 22:17:58 -0600 Subject: [PATCH] update the test and return a list of installations --- .../org/xmtp/android/library/GroupTest.kt | 44 +++++++++---------- .../org/xmtp/android/library/Conversation.kt | 4 +- .../android/library/libxmtp/InboxState.kt | 5 +-- .../android/library/libxmtp/Installation.kt | 14 ++++++ 4 files changed, 40 insertions(+), 27 deletions(-) create mode 100644 library/src/main/java/org/xmtp/android/library/libxmtp/Installation.kt diff --git a/library/src/androidTest/java/org/xmtp/android/library/GroupTest.kt b/library/src/androidTest/java/org/xmtp/android/library/GroupTest.kt index cdcec72cd..58b6c5423 100644 --- a/library/src/androidTest/java/org/xmtp/android/library/GroupTest.kt +++ b/library/src/androidTest/java/org/xmtp/android/library/GroupTest.kt @@ -84,8 +84,8 @@ class GroupTest { alixGroup.addMembers(listOf(caro.walletAddress)) boGroup.sync() } - assertEquals(alixGroup.members().size, 3) - assertEquals(boGroup.members().size, 3) + assertEquals(runBlocking { alixGroup.members().size }, 3) + assertEquals(runBlocking { boGroup.members().size }, 3) // All members also defaults remove to admin only now. assertThrows(XMTPException::class.java) { @@ -95,8 +95,8 @@ class GroupTest { } } - assertEquals(alixGroup.members().size, 3) - assertEquals(boGroup.members().size, 3) + assertEquals(runBlocking { alixGroup.members().size }, 3) + assertEquals(runBlocking { boGroup.members().size }, 3) assertEquals(boGroup.permissionPolicySet().addMemberPolicy, PermissionOption.Allow) assertEquals(alixGroup.permissionPolicySet().addMemberPolicy, PermissionOption.Allow) @@ -135,31 +135,31 @@ class GroupTest { alixGroup.sync() } - assertEquals(alixGroup.members().size, 3) - assertEquals(boGroup.members().size, 3) + assertEquals(runBlocking { alixGroup.members().size }, 3) + assertEquals(runBlocking { boGroup.members().size }, 3) assertThrows(XMTPException::class.java) { runBlocking { alixGroup.removeMembers(listOf(caro.walletAddress)) } } runBlocking { boGroup.sync() } - assertEquals(alixGroup.members().size, 3) - assertEquals(boGroup.members().size, 3) + assertEquals(runBlocking { alixGroup.members().size }, 3) + assertEquals(runBlocking { boGroup.members().size }, 3) runBlocking { boGroup.removeMembers(listOf(caro.walletAddress)) alixGroup.sync() } - assertEquals(alixGroup.members().size, 2) - assertEquals(boGroup.members().size, 2) + assertEquals(runBlocking { alixGroup.members().size }, 2) + assertEquals(runBlocking { boGroup.members().size }, 2) assertThrows(XMTPException::class.java) { runBlocking { alixGroup.addMembers(listOf(caro.walletAddress)) } } runBlocking { boGroup.sync() } - assertEquals(alixGroup.members().size, 2) - assertEquals(boGroup.members().size, 2) + assertEquals(runBlocking { alixGroup.members().size }, 2) + assertEquals(runBlocking { boGroup.members().size }, 2) assertEquals(boGroup.permissionPolicySet().addMemberPolicy, PermissionOption.Admin) assertEquals(alixGroup.permissionPolicySet().addMemberPolicy, PermissionOption.Admin) @@ -183,7 +183,7 @@ class GroupTest { ) } assertEquals( - group.members().map { it.inboxId }.sorted(), + runBlocking { group.members().map { it.inboxId }.sorted() }, listOf( caroClient.inboxId, alixClient.inboxId, @@ -200,7 +200,7 @@ class GroupTest { ) assertEquals( - group.peerInboxIds().sorted(), + runBlocking { group.peerInboxIds().sorted() }, listOf( caroClient.inboxId, alixClient.inboxId, @@ -238,7 +238,7 @@ class GroupTest { val group = runBlocking { boClient.conversations.newGroup(listOf(alix.walletAddress)) } runBlocking { group.addMembers(listOf(caro.walletAddress)) } assertEquals( - group.members(boClient).map { it.inboxId }.sorted(), + runBlocking { group.members().map { it.inboxId }.sorted() }, listOf( caroClient.inboxId, alixClient.inboxId, @@ -259,7 +259,7 @@ class GroupTest { } runBlocking { group.removeMembers(listOf(caro.walletAddress)) } assertEquals( - group.members(boClient).map { it.inboxId }.sorted(), + runBlocking { group.members().map { it.inboxId }.sorted() }, listOf( alixClient.inboxId, boClient.inboxId @@ -291,7 +291,7 @@ class GroupTest { boGroup.sync() } assertEquals( - boGroup.members().map { it.inboxId }.sorted(), + runBlocking { boGroup.members().map { it.inboxId }.sorted() }, listOf( alixClient.inboxId, boClient.inboxId @@ -303,7 +303,7 @@ class GroupTest { val group = runBlocking { boClient.conversations.newGroup(listOf(alix.walletAddress)) } runBlocking { group.addMembersByInboxId(listOf(caroClient.inboxId)) } assertEquals( - group.members().map { it.inboxId }.sorted(), + runBlocking { group.members().map { it.inboxId }.sorted() }, listOf( caroClient.inboxId, alixClient.inboxId, @@ -324,7 +324,7 @@ class GroupTest { } runBlocking { group.removeMembersByInboxId(listOf(caroClient.inboxId)) } assertEquals( - group.members().map { it.inboxId }.sorted(), + runBlocking { group.members().map { it.inboxId }.sorted() }, listOf( alixClient.inboxId, boClient.inboxId @@ -808,21 +808,21 @@ class GroupTest { assert(!boClient.contacts.isInboxDenied(alixClient.inboxId)) boClient.contacts.allowInboxes(listOf(alixClient.inboxId)) - var alixMember = boGroup.members(boClient).firstOrNull { it.inboxId == alixClient.inboxId } + var alixMember = boGroup.members().firstOrNull { it.inboxId == alixClient.inboxId } assertEquals(alixMember!!.consentState, ConsentState.ALLOWED) assert(boClient.contacts.isInboxAllowed(alixClient.inboxId)) assert(!boClient.contacts.isInboxDenied(alixClient.inboxId)) boClient.contacts.denyInboxes(listOf(alixClient.inboxId)) - alixMember = boGroup.members(boClient).firstOrNull { it.inboxId == alixClient.inboxId } + alixMember = boGroup.members().firstOrNull { it.inboxId == alixClient.inboxId } assertEquals(alixMember!!.consentState, ConsentState.DENIED) assert(!boClient.contacts.isInboxAllowed(alixClient.inboxId)) assert(boClient.contacts.isInboxDenied(alixClient.inboxId)) boClient.contacts.allow(listOf(alixClient.address)) - alixMember = boGroup.members(boClient).firstOrNull { it.inboxId == alixClient.inboxId } + alixMember = boGroup.members().firstOrNull { it.inboxId == alixClient.inboxId } assertEquals(alixMember!!.consentState, ConsentState.ALLOWED) assert(boClient.contacts.isInboxAllowed(alixClient.inboxId)) assert(!boClient.contacts.isInboxDenied(alixClient.inboxId)) diff --git a/library/src/main/java/org/xmtp/android/library/Conversation.kt b/library/src/main/java/org/xmtp/android/library/Conversation.kt index d19cb4c1a..00294cc8e 100644 --- a/library/src/main/java/org/xmtp/android/library/Conversation.kt +++ b/library/src/main/java/org/xmtp/android/library/Conversation.kt @@ -61,11 +61,11 @@ sealed class Conversation { } } - suspend fun peerAddresses(): List { + fun peerAddresses(): List { return when (this) { is V1 -> listOf(conversationV1.peerAddress) is V2 -> listOf(conversationV2.peerAddress) - is Group -> group.peerInboxIds() + is Group -> runBlocking { group.peerInboxIds() } } } diff --git a/library/src/main/java/org/xmtp/android/library/libxmtp/InboxState.kt b/library/src/main/java/org/xmtp/android/library/libxmtp/InboxState.kt index efa97b756..376fe9f67 100644 --- a/library/src/main/java/org/xmtp/android/library/libxmtp/InboxState.kt +++ b/library/src/main/java/org/xmtp/android/library/libxmtp/InboxState.kt @@ -1,6 +1,5 @@ package uniffi.xmtpv3.org.xmtp.android.library.libxmtp -import org.xmtp.android.library.toHex import uniffi.xmtpv3.FfiInboxState class InboxState(private val ffiInboxState: FfiInboxState) { @@ -9,8 +8,8 @@ class InboxState(private val ffiInboxState: FfiInboxState) { val addresses: List get() = ffiInboxState.accountAddresses - val installationIds: List - get() = ffiInboxState.installationIds.map { it.toHex() } + val installations: List + get() = ffiInboxState.installations.map { Installation(it) } val recoveryAddress: String get() = ffiInboxState.recoveryAddress diff --git a/library/src/main/java/org/xmtp/android/library/libxmtp/Installation.kt b/library/src/main/java/org/xmtp/android/library/libxmtp/Installation.kt new file mode 100644 index 000000000..cd3814b43 --- /dev/null +++ b/library/src/main/java/org/xmtp/android/library/libxmtp/Installation.kt @@ -0,0 +1,14 @@ +package uniffi.xmtpv3.org.xmtp.android.library.libxmtp + +import org.xmtp.android.library.toHex +import uniffi.xmtpv3.FfiInstallation +import java.util.Date + +class Installation(private val ffiInstallation: FfiInstallation) { + val installationId: String + get() = ffiInstallation.id.toHex() + val createdAt: Date? + get() = ffiInstallation.clientTimestampNs?.let { + Date(it.toLong()) + } +} \ No newline at end of file