Kuzzle / how to dispatch event only to subscribed user based on a condition

79 Views Asked by At

I'm looking for the best approach to dispatch event to subscribed user based on user info condition.

My use case is:

Any advice for this use case?

1

There are 1 best solutions below

0
Aschen On

In order to achieve that, the best way would be to inject users subscriptions with a filter on the documents author metadata.

This injection could be done with a pipe on the realtime:beforeSubscribe event.

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:

app.pipe.register('realtime:beforeSubscribe', request => {
  request.input.body = {
    and: [
      {
        equals: { '_kuzzle_info.createdAt': request.context.user._id }
      },
      request.input.body
    ]
  };

  return request;
});