PrivMX DOCS
Java

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:

Java
String threadCallbackID = "THREAD_CALLBACK_ID";
String messageCallbackID = "MESSAGE_CALLBACK_ID";
String threadID = "THREAD_ID";

// Starting the Event Loop
endpointContainer.startListening();

endpointSession.registerManyCallbacks(

     // Handling Thread events
     new CallbackRegistration<>(
             threadCallbackID,
             EventType.ThreadCreatedEvent(contextId),
             newThread -> {
                 System.out.println(newThread.threadId);
             }
     ),

     //Handling message Events
     new CallbackRegistration<>(
             messageCallbackID,
             EventType.ThreadNewMessageEvent(
                     ThreadEventSelectorType.THREAD_ID,
                     threadID
             ),
             newMessage -> {
                 System.out.println(newMessage.info.messageId);
             }
     )
);

endpointSession.unregisterCallbacks(threadCallbackID, messageCallbackID);

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 Java 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