Seb
Seb2y ago

Tips/advice on how to build an activity/updates feed for a multi-user app

We're building an internal CRM/Project Management tool for our team to use and we want full realtime support (hence why were looking at Convex) but we're curious about the best approach to build an activity/updates feed. I.e. if user A logs in and creates a new client or project, when user B logs in next they should see an indicator that there has been an update and they can click to show a feed which would show that user A created a client or project. User b can then dismiss/delete these notifications or mark them as read. Now user C logs in and they also see these updates and they remain unread. Likewise this would also work in realtime so if user A and user B are both logged in and user A creates a new client, user B should see it immediately and perhaps also a toast notification. I would love to see a tutorial on this kind of use case!
4 Replies
Michal Srb
Michal Srb2y ago
Hey @Seb, high level how I’d model this: - “events” (fe adding a client) table - “users” table - “notifications” table has user_id, event_id, read_status fields When a user takes an action that creates an event, you also create a notification for all relevant other users. For each user you can then query their notifications and manage their read status, deletion etc.
Seb
SebOP2y ago
Ok and how would we create these new documents for notifications and events? Is that a function that runs on the server? Is there some kind of trigger we can use to run this function? Or do we need to do it in our code? So let's say we have 10 users, that means every action that creates an event also creates 10 notification documents. That seems overkill and would very quickly create hundreds and thousands of documents in the notifications table. But maybe this is ok? And I guess there is no real other way to do it?
ian
ian2y ago
You would insert the documents the same as other data in Convex: in mutations which run server-side. https://docs.convex.dev/functions/mutation-functions You could have a query for recent notifications for each user, and compute an unread badge from that. https://docs.convex.dev/functions/query-functions If you wanted to trigger an action, like sending an email, you could do that from the mutation using the scheduler https://docs.convex.dev/scheduling/scheduled-functions For cleanup I would recommend a cron that deletes notifications older than 30 days, or whatever period feels right for your application. https://docs.convex.dev/scheduling/cron-jobs
Mutations | Convex Developer Hub
Mutations insert, update and remove data from the database, check authentication
Queries | Convex Developer Hub
Queries are the bread and butter of your backend API. They fetch data from the
Scheduled Functions | Convex Developer Hub
Convex allows you to schedule functions to run in the future. This allows you to
Cron Jobs | Convex Developer Hub
Convex allows you to schedule functions to run on a recurring basis. For
Michal Srb
Michal Srb2y ago
That seems overkill and would very quickly create hundreds and thousands of documents in the notifications table. But maybe this is ok? And I guess there is no real other way to do it?
@Seb this is how stateful notifications work, for example on Facebook/Instagram. Alternatively, for mobile, you could use push notifications and rely only on client state, but this could lead to users missing notifications and wouldn't work if you have multiple platforms. To limit the total number of documents you could also implement a retention period, and automatically delete notifications older than <X> days.

Did you find this page helpful?