Hotwire Discussion

Push data to selected users

Hello,
I am using Turbo Streams.
I wanted to know if it is possible to push data to selected users through a query, but also push other data to a single user.
The idea is to recreate a kind of notification bar like Facebook.
With the example image attached: “Leslie Alexander” mentions me in a comment. I would then be the only one to be notified. Only me will receive this notification.
Another case, “Kathryn Murphy” posts a link. All users who are friends of this person should be notified.
I don’t see how to do it at all. Thank you for helping me :slight_smile:
Capture

Hi,

A have a polymorphic notification model, a user that mention me create a notification, a user that post a link create a notification…
A notification belongs to a user and is related to an object… create by another user.

So, in the Kathryn Murphy case:

  1. she post a link
  2. after_create a link, we check if Kathryn Murphy has some friends, or some followers, and, if so, then we create a notification for each friends/followers
  3. after_create a notification, we broadcast it to the correct turbo_stream channel

You can customize the notification to know when Kathryn create a new link or update a link.

Cordialement,

Thanks @nodalailama
Is it possible to see some code to understand better?

You might want to have a look at the noticed gem

It provides you a nice model for notifications and different delivery methods.