rodwatkins

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

Showing Posts 1 to 9

OvermindDL1

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

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

OvermindDL1

In what way? The notifications via broadcasting? The database itself? The helpers that tie them together?

david

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?

  1. A separate notification table for each model) ie model_a_notifications, model_b_notifications.
  2. A many-to-many association with a generalized notification?

Thanks

OvermindDL1

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

josevalim

Creator of Elixir

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

david

Thanks for the advice José! :smile:

rodwatkins

rodwatkins OP

Good idea. That will simplify the approach In was taking. Thanks

OvermindDL1

OvermindDL1

That’s what I do via a PostgreSQL JSONB (Ecto :map) type for my generic notification store. :slight_smile:

— All posts loaded —

Where Next? Top

Trending in Discussions Top

budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
axelson
Hi there! :wave: @frigidcode and I (but mostly him) have been running an Elixir Book club, we’re almost done with Designing Elixir Syste...
New
budgie
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with. But I don’t use it anymore. Serverless was the promis...
New
jtormey
Lately I’ve been thinking about how to organize components as a LiveView application grows. One of the pain points I’ve found (for myself...
New
Null-logic-0
What IDE or editor are you using for Elixir development? Personally, I use Zed, and I really like it, but sometimes I wish there were a ...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New

Other Trending Topics Top

KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
kip
In 2021 I started a new library called Tempo with the objective of modelling time as a set of intervals - not as instants. In 2022 I gave...
New
OndrejValenta
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly) AI dream has many faces, but general...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews