Skip to content

Commit 1253152

Browse files
committed
Add insertedAt field and sortBy options
1 parent 7a0be54 commit 1253152

File tree

15 files changed

+421
-218
lines changed

15 files changed

+421
-218
lines changed

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ repositories {
9595
dependencies {
9696
implementation project(':expo-modules-core')
9797
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${getKotlinVersion()}"
98-
implementation "org.xmtp:android:4.6.1-rc1"
98+
implementation "org.xmtp:android:4.7.0-dev.252eebc"
9999
implementation 'com.google.code.gson:gson:2.10.1'
100100
implementation 'com.facebook.react:react-native:0.71.3'
101101
implementation "com.daveanthonythomas.moshipack:moshipack:1.0.1"

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

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ import org.xmtp.android.library.hexToByteArray
7171
import org.xmtp.android.library.libxmtp.ArchiveElement
7272
import org.xmtp.android.library.libxmtp.ArchiveOptions
7373
import org.xmtp.android.library.libxmtp.DecodedMessage
74+
import org.xmtp.android.library.libxmtp.DecodedMessage.SortBy
7475
import org.xmtp.android.library.libxmtp.DisappearingMessageSettings
7576
import org.xmtp.android.library.libxmtp.GroupPermissionPreconfiguration
7677
import org.xmtp.android.library.libxmtp.PermissionOption
@@ -1012,7 +1013,13 @@ class XMTPModule : Module() {
10121013
afterNs = queryParams.afterNs,
10131014
direction = DecodedMessage.SortDirection.valueOf(
10141015
queryParams.direction ?: "DESCENDING"
1015-
)
1016+
),
1017+
insertedAfterNs = queryParams.insertedAfterNs,
1018+
insertedBeforeNs = queryParams.insertedBeforeNs,
1019+
sortBy = when (queryParams.sortBy) {
1020+
"INSERTED" -> SortBy.INSERTED_TIME
1021+
else -> SortBy.SENT_TIME
1022+
}
10161023
)?.map { MessageWrapper.encode(it) }
10171024
}
10181025
}
@@ -1029,11 +1036,32 @@ class XMTPModule : Module() {
10291036
afterNs = queryParams.afterNs,
10301037
direction = DecodedMessage.SortDirection.valueOf(
10311038
queryParams.direction ?: "DESCENDING"
1032-
)
1039+
),
1040+
insertedAfterNs = queryParams.insertedAfterNs,
1041+
insertedBeforeNs = queryParams.insertedBeforeNs,
1042+
sortBy = when (queryParams.sortBy) {
1043+
"INSERTED" -> SortBy.INSERTED_TIME
1044+
else -> SortBy.SENT_TIME
1045+
}
10331046
)?.map { MessageWrapper.encode(it) }
10341047
}
10351048
}
10361049

1050+
AsyncFunction("countMessages") Coroutine { installationId: String, conversationId: String, queryParamsJson: String? ->
1051+
withContext(Dispatchers.IO) {
1052+
logV("countMessages")
1053+
val client = clients[installationId] ?: throw XMTPException("No client")
1054+
val conversation = client.conversations.findConversation(conversationId)
1055+
val queryParams = MessageQueryParamsWrapper.messageQueryParamsFromJson(queryParamsJson ?: "")
1056+
conversation?.countMessages(
1057+
beforeNs = queryParams.beforeNs,
1058+
afterNs = queryParams.afterNs,
1059+
insertedAfterNs = queryParams.insertedAfterNs,
1060+
insertedBeforeNs = queryParams.insertedBeforeNs
1061+
) ?: 0
1062+
}
1063+
}
1064+
10371065
AsyncFunction("findMessage") Coroutine { installationId: String, messageId: String ->
10381066
withContext(Dispatchers.IO) {
10391067
logV("findMessage")

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ class MessageQueryParamsWrapper(
99
val direction: String?,
1010
val excludeContentTypes: List<String>?,
1111
val excludeSenderInboxIds: List<String>?,
12+
val insertedAfterNs: Long?,
13+
val insertedBeforeNs: Long?,
14+
val sortBy: String?,
1215
) {
1316
companion object {
1417
fun messageQueryParamsFromJson(paramsJson: String): MessageQueryParamsWrapper {
@@ -20,6 +23,9 @@ class MessageQueryParamsWrapper(
2023
null,
2124
null,
2225
null,
26+
null,
27+
null,
28+
null,
2329
)
2430
}
2531

@@ -69,13 +75,37 @@ class MessageQueryParamsWrapper(
6975
null
7076
}
7177

78+
val insertedAfterNs =
79+
if (jsonOptions.has("insertedAfterNs")) {
80+
jsonOptions.get("insertedAfterNs").asLong
81+
} else {
82+
null
83+
}
84+
85+
val insertedBeforeNs =
86+
if (jsonOptions.has("insertedBeforeNs")) {
87+
jsonOptions.get("insertedBeforeNs").asLong
88+
} else {
89+
null
90+
}
91+
92+
val sortBy =
93+
if (jsonOptions.has("sortBy")) {
94+
jsonOptions.get("sortBy").asString
95+
} else {
96+
null
97+
}
98+
7299
return MessageQueryParamsWrapper(
73100
limit,
74101
beforeNs,
75102
afterNs,
76103
direction,
77104
excludeContentTypes,
78105
excludeSenderInboxIds,
106+
insertedAfterNs,
107+
insertedBeforeNs,
108+
sortBy,
79109
)
80110
}
81111
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import org.xmtp.android.library.codecs.description
55
import org.xmtp.android.library.libxmtp.DecodedMessage
66

77
class MessageWrapper {
8-
98
companion object {
109
fun encode(model: DecodedMessage): String {
1110
val gson = GsonBuilder().create()
@@ -24,9 +23,10 @@ class MessageWrapper {
2423
"content" to ContentJson(model.encodedContent).toJsonMap(),
2524
"senderInboxId" to model.senderInboxId,
2625
"sentNs" to model.sentAtNs,
26+
"insertedAtNs" to model.insertedAtNs,
2727
"fallback" to fallback,
2828
"deliveryStatus" to model.deliveryStatus.toString(),
29-
"childMessages" to model.childMessages?.map { childMessage -> encodeMap(childMessage) }
29+
"childMessages" to model.childMessages?.map { childMessage -> encodeMap(childMessage) },
3030
)
3131
}
3232
}

example/ios/Podfile.lock

Lines changed: 21 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ PODS:
1010
- EXImageLoader (5.0.0):
1111
- ExpoModulesCore
1212
- React-Core
13-
- Expo (52.0.47):
13+
- Expo (52.0.44):
1414
- ExpoModulesCore
1515
- ExpoAsset (11.0.5):
1616
- ExpoModulesCore
@@ -51,9 +51,7 @@ PODS:
5151
- ReactCommon/turbomodule/bridging
5252
- ReactCommon/turbomodule/core
5353
- Yoga
54-
- ExpoSplashScreen (0.29.24):
55-
- ExpoModulesCore
56-
- ExpoSystemUI (4.0.9):
54+
- ExpoSplashScreen (0.29.22):
5755
- ExpoModulesCore
5856
- fast_float (6.1.4)
5957
- FBLazyVector (0.76.9)
@@ -1377,7 +1375,7 @@ PODS:
13771375
- ReactCommon/turbomodule/bridging
13781376
- ReactCommon/turbomodule/core
13791377
- Yoga
1380-
- react-native-netinfo (11.4.1):
1378+
- react-native-netinfo (9.3.7):
13811379
- React-Core
13821380
- react-native-quick-base64 (2.1.2):
13831381
- DoubleConversion
@@ -1425,31 +1423,12 @@ PODS:
14251423
- Yoga
14261424
- react-native-randombytes (3.6.1):
14271425
- React-Core
1428-
- react-native-safe-area-context (4.12.0):
1426+
- react-native-safe-area-context (5.3.0):
14291427
- React-Core
14301428
- react-native-sqlite-storage (6.0.1):
14311429
- React-Core
1432-
- react-native-webview (13.12.5):
1433-
- DoubleConversion
1434-
- glog
1435-
- hermes-engine
1436-
- RCT-Folly (= 2024.10.14.00)
1437-
- RCTRequired
1438-
- RCTTypeSafety
1430+
- react-native-webview (11.26.0):
14391431
- React-Core
1440-
- React-debug
1441-
- React-Fabric
1442-
- React-featureflags
1443-
- React-graphics
1444-
- React-ImageManager
1445-
- React-NativeModulesApple
1446-
- React-RCTFabric
1447-
- React-rendererdebug
1448-
- React-utils
1449-
- ReactCodegen
1450-
- ReactCommon/turbomodule/bridging
1451-
- ReactCommon/turbomodule/core
1452-
- Yoga
14531432
- React-nativeconfig (0.76.9)
14541433
- React-NativeModulesApple (0.76.9):
14551434
- glog
@@ -1722,11 +1701,11 @@ PODS:
17221701
- React-logger
17231702
- React-perflogger
17241703
- React-utils (= 0.76.9)
1725-
- RNCAsyncStorage (1.23.1):
1704+
- RNCAsyncStorage (1.17.11):
17261705
- React-Core
17271706
- RNFS (2.20.0):
17281707
- React-Core
1729-
- RNScreens (4.4.0):
1708+
- RNScreens (4.10.0):
17301709
- DoubleConversion
17311710
- glog
17321711
- hermes-engine
@@ -1748,7 +1727,7 @@ PODS:
17481727
- ReactCommon/turbomodule/bridging
17491728
- ReactCommon/turbomodule/core
17501729
- Yoga
1751-
- RNSVG (15.8.0):
1730+
- RNSVG (15.11.2):
17521731
- React-Core
17531732
- SocketRocket (0.7.1)
17541733
- SQLCipher (4.5.7):
@@ -1757,16 +1736,16 @@ PODS:
17571736
- SQLCipher/standard (4.5.7):
17581737
- SQLCipher/common
17591738
- SwiftProtobuf (1.28.2)
1760-
- XMTP (4.6.1-rc3):
1739+
- XMTP (4.7.0-dev.ff66c0f):
17611740
- Connect-Swift (= 1.0.0)
17621741
- CryptoSwift (= 1.8.3)
17631742
- SQLCipher (= 4.5.7)
1764-
- XMTPReactNative (5.0.6):
1743+
- XMTPReactNative (5.1.0-rc1):
17651744
- CSecp256k1 (~> 0.2)
17661745
- ExpoModulesCore
17671746
- MessagePacker
17681747
- SQLCipher (= 4.5.7)
1769-
- XMTP (= 4.6.1-rc3)
1748+
- XMTP (= 4.7.0-dev.ff66c0f)
17701749
- Yoga (0.0.0)
17711750

17721751
DEPENDENCIES:
@@ -1785,7 +1764,6 @@ DEPENDENCIES:
17851764
- ExpoKeepAwake (from `../node_modules/expo-keep-awake/ios`)
17861765
- ExpoModulesCore (from `../node_modules/expo-modules-core`)
17871766
- ExpoSplashScreen (from `../node_modules/expo-splash-screen/ios`)
1788-
- ExpoSystemUI (from `../node_modules/expo-system-ui/ios`)
17891767
- fast_float (from `../node_modules/react-native/third-party-podspecs/fast_float.podspec`)
17901768
- FBLazyVector (from `../node_modules/react-native/Libraries/FBLazyVector`)
17911769
- fmt (from `../node_modules/react-native/third-party-podspecs/fmt.podspec`)
@@ -1913,8 +1891,6 @@ EXTERNAL SOURCES:
19131891
:path: "../node_modules/expo-modules-core"
19141892
ExpoSplashScreen:
19151893
:path: "../node_modules/expo-splash-screen/ios"
1916-
ExpoSystemUI:
1917-
:path: "../node_modules/expo-system-ui/ios"
19181894
fast_float:
19191895
:podspec: "../node_modules/react-native/third-party-podspecs/fast_float.podspec"
19201896
FBLazyVector:
@@ -2083,7 +2059,7 @@ SPEC CHECKSUMS:
20832059
DoubleConversion: f16ae600a246532c4020132d54af21d0ddb2a385
20842060
EXConstants: fcfc75800824ac2d5c592b5bc74130bad17b146b
20852061
EXImageLoader: e5da974e25b13585c196b658a440720c075482d5
2086-
Expo: 1687edb10c76b0c0f135306d6ae245379f50ed54
2062+
Expo: 75e002fc29a18a72aa3db967b41b29c2b206875d
20872063
ExpoAsset: 48386d40d53a8c1738929b3ed509bcad595b5516
20882064
ExpoClipboard: 44fd1c8959ee8f6175d059dc011b154c9709a969
20892065
ExpoCrypto: e97e864c8d7b9ce4a000bca45dddb93544a1b2b4
@@ -2093,8 +2069,7 @@ SPEC CHECKSUMS:
20932069
ExpoImagePicker: 24e5ba8da111f74519b1e6dc556e0b438b2b8464
20942070
ExpoKeepAwake: b0171a73665bfcefcfcc311742a72a956e6aa680
20952071
ExpoModulesCore: 725faec070d590810d2ea5983d9f78f7cf6a38ec
2096-
ExpoSplashScreen: 399ee9f85b6c8a61b965e13a1ecff8384db591c2
2097-
ExpoSystemUI: b82a45cf0f6a4fa18d07c46deba8725dd27688b4
2072+
ExpoSplashScreen: cb4e3d3ee646ed59810f7776cca0ae5c03ab4285
20982073
fast_float: 06eeec4fe712a76acc9376682e4808b05ce978b6
20992074
FBLazyVector: 7605ea4810e0e10ae4815292433c09bf4324ba45
21002075
fmt: 01b82d4ca6470831d1cc0852a1af644be019e8f6
@@ -2138,13 +2113,13 @@ SPEC CHECKSUMS:
21382113
react-native-encrypted-storage: 569d114e329b1c2c2d9f8c84bcdbe4478dda2258
21392114
react-native-get-random-values: d16467cf726c618e9c7a8c3c39c31faa2244bbba
21402115
react-native-mmkv: f0574e88f254d13d1a87cf6d38c36bc5d3910d49
2141-
react-native-netinfo: cec9c4e86083cb5b6aba0e0711f563e2fbbff187
2116+
react-native-netinfo: be701059f57093572e5ba08cba14483d334b425d
21422117
react-native-quick-base64: 5565249122493bef017004646d73f918e8c2dfb0
21432118
react-native-quick-crypto: c168ffba24470d8edfd03961d9492638431b9869
21442119
react-native-randombytes: 3c8f3e89d12487fd03a2f966c288d495415fc116
2145-
react-native-safe-area-context: 8b8404e70b0cbf2a56428a17017c14c1dcc16448
2120+
react-native-safe-area-context: fdb0a66feac038cb6eb1edafcf2ccee2b5cf0284
21462121
react-native-sqlite-storage: 0c84826214baaa498796c7e46a5ccc9a82e114ed
2147-
react-native-webview: 69a5462ca94921ff695e1b52b12fffe62af7d312
2122+
react-native-webview: 5bb1454f1eb43e0bad229bb428a378d6b865a0ad
21482123
React-nativeconfig: 8efdb1ef1e9158c77098a93085438f7e7b463678
21492124
React-NativeModulesApple: cebca2e5320a3d66e123cade23bd90a167ffce5e
21502125
React-perflogger: 72e653eb3aba9122f9e57cf012d22d2486f33358
@@ -2172,15 +2147,15 @@ SPEC CHECKSUMS:
21722147
React-utils: ed818f19ab445000d6b5c4efa9d462449326cc9f
21732148
ReactCodegen: f853a20cc9125c5521c8766b4b49375fec20648b
21742149
ReactCommon: 300d8d9c5cb1a6cd79a67cf5d8f91e4d477195f9
2175-
RNCAsyncStorage: aa75595c1aefa18f868452091fa0c411a516ce11
2150+
RNCAsyncStorage: 357676e1dc19095208c80d4271066c407cd02ed1
21762151
RNFS: 89de7d7f4c0f6bafa05343c578f61118c8282ed8
2177-
RNScreens: 295d9c0aaeb7f680d03d7e9b476569a4959aae89
2178-
RNSVG: 8542aa11770b27563714bbd8494a8436385fc85f
2152+
RNScreens: 5cac36d8f7b3d92fb4304abcb44c5de336413df8
2153+
RNSVG: a07e14363aa208062c6483bad24a438d5986d490
21792154
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
21802155
SQLCipher: 5e6bfb47323635c8b657b1b27d25c5f1baf63bf5
21812156
SwiftProtobuf: 4dbaffec76a39a8dc5da23b40af1a5dc01a4c02d
2182-
XMTP: d9e99e75df20472dd4845f5b9f0476e4748d1fd6
2183-
XMTPReactNative: ae7fe2223f35aae19235a1c792f3035f8ff70cb9
2157+
XMTP: fbef51f8aa0cb762cfac902668f9648b77465a7f
2158+
XMTPReactNative: 439874cb0553196c7f6804014f829a2f5ec9c215
21842159
Yoga: feb4910aba9742cfedc059e2b2902e22ffe9954a
21852160

21862161
PODFILE CHECKSUM: 5b1b93f724b9cde6043d1824960f7bfd9a7973cd

ios/Wrappers/MessageQueryParamsWrapper.swift

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ struct MessageQueryParamsWrapper {
88
let direction: String?
99
let excludeContentTypes: [String]?
1010
let excludeSenderInboxIds: [String]?
11+
let insertedAfterNs: Int64?
12+
let insertedBeforeNs: Int64?
13+
let sortBy: String?
1114

1215
static func messageQueryParamsFromJson(_ paramsJson: String)
1316
-> MessageQueryParamsWrapper
@@ -19,29 +22,38 @@ struct MessageQueryParamsWrapper {
1922
afterNs: nil,
2023
direction: nil,
2124
excludeContentTypes: nil,
22-
excludeSenderInboxIds: nil
25+
excludeSenderInboxIds: nil,
26+
insertedAfterNs: nil,
27+
insertedBeforeNs: nil,
28+
sortBy: nil
2329
)
2430
}
2531

2632
let data = paramsJson.data(using: .utf8) ?? Data()
2733
let jsonOptions =
2834
(try? JSONSerialization.jsonObject(with: data, options: []))
29-
as? [String: Any] ?? [:]
35+
as? [String: Any] ?? [:]
3036

3137
let limit = jsonOptions["limit"] as? Int
3238
let beforeNs = jsonOptions["beforeNs"] as? Int64
3339
let afterNs = jsonOptions["afterNs"] as? Int64
3440
let direction = jsonOptions["direction"] as? String
3541
let excludeContentTypes = jsonOptions["excludeContentTypes"] as? [String]
3642
let excludeSenderInboxIds = jsonOptions["excludeSenderInboxIds"] as? [String]
43+
let insertedAfterNs = jsonOptions["insertedAfterNs"] as? Int64
44+
let insertedBeforeNs = jsonOptions["insertedBeforeNs"] as? Int64
45+
let sortBy = jsonOptions["sortBy"] as? String
3746

3847
return MessageQueryParamsWrapper(
3948
limit: limit,
4049
beforeNs: beforeNs,
4150
afterNs: afterNs,
4251
direction: direction,
4352
excludeContentTypes: excludeContentTypes,
44-
excludeSenderInboxIds: excludeSenderInboxIds
53+
excludeSenderInboxIds: excludeSenderInboxIds,
54+
insertedAfterNs: insertedAfterNs,
55+
insertedBeforeNs: insertedBeforeNs,
56+
sortBy: sortBy
4557
)
4658
}
4759
}

0 commit comments

Comments
 (0)