Skip to content

Commit

Permalink
push notification methods
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Oct 22, 2024
1 parent e98f118 commit 27a2fc6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
18 changes: 14 additions & 4 deletions library/src/main/java/org/xmtp/android/library/Conversations.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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(
Expand All @@ -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
Expand Down Expand Up @@ -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<SealedInvitation> {
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)
Expand All @@ -966,7 +976,7 @@ data class Conversations(
}

private suspend fun listIntroductionPeers(pagination: Pagination? = null): Map<String, Date> {
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),
Expand Down

0 comments on commit 27a2fc6

Please sign in to comment.