Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Legacy improvements for forks #327

Merged
merged 3 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Release XMTP Android Package
on:
push:
branches:
- release
- xmtp-legacy

jobs:
library:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class DmTest {
assertEquals(dm.messages().first().body, "gm")
assertEquals(dm.messages().first().id, messageId)
assertEquals(dm.messages().first().deliveryStatus, MessageDeliveryStatus.PUBLISHED)
assertEquals(dm.messages().size, 3)
assertEquals(dm.messages().size, 2)

runBlocking { alixClient.conversations.syncConversations() }
val sameDm = runBlocking { alixClient.conversations.listDms().last() }
Expand All @@ -181,12 +181,12 @@ class DmTest {
dm.send("gm")
}

assertEquals(dm.messages().size, 3)
assertEquals(dm.messages(deliveryStatus = MessageDeliveryStatus.PUBLISHED).size, 3)
assertEquals(dm.messages().size, 2)
assertEquals(dm.messages(deliveryStatus = MessageDeliveryStatus.PUBLISHED).size, 2)
runBlocking { dm.sync() }
assertEquals(dm.messages().size, 3)
assertEquals(dm.messages().size, 2)
assertEquals(dm.messages(deliveryStatus = MessageDeliveryStatus.UNPUBLISHED).size, 0)
assertEquals(dm.messages(deliveryStatus = MessageDeliveryStatus.PUBLISHED).size, 3)
assertEquals(dm.messages(deliveryStatus = MessageDeliveryStatus.PUBLISHED).size, 2)

runBlocking { alixClient.conversations.syncConversations() }
val sameDm = runBlocking { alixClient.conversations.listDms().last() }
Expand Down Expand Up @@ -219,7 +219,7 @@ class DmTest {
runBlocking { dm.sync() }

val messages = dm.messages()
assertEquals(messages.size, 3)
assertEquals(messages.size, 2)
val content: Reaction? = messages.first().content()
assertEquals("U+1F603", content?.content)
assertEquals(messageToReact.id, content?.reference)
Expand Down
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: 257063e9
Version: 29a955a1
Branch: main
Date: 2024-10-29 02:56:38 +0000
Date: 2024-11-14 22:21:21 +0000
44 changes: 21 additions & 23 deletions library/src/main/java/org/xmtp/android/library/Client.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import org.xmtp.android.library.messages.walletAddress
import org.xmtp.proto.message.api.v1.MessageApiOuterClass
import org.xmtp.proto.message.api.v1.MessageApiOuterClass.BatchQueryResponse
import org.xmtp.proto.message.api.v1.MessageApiOuterClass.QueryRequest
import uniffi.xmtpv3.FfiConversationType
import uniffi.xmtpv3.FfiDeviceSyncKind
import uniffi.xmtpv3.FfiV2SubscribeRequest
import uniffi.xmtpv3.FfiV2Subscription
import uniffi.xmtpv3.FfiV2SubscriptionCallback
Expand Down Expand Up @@ -110,10 +112,10 @@ class Client() {
logger = XMTPLogger(),
host = options.api.env.getUrl(),
isSecure = options.api.isSecure,
accountAddress = address
accountAddress = address.lowercase()
)
if (inboxId.isNullOrBlank()) {
inboxId = generateInboxId(address, 0.toULong())
inboxId = generateInboxId(address.lowercase(), 0.toULong())
}
return inboxId
}
Expand Down Expand Up @@ -188,7 +190,7 @@ class Client() {
installationId: String = "",
inboxId: String,
) : this() {
this.address = address
this.address = address.lowercase()
this.privateKeyBundleV1 = privateKeyBundleV1
this.apiClient = apiClient
this.contacts = Contacts(client = this)
Expand All @@ -210,7 +212,7 @@ class Client() {
inboxId: String,
environment: XMTPEnvironment,
) : this() {
this.address = address
this.address = address.lowercase()
this.contacts = Contacts(client = this)
this.v3Client = libXMTPClient
this.conversations =
Expand Down Expand Up @@ -261,14 +263,14 @@ class Client() {
apiClient,
clientOptions
)
val inboxId = getOrCreateInboxId(clientOptions, account.address)
val inboxId = getOrCreateInboxId(clientOptions, account.address.lowercase())
val (libXMTPClient, dbPath) =
ffiXmtpClient(
clientOptions,
account,
clientOptions.appContext,
privateKeyBundleV1,
account.address,
account.address.lowercase(),
inboxId
)

Expand All @@ -294,14 +296,14 @@ class Client() {
clientOptions: ClientOptions,
signingKey: SigningKey? = null,
): Client {
val inboxId = getOrCreateInboxId(clientOptions, accountAddress)
val inboxId = getOrCreateInboxId(clientOptions, accountAddress.lowercase())

val (libXMTPClient, dbPath) = ffiXmtpClient(
clientOptions,
signingKey,
clientOptions.appContext,
null,
accountAddress,
accountAddress.lowercase(),
inboxId
)

Expand Down Expand Up @@ -368,14 +370,14 @@ class Client() {
)
newOptions.api.appVersion?.let { v2Client.setAppVersion(it) }
val apiClient = GRPCApiClient(environment = newOptions.api.env, rustV2Client = v2Client)
val inboxId = getOrCreateInboxId(newOptions, address)
val inboxId = getOrCreateInboxId(newOptions, address.lowercase())
val (v3Client, dbPath) = if (isV3Enabled(options)) {
ffiXmtpClient(
newOptions,
account,
options?.appContext,
v1Bundle,
address,
address.lowercase(),
inboxId
)
} else Pair(null, "")
Expand Down Expand Up @@ -616,12 +618,10 @@ class Client() {
fun findConversation(conversationId: String): Conversation? {
val client = v3Client ?: throw XMTPException("Error no V3 client initialized")
val conversation = client.conversation(conversationId.hexToByteArray())
return if (conversation.groupMetadata().conversationType() == "dm") {
Conversation.Dm(Dm(this, conversation))
} else if (conversation.groupMetadata().conversationType() == "group") {
Conversation.Group(Group(this, conversation))
} else {
null
return when (conversation.conversationType()) {
FfiConversationType.GROUP -> Conversation.Group(Group(this, conversation))
FfiConversationType.DM -> Conversation.Dm(Dm(this, conversation))
else -> null
}
}

Expand All @@ -631,12 +631,10 @@ class Client() {
val matchResult = regex.find(topic)
val conversationId = matchResult?.groupValues?.get(1) ?: ""
val conversation = client.conversation(conversationId.hexToByteArray())
return if (conversation.groupMetadata().conversationType() == "dm") {
Conversation.Dm(Dm(this, conversation))
} else if (conversation.groupMetadata().conversationType() == "group") {
Conversation.Group(Group(this, conversation))
} else {
null
return when (conversation.conversationType()) {
FfiConversationType.GROUP -> Conversation.Group(Group(this, conversation))
FfiConversationType.DM -> Conversation.Dm(Dm(this, conversation))
else -> null
}
}

Expand Down Expand Up @@ -775,7 +773,7 @@ class Client() {
}

suspend fun requestMessageHistorySync() {
v3Client?.requestHistorySync() ?: throw XMTPException("Error no V3 client initialized")
v3Client?.sendSyncRequest(FfiDeviceSyncKind.MESSAGES) ?: throw XMTPException("Error no V3 client initialized")
}

suspend fun revokeAllOtherInstallations(signingKey: SigningKey) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import org.xmtp.android.library.messages.walletAddress
import org.xmtp.proto.message.api.v1.MessageApiOuterClass
import uniffi.xmtpv3.FfiEnvelope
import uniffi.xmtpv3.FfiV2SubscriptionCallback
import uniffi.xmtpv3.GenericException
import java.util.Date

data class ConversationV1(
Expand All @@ -49,6 +50,9 @@ data class ConversationV1(
override fun onMessage(message: FfiEnvelope) {
trySend(decode(envelope = envelopeFromFFi(message)))
}

override fun onError(error: GenericException) {
}
}
val stream = client.subscribe(listOf(topic.description), streamCallback)
awaitClose { launch { stream.end() } }
Expand Down Expand Up @@ -283,6 +287,9 @@ data class ConversationV1(
override fun onMessage(message: FfiEnvelope) {
trySend(envelopeFromFFi(message))
}

override fun onError(error: GenericException) {
}
}
val stream = client.subscribe(listOf(ephemeralTopic), streamCallback)
awaitClose { launch { stream.end() } }
Expand All @@ -293,6 +300,9 @@ data class ConversationV1(
override fun onMessage(message: FfiEnvelope) {
trySend(decrypt(envelope = envelopeFromFFi(message)))
}

override fun onError(error: GenericException) {
}
}
val stream = client.subscribe(listOf(topic.description), streamCallback)
awaitClose { launch { stream.end() } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import org.xmtp.proto.message.api.v1.MessageApiOuterClass
import org.xmtp.proto.message.contents.Invitation
import uniffi.xmtpv3.FfiEnvelope
import uniffi.xmtpv3.FfiV2SubscriptionCallback
import uniffi.xmtpv3.GenericException
import java.util.Date

data class ConversationV2(
Expand Down Expand Up @@ -149,6 +150,9 @@ data class ConversationV2(
trySend(it)
}
}

override fun onError(error: GenericException) {
}
}
val stream = client.subscribe(listOf(topic), streamCallback)
awaitClose { launch { stream.end() } }
Expand Down Expand Up @@ -284,6 +288,9 @@ data class ConversationV2(
override fun onMessage(message: FfiEnvelope) {
trySend(Util.envelopeFromFFi(message))
}

override fun onError(error: GenericException) {
}
}
val stream = client.subscribe(listOf(ephemeralTopic), streamCallback)
awaitClose { launch { stream.end() } }
Expand All @@ -294,6 +301,9 @@ data class ConversationV2(
override fun onMessage(message: FfiEnvelope) {
trySend(decrypt(envelope = Util.envelopeFromFFi(message)))
}

override fun onError(error: GenericException) {
}
}
val stream = client.subscribe(listOf(topic), streamCallback)
awaitClose { launch { stream.end() } }
Expand Down
26 changes: 20 additions & 6 deletions library/src/main/java/org/xmtp/android/library/Conversations.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import org.xmtp.proto.message.contents.Contact
import org.xmtp.proto.message.contents.Invitation
import uniffi.xmtpv3.FfiConversation
import uniffi.xmtpv3.FfiConversationCallback
import uniffi.xmtpv3.FfiConversationType
import uniffi.xmtpv3.FfiConversations
import uniffi.xmtpv3.FfiCreateGroupOptions
import uniffi.xmtpv3.FfiDirection
Expand All @@ -53,6 +54,7 @@ import uniffi.xmtpv3.FfiSubscribeException
import uniffi.xmtpv3.FfiV2SubscribeRequest
import uniffi.xmtpv3.FfiV2Subscription
import uniffi.xmtpv3.FfiV2SubscriptionCallback
import uniffi.xmtpv3.GenericException
import uniffi.xmtpv3.NoPointer
import uniffi.xmtpv3.org.xmtp.android.library.libxmtp.GroupPermissionPreconfiguration
import uniffi.xmtpv3.org.xmtp.android.library.libxmtp.PermissionPolicySet
Expand All @@ -78,7 +80,7 @@ data class Conversations(
suspend fun conversationFromWelcome(envelopeBytes: ByteArray): Conversation {
val conversation = libXMTPConversations?.processStreamedWelcomeMessage(envelopeBytes)
?: throw XMTPException("Client does not support Groups")
if (conversation.groupMetadata().conversationType() == "dm") {
if (conversation.conversationType() == FfiConversationType.DM) {
return Conversation.Dm(Dm(client, conversation))
} else {
return Conversation.Group(Group(client, conversation))
Expand Down Expand Up @@ -312,7 +314,8 @@ data class Conversations(
opts = FfiListConversationsOptions(
after?.time?.nanoseconds?.toLong(DurationUnit.NANOSECONDS),
before?.time?.nanoseconds?.toLong(DurationUnit.NANOSECONDS),
limit?.toLong()
limit?.toLong(),
null
)
) ?: throw XMTPException("Client does not support V3 dms")

Expand All @@ -331,7 +334,8 @@ data class Conversations(
opts = FfiListConversationsOptions(
after?.time?.nanoseconds?.toLong(DurationUnit.NANOSECONDS),
before?.time?.nanoseconds?.toLong(DurationUnit.NANOSECONDS),
limit?.toLong()
limit?.toLong(),
null
)
) ?: throw XMTPException("Client does not support V3 dms")

Expand All @@ -354,7 +358,8 @@ data class Conversations(
FfiListConversationsOptions(
after?.time?.nanoseconds?.toLong(DurationUnit.NANOSECONDS),
before?.time?.nanoseconds?.toLong(DurationUnit.NANOSECONDS),
limit?.toLong()
limit?.toLong(),
null
)
) ?: throw XMTPException("Client does not support V3 dms")

Expand Down Expand Up @@ -404,7 +409,7 @@ data class Conversations(
}

private fun FfiConversation.toConversation(): Conversation {
return if (groupMetadata().conversationType() == "dm") {
return if (conversationType() == FfiConversationType.DM) {
Conversation.Dm(Dm(client, this))
} else {
Conversation.Group(Group(client, this))
Expand Down Expand Up @@ -533,6 +538,9 @@ data class Conversations(
}
}
}

override fun onError(error: GenericException) {
}
}

val stream = client.subscribe2(
Expand All @@ -556,7 +564,7 @@ data class Conversations(
if (client.hasV2Client) throw XMTPException("Only supported for V3 only clients.")
val conversationCallback = object : FfiConversationCallback {
override fun onConversation(conversation: FfiConversation) {
if (conversation.groupMetadata().conversationType() == "dm") {
if (conversation.conversationType() == FfiConversationType.DM) {
trySend(Conversation.Dm(Dm(client, conversation)))
} else {
trySend(Conversation.Group(Group(client, conversation)))
Expand Down Expand Up @@ -963,6 +971,9 @@ data class Conversations(
else -> {}
}
}

override fun onError(error: GenericException) {
}
}

stream = client.subscribe2(subscriptionRequest, subscriptionCallback)
Expand Down Expand Up @@ -1013,6 +1024,9 @@ data class Conversations(
else -> {}
}
}

override fun onError(error: GenericException) {
}
}

stream = client.subscribe2(subscriptionRequest, subscriptionCallback)
Expand Down
Loading
Loading