From f947b33e21018e48ed868a3ef74e09ff81592ecf Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Fri, 19 Apr 2024 13:04:16 -0700 Subject: [PATCH 01/10] bump to latest version so that we get message id returned instead of group --- android/build.gradle | 2 +- ios/XMTPReactNative.podspec | 2 +- src/lib/DecodedMessage.ts | 19 ++++++++++++++++--- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index e922dc08c..6dfab186e 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -98,7 +98,7 @@ repositories { dependencies { implementation project(':expo-modules-core') implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${getKotlinVersion()}" - implementation "org.xmtp:android:0.10.4" + implementation "org.xmtp:android:0.10.5" 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" diff --git a/ios/XMTPReactNative.podspec b/ios/XMTPReactNative.podspec index 0aa246e1c..b3efbe6a0 100644 --- a/ios/XMTPReactNative.podspec +++ b/ios/XMTPReactNative.podspec @@ -26,5 +26,5 @@ Pod::Spec.new do |s| s.source_files = "**/*.{h,m,swift}" s.dependency 'secp256k1.swift' s.dependency "MessagePacker" - s.dependency "XMTP", "= 0.10.3" + s.dependency "XMTP", "= 0.10.4" end diff --git a/src/lib/DecodedMessage.ts b/src/lib/DecodedMessage.ts index 244dcfb49..4eea4ad29 100644 --- a/src/lib/DecodedMessage.ts +++ b/src/lib/DecodedMessage.ts @@ -13,6 +13,13 @@ const allowEmptyProperties: (keyof NativeMessageContent)[] = [ 'text', 'readReceipt', ] +export enum MessageDeliveryStatus { + UNPUBLISHED = 'UNPUBLISHED', + PUBLISHED = 'PUBLISHED', + FAILED = 'FAILED', + ALL = 'ALL', +} + export class DecodedMessage< ContentTypes extends DefaultContentTypes = DefaultContentTypes, > { @@ -24,6 +31,7 @@ export class DecodedMessage< sent: number // timestamp in milliseconds nativeContent: NativeMessageContent fallback: string | undefined + deliveryStatus: MessageDeliveryStatus = MessageDeliveryStatus.PUBLISHED static from( json: string, @@ -38,7 +46,8 @@ export class DecodedMessage< decoded.senderAddress, decoded.sent, decoded.content, - decoded.fallback + decoded.fallback, + decoded.deliveryStatus ) } @@ -53,6 +62,7 @@ export class DecodedMessage< sent: number // timestamp in milliseconds content: any fallback: string | undefined + deliveryStatus: MessageDeliveryStatus | undefined }, client: Client ): DecodedMessage { @@ -64,7 +74,8 @@ export class DecodedMessage< object.senderAddress, object.sent, object.content, - object.fallback + object.fallback, + object.deliveryStatus ) } @@ -76,7 +87,8 @@ export class DecodedMessage< senderAddress: string, sent: number, content: any, - fallback: string | undefined + fallback: string | undefined, + deliveryStatus: MessageDeliveryStatus = MessageDeliveryStatus.PUBLISHED ) { this.client = client this.id = id @@ -87,6 +99,7 @@ export class DecodedMessage< this.nativeContent = content // undefined comes back as null when bridged, ensure undefined so integrators don't have to add a new check for null as well this.fallback = fallback ?? undefined + this.deliveryStatus = deliveryStatus } content(): ExtractDecodedType<[...ContentTypes, TextCodec][number] | string> { From a2abf63c8e65466a3d2036356418b72564144deb Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Fri, 19 Apr 2024 13:08:41 -0700 Subject: [PATCH 02/10] add filtering and expose type in the wrapper --- .../main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt | 6 +++++- .../xmtpreactnativesdk/wrappers/DecodedMessageWrapper.kt | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt index 2c5be7b18..2a37240d7 100644 --- a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt +++ b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt @@ -66,6 +66,7 @@ import kotlin.coroutines.Continuation import kotlin.coroutines.resume import kotlin.coroutines.resumeWithException import com.facebook.common.util.Hex +import org.xmtp.android.library.messages.MessageDeliveryStatus import org.xmtp.android.library.messages.Topic import org.xmtp.android.library.push.Service @@ -527,7 +528,7 @@ class XMTPModule : Module() { } } - AsyncFunction("groupMessages") Coroutine { clientAddress: String, id: String, limit: Int?, before: Long?, after: Long?, direction: String? -> + AsyncFunction("groupMessages") Coroutine { clientAddress: String, id: String, limit: Int?, before: Long?, after: Long?, direction: String?, deliveryStatus: String? -> withContext(Dispatchers.IO) { logV("groupMessages") val client = clients[clientAddress] ?: throw XMTPException("No client") @@ -540,6 +541,9 @@ class XMTPModule : Module() { after = afterDate, direction = MessageApiOuterClass.SortDirection.valueOf( direction ?: "SORT_DIRECTION_DESCENDING" + ), + deliveryStatus = MessageDeliveryStatus.valueOf( + deliveryStatus ?: "ALL" ) )?.map { DecodedMessageWrapper.encode(it) } } diff --git a/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/DecodedMessageWrapper.kt b/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/DecodedMessageWrapper.kt index 6b87624f7..b6b683a44 100644 --- a/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/DecodedMessageWrapper.kt +++ b/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/DecodedMessageWrapper.kt @@ -24,7 +24,8 @@ class DecodedMessageWrapper { "content" to ContentJson(model.encodedContent).toJsonMap(), "senderAddress" to model.senderAddress, "sent" to model.sentAt.time, - "fallback" to fallback + "fallback" to fallback, + "deliveryStatus" to model.deliveryStatus.toString().lowercase() ) } } From 8def38d56d0cf37047d103207dea389b67aaab61 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Fri, 19 Apr 2024 13:16:06 -0700 Subject: [PATCH 03/10] add the RN side of the function --- src/index.ts | 8 +++++--- src/lib/Group.ts | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/index.ts b/src/index.ts index 8cd7d959f..00388f49e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -16,7 +16,7 @@ import { ConversationContainer, ConversationVersion, } from './lib/ConversationContainer' -import { DecodedMessage } from './lib/DecodedMessage' +import { DecodedMessage, MessageDeliveryStatus } from './lib/DecodedMessage' import { Group } from './lib/Group' import type { Query } from './lib/Query' import { ConversationSendPayload } from './lib/types' @@ -165,7 +165,8 @@ export async function groupMessages< direction?: | 'SORT_DIRECTION_ASCENDING' | 'SORT_DIRECTION_DESCENDING' - | undefined + | undefined, + deliveryStatus?: MessageDeliveryStatus | undefined ): Promise[]> { const messages = await XMTPModule.groupMessages( client.address, @@ -173,7 +174,8 @@ export async function groupMessages< limit, before, after, - direction + direction, + deliveryStatus ) return messages.map((json: string) => { return DecodedMessage.from(json, client) diff --git a/src/lib/Group.ts b/src/lib/Group.ts index c34f172e8..c311a18ff 100644 --- a/src/lib/Group.ts +++ b/src/lib/Group.ts @@ -2,7 +2,7 @@ import { ConversationVersion, ConversationContainer, } from './ConversationContainer' -import { DecodedMessage } from './DecodedMessage' +import { DecodedMessage, MessageDeliveryStatus } from './DecodedMessage' import { ConversationSendPayload } from './types/ConversationCodecs' import { DefaultContentTypes } from './types/DefaultContentType' import { EventTypes } from './types/EventTypes' @@ -116,7 +116,8 @@ export class Group< direction?: | 'SORT_DIRECTION_ASCENDING' | 'SORT_DIRECTION_DESCENDING' - | undefined + | undefined, + deliveryStatus?: MessageDeliveryStatus | undefined ): Promise[]> { if (!skipSync) { await this.sync() @@ -127,7 +128,8 @@ export class Group< limit, before, after, - direction + direction, + deliveryStatus ?? MessageDeliveryStatus.ALL ) } From 1d3b3dde5140e4484c5424278073f239eccbd88f Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Mon, 22 Apr 2024 21:51:19 -0700 Subject: [PATCH 04/10] do ios side and write tests --- example/ios/Podfile.lock | 14 ++--- example/src/tests/groupTests.ts | 70 ++++++++++++++++++++++-- ios/Wrappers/DecodedMessageWrapper.swift | 1 + ios/XMTPModule.swift | 8 ++- 4 files changed, 80 insertions(+), 13 deletions(-) diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 287ba6143..59557d542 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -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.4.4-beta2) + - LibXMTP (0.4.4-beta3) - Logging (1.0.0) - MessagePacker (0.4.7) - MMKV (1.3.4): @@ -449,16 +449,16 @@ PODS: - GenericJSON (~> 2.0) - Logging (~> 1.0.0) - secp256k1.swift (~> 0.1) - - XMTP (0.10.3): + - XMTP (0.10.4): - Connect-Swift (= 0.12.0) - GzipSwift - - LibXMTP (= 0.4.4-beta2) + - LibXMTP (= 0.4.4-beta3) - web3.swift - XMTPReactNative (0.1.0): - ExpoModulesCore - MessagePacker - secp256k1.swift - - XMTP (= 0.10.3) + - XMTP (= 0.10.4) - Yoga (1.14.0) DEPENDENCIES: @@ -711,7 +711,7 @@ SPEC CHECKSUMS: GzipSwift: 893f3e48e597a1a4f62fafcb6514220fcf8287fa hermes-engine: d7cc127932c89c53374452d6f93473f1970d8e88 libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913 - LibXMTP: 0c073613451e3850bfcaaab5438b481fe887cd97 + LibXMTP: 1422d36d715fe868b5800692f3d9b8a218a41e9d Logging: 9ef4ecb546ad3169398d5a723bc9bea1c46bef26 MessagePacker: ab2fe250e86ea7aedd1a9ee47a37083edd41fd02 MMKV: ed58ad794b3f88c24d604a5b74f3fba17fcbaf74 @@ -763,8 +763,8 @@ SPEC CHECKSUMS: secp256k1.swift: a7e7a214f6db6ce5db32cc6b2b45e5c4dd633634 SwiftProtobuf: 407a385e97fd206c4fbe880cc84123989167e0d1 web3.swift: 2263d1e12e121b2c42ffb63a5a7beb1acaf33959 - XMTP: bf00ef58d4fbcc8ab740145a6303591adf3fb355 - XMTPReactNative: fae44562e5e457c66fde8e2613e1dfd3c1a71113 + XMTP: 072cb1bbb1d0c1cc9487fff6fd9c4b0770dcde6e + XMTPReactNative: 46199b8025e1afa514c49a07348d82ef5cfd60db Yoga: e71803b4c1fff832ccf9b92541e00f9b873119b9 PODFILE CHECKSUM: 95d6ace79946933ecf80684613842ee553dd76a2 diff --git a/example/src/tests/groupTests.ts b/example/src/tests/groupTests.ts index 5544f1c95..4250ca63d 100644 --- a/example/src/tests/groupTests.ts +++ b/example/src/tests/groupTests.ts @@ -1,5 +1,8 @@ import RNFS from 'react-native-fs' -import { DecodedMessage } from 'xmtp-react-native-sdk/lib/DecodedMessage' +import { + DecodedMessage, + MessageDeliveryStatus, +} from 'xmtp-react-native-sdk/lib/DecodedMessage' import { Test, @@ -14,6 +17,7 @@ import { Group, ConversationContainer, ConversationVersion, + syncGroup, } from '../../../src/index' export const groupTests: Test[] = [] @@ -205,11 +209,69 @@ test('production MLS V3 client creation throws error', async () => { ) }) +test('group message delivery status', async () => { + const [alixClient, boClient] = await createClients(2) + const alixGroup = await alixClient.conversations.newGroup([boClient.address]) + + await alixGroup.send('hello, world') + + const alixMessages: DecodedMessage[] = await alixGroup.messages(true) + + assert( + alixMessages.length === 2, + `the messages length should be 2 but was ${alixMessages.length}` + ) + + assert( + alixMessages[0].content() === 'hello, world', + `the message content should be hello, world not ${alixMessages[0].content()}` + ) + + assert( + alixMessages[0].deliveryStatus === 'UNPUBLISHED', + `the message should have a delivery status of UNPUBLISHED but was ${alixMessages[0].deliveryStatus}` + ) + + const alexMessagesFiltered: DecodedMessage[] = await alixGroup.messages( + undefined, + undefined, + undefined, + undefined, + undefined, + MessageDeliveryStatus.UNPUBLISHED + ) + + assert( + alexMessagesFiltered.length === 1, + `the messages length should be 1 but was ${alexMessagesFiltered.length}` + ) + + const alixMessages2: DecodedMessage[] = await alixGroup.messages(false) + + assert( + alixMessages2[0].deliveryStatus === 'PUBLISHED', + `the message should have a delivery status of PUBLISHED but was ${alixMessages2[0].deliveryStatus}` + ) + + const boGroup = (await boClient.conversations.listGroups())[0] + const boMessages: DecodedMessage[] = await boGroup.messages(true) + + assert( + boMessages.length === 1, + `the messages length should be 1 but was ${boMessages.length}` + ) + + assert( + boMessages[0].deliveryStatus === 'PUBLISHED', + `the message should have a delivery status of PUBLISHED but was ${boMessages[0].deliveryStatus}` + ) + + return true +}) + test('who added me to a group', async () => { const [alixClient, boClient] = await createClients(2) - const alixGroup = await alixClient.conversations.newGroup([ - boClient.address, - ]) + const alixGroup = await alixClient.conversations.newGroup([boClient.address]) const boGroup = (await boClient.conversations.listGroups())[0] const addedByAddress = await boGroup.addedByAddress() diff --git a/ios/Wrappers/DecodedMessageWrapper.swift b/ios/Wrappers/DecodedMessageWrapper.swift index b9780396d..334a67bde 100644 --- a/ios/Wrappers/DecodedMessageWrapper.swift +++ b/ios/Wrappers/DecodedMessageWrapper.swift @@ -16,6 +16,7 @@ struct DecodedMessageWrapper { "senderAddress": model.senderAddress, "sent": UInt64(model.sentAt.timeIntervalSince1970 * 1000), "fallback": fallback, + "deliveryStatus": model.deliveryStatus, ] } diff --git a/ios/XMTPModule.swift b/ios/XMTPModule.swift index 01331862d..818b191e4 100644 --- a/ios/XMTPModule.swift +++ b/ios/XMTPModule.swift @@ -418,7 +418,7 @@ public class XMTPModule: Module { } } - AsyncFunction("groupMessages") { (clientAddress: String, id: String, limit: Int?, before: Double?, after: Double?, direction: String?) -> [String] in + AsyncFunction("groupMessages") { (clientAddress: String, id: String, limit: Int?, before: Double?, after: Double?, direction: String?, deliveryStatus: String?) -> [String] in guard let client = await clientsManager.getClient(key: clientAddress) else { throw Error.noClient } @@ -427,6 +427,8 @@ public class XMTPModule: Module { let afterDate = after != nil ? Date(timeIntervalSince1970: TimeInterval(after!) / 1000) : nil let sortDirection: Int = (direction != nil && direction == "SORT_DIRECTION_ASCENDING") ? 1 : 2 + + let status: String = (deliveryStatus != nil) ? deliveryStatus!.lowercased() : "all" guard let group = try await findGroup(clientAddress: clientAddress, id: id) else { throw Error.conversationNotFound("no group found for \(id)") @@ -435,7 +437,9 @@ public class XMTPModule: Module { before: beforeDate, after: afterDate, limit: limit, - direction: PagingInfoSortDirection(rawValue: sortDirection)) + direction: PagingInfoSortDirection(rawValue: sortDirection), + deliveryStatus: MessageDeliveryStatus(rawValue: status) + ) return decryptedMessages.compactMap { msg in do { From bab2e57997c07b3898a56eca27c2b904e7bf5a9d Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Mon, 22 Apr 2024 22:36:37 -0700 Subject: [PATCH 05/10] fix up the test and get android passing --- .../wrappers/DecodedMessageWrapper.kt | 2 +- example/src/tests/groupTests.ts | 19 ++++++------------- ios/Wrappers/DecodedMessageWrapper.swift | 2 +- src/index.ts | 2 +- 4 files changed, 9 insertions(+), 16 deletions(-) diff --git a/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/DecodedMessageWrapper.kt b/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/DecodedMessageWrapper.kt index b6b683a44..ab871f023 100644 --- a/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/DecodedMessageWrapper.kt +++ b/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/DecodedMessageWrapper.kt @@ -25,7 +25,7 @@ class DecodedMessageWrapper { "senderAddress" to model.senderAddress, "sent" to model.sentAt.time, "fallback" to fallback, - "deliveryStatus" to model.deliveryStatus.toString().lowercase() + "deliveryStatus" to model.deliveryStatus.toString() ) } } diff --git a/example/src/tests/groupTests.ts b/example/src/tests/groupTests.ts index 4250ca63d..e00b424aa 100644 --- a/example/src/tests/groupTests.ts +++ b/example/src/tests/groupTests.ts @@ -1,8 +1,5 @@ import RNFS from 'react-native-fs' -import { - DecodedMessage, - MessageDeliveryStatus, -} from 'xmtp-react-native-sdk/lib/DecodedMessage' +import { DecodedMessage } from 'xmtp-react-native-sdk/lib/DecodedMessage' import { Test, @@ -18,6 +15,7 @@ import { ConversationContainer, ConversationVersion, syncGroup, + MessageDeliveryStatus, } from '../../../src/index' export const groupTests: Test[] = [] @@ -223,17 +221,12 @@ test('group message delivery status', async () => { ) assert( - alixMessages[0].content() === 'hello, world', - `the message content should be hello, world not ${alixMessages[0].content()}` - ) - - assert( - alixMessages[0].deliveryStatus === 'UNPUBLISHED', - `the message should have a delivery status of UNPUBLISHED but was ${alixMessages[0].deliveryStatus}` + alixMessages[1].deliveryStatus === 'UNPUBLISHED', + `the message should have a delivery status of ${MessageDeliveryStatus.UNPUBLISHED} but was ${alixMessages[1].deliveryStatus}` ) const alexMessagesFiltered: DecodedMessage[] = await alixGroup.messages( - undefined, + true, undefined, undefined, undefined, @@ -254,7 +247,7 @@ test('group message delivery status', async () => { ) const boGroup = (await boClient.conversations.listGroups())[0] - const boMessages: DecodedMessage[] = await boGroup.messages(true) + const boMessages: DecodedMessage[] = await boGroup.messages() assert( boMessages.length === 1, diff --git a/ios/Wrappers/DecodedMessageWrapper.swift b/ios/Wrappers/DecodedMessageWrapper.swift index 334a67bde..8bc453bdd 100644 --- a/ios/Wrappers/DecodedMessageWrapper.swift +++ b/ios/Wrappers/DecodedMessageWrapper.swift @@ -16,7 +16,7 @@ struct DecodedMessageWrapper { "senderAddress": model.senderAddress, "sent": UInt64(model.sentAt.timeIntervalSince1970 * 1000), "fallback": fallback, - "deliveryStatus": model.deliveryStatus, + "deliveryStatus": model.deliveryStatus.rawValue.uppercased(), ] } diff --git a/src/index.ts b/src/index.ts index 00388f49e..f07e0e770 100644 --- a/src/index.ts +++ b/src/index.ts @@ -749,5 +749,5 @@ export { } from './lib/ConversationContainer' export { Query } from './lib/Query' export { XMTPPush } from './lib/XMTPPush' -export { ConsentListEntry, DecodedMessage } +export { ConsentListEntry, DecodedMessage, MessageDeliveryStatus } export { Group } from './lib/Group' From 9ccc326884f19ca42a66876eae7d098a25c42014 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Mon, 22 Apr 2024 22:42:28 -0700 Subject: [PATCH 06/10] should be 0 --- example/src/tests/groupTests.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/example/src/tests/groupTests.ts b/example/src/tests/groupTests.ts index e00b424aa..cf8c01f12 100644 --- a/example/src/tests/groupTests.ts +++ b/example/src/tests/groupTests.ts @@ -220,9 +220,13 @@ test('group message delivery status', async () => { `the messages length should be 2 but was ${alixMessages.length}` ) + if (alixMessages[0].content() !== 'hello, world') { + throw new Error("newest message should be 'hello, world'") + } + assert( - alixMessages[1].deliveryStatus === 'UNPUBLISHED', - `the message should have a delivery status of ${MessageDeliveryStatus.UNPUBLISHED} but was ${alixMessages[1].deliveryStatus}` + alixMessages[0].deliveryStatus === 'UNPUBLISHED', + `the message should have a delivery status of ${MessageDeliveryStatus.UNPUBLISHED} but was ${alixMessages[0].deliveryStatus}` ) const alexMessagesFiltered: DecodedMessage[] = await alixGroup.messages( From 7663ffd5ab62e553359cb9060f0908ff0771b8ab Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Mon, 22 Apr 2024 22:57:22 -0700 Subject: [PATCH 07/10] bump to the correct pod --- ios/XMTPReactNative.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/XMTPReactNative.podspec b/ios/XMTPReactNative.podspec index b3efbe6a0..814453097 100644 --- a/ios/XMTPReactNative.podspec +++ b/ios/XMTPReactNative.podspec @@ -26,5 +26,5 @@ Pod::Spec.new do |s| s.source_files = "**/*.{h,m,swift}" s.dependency 'secp256k1.swift' s.dependency "MessagePacker" - s.dependency "XMTP", "= 0.10.4" + s.dependency "XMTP", "= 0.10.5" end From ca77d8a0f4be045d08696bbe168aa0dbacb6990c Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Tue, 23 Apr 2024 15:58:51 -0700 Subject: [PATCH 08/10] fix: change message options to a object --- example/ios/Podfile.lock | 8 ++++---- src/lib/Group.ts | 21 ++++++++------------- src/lib/types/MessagesOptions.ts | 12 ++++++++++++ src/lib/types/index.ts | 1 + 4 files changed, 25 insertions(+), 17 deletions(-) create mode 100644 src/lib/types/MessagesOptions.ts diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 59557d542..6d1408b5a 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -449,7 +449,7 @@ PODS: - GenericJSON (~> 2.0) - Logging (~> 1.0.0) - secp256k1.swift (~> 0.1) - - XMTP (0.10.4): + - XMTP (0.10.5): - Connect-Swift (= 0.12.0) - GzipSwift - LibXMTP (= 0.4.4-beta3) @@ -458,7 +458,7 @@ PODS: - ExpoModulesCore - MessagePacker - secp256k1.swift - - XMTP (= 0.10.4) + - XMTP (= 0.10.5) - Yoga (1.14.0) DEPENDENCIES: @@ -763,8 +763,8 @@ SPEC CHECKSUMS: secp256k1.swift: a7e7a214f6db6ce5db32cc6b2b45e5c4dd633634 SwiftProtobuf: 407a385e97fd206c4fbe880cc84123989167e0d1 web3.swift: 2263d1e12e121b2c42ffb63a5a7beb1acaf33959 - XMTP: 072cb1bbb1d0c1cc9487fff6fd9c4b0770dcde6e - XMTPReactNative: 46199b8025e1afa514c49a07348d82ef5cfd60db + XMTP: ec7fa7f9a2bd3990a7142c2f454e04c5b83b834a + XMTPReactNative: 42d61df711ce3c094d9fac9e3f44671f5466e93e Yoga: e71803b4c1fff832ccf9b92541e00f9b873119b9 PODFILE CHECKSUM: 95d6ace79946933ecf80684613842ee553dd76a2 diff --git a/src/lib/Group.ts b/src/lib/Group.ts index c311a18ff..be63c1ff1 100644 --- a/src/lib/Group.ts +++ b/src/lib/Group.ts @@ -6,6 +6,7 @@ import { DecodedMessage, MessageDeliveryStatus } from './DecodedMessage' import { ConversationSendPayload } from './types/ConversationCodecs' import { DefaultContentTypes } from './types/DefaultContentType' import { EventTypes } from './types/EventTypes' +import { MessagesOptions } from './types/MessagesOptions' import { SendOptions } from './types/SendOptions' import * as XMTP from '../index' @@ -110,26 +111,20 @@ export class Group< */ async messages( skipSync: boolean = false, - limit?: number | undefined, - before?: number | Date | undefined, - after?: number | Date | undefined, - direction?: - | 'SORT_DIRECTION_ASCENDING' - | 'SORT_DIRECTION_DESCENDING' - | undefined, - deliveryStatus?: MessageDeliveryStatus | undefined + opts?: MessagesOptions ): Promise[]> { if (!skipSync) { await this.sync() } + return await XMTP.groupMessages( this.client, this.id, - limit, - before, - after, - direction, - deliveryStatus ?? MessageDeliveryStatus.ALL + opts?.limit, + opts?.before, + opts?.after, + opts?.direction, + opts?.deliveryStatus ?? MessageDeliveryStatus.ALL ) } diff --git a/src/lib/types/MessagesOptions.ts b/src/lib/types/MessagesOptions.ts new file mode 100644 index 000000000..089d098d1 --- /dev/null +++ b/src/lib/types/MessagesOptions.ts @@ -0,0 +1,12 @@ +import { MessageDeliveryStatus } from '../DecodedMessage' + +export type MessagesOptions = { + limit?: number | undefined + before?: number | Date | undefined + after?: number | Date | undefined + direction?: + | 'SORT_DIRECTION_ASCENDING' + | 'SORT_DIRECTION_DESCENDING' + | undefined + deliveryStatus?: MessageDeliveryStatus | undefined +} diff --git a/src/lib/types/index.ts b/src/lib/types/index.ts index 1248d4ea3..ac9b03879 100644 --- a/src/lib/types/index.ts +++ b/src/lib/types/index.ts @@ -2,3 +2,4 @@ export * from './ContentCodec' export * from './SendOptions' export * from './ExtractDecodedType' export * from './ConversationCodecs' +export * from './MessagesOptions' From ef323b662994fcb0f5134ab7d849613313b1b00b Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Tue, 23 Apr 2024 16:07:50 -0700 Subject: [PATCH 09/10] fix up all the tests on iOS --- example/src/tests/groupTests.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/example/src/tests/groupTests.ts b/example/src/tests/groupTests.ts index cf8c01f12..26ae6f53f 100644 --- a/example/src/tests/groupTests.ts +++ b/example/src/tests/groupTests.ts @@ -231,11 +231,9 @@ test('group message delivery status', async () => { const alexMessagesFiltered: DecodedMessage[] = await alixGroup.messages( true, - undefined, - undefined, - undefined, - undefined, - MessageDeliveryStatus.UNPUBLISHED + { + deliveryStatus: MessageDeliveryStatus.UNPUBLISHED, + } ) assert( @@ -901,7 +899,9 @@ test('can paginate group messages', async () => { } await delayToPropogate() // bo can read messages from alix - const boMessages: DecodedMessage[] = await boGroups[0].messages(false, 1) + const boMessages: DecodedMessage[] = await boGroups[0].messages(false, { + limit: 1, + }) if (boMessages.length !== 1) { throw Error(`Should limit just 1 message but was ${boMessages.length}`) From 38d7d2e00babd02c9e50f73bcf97ab185ce0dc6a Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Tue, 23 Apr 2024 17:01:15 -0700 Subject: [PATCH 10/10] get it so the tests pass on both ios and android --- example/src/tests/groupTests.ts | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/example/src/tests/groupTests.ts b/example/src/tests/groupTests.ts index 26ae6f53f..07d38cd4f 100644 --- a/example/src/tests/groupTests.ts +++ b/example/src/tests/groupTests.ts @@ -220,15 +220,6 @@ test('group message delivery status', async () => { `the messages length should be 2 but was ${alixMessages.length}` ) - if (alixMessages[0].content() !== 'hello, world') { - throw new Error("newest message should be 'hello, world'") - } - - assert( - alixMessages[0].deliveryStatus === 'UNPUBLISHED', - `the message should have a delivery status of ${MessageDeliveryStatus.UNPUBLISHED} but was ${alixMessages[0].deliveryStatus}` - ) - const alexMessagesFiltered: DecodedMessage[] = await alixGroup.messages( true, { @@ -243,6 +234,11 @@ test('group message delivery status', async () => { const alixMessages2: DecodedMessage[] = await alixGroup.messages(false) + assert( + alixMessages2.length === 2, + `the messages length should be 2 but was ${alixMessages.length}` + ) + assert( alixMessages2[0].deliveryStatus === 'PUBLISHED', `the message should have a delivery status of PUBLISHED but was ${alixMessages2[0].deliveryStatus}`