-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #411 from xmtp/np/expose-installation-id
Exposes client installationId
- Loading branch information
Showing
7 changed files
with
93 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/ClientWrapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package expo.modules.xmtpreactnativesdk.wrappers | ||
|
||
import com.google.gson.GsonBuilder | ||
import org.xmtp.android.library.Client | ||
|
||
class ClientWrapper { | ||
companion object { | ||
fun encodeToObj(client: Client): Map<String, String> { | ||
return mapOf( | ||
"inboxId" to client.inboxId, | ||
"address" to client.address, | ||
"installationId" to client.installationId | ||
) | ||
} | ||
|
||
fun encode(client: Client): String { | ||
val gson = GsonBuilder().create() | ||
val obj = encodeToObj(client) | ||
return gson.toJson(obj) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// | ||
// ClientWrapper.swift | ||
// XMTPReactNative | ||
// | ||
// Created by Naomi Plasterer on 6/10/24. | ||
// | ||
|
||
import Foundation | ||
import XMTP | ||
|
||
// Wrapper around XMTP.Client to allow passing these objects back into react native. | ||
struct ClientWrapper { | ||
static func encodeToObj(_ client: XMTP.Client) throws -> [String: String] { | ||
return [ | ||
"inboxId": client.inboxID, | ||
"address": client.address, | ||
"installationId": client.installationID, | ||
] | ||
} | ||
|
||
static func encode(_ client: XMTP.Client) throws -> String { | ||
let obj = try encodeToObj(client) | ||
let data = try JSONSerialization.data(withJSONObject: obj) | ||
guard let result = String(data: data, encoding: .utf8) else { | ||
throw WrapperError.encodeError("could not encode client") | ||
} | ||
return result | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters