rodwatkins
Hello,
I am looking for some advice about setting up notifications through channels. Here is what I am designing.
I have a private web site where users work closely together. So I wanted a way to send notifications of (model) changes to all users currently online. Notifications will be saved to the database (as part of a completely audited system).
Here is how I want it to behave. When a user is logged in, they receive notifications whenever a model is changed. As described in the channels chapter in “Programming Phoenix”, I planned to store a last_seen_id so that users can receive only the notifications they missed while disconnected. But I want that last_seen_id to be stored somewhere and not be lost when the user closes their browser or uses a different browser. So the best answer seems to be storing that id in the database.
Thus, when a message is sent successfully, the browser could send a message back with the new last_seen_id and then the server persists that to the database. Then when the client reconnects, the last_seen_id can be retrieved from the channel if it exists or look it up in the db if not.
Does that design makes sense? Or is there a better way.
Cheers
Rod
Trending in Discussions
Other Trending Topics
Latest Phoenix Threads
Chat & Discussions>Discussions
Latest on Elixir Forum
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #phoenix_html
- #iex
- #graphql
- #genstage
- #ai
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #performance











First 9 of 9 Posts
OvermindDL1
That is precisely what I am doing. The client just sends a ‘seen’ message to the notification channels (I have multiple for different notification types) to indicate that it has seen up to ‘now’.
david
Would you mind elaborating on how you structured your notification relationships?
I’m trying to accomplish something similar, Multiple Polymorphic Associations in Ecto, and would be curious how you tracked your model changes in the db.
Thanks!
OvermindDL1
In what way? The notifications via broadcasting? The database itself? The helpers that tie them together?
david
Hi there!
I was predominantly meaning in the database itself and/or the helpers.
My biggest challenge was:
How do you structure your tables to track the model changes?
model_a_notifications,model_b_notifications.notification?Thanks
OvermindDL1
I just did it very simple, a table of just ‘topics’, ‘users’, and 'datetime’s as I recall (do not have it in front of me at moment).
josevalim
For the notifications case, you can also put all the relevant information in a
map, including the user_id, post_id and everything else you may want to show the user. When doing a notification system, it is often best to have all the data you need in a single lookup instead of traversing multiple tables after the information you want. However, do include the source data in case you need to reconstruct the notifications later on.david
Thanks for the advice José!
rodwatkins
Good idea. That will simplify the approach In was taking. Thanks
OvermindDL1
That’s what I do via a PostgreSQL JSONB (Ecto :map) type for my generic notification store.