PrivMX DOCS
Swift

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:

Swift

    let threadId = "THREAD_ID"
    let messageId = "MESSAGE_ID"
    
    Task{
        try? await endpointContainer?.startListening()
    }
    
    let registrationErrors = endpointSession?.registerCallbacksInBulk(
        [
            PMXEventCallbackRegistration(
                request: .thread(
                    eventType: privmx.endpoint.thread.THREAD_CREATE,
                    selectorType: .Context,
                    selectorId: CONTEXT_ID),
                group: "SOME_UNIQUE_IDENTIFIER",
                cb:{ eventData in
                    // some actions when a new thread created
                }),
            PMXEventCallbackRegistration(
                request: .thread(
                    eventType: privmx.endpoint.thread.THREAD_UPDATE,
                    selectorType: .Context,
                    selectorId: CONTEXT_ID),
                group: "SOME_UNIQUE_IDENTIFIER",
                cb:{ eventData in
                    // some actions when a thread is updated
                }),
            PMXEventCallbackRegistration(
                request: .thread(
                    eventType: privmx.endpoint.thread.THREAD_UPDATE,
                    selectorType: .Container,
                    selectorId: threadId),
                group: "SOME_UNIQUE_IDENTIFIER",
                cb:{ eventData in
                    // some actions when a thread is updated
                }),
            PMXEventCallbackRegistration(
                request: .thread(
                    eventType: privmx.endpoint.thread.THREAD_STATS,
                    selectorType: .Context,
                    selectorId: CONTEXT_ID),
                group: "SOME_UNIQUE_IDENTIFIER",
                cb:{ eventData in
                    // some actions when a thread's stats change
                }),
            PMXEventCallbackRegistration(
                request: .thread(
                    eventType: privmx.endpoint.thread.THREAD_STATS,
                    selectorType: .Container,
                    selectorId: threadId),
                group: "SOME_UNIQUE_IDENTIFIER",
                cb:{ eventData in
                    // some actions when a thread's stats change
                }),
            PMXEventCallbackRegistration(
                request: .thread(
                    eventType: privmx.endpoint.thread.THREAD_DELETE,
                    selectorType: .Context,
                    selectorId: CONTEXT_ID),
                group: "SOME_UNIQUE_IDENTIFIER",
                cb:{ eventData in
                    // some actions when a thread is deleted
                }),
            PMXEventCallbackRegistration(
                request: .thread(
                    eventType: privmx.endpoint.thread.THREAD_DELETE,
                    selectorType: .Container,
                    selectorId: threadId),
                group: "SOME_UNIQUE_IDENTIFIER",
                cb:{ eventData in
                    // some actions when a thread is deleted
                }),
            PMXEventCallbackRegistration(
                request: .thread(
                    eventType: privmx.endpoint.thread.COLLECTION_CHANGE,
                    selectorType: .Context,
                    selectorId: CONTEXT_ID),
                group: "SOME_UNIQUE_IDENTIFIER",
                cb:{ eventData in
                    // some actions when any thread's contents change
                }),
            PMXEventCallbackRegistration(
                request: .thread(
                    eventType: privmx.endpoint.thread.COLLECTION_CHANGE,
                    selectorType: .Container,
                    selectorId: threadId),
                group: "SOME_UNIQUE_IDENTIFIER",
                cb:{ eventData in
                    // some actions when a particular thread's contents change
                }),
            PMXEventCallbackRegistration(
                request: .thread(
                    eventType: privmx.endpoint.thread.MESSAGE_CREATE,
                    selectorType: .Context,
                    selectorId: CONTEXT_ID),
                group: "SOME_UNIQUE_IDENTIFIER",
                cb:{ eventData in
                    // some actions on any new message
                }),
            PMXEventCallbackRegistration(
                request: .thread(
                    eventType: privmx.endpoint.thread.MESSAGE_CREATE,
                    selectorType: .Container,
                    selectorId: threadId),
                group: "SOME_UNIQUE_IDENTIFIER",
                cb:{ eventData in
                    // some actions on new message in a particular thread
                }),
            PMXEventCallbackRegistration(
                request: .thread(
                    eventType: privmx.endpoint.thread.MESSAGE_UPDATE,
                    selectorType: .Context,
                    selectorId: CONTEXT_ID),
                group: "SOME_UNIQUE_IDENTIFIER",
                cb:{ eventData in
                    // some actions when any message is updated
                }),
            PMXEventCallbackRegistration(
                request: .thread(
                    eventType: privmx.endpoint.thread.MESSAGE_UPDATE,
                    selectorType: .Container,
                    selectorId: threadId),
                group: "SOME_UNIQUE_IDENTIFIER",
                cb:{ eventData in
                    // some actions when a message in a particular thread is updated
                }),
            PMXEventCallbackRegistration(
                request: .thread(
                    eventType: privmx.endpoint.thread.MESSAGE_UPDATE,
                    selectorType: .Item,
                    selectorId: messageId),
                group: "SOME_UNIQUE_IDENTIFIER",
                cb:{ eventData in
                    // some actions when a particular message is updated
                }),
            
            PMXEventCallbackRegistration(
                request: .thread(
                    eventType: privmx.endpoint.thread.MESSAGE_DELETE,
                    selectorType: .Context,
                    selectorId: CONTEXT_ID),
                group: "SOME_UNIQUE_IDENTIFIER",
                cb:{ eventData in
                    // some actions when any message is deleted
                }),
            
            PMXEventCallbackRegistration(
                request: .thread(
                    eventType: privmx.endpoint.thread.MESSAGE_DELETE,
                    selectorType: .Container,
                    selectorId: threadId),
                group: "SOME_UNIQUE_IDENTIFIER",
                cb:{ eventData in
                    // some actions when a message in a particular thread is deleted
                }),
            PMXEventCallbackRegistration(
                request: .thread(
                    eventType: privmx.endpoint.thread.MESSAGE_DELETE,
                    selectorType: .Item,
                    selectorId: messageId),
                group: "SOME_UNIQUE_IDENTIFIER",
                cb:{ eventData in
                    // some actions when a particular message is deleted
                })
        ])

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