PrivMX DOCS
Version 2.6/Inboxes

Inbox Updates

Events play a crucial role in modern applications, allowing them to instantly respond to changes in stored data. Monitoring and reacting to entries and Inbox-related events, is essential for maintaining up-to-date records, triggering workflows, and ensuring synchronization across various parts of the system.

Types of Events

Before receiving Events, your application must first subscribe to a group of events. In the case of Inbox, types of events are the following:

Inbox events:

  • inboxCreated - triggers when a new Inbox is created in your Context
  • inboxDeleted - triggers when an Inbox is deleted from your Context
  • inboxUpdated - triggers when an Inbox is updated in your Context

Entry events:

  • inboxEntryCreated - triggers when an entry is sent to an Inbox
  • inboxEntryDeleted - triggers when an entry is deleted from an Inbox

Handling Inbox Events

The sample code on this page is based on the same assumptions mentioned in Working with Inboxes.

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

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

// handle events
core::EventQueue eventQueue {core::EventQueue::getInstance()};
std::thread t([&](){
    while(true) {
        core::EventHolder event = eventQueue.waitEvent();
        std::cout << "onEvent: " << event.type() << std::endl;
        std::cout << event.toJSON() << std::endl;
    }
});
t.detach();

auto subscriptions = inboxApi.subscribeFor(std::vector<std::string>{
    // subscribe to `inboxCreated` events in the given Context
    inboxApi.buildSubscriptionQuery(
        inbox::EventType::INBOX_CREATE, 
        inbox::EventSelectorType::CONTEXT_ID, 
        CONTEXT_ID
    ),
    // subscribe to `inboxUpdated` events in the given Context
    inboxApi.buildSubscriptionQuery(
        inbox::EventType::INBOX_UPDATE, 
        inbox::EventSelectorType::CONTEXT_ID, 
        CONTEXT_ID
    ),

    // subscribe to `inboxEntryCreated` events in the given Inbox
    inboxApi.buildSubscriptionQuery(
        inbox::EventType::ENTRY_CREATE, 
        inbox::EventSelectorType::INBOX_ID, 
        inboxId
    )
});

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.

On this page