Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import expo.modules.xmtpreactnativesdk.wrappers.DisappearingMessageSettingsWrapp
import expo.modules.xmtpreactnativesdk.wrappers.DmWrapper
import expo.modules.xmtpreactnativesdk.wrappers.EncryptedLocalAttachment
import expo.modules.xmtpreactnativesdk.wrappers.EnrichedMessageQueryParamsWrapper
import expo.modules.xmtpreactnativesdk.wrappers.GroupSyncSummaryWrapper
import expo.modules.xmtpreactnativesdk.wrappers.GroupWrapper
import expo.modules.xmtpreactnativesdk.wrappers.InboxStateWrapper
import expo.modules.xmtpreactnativesdk.wrappers.KeyPackageStatusWrapper
Expand Down Expand Up @@ -72,6 +73,7 @@ import org.xmtp.android.library.hexToByteArray
import org.xmtp.android.library.libxmtp.ArchiveElement
import org.xmtp.android.library.libxmtp.ArchiveOptions
import org.xmtp.android.library.libxmtp.DecodedMessage
import uniffi.xmtpv3.FfiContentType
import org.xmtp.android.library.libxmtp.DisappearingMessageSettings
import org.xmtp.android.library.libxmtp.GroupPermissionPreconfiguration
import org.xmtp.android.library.libxmtp.PermissionOption
Expand Down Expand Up @@ -1023,7 +1025,12 @@ class XMTPModule : Module() {
afterNs = queryParams.afterNs,
direction = DecodedMessage.SortDirection.valueOf(
queryParams.direction ?: "DESCENDING"
)
),
excludedContentTypes = getExcludedContentTypes(queryParams.excludeContentTypes),
excludeSenderInboxIds = queryParams.excludeSenderInboxIds,
insertedAfterNs = queryParams.insertedAfterNs,
insertedBeforeNs = queryParams.insertedBeforeNs,
sortBy = getMessageSortBy(queryParams.sortBy)
)?.map { MessageWrapper.encode(it) }
}
}
Expand All @@ -1040,7 +1047,12 @@ class XMTPModule : Module() {
afterNs = queryParams.afterNs,
direction = DecodedMessage.SortDirection.valueOf(
queryParams.direction ?: "DESCENDING"
)
),
excludedContentTypes = getExcludedContentTypes(queryParams.excludeContentTypes),
excludeSenderInboxIds = queryParams.excludeSenderInboxIds,
insertedAfterNs = queryParams.insertedAfterNs,
insertedBeforeNs = queryParams.insertedBeforeNs,
sortBy = getMessageSortBy(queryParams.sortBy)
)?.map { MessageWrapper.encode(it) }
}
}
Expand Down Expand Up @@ -1437,9 +1449,8 @@ class XMTPModule : Module() {
logV("syncAllConversations")
val client = clients[installationId] ?: throw XMTPException("No client")
val consentStates = consentStringStates?.let { ConsentWrapper.getConsentStates(it) }
val numGroupsSyncedInt: Int =
client.conversations.syncAllConversations(consentStates).numSynced.toInt()
numGroupsSyncedInt
val summary = client.conversations.syncAllConversations(consentStates)
GroupSyncSummaryWrapper.encode(summary)
}
}

Expand Down Expand Up @@ -1557,6 +1568,26 @@ class XMTPModule : Module() {
}
}

AsyncFunction("groupAppData") Coroutine { installationId: String, groupId: String ->
withContext(Dispatchers.IO) {
logV("groupAppData")
val client = clients[installationId] ?: throw XMTPException("No client")
val group = client.conversations.findGroup(groupId)
?: throw XMTPException("no group found for $groupId")
group.appData()
}
}

AsyncFunction("updateGroupAppData") Coroutine { installationId: String, groupId: String, appData: String ->
withContext(Dispatchers.IO) {
logV("updateGroupAppData")
val client = clients[installationId] ?: throw XMTPException("No client")
val group = client.conversations.findGroup(groupId)
?: throw XMTPException("no group found for $groupId")
group.updateAppData(appData)
}
}

