Skip to content

Commit

Permalink
adds content type filter libxmtp update
Browse files Browse the repository at this point in the history
  • Loading branch information
cameronvoell committed Dec 21, 2024
1 parent 93b808b commit 5f3236c
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 7 deletions.
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: 7d863bde
Version: a9111a13
Branch: main
Date: 2024-12-20 22:46:38 +0000
Date: 2024-12-21 00:25:32 +0000
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ data class Conversations(
null,
1,
null,
FfiDirection.DESCENDING
FfiDirection.DESCENDING,
null
)
)
.firstOrNull()
Expand Down
5 changes: 4 additions & 1 deletion library/src/main/java/org/xmtp/android/library/Dm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import org.xmtp.android.library.libxmtp.Message
import org.xmtp.android.library.libxmtp.Message.MessageDeliveryStatus
import org.xmtp.android.library.libxmtp.Message.SortDirection
import org.xmtp.android.library.messages.Topic
import uniffi.xmtpv3.FfiContentType
import uniffi.xmtpv3.FfiConversation
import uniffi.xmtpv3.FfiConversationMetadata
import uniffi.xmtpv3.FfiDeliveryStatus
Expand Down Expand Up @@ -109,6 +110,7 @@ class Dm(val client: Client, private val libXMTPGroup: FfiConversation) {
afterNs: Long? = null,
direction: SortDirection = SortDirection.DESCENDING,
deliveryStatus: MessageDeliveryStatus = MessageDeliveryStatus.ALL,
contentTypes: List<FfiContentType>? = null
): List<DecodedMessage> {
return libXMTPGroup.findMessages(
opts = FfiListMessagesOptions(
Expand All @@ -124,7 +126,8 @@ class Dm(val client: Client, private val libXMTPGroup: FfiConversation) {
direction = when (direction) {
SortDirection.ASCENDING -> FfiDirection.ASCENDING
else -> FfiDirection.DESCENDING
}
},
contentTypes = contentTypes
)
).mapNotNull {
Message(client, it).decodeOrNull()
Expand Down
5 changes: 4 additions & 1 deletion library/src/main/java/org/xmtp/android/library/Group.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import org.xmtp.android.library.libxmtp.Message
import org.xmtp.android.library.libxmtp.Message.MessageDeliveryStatus
import org.xmtp.android.library.libxmtp.Message.SortDirection
import org.xmtp.android.library.messages.Topic
import uniffi.xmtpv3.FfiContentType
import uniffi.xmtpv3.FfiConversation
import uniffi.xmtpv3.FfiConversationMetadata
import uniffi.xmtpv3.FfiDeliveryStatus
Expand Down Expand Up @@ -126,6 +127,7 @@ class Group(val client: Client, private val libXMTPGroup: FfiConversation) {
afterNs: Long? = null,
direction: SortDirection = SortDirection.DESCENDING,
deliveryStatus: MessageDeliveryStatus = MessageDeliveryStatus.ALL,
contentTypes: List<FfiContentType>? = null
): List<DecodedMessage> {
return libXMTPGroup.findMessages(
opts = FfiListMessagesOptions(
Expand All @@ -141,7 +143,8 @@ class Group(val client: Client, private val libXMTPGroup: FfiConversation) {
direction = when (direction) {
SortDirection.ASCENDING -> FfiDirection.ASCENDING
else -> FfiDirection.DESCENDING
}
},
contentTypes = contentTypes
)
).mapNotNull {
Message(client, it).decodeOrNull()
Expand Down
101 changes: 99 additions & 2 deletions library/src/main/java/xmtpv3.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10430,6 +10430,7 @@ data class FfiListMessagesOptions(
var `limit`: kotlin.Long?,
var `deliveryStatus`: FfiDeliveryStatus?,
var `direction`: FfiDirection?,
var `contentTypes`: List<FfiContentType>?,
) {

companion object
Expand All @@ -10447,6 +10448,7 @@ public object FfiConverterTypeFfiListMessagesOptions :
FfiConverterOptionalLong.read(buf),
FfiConverterOptionalTypeFfiDeliveryStatus.read(buf),
FfiConverterOptionalTypeFfiDirection.read(buf),
FfiConverterOptionalSequenceTypeFfiContentType.read(buf),
)
}

Expand All @@ -10455,7 +10457,8 @@ public object FfiConverterTypeFfiListMessagesOptions :
FfiConverterOptionalLong.allocationSize(value.`sentAfterNs`) +
FfiConverterOptionalLong.allocationSize(value.`limit`) +
FfiConverterOptionalTypeFfiDeliveryStatus.allocationSize(value.`deliveryStatus`) +
FfiConverterOptionalTypeFfiDirection.allocationSize(value.`direction`)
FfiConverterOptionalTypeFfiDirection.allocationSize(value.`direction`) +
FfiConverterOptionalSequenceTypeFfiContentType.allocationSize(value.`contentTypes`)
)

override fun write(value: FfiListMessagesOptions, buf: ByteBuffer) {
Expand All @@ -10464,6 +10467,7 @@ public object FfiConverterTypeFfiListMessagesOptions :
FfiConverterOptionalLong.write(value.`limit`, buf)
FfiConverterOptionalTypeFfiDeliveryStatus.write(value.`deliveryStatus`, buf)
FfiConverterOptionalTypeFfiDirection.write(value.`direction`, buf)
FfiConverterOptionalSequenceTypeFfiContentType.write(value.`contentTypes`, buf)
}
}

Expand Down Expand Up @@ -10847,6 +10851,41 @@ public object FfiConverterTypeFfiConsentState : FfiConverterRustBuffer<FfiConsen
}


