PrivMX DOCS
Java

Custom Fields and Queries

Using custom fields and querying them in Thread and Store containers.

Custom fields and querying them is a functionality that works with Threads and Stores containers.

It allows you to define new fields by placing them in the publicMeta of a container or an object within a given container, and then querying the PrivMX Endpoint Client (using existing listing methods) for elements containing these previously defined fields.

Sample code on this page is based on the initial assumptions.

Working with Custom Fields and Queries

Below there is a simple code example of how to add a custom field to a batch of Threads, and then search for them using custom query.

Creating Thread with a Custom Field

val contextId = "CONTEXT_ID"
val users: List<UserWithPubKey> = listOf(
    UserWithPubKey(user1Id, user1PublicKey),
    UserWithPubKey(user2Id, user2PublicKey)
)
val managers: List<UserWithPubKey> = listOf(
    UserWithPubKey(user1Id, user1PublicKey)
)
val privateMeta = "PRIVATE_META"

val publicMeta = """
{
    "threadType": "special"
    "numberOfMessages": 20
    "tags": ["TAG1", "TAG2", "TAG3"]
}
""".trimIndent()

endpointSession.threadApi.createThread(
    contextId,
    users,
    managers,
    publicMeta.encodeToByteArray(),
    privateMeta.encodeToByteArray()
)

List Threads with Custom Queries

Custom Queries

Query that matches threads where publicMeta contains a field with the specified key and value:

val query = """
{
    "threadType": "special"
}
""".trimIndent()

Query that matches threads where publicMeta contains both values - one of them must meet a condition (value > 10):

val query = """
{
    "numberOfMessages": { "${'$'}gt": 10 },
    "tags": "TAG2"
}
""".trimIndent()

Query that matches threads where publicMeta contains at least one of the given values:

val query = """
{
    "${'$'}or": [
        { "threadType": "archived"},
        { "numberOfMessages": 20}
    ]
}
""".trimIndent()

List Threads with Custom Queries

val startIndex = 0L
val pageSize = 100L
val lastId = null

endpointSession.threadApi.listThreads(
    contextId,
    startIndex,
    pageSize,
    SortOrder.ASC,
    lastId,
    query
)

You can find more query options in PrivMX Bridge API.

We use cookies on our website. We use them to ensure the proper functioning of the site and, if you agree, for purposes we set, such as analytics or marketing.

PrivMX Endpoint Java v2.3

This package is not up to date with the core documentation. Some of the features you've seen described in other parts of the documentation might not be mentioned here. Those changes do not influence compatibility, however

On this page