Skip to content

Commit

Permalink
Android App Version (#73)
Browse files Browse the repository at this point in the history
* add api client with grpc kotlin

* add app version to the android app

* a few more small tweaks

* Empty-Commit to trigger build
  • Loading branch information
nplasterer authored May 10, 2023
1 parent e7612c1 commit dc4d0bd
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import org.xmtp.android.library.messages.PrivateKeyBundleV1Builder

object ClientManager {

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

private val _clientState = MutableStateFlow<ClientState>(ClientState.Unknown)
val clientState: StateFlow<ClientState> = _clientState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class InstrumentedTest {
val aliceWallet = PrivateKeyBuilder()
val alicePrivateKey = aliceWallet.getPrivateKey()
val clientOptions =
ClientOptions(api = ClientOptions.Api(env = XMTPEnvironment.LOCAL, isSecure = false))
ClientOptions(api = ClientOptions.Api(env = XMTPEnvironment.LOCAL, isSecure = false, appVersion = "XMTPTest/v1.0.0"))
val client = Client().create(aliceWallet, clientOptions)
assertEquals(XMTPEnvironment.LOCAL, client.apiClient.environment)
runBlocking {
Expand Down
19 changes: 16 additions & 3 deletions library/src/main/java/org/xmtp/android/library/ApiClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ interface ApiClient {
suspend fun subscribe(topics: List<String>): Flow<Envelope>
}

data class GRPCApiClient(override val environment: XMTPEnvironment, val secure: Boolean = true) :
data class GRPCApiClient(override val environment: XMTPEnvironment, val secure: Boolean = true, val appVersion: String? = null) :
ApiClient, Closeable {
companion object {
val AUTHORIZATION_HEADER_KEY: Metadata.Key<String> =
Expand Down Expand Up @@ -102,6 +102,10 @@ data class GRPCApiClient(override val environment: XMTPEnvironment, val secure:
authToken?.let { token ->
headers.put(AUTHORIZATION_HEADER_KEY, "Bearer $token")
}
headers.put(CLIENT_VERSION_HEADER_KEY, Constants.VERSION)
if (appVersion != null) {
headers.put(APP_VERSION_HEADER_KEY, appVersion)
}
return client.query(request, headers = headers)
}

Expand Down Expand Up @@ -131,15 +135,24 @@ data class GRPCApiClient(override val environment: XMTPEnvironment, val secure:
}

headers.put(CLIENT_VERSION_HEADER_KEY, Constants.VERSION)
headers.put(APP_VERSION_HEADER_KEY, Constants.VERSION)
if (appVersion != null) {
headers.put(APP_VERSION_HEADER_KEY, appVersion)
}

return client.publish(request, headers)
}

override suspend fun subscribe(topics: List<String>): Flow<Envelope> {
val request =
MessageApiOuterClass.SubscribeRequest.newBuilder().addAllContentTopics(topics).build()
return client.subscribe(request)
val headers = Metadata()

headers.put(CLIENT_VERSION_HEADER_KEY, Constants.VERSION)
if (appVersion != null) {
headers.put(APP_VERSION_HEADER_KEY, appVersion)
}

return client.subscribe(request, headers)
}

override fun close() {
Expand Down
2 changes: 1 addition & 1 deletion library/src/main/java/org/xmtp/android/library/Client.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ typealias PublishResponse = org.xmtp.proto.message.api.v1.MessageApiOuterClass.P
typealias QueryResponse = org.xmtp.proto.message.api.v1.MessageApiOuterClass.QueryResponse

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

class Client() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package org.xmtp.android.library

object Constants {
const val VERSION = "0.0.0-development"
const val VERSION = "0.1.3-development"
}

0 comments on commit dc4d0bd

Please sign in to comment.