Skip to content

Commit dc4d0bd

Browse files
authored
Android App Version (#73)
* add api client with grpc kotlin * add app version to the android app * a few more small tweaks * Empty-Commit to trigger build
1 parent e7612c1 commit dc4d0bd

File tree

5 files changed

+20
-7
lines changed

5 files changed

+20
-7
lines changed

example/src/main/java/org/xmtp/android/example/ClientManager.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import org.xmtp.android.library.messages.PrivateKeyBundleV1Builder
1313

1414
object ClientManager {
1515

16-
val CLIENT_OPTIONS = ClientOptions(api = ClientOptions.Api(XMTPEnvironment.DEV))
16+
val CLIENT_OPTIONS = ClientOptions(api = ClientOptions.Api(XMTPEnvironment.DEV, appVersion = "XMTPAndroidExample/v1.0.0"))
1717

1818
private val _clientState = MutableStateFlow<ClientState>(ClientState.Unknown)
1919
val clientState: StateFlow<ClientState> = _clientState

library/src/androidTest/java/org/xmtp/android/library/InstrumentedTest.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class InstrumentedTest {
3131
val aliceWallet = PrivateKeyBuilder()
3232
val alicePrivateKey = aliceWallet.getPrivateKey()
3333
val clientOptions =
34-
ClientOptions(api = ClientOptions.Api(env = XMTPEnvironment.LOCAL, isSecure = false))
34+
ClientOptions(api = ClientOptions.Api(env = XMTPEnvironment.LOCAL, isSecure = false, appVersion = "XMTPTest/v1.0.0"))
3535
val client = Client().create(aliceWallet, clientOptions)
3636
assertEquals(XMTPEnvironment.LOCAL, client.apiClient.environment)
3737
runBlocking {

library/src/main/java/org/xmtp/android/library/ApiClient.kt

+16-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ interface ApiClient {
3434
suspend fun subscribe(topics: List<String>): Flow<Envelope>
3535
}
3636

37-
data class GRPCApiClient(override val environment: XMTPEnvironment, val secure: Boolean = true) :
37+
data class GRPCApiClient(override val environment: XMTPEnvironment, val secure: Boolean = true, val appVersion: String? = null) :
3838
ApiClient, Closeable {
3939
companion object {
4040
val AUTHORIZATION_HEADER_KEY: Metadata.Key<String> =
@@ -102,6 +102,10 @@ data class GRPCApiClient(override val environment: XMTPEnvironment, val secure:
102102
authToken?.let { token ->
103103
headers.put(AUTHORIZATION_HEADER_KEY, "Bearer $token")
104104
}
105+
headers.put(CLIENT_VERSION_HEADER_KEY, Constants.VERSION)
106+
if (appVersion != null) {
107+
headers.put(APP_VERSION_HEADER_KEY, appVersion)
108+
}
105109
return client.query(request, headers = headers)
106110
}
107111

@@ -131,15 +135,24 @@ data class GRPCApiClient(override val environment: XMTPEnvironment, val secure:
131135
}
132136

133137
headers.put(CLIENT_VERSION_HEADER_KEY, Constants.VERSION)
134-
headers.put(APP_VERSION_HEADER_KEY, Constants.VERSION)
138+
if (appVersion != null) {
139+
headers.put(APP_VERSION_HEADER_KEY, appVersion)
140+
}
135141

136142
return client.publish(request, headers)
137143
}
138144

139145
override suspend fun subscribe(topics: List<String>): Flow<Envelope> {
140146
val request =
141147
MessageApiOuterClass.SubscribeRequest.newBuilder().addAllContentTopics(topics).build()
142-
return client.subscribe(request)
148+
val headers = Metadata()
149+
150+
headers.put(CLIENT_VERSION_HEADER_KEY, Constants.VERSION)
151+
if (appVersion != null) {
152+
headers.put(APP_VERSION_HEADER_KEY, appVersion)
153+
}
154+
155+
return client.subscribe(request, headers)
143156
}
144157

145158
override fun close() {

library/src/main/java/org/xmtp/android/library/Client.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ typealias PublishResponse = org.xmtp.proto.message.api.v1.MessageApiOuterClass.P
4343
typealias QueryResponse = org.xmtp.proto.message.api.v1.MessageApiOuterClass.QueryResponse
4444

4545
data class ClientOptions(val api: Api = Api()) {
46-
data class Api(val env: XMTPEnvironment = XMTPEnvironment.DEV, val isSecure: Boolean = true)
46+
data class Api(val env: XMTPEnvironment = XMTPEnvironment.DEV, val isSecure: Boolean = true, val appVersion: String? = null)
4747
}
4848

4949
class Client() {
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package org.xmtp.android.library
22

33
object Constants {
4-
const val VERSION = "0.0.0-development"
4+
const val VERSION = "0.1.3-development"
55
}

0 commit comments

Comments
 (0)