AsyncFunction("disappearingMessageSettings") Coroutine { installationId: String, conversationId: String ->
withContext(Dispatchers.IO) {
logV("disappearingMessageSettings")
Expand Down Expand Up @@ -2111,15 +2142,15 @@ class XMTPModule : Module() {
}
}

AsyncFunction("createArchive") Coroutine { installationId: String, path: String, encryptionKey: List<Int>, startNs: Int?, endNs: Int?, archiveElements: List<String>? ->
AsyncFunction("createArchive") Coroutine { installationId: String, path: String, encryptionKey: List<Int>, startNs: Int?, endNs: Int?, archiveElements: List<String>?, excludeDisappearingMessages: Boolean? ->
withContext(Dispatchers.IO) {
val client = clients[installationId] ?: throw XMTPException("No client")
val encryptionKeyBytes =
encryptionKey.foldIndexed(ByteArray(encryptionKey.size)) { i, a, v ->
a.apply { set(i, v.toByte()) }
}
val elements = archiveElements?.map { getArchiveElement(it) } ?: listOf(ArchiveElement.MESSAGES, ArchiveElement.CONSENT)
val archiveOptions = ArchiveOptions(startNs?.toLong(), endNs?.toLong(), elements)
val archiveOptions = ArchiveOptions(startNs?.toLong(), endNs?.toLong(), elements, excludeDisappearingMessages ?: false)
client.createArchive(path, encryptionKeyBytes, archiveOptions)
}
}
Expand Down Expand Up @@ -2459,6 +2490,48 @@ class XMTPModule : Module() {
}
}

private fun getMessageSortBy(sortBy: String?): DecodedMessage.SortBy {
return when (sortBy) {
"INSERTED_TIME" -> DecodedMessage.SortBy.INSERTED_TIME
else -> DecodedMessage.SortBy.SENT_TIME
}
}

/**
* Converts content type ID strings (e.g. "xmtp.org/text:1.0") to [List][FfiContentType] for the SDK.
* Unrecognized or custom content types are skipped.
*/
private fun getExcludedContentTypes(strings: List<String>?): List<FfiContentType>? {
if (strings.isNullOrEmpty()) return null
val mapped = strings.mapNotNull { contentTypeIdString ->
val typeId = if (contentTypeIdString.contains(":")) {
contentTypeIdString.substringBefore(":").substringAfterLast("/")
} else {
contentTypeIdString
}
when (typeId.lowercase()) {
"text" -> FfiContentType.TEXT
"group_updated" -> FfiContentType.GROUP_UPDATED
"group_membership_change" -> FfiContentType.GROUP_MEMBERSHIP_CHANGE
"reaction" -> FfiContentType.REACTION
"read_receipt" -> FfiContentType.READ_RECEIPT
"reply" -> FfiContentType.REPLY
"attachment" -> FfiContentType.ATTACHMENT
"remote_attachment" -> FfiContentType.REMOTE_ATTACHMENT
"multi_remote_attachment" -> FfiContentType.MULTI_REMOTE_ATTACHMENT
"leave_request" -> FfiContentType.LEAVE_REQUEST
"delete_message" -> FfiContentType.UNKNOWN
"markdown" -> FfiContentType.MARKDOWN
"actions" -> FfiContentType.ACTIONS
"intent" -> FfiContentType.INTENT
"transaction_reference" -> FfiContentType.TRANSACTION_REFERENCE
"wallet_send_calls" -> FfiContentType.WALLET_SEND_CALLS
else -> null
}
}
return mapped.ifEmpty { null }
}

private val preAuthenticateToInboxCallback: suspend () -> Unit = {
sendEvent("preAuthenticateToInboxCallback")
preAuthenticateToInboxCallbackDeferred?.await()
Expand Down
Loading
Loading