I'm looking for the best approach to dispatch event to subscribed user based on user info condition.
My use case is:
- user with username = "A" subscribed to doc_created events (https://docs.kuzzle.io/sdk/js/7/controllers/realtime/subscribe/#subscribe)
- user with username = "B" also subscribed to doc_created events (same index + collection)
- Then I have a doc created with a field : forUser = "A"
- My goal is to dispatch the "doc_created" (https://docs.kuzzle.io/core/2/framework/events/generic-document/#generic-document-afterwrite) event only to user with username = "A" and drop the message that is sent to the user with username = "B".
Any advice for this use case?
In order to achieve that, the best way would be to inject users subscriptions with a filter on the documents
authormetadata.This injection could be done with a pipe on the
realtime:beforeSubscribeevent.You need to modify the filters to include a clause on the document author but also keep the original filters with the and operator. You can get inspiration with this example: