From 27a2fc66382196fb39f66a0533eba71bdaeb2eff Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Mon, 21 Oct 2024 17:49:15 -0700 Subject: [PATCH] push notification methods --- .../org/xmtp/android/library/Conversation.kt | 9 +++++++++ .../org/xmtp/android/library/Conversations.kt | 18 ++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) 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 1479e1a6c..e7406327b 100644 --- a/library/src/main/java/org/xmtp/android/library/Conversation.kt +++ b/library/src/main/java/org/xmtp/android/library/Conversation.kt @@ -274,6 +274,15 @@ sealed class Conversation { } } + suspend fun processMessage(envelopeBytes: ByteArray): MessageV3 { + return when (this) { + is V1 -> throw XMTPException("Only supported for V3") + is V2 -> throw XMTPException("Only supported for V3") + is Group -> group.processMessage(envelopeBytes) + is Dm -> dm.processMessage(envelopeBytes) + } + } + val consentProof: ConsentProofPayload? get() { return when (this) { diff --git a/library/src/main/java/org/xmtp/android/library/Conversations.kt b/library/src/main/java/org/xmtp/android/library/Conversations.kt index 3736bbe91..a50da5631 100644 --- a/library/src/main/java/org/xmtp/android/library/Conversations.kt +++ b/library/src/main/java/org/xmtp/android/library/Conversations.kt @@ -72,6 +72,16 @@ data class Conversations( LAST_MESSAGE; } + suspend fun conversationFromWelcome(envelopeBytes: ByteArray): Conversation { + val conversation = libXMTPConversations?.processStreamedWelcomeMessage(envelopeBytes) + ?: throw XMTPException("Client does not support Groups") + if (conversation.groupMetadata().conversationType() == "dm") { + return Conversation.Dm(Dm(client, conversation)) + } else { + return Conversation.Group(Group(client, conversation)) + } + } + suspend fun fromWelcome(envelopeBytes: ByteArray): Group { val group = libXMTPConversations?.processStreamedWelcomeMessage(envelopeBytes) ?: throw XMTPException("Client does not support Groups") @@ -758,7 +768,7 @@ data class Conversations( * @return [Conversation] from an invitation suing the current [Client]. */ fun fromInvite(envelope: Envelope): Conversation { - if (!client.hasV2Client) throw XMTPException("Not supported for V3. Use fromWelcome.") + if (!client.hasV2Client) throw XMTPException("Not supported for V3. Use conversationFromWelcome.") val sealedInvitation = Invitation.SealedInvitation.parseFrom(envelope.message) val unsealed = sealedInvitation.v1.getInvitation(viewer = client.keys) return Conversation.V2( @@ -777,7 +787,7 @@ data class Conversations( * @return [Conversation] from an Intro suing the current [Client]. */ fun fromIntro(envelope: Envelope): Conversation { - if (!client.hasV2Client) throw XMTPException("Not supported for V3. Use fromWelcome.") + if (!client.hasV2Client) throw XMTPException("Not supported for V3. Use conversationFromWelcome.") val messageV1 = MessageV1Builder.buildFromBytes(envelope.message.toByteArray()) val senderAddress = messageV1.header.sender.walletAddress val recipientAddress = messageV1.header.recipient.walletAddress @@ -956,7 +966,7 @@ data class Conversations( * @return List of [SealedInvitation] that are inside of the range specified by [pagination] */ private suspend fun listInvitations(pagination: Pagination? = null): List { - if (!client.hasV2Client) throw XMTPException("Not supported for V3. Use fromWelcome.") + if (!client.hasV2Client) throw XMTPException("Not supported for V3. Use conversationFromWelcome.") val apiClient = client.apiClient ?: throw XMTPException("V2 only function") val envelopes = apiClient.envelopes(Topic.userInvite(client.address).description, pagination) @@ -966,7 +976,7 @@ data class Conversations( } private suspend fun listIntroductionPeers(pagination: Pagination? = null): Map { - if (!client.hasV2Client) throw XMTPException("Not supported for V3. Use fromWelcome.") + if (!client.hasV2Client) throw XMTPException("Not supported for V3. Use conversationFromWelcome.") val apiClient = client.apiClient ?: throw XMTPException("V2 only function") val envelopes = apiClient.queryTopic( topic = Topic.userIntro(client.address),