Overview
Inboxes are a secure way for assigned members to receive encrypted inbound traffic from public sources. Before working with Inboxes, follow our Getting Started Guide. It will show you how to set up your project to work with PrivMX Bridge.
Info
Inbox publicMeta
and privateMeta
fields support any kind of data formats encoded to byte arrays.
Examples in this section use kotlinx-serialization-json-jvm
dependency for Kotlin and com.google.code.gson:gson
for Java to serialize object to JSON format.
What is an Inbox?
Inbox is a container, which is designed to be accessed only by the assigned users. It is managed similarly as Threads and Stores. However, writing to an Inbox is possible with public API, which doesn't require writer registration and access specification.
Working with Inboxes
To access Threads methods, get the field inboxApi
from active connection. Connection should be initialized with Modules.INBOX
and passed to PrivmxEndpoint()
.
InboxApi inboxApi = connection.inboxApi;
Creating Inboxes
Creating a basic, unnamed Inbox, which can act as an encrypted data container:
val contextId = "CONTEXT_ID"
val users : List<UserWithPubKey> = listOf() // users to add to the Inbox
val managers : List<UserWithPubKey> = listOf() // managers to add to the Inbox
val inboxApi = connection.inboxApi
val inboxId = inboxApi.createInbox(
contextId,
users,
managers,
ByteArray(0),
ByteArray(0)
)
Getting Inboxes
Define Inbox item class with decoded publicMeta
and privateMeta
:
data class InboxItem(
val inbox: Inbox,
val decodedPrivateMeta: String,
val decodedPublicMeta: InboxPublicMeta
)
Fetching the most recent Inboxes in given Context:
val contextId = "CONTEXT_ID"
val startIndex = 0L
val pageSize = 100L
val inboxApi = connection.inboxApi
val inboxesPagingList = inboxApi.listInboxes(
contextId,
startIndex,
pageSize,
SortOrder.DESC
)
val inboxes = inboxesPagingList.readItems.map {
InboxItem(
it,
it.privateMeta.decodeToString(),
Json.decodeFromString(it.publicMeta.decodeToString())
)
}
Getting Public View
Users with public connection (created by Connection.platformConnectPublic
)
have access to the Public View which shares not encrypted fields of the Inbox, such as publicMeta
.
val inboxID = "INBOX_ID"
val inboxApi = connection.inboxApi
val inboxPublicView = inboxApi.getInboxPublicView(inboxID)
val inboxPublicMeta: InboxPublicMeta = Json.decodeFromString(
inboxPublicView.publicMeta.decodeToString()
)
Managing Inboxes
To update an Inbox you must always provide its current version, as well as:
- list of users
- list of managers
- new private and public meta (even if it didn't change)
- Inbox's current version
- Inbox FilesConfig
true
if update action should be forced
val inboxID = "INBOX_ID"
val inbox: Inbox = connection.inboxApi.getInbox(inboxID)
val users = inbox
.users
.map { userId ->
//Your application must provide a way,
//to get user's public key from their userId.
UserWithPubKey(
userId,
"USER_PUBLIC_KEY"
)
}
val managers = inbox
.managers
.map { userId ->
//Your application must provide a way,
//to get user's public key from their userId.
UserWithPubKey(
userId,
"USER_PUBLIC_KEY"
)
}
val newInboxNameAsPrivateMeta = "New inbox name"
val inboxApi = connection.inboxApi
inboxApi.updateInbox(
inboxID,
users,
managers,
inbox.publicMeta,
newInboxNameAsPrivateMeta.encodeToByteArray(),
inbox.filesConfig,
inbox.version,
false
)