Skip to content

Commit 6653bf3

Browse files
committed
get on latest RN
1 parent 1ed6783 commit 6653bf3

File tree

6 files changed

+54
-33
lines changed

6 files changed

+54
-33
lines changed

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ repositories {
9898
dependencies {
9999
implementation project(':expo-modules-core')
100100
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${getKotlinVersion()}"
101-
implementation "org.xmtp:android:3.0.19"
101+
implementation "org.xmtp:android:3.0.20"
102102
implementation 'com.google.code.gson:gson:2.10.1'
103103
implementation 'com.facebook.react:react-native:0.71.3'
104104
implementation "com.daveanthonythomas.moshipack:moshipack:1.0.1"

android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import expo.modules.xmtpreactnativesdk.wrappers.ContentJson
1818
import expo.modules.xmtpreactnativesdk.wrappers.ConversationWrapper
1919
import expo.modules.xmtpreactnativesdk.wrappers.ConversationParamsWrapper
2020
import expo.modules.xmtpreactnativesdk.wrappers.CreateGroupParamsWrapper
21-
import expo.modules.xmtpreactnativesdk.wrappers.DecodedMessageWrapper
21+
import expo.modules.xmtpreactnativesdk.wrappers.MessageWrapper
2222
import expo.modules.xmtpreactnativesdk.wrappers.DecryptedLocalAttachment
2323
import expo.modules.xmtpreactnativesdk.wrappers.DmWrapper
2424
import expo.modules.xmtpreactnativesdk.wrappers.EncryptedLocalAttachment
@@ -54,13 +54,13 @@ import org.xmtp.android.library.codecs.EncryptedEncodedContent
5454
import org.xmtp.android.library.codecs.RemoteAttachment
5555
import org.xmtp.android.library.codecs.decoded
5656
import org.xmtp.android.library.hexToByteArray
57+
import org.xmtp.android.library.libxmtp.GroupPermissionPreconfiguration
5758
import org.xmtp.android.library.libxmtp.Message
59+
import org.xmtp.android.library.libxmtp.PermissionOption
5860
import org.xmtp.android.library.messages.PrivateKeyBuilder
5961
import org.xmtp.android.library.messages.Signature
6062
import org.xmtp.android.library.push.Service
6163
import org.xmtp.android.library.push.XMTPPush
62-
import uniffi.xmtpv3.org.xmtp.android.library.libxmtp.GroupPermissionPreconfiguration
63-
import uniffi.xmtpv3.org.xmtp.android.library.libxmtp.PermissionOption
6464
import java.io.BufferedReader
6565
import java.io.File
6666
import java.io.InputStreamReader
@@ -520,15 +520,13 @@ class XMTPModule : Module() {
520520
).toJson()
521521
}
522522

523-
AsyncFunction("listGroups") Coroutine { installationId: String, groupParams: String?, sortOrder: String?, limit: Int?, consentState: String? ->
523+
AsyncFunction("listGroups") Coroutine { installationId: String, groupParams: String?, limit: Int?, consentState: String? ->
524524
withContext(Dispatchers.IO) {
525525
logV("listGroups")
526526
val client = clients[installationId] ?: throw XMTPException("No client")
527527
val params = ConversationParamsWrapper.conversationParamsFromJson(groupParams ?: "")
528-
val order = getConversationSortOrder(sortOrder ?: "")
529528
val consent = consentState?.let { getConsentState(it) }
530529
val groups = client.conversations.listGroups(
531-
order = order,
532530
limit = limit,
533531
consentState = consent
534532
)
@@ -538,15 +536,13 @@ class XMTPModule : Module() {
538536
}
539537
}
540538

541-
AsyncFunction("listDms") Coroutine { installationId: String, groupParams: String?, sortOrder: String?, limit: Int?, consentState: String? ->
539+
AsyncFunction("listDms") Coroutine { installationId: String, groupParams: String?, limit: Int?, consentState: String? ->
542540
withContext(Dispatchers.IO) {
543541
logV("listDms")
544542
val client = clients[installationId] ?: throw XMTPException("No client")
545543
val params = ConversationParamsWrapper.conversationParamsFromJson(groupParams ?: "")
546-
val order = getConversationSortOrder(sortOrder ?: "")
547544
val consent = consentState?.let { getConsentState(it) }
548545
val dms = client.conversations.listDms(
549-
order = order,
550546
limit = limit,
551547
consentState = consent
552548
)
@@ -556,16 +552,15 @@ class XMTPModule : Module() {
556552
}
557553
}
558554

559-
AsyncFunction("listConversations") Coroutine { installationId: String, conversationParams: String?, sortOrder: String?, limit: Int?, consentState: String? ->
555+
AsyncFunction("listConversations") Coroutine { installationId: String, conversationParams: String?, limit: Int?, consentState: String? ->
560556
withContext(Dispatchers.IO) {
561557
logV("listConversations")
562558
val client = clients[installationId] ?: throw XMTPException("No client")
563559
val params =
564560
ConversationParamsWrapper.conversationParamsFromJson(conversationParams ?: "")
565-
val order = getConversationSortOrder(sortOrder ?: "")
566561
val consent = consentState?.let { getConsentState(it) }
567562
val conversations =
568-
client.conversations.list(order = order, limit = limit, consentState = consent)
563+
client.conversations.list(limit = limit, consentState = consent)
569564
conversations.map { conversation ->
570565
ConversationWrapper.encode(client, conversation, params)
571566
}
@@ -592,7 +587,7 @@ class XMTPModule : Module() {
592587
direction = Message.SortDirection.valueOf(
593588
direction ?: "DESCENDING"
594589
)
595-
)?.map { DecodedMessageWrapper.encode(it) }
590+
)?.map { MessageWrapper.encode(it) }
596591
}
597592
}
598593

@@ -602,7 +597,7 @@ class XMTPModule : Module() {
602597
val client = clients[installationId] ?: throw XMTPException("No client")
603598
val message = client.findMessage(messageId)
604599
message?.let {
605-
DecodedMessageWrapper.encode(it.decode())
600+
MessageWrapper.encode(it)
606601
}
607602
}
608603
}
@@ -1182,7 +1177,9 @@ class XMTPModule : Module() {
11821177
val conversation = client.findConversation(id)
11831178
?: throw XMTPException("no conversation found for $id")
11841179
val message = conversation.processMessage(Base64.decode(encryptedMessage, NO_WRAP))
1185-
DecodedMessageWrapper.encode(message.decode())
1180+
message?.let {
1181+
MessageWrapper.encode(it)
1182+
}
11861183
}
11871184
}
11881185

@@ -1412,13 +1409,6 @@ class XMTPModule : Module() {
14121409
}
14131410
}
14141411

1415-
private fun getConversationSortOrder(order: String): ConversationOrder {
1416-
return when (order) {
1417-
"lastMessage" -> ConversationOrder.LAST_MESSAGE
1418-
else -> ConversationOrder.CREATED_AT
1419-
}
1420-
}
1421-
14221412
private fun consentStateToString(state: ConsentState): String {
14231413
return when (state) {
14241414
ConsentState.ALLOWED -> "allowed"
@@ -1487,7 +1477,7 @@ class XMTPModule : Module() {
14871477
"message",
14881478
mapOf(
14891479
"installationId" to installationId,
1490-
"message" to DecodedMessageWrapper.encodeMap(message),
1480+
"message" to MessageWrapper.encodeMap(message),
14911481
)
14921482
)
14931483
}
@@ -1511,7 +1501,7 @@ class XMTPModule : Module() {
15111501
"conversationMessage",
15121502
mapOf(
15131503
"installationId" to installationId,
1514-
"message" to DecodedMessageWrapper.encodeMap(message),
1504+
"message" to MessageWrapper.encodeMap(message),
15151505
"conversationId" to id,
15161506
)
15171507
)

android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/DmWrapper.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class DmWrapper {
2424
if (dmParams.lastMessage) {
2525
val lastMessage = dm.messages(limit = 1).firstOrNull()
2626
if (lastMessage != null) {
27-
put("lastMessage", DecodedMessageWrapper.encode(lastMessage))
27+
put("lastMessage", MessageWrapper.encode(lastMessage))
2828
}
2929
}
3030
}

android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/GroupWrapper.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class GroupWrapper {
3131
if (groupParams.lastMessage) {
3232
val lastMessage = group.messages(limit = 1).firstOrNull()
3333
if (lastMessage != null) {
34-
put("lastMessage", DecodedMessageWrapper.encode(lastMessage))
34+
put("lastMessage", MessageWrapper.encode(lastMessage))
3535
}
3636
}
3737
}

android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/DecodedMessageWrapper.kt renamed to android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/MessageWrapper.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
package expo.modules.xmtpreactnativesdk.wrappers
22

33
import com.google.gson.GsonBuilder
4-
import org.xmtp.android.library.DecodedMessage
54
import org.xmtp.android.library.codecs.description
5+
import org.xmtp.android.library.libxmtp.Message
66

7-
class DecodedMessageWrapper {
7+
class MessageWrapper {
88

99
companion object {
10-
fun encode(model: DecodedMessage): String {
10+
fun encode(model: Message): String {
1111
val gson = GsonBuilder().create()
1212
val message = encodeMap(model)
1313
return gson.toJson(message)
1414
}
1515

16-
fun encodeMap(model: DecodedMessage): Map<String, Any?> {
16+
fun encodeMap(model: Message): Map<String, Any?> {
1717
// Kotlin/Java Protos don't support null values and will always put the default ""
1818
// Check if there is a fallback, if there is then make it the set fallback, if not null
1919
val fallback = if (model.encodedContent.hasFallback()) model.encodedContent.fallback else null
@@ -23,7 +23,7 @@ class DecodedMessageWrapper {
2323
"contentTypeId" to model.encodedContent.type.description,
2424
"content" to ContentJson(model.encodedContent).toJsonMap(),
2525
"senderInboxId" to model.senderInboxId,
26-
"sentNs" to model.sentNs,
26+
"sentNs" to model.sentAtNs,
2727
"fallback" to fallback,
2828
"deliveryStatus" to model.deliveryStatus.toString()
2929
)

ios/XMTPModule.swift

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,17 @@ public class XMTPModule: Module {
582582
return results
583583
}
584584

585+
AsyncFunction("getHmacKeys") { (installationId: String) -> [UInt8] in
586+
guard
587+
let client = await clientsManager.getClient(key: installationId)
588+
else {
589+
throw Error.noClient
590+
}
591+
let hmacKeys = await client.conversations.getHmacKeys()
592+
593+
return try [UInt8](hmacKeys.serializedData())
594+
}
595+
585596
AsyncFunction("conversationMessages") {
586597
(
587598
installationId: String, conversationId: String, limit: Int?,
@@ -1742,11 +1753,31 @@ public class XMTPModule: Module {
17421753
}
17431754
}
17441755

1745-
AsyncFunction("subscribePushTopics") { (topics: [String]) in
1756+
AsyncFunction("subscribePushTopics") {
1757+
(installationId: String, topics: [String]) in
17461758
do {
1759+
guard
1760+
let client = await clientsManager.getClient(
1761+
key: installationId)
1762+
else {
1763+
throw Error.noClient
1764+
}
1765+
let hmacKeysResult = await client.conversations.getHmacKeys()
17471766
let subscriptions = topics.map {
17481767
topic -> NotificationSubscription in
1768+
let hmacKeys = hmacKeysResult.hmacKeys
1769+
1770+
let result = hmacKeys[topic]?.values.map {
1771+
hmacKey -> NotificationSubscriptionHmacKey in
1772+
NotificationSubscriptionHmacKey.with { sub_key in
1773+
sub_key.key = hmacKey.hmacKey
1774+
sub_key.thirtyDayPeriodsSinceEpoch = UInt32(
1775+
hmacKey.thirtyDayPeriodsSinceEpoch)
1776+
}
1777+
}
1778+
17491779
return NotificationSubscription.with { sub in
1780+
sub.hmacKeys = result ?? []
17501781
sub.topic = topic
17511782
}
17521783
}

0 commit comments

Comments
 (0)