PrivMX DOCS
Kotlin

Thread Events

Listening for events related new messages and updating your app's state accordingly will allow you to build e.g., instant messaging features.

Types of Events

The lists below outline all the event types available in Threads and messages in PrivMX.

Thread events:

  • threadCreated - triggers when a new Thread is created in your Context
  • threadDeleted - triggers when a Thread is deleted from your Context
  • threadUpdated - triggers when a Thread is updated
  • threadStatsChanged - triggers when a message is sent to a thread or a message has been deleted

Message events:

  • threadNewMessage - triggers a message was sent to a Thread
  • threadDeletedMessage triggers when a message was deleted from a Thread
  • threadMessageUpdated - triggers when a message was updated

Handling Thread and Message Events

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

Before receiving Events, your application has to start an event loop and subscribe to specific events in the given scope. Afterwards you can setup a listener.

Here is an example how to do it in your own project:

Kotlin
val threadCallbacksGroup = "THREAD_CALLBACKS_GROUP"
val messageCallbacksGroup = "MESSAGE_CALLBACKS_GROUP"
val threadID = "THREAD_ID"

// Starting the Event Loop
endpointContainer.startListening()

endpointSession.registerManyCallbacks(

    // Handling Thread events
    CallbackRegistration(
        threadCallbacksGroup,
        EventType.ThreadCreatedEvent(contextId)
    ) { newThread ->
        println(newThread.threadId)
    },

    //Handling message Events
    CallbackRegistration(
        messageCallbacksGroup,
        EventType.ThreadNewMessageEvent(
            ThreadEventSelectorType.THREAD_ID,
            threadID
        )
    ) { newMessage ->
        println(newMessage.info.messageId)
    }
)

endpointSession.unregisterCallbacks(threadCallbacksGroup, messageCallbacksGroup)

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

PrivMX Endpoint Kotlin v2.6

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

Thread Events | PrivMX Docs