Skip to content

Commit

Permalink
Merge pull request #507 from xmtp/np/merge-main-beta
Browse files Browse the repository at this point in the history
Merge main into beta
  • Loading branch information
nplasterer authored Oct 2, 2024
2 parents 54be3f3 + af4486b commit 6383b9c
Show file tree
Hide file tree
Showing 21 changed files with 522 additions and 207 deletions.
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ repositories {
dependencies {
implementation project(':expo-modules-core')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${getKotlinVersion()}"
implementation "org.xmtp:android:0.15.10"
implementation "org.xmtp:android:0.15.12"
implementation 'com.google.code.gson:gson:2.10.1'
implementation 'com.facebook.react:react-native:0.71.3'
implementation "com.daveanthonythomas.moshipack:moshipack:1.0.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import kotlinx.coroutines.withContext
import org.json.JSONObject
import org.xmtp.android.library.Client
import org.xmtp.android.library.ClientOptions
import org.xmtp.android.library.ConsentState
import org.xmtp.android.library.Conversation
import org.xmtp.android.library.Group
import org.xmtp.android.library.PreEventCallback
Expand Down Expand Up @@ -372,7 +373,7 @@ class XMTPModule : Module() {
}
}

AsyncFunction("createOrBuild") Coroutine { address: String, hasCreateIdentityCallback: Boolean?, hasEnableIdentityCallback: Boolean?, hasAuthInboxCallback: Boolean?, dbEncryptionKey: List<Int>?, authParams: String ->
AsyncFunction("createOrBuild") Coroutine { address: String, hasCreateIdentityCallback: Boolean?, hasEnableIdentityCallback: Boolean?, hasAuthInboxCallback: Boolean?, dbEncryptionKey: List<Int>?, authParams: String ->
withContext(Dispatchers.IO) {
logV("createOrBuild")
val reactSigner = ReactNativeSigner(module = this@XMTPModule, address = address)
Expand Down Expand Up @@ -1029,7 +1030,10 @@ class XMTPModule : Module() {
val client = clients[inboxId] ?: throw XMTPException("No client")
client.conversations.syncAllGroups()
// Expo Modules do not support UInt, so we need to convert to Int
val numGroupsSyncedInt: Int = client.conversations.syncAllGroups()?.toInt() ?: throw IllegalArgumentException("Value cannot be null")
val numGroupsSyncedInt: Int =
client.conversations.syncAllGroups()?.toInt() ?: throw IllegalArgumentException(
"Value cannot be null"
)
numGroupsSyncedInt
}
}
Expand Down Expand Up @@ -1610,7 +1614,7 @@ class XMTPModule : Module() {
withContext(Dispatchers.IO) {
val group = findGroup(inboxId, groupId)
?: throw XMTPException("no group found for $groupId")
consentStateToString(Conversation.Group(group).consentState())
consentStateToString(group.consentState())
}
}

Expand Down Expand Up @@ -1664,6 +1668,14 @@ class XMTPModule : Module() {
client.contacts.isGroupDenied(groupId)
}
}
AsyncFunction("updateGroupConsent") Coroutine { inboxId: String, groupId: String, state: String ->
withContext(Dispatchers.IO) {
logV("updateGroupConsent")
val group = findGroup(inboxId, groupId)

group?.updateConsentState(getConsentState(state))
}
}

AsyncFunction("exportNativeLogs") Coroutine { ->
withContext(Dispatchers.IO) {
Expand All @@ -1688,7 +1700,7 @@ class XMTPModule : Module() {
// Helpers
//

private suspend fun getPermissionOption(permissionString: String): PermissionOption {
private fun getPermissionOption(permissionString: String): PermissionOption {
return when (permissionString) {
"allow" -> PermissionOption.Allow
"deny" -> PermissionOption.Deny
Expand All @@ -1698,6 +1710,14 @@ class XMTPModule : Module() {
}
}

private fun getConsentState(stateString: String): ConsentState {
return when (stateString) {
"allowed" -> ConsentState.ALLOWED
"denied" -> ConsentState.DENIED
else -> ConsentState.UNKNOWN
}
}

private suspend fun findConversation(
inboxId: String,
topic: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import org.xmtp.android.library.Conversation
class ConversationContainerWrapper {

companion object {
fun encodeToObj(client: Client, conversation: Conversation): Map<String, Any?> {
suspend fun encodeToObj(client: Client, conversation: Conversation): Map<String, Any?> {
when (conversation.version) {
Conversation.Version.GROUP -> {
val group = (conversation as Conversation.Group).group
Expand All @@ -20,7 +20,7 @@ class ConversationContainerWrapper {
}
}

fun encode(client: Client, conversation: Conversation): String {
suspend fun encode(client: Client, conversation: Conversation): String {
val gson = GsonBuilder().create()
val obj = ConversationContainerWrapper.encodeToObj(client, conversation)
return gson.toJson(obj)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package expo.modules.xmtpreactnativesdk.wrappers

import com.google.gson.GsonBuilder
import expo.modules.xmtpreactnativesdk.wrappers.ConsentWrapper.Companion.consentStateToString
import org.xmtp.android.library.Client
import org.xmtp.android.library.Group
import org.xmtp.android.library.toHex

class GroupWrapper {

companion object {
fun encodeToObj(client: Client, group: Group): Map<String, Any> {
suspend fun encodeToObj(client: Client, group: Group): Map<String, Any> {
return mapOf(
"clientAddress" to client.address,
"id" to group.id,
Expand All @@ -21,12 +21,13 @@ class GroupWrapper {
"addedByInboxId" to group.addedByInboxId(),
"name" to group.name,
"imageUrlSquare" to group.imageUrlSquare,
"description" to group.description
"description" to group.description,
"consentState" to consentStateToString(group.consentState())
// "pinnedFrameUrl" to group.pinnedFrameUrl
)
}

fun encode(client: Client, group: Group): String {
suspend fun encode(client: Client, group: Group): String {
val gson = GsonBuilder().create()
val obj = encodeToObj(client, group)
return gson.toJson(obj)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
package expo.modules.xmtpreactnativesdk.wrappers

import com.google.gson.Gson
import com.google.gson.GsonBuilder
import uniffi.xmtpv3.org.xmtp.android.library.libxmtp.InboxState

class InboxStateWrapper {
companion object {
val gson: Gson = GsonBuilder().create()
fun encodeToObj(inboxState: InboxState): Map<String, Any> {
return mapOf(
"inboxId" to inboxState.inboxId,
"addresses" to inboxState.addresses,
"installationIds" to inboxState.installationIds,
"installations" to inboxState.installations.map {
gson.toJson(
mapOf(
"id" to it.installationId,
"createdAt" to it.createdAt?.time
)
)
},
"recoveryAddress" to inboxState.recoveryAddress
)
}

fun encode(inboxState: InboxState): String {
val gson = GsonBuilder().create()
val obj = encodeToObj(inboxState)
return gson.toJson(obj)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class MemberWrapper {
return mapOf(
"inboxId" to member.inboxId,
"addresses" to member.addresses,
"permissionLevel" to permissionString
"permissionLevel" to permissionString,
"consentState" to ConsentWrapper.consentStateToString(member.consentState)
)
}

Expand Down
14 changes: 7 additions & 7 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ PODS:
- hermes-engine/Pre-built (= 0.71.14)
- hermes-engine/Pre-built (0.71.14)
- libevent (2.1.12)
- LibXMTP (0.5.8-beta6)
- LibXMTP (0.5.9-beta0)
- Logging (1.0.0)
- MessagePacker (0.4.7)
- MMKV (1.3.9):
Expand Down Expand Up @@ -449,16 +449,16 @@ PODS:
- GenericJSON (~> 2.0)
- Logging (~> 1.0.0)
- secp256k1.swift (~> 0.1)
- XMTP (0.14.14):
- XMTP (0.15.0):
- Connect-Swift (= 0.12.0)
- GzipSwift
- LibXMTP (= 0.5.8-beta6)
- LibXMTP (= 0.5.9-beta0)
- web3.swift
- XMTPReactNative (0.1.0):
- ExpoModulesCore
- MessagePacker
- secp256k1.swift
- XMTP (= 0.14.14)
- XMTP (= 0.15.0)
- Yoga (1.14.0)

DEPENDENCIES:
Expand Down Expand Up @@ -711,7 +711,7 @@ SPEC CHECKSUMS:
GzipSwift: 893f3e48e597a1a4f62fafcb6514220fcf8287fa
hermes-engine: d7cc127932c89c53374452d6f93473f1970d8e88
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
LibXMTP: c7338cace222bed90f950579300725325a2c0bfd
LibXMTP: 5a38722a68a9469be2e711857a5e7d9dd3aa8a61
Logging: 9ef4ecb546ad3169398d5a723bc9bea1c46bef26
MessagePacker: ab2fe250e86ea7aedd1a9ee47a37083edd41fd02
MMKV: 817ba1eea17421547e01e087285606eb270a8dcb
Expand Down Expand Up @@ -763,8 +763,8 @@ SPEC CHECKSUMS:
secp256k1.swift: a7e7a214f6db6ce5db32cc6b2b45e5c4dd633634
SwiftProtobuf: 407a385e97fd206c4fbe880cc84123989167e0d1
web3.swift: 2263d1e12e121b2c42ffb63a5a7beb1acaf33959
XMTP: 37621f1258b12629af305e6697414ccb2fbd4ea8
XMTPReactNative: 7bec275ed26997e6a73f06a678c328e6ba852cd5
XMTP: 09faa347569b092005997364f7fe787ccc33f3d5
XMTPReactNative: 6404c11e6dd11820742d4af899daeea389fc442f
Yoga: e71803b4c1fff832ccf9b92541e00f9b873119b9

PODFILE CHECKSUM: 0e6fe50018f34e575d38dc6a1fdf1f99c9596cdd
Expand Down
Loading

0 comments on commit 6383b9c

Please sign in to comment.