Skip to content

Commit

Permalink
Only set app version on Client init (#144)
Browse files Browse the repository at this point in the history
* only set it on client init

* don't need to store the app version in swift
  • Loading branch information
nplasterer authored Aug 7, 2023
1 parent 7bf1fd0 commit 2446711
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions Sources/XMTP/ApiClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,13 @@ class GRPCApiClient: ApiClient {
var authToken = ""

var rustClient: XMTPRust.RustClient
var appVersion: String

required init(environment: XMTPEnvironment, secure _: Bool = true, rustClient: XMTPRust.RustClient, appVersion: String? = nil) throws {
self.environment = environment
self.rustClient = rustClient
self.appVersion = appVersion ?? "0.0.0"
if let appVersion = appVersion {
rustClient.set_app_version(appVersion.intoRustString())
}
}

static func envToUrl(env: XMTPEnvironment) -> String {
Expand All @@ -89,7 +90,6 @@ class GRPCApiClient: ApiClient {

func batchQuery(request: BatchQueryRequest) async throws -> BatchQueryResponse {
do {
rustClient.set_app_version(appVersion.intoRustString())
let req = RustVec<UInt8>(try request.serializedData())
let res: RustVec<UInt8> = try await rustClient.batch_query(req)
return try BatchQueryResponse(serializedData: Data(res))
Expand All @@ -100,7 +100,6 @@ class GRPCApiClient: ApiClient {

func query(request: QueryRequest) async throws -> QueryResponse {
do {
rustClient.set_app_version(appVersion.intoRustString())
let req = RustVec<UInt8>(try request.serializedData())
let res: RustVec<UInt8> = try await rustClient.query(req)
return try QueryResponse(serializedData: Data(res))
Expand Down Expand Up @@ -142,7 +141,6 @@ class GRPCApiClient: ApiClient {
func subscribe(topics: [String]) -> AsyncThrowingStream<Envelope, Error> {
return AsyncThrowingStream { continuation in
Task {
rustClient.set_app_version(appVersion.intoRustString())
let request = SubscribeRequest.with { $0.contentTopics = topics }
let req = RustVec<UInt8>(try request.serializedData())
do {
Expand All @@ -166,7 +164,6 @@ class GRPCApiClient: ApiClient {

func publish(request: PublishRequest) async throws -> PublishResponse {
do {
rustClient.set_app_version(appVersion.intoRustString())
let req = RustVec<UInt8>(try request.serializedData())
let res: RustVec<UInt8> = try await rustClient.publish(authToken.intoRustString(), req)
return try PublishResponse(serializedData: Data(res))
Expand Down

0 comments on commit 2446711

Please sign in to comment.