enum class FfiContentType {

UNKNOWN,
TEXT,
GROUP_MEMBERSHIP_CHANGE,
GROUP_UPDATED,
REACTION,
READ_RECEIPT,
REPLY,
ATTACHMENT,
REMOTE_ATTACHMENT,
TRANSACTION_REFERENCE;

companion object
}


/**
* @suppress
*/
public object FfiConverterTypeFfiContentType : FfiConverterRustBuffer<FfiContentType> {
override fun read(buf: ByteBuffer) = try {
FfiContentType.values()[buf.getInt() - 1]
} catch (e: IndexOutOfBoundsException) {
throw RuntimeException("invalid enum value, something is very wrong!!", e)
}

override fun allocationSize(value: FfiContentType) = 4UL

override fun write(value: FfiContentType, buf: ByteBuffer) {
buf.putInt(value.ordinal + 1)
}
}


enum class FfiConversationMessageKind {

APPLICATION,
Expand Down Expand Up @@ -11965,6 +12004,37 @@ public object FfiConverterOptionalTypeFfiMetadataField : FfiConverterRustBuffer<
}


/**
* @suppress
*/
public object FfiConverterOptionalSequenceTypeFfiContentType :
FfiConverterRustBuffer<List<FfiContentType>?> {
override fun read(buf: ByteBuffer): List<FfiContentType>? {
if (buf.get().toInt() == 0) {
return null
}
return FfiConverterSequenceTypeFfiContentType.read(buf)
}

override fun allocationSize(value: List<FfiContentType>?): ULong {
if (value == null) {
return 1UL
} else {
return 1UL + FfiConverterSequenceTypeFfiContentType.allocationSize(value)
}
}

override fun write(value: List<FfiContentType>?, buf: ByteBuffer) {
if (value == null) {
buf.put(0)
} else {
buf.put(1)
FfiConverterSequenceTypeFfiContentType.write(value, buf)
}
}
}


/**
* @suppress
*/
Expand Down Expand Up @@ -12311,6 +12381,33 @@ public object FfiConverterSequenceTypeFfiV2QueryResponse :
}


/**
* @suppress
*/
public object FfiConverterSequenceTypeFfiContentType :
FfiConverterRustBuffer<List<FfiContentType>> {
override fun read(buf: ByteBuffer): List<FfiContentType> {
val len = buf.getInt()
return List<FfiContentType>(len) {
FfiConverterTypeFfiContentType.read(buf)
}
}

override fun allocationSize(value: List<FfiContentType>): ULong {
val sizeForLength = 4UL
val sizeForItems = value.map { FfiConverterTypeFfiContentType.allocationSize(it) }.sum()
return sizeForLength + sizeForItems
}

override fun write(value: List<FfiContentType>, buf: ByteBuffer) {
buf.putInt(value.size)
value.iterator().forEach {
FfiConverterTypeFfiContentType.write(it, buf)
}
}
}


/**
* @suppress
*/
Expand Down Expand Up @@ -12369,7 +12466,7 @@ public object FfiConverterMapStringBoolean :
// The parens on `(k, v)` here ensure we're calling the right method,
// which is important for compatibility with older android devices.
// Ref https://blog.danlew.net/2017/03/16/kotlin-puzzler-whose-line-is-it-anyways/
value.iterator().forEach { (k, v) ->
value.forEach { (k, v) ->
FfiConverterString.write(k, buf)
FfiConverterBoolean.write(v, buf)
}
Expand Down
Binary file modified library/src/main/jniLibs/arm64-v8a/libuniffi_xmtpv3.so
Binary file not shown.
Binary file modified library/src/main/jniLibs/armeabi-v7a/libuniffi_xmtpv3.so
Binary file not shown.
Binary file modified library/src/main/jniLibs/x86/libuniffi_xmtpv3.so
Binary file not shown.
Binary file modified library/src/main/jniLibs/x86_64/libuniffi_xmtpv3.so
Binary file not shown.

0 comments on commit 5f3236c

Please sign in to comment.