@@ -37,7 +37,11 @@ interface ApiClient {
37
37
suspend fun subscribe (topics : List <String >): Flow <Envelope >
38
38
}
39
39
40
- data class GRPCApiClient (override val environment : XMTPEnvironment , val secure : Boolean = true , val appVersion : String? = null ) :
40
+ data class GRPCApiClient (
41
+ override val environment : XMTPEnvironment ,
42
+ val secure : Boolean = true ,
43
+ val appVersion : String? = null ,
44
+ ) :
41
45
ApiClient , Closeable {
42
46
companion object {
43
47
val AUTHORIZATION_HEADER_KEY : Metadata .Key <String > =
@@ -48,6 +52,37 @@ data class GRPCApiClient(override val environment: XMTPEnvironment, val secure:
48
52
49
53
val APP_VERSION_HEADER_KEY : Metadata .Key <String > =
50
54
Metadata .Key .of(" X-App-Version" , Metadata .ASCII_STRING_MARSHALLER )
55
+
56
+ fun makeQueryRequest (
57
+ topic : String ,
58
+ pagination : Pagination ? = null,
59
+ cursor : Cursor ? = null,
60
+ ): QueryRequest =
61
+ QueryRequest .newBuilder()
62
+ .addContentTopics(topic).also {
63
+ if (pagination != null ) {
64
+ it.pagingInfo = pagination.pagingInfo
65
+ }
66
+ if (pagination?.startTime != null ) {
67
+ it.endTimeNs = pagination.startTime.time * 1_000_000
68
+ it.pagingInfo = it.pagingInfo.toBuilder().also { info ->
69
+ info.direction =
70
+ MessageApiOuterClass .SortDirection .SORT_DIRECTION_DESCENDING
71
+ }.build()
72
+ }
73
+ if (pagination?.endTime != null ) {
74
+ it.startTimeNs = pagination.endTime.time * 1_000_000
75
+ it.pagingInfo = it.pagingInfo.toBuilder().also { info ->
76
+ info.direction =
77
+ MessageApiOuterClass .SortDirection .SORT_DIRECTION_DESCENDING
78
+ }.build()
79
+ }
80
+ if (cursor != null ) {
81
+ it.pagingInfo = it.pagingInfo.toBuilder().also { info ->
82
+ info.cursor = cursor
83
+ }.build()
84
+ }
85
+ }.build()
51
86
}
52
87
53
88
private val channel: ManagedChannel =
@@ -74,32 +109,7 @@ data class GRPCApiClient(override val environment: XMTPEnvironment, val secure:
74
109
pagination : Pagination ? ,
75
110
cursor : Cursor ? ,
76
111
): QueryResponse {
77
- val request = QueryRequest .newBuilder()
78
- .addContentTopics(topic).also {
79
- if (pagination != null ) {
80
- it.pagingInfo = pagination.pagingInfo
81
- }
82
- if (pagination?.startTime != null ) {
83
- it.endTimeNs = pagination.startTime.time * 1_000_000
84
- it.pagingInfo = it.pagingInfo.toBuilder().also { info ->
85
- info.direction =
86
- MessageApiOuterClass .SortDirection .SORT_DIRECTION_DESCENDING
87
- }.build()
88
- }
89
- if (pagination?.endTime != null ) {
90
- it.startTimeNs = pagination.endTime.time * 1_000_000
91
- it.pagingInfo = it.pagingInfo.toBuilder().also { info ->
92
- info.direction =
93
- MessageApiOuterClass .SortDirection .SORT_DIRECTION_DESCENDING
94
- }.build()
95
- }
96
- if (cursor != null ) {
97
- it.pagingInfo = it.pagingInfo.toBuilder().also { info ->
98
- info.cursor = cursor
99
- }.build()
100
- }
101
- }.build()
102
-
112
+ val request = makeQueryRequest(topic, pagination, cursor)
103
113
val headers = Metadata ()
104
114
105
115
authToken?.let { token ->
0 commit comments