How to Create Unread Message Notifications for an App

Hi everyone,

I am trying to create some user notifications that show a feed of recent activity like messages or other actions that have been done, similar to the example below:

image

However I don’t know where to get started in order to develop a feature like this. Can anyone provide some guidance with regards to the table structure that I should have in order to enable this type of functionality.

Should I create a new table for notifications and then everytime a certain action happens, I would push it to the notification table and have a read/unread field in there to identify new notifications? or would you do it in a different way?

Your feedback is much appreciated.

How about a field in the notifications table which contains a status? Then you can use values like ‘new’ or ‘unread’ or ‘read’. Once that’s in place, do a query which counts all the records with the status ‘unread’ and that will give you your number to display in the badge.

Yes I can have a status field in there, but my question is would that be the best option to create the notification feed functionality? or would you do it differently?

For example how would I do this if I have different users, and each user views different information at a time?

Create your query where the conditions are made up of logged in user ID and notification status. This would mean each user would see the total for their login.

Sorry I still don’t understand, can you explain how that would work. Lets say I have created the following table for notifications feed:

Action: New message
Status: New
Created date: 07/09/2020
Created by: 1
Logged in user: ??? ( how will this work if this notification has to show up to 5 or more users?)

I’m not sure what you mean by showing up for 5 or more users.

You should use Security Provider to get the logged in user identity. Then you do your query along the lines of status = 'New' and created_by = {{identity}}.

Ok I will give it a try like this. Thanks

1 Like

Hey @webmaster,
I would definitely create a new specific table for notifications, here is how I would do that, with for example these rows:

  • ID
  • Title
  • Description
  • Date
  • Recipients
  • Read_by

So every time a notification is created, at least one User ID is added in the Recipients row.

Let’s say you send a notification for a new post in the forum, people who subscribed to this thread will have their User ID added as a Recipient in this notifications table.

This notification will appear as “New” or “Unread” until the recipient read this post or click on a “Mark as read” button for example, which will simply add the current user ID in the “Read_by” row of this notification.

Then, to show the correct notifications to your users, you can simply create a request (Server action) to look for all notifications to show with those conditions:

  • The Recipients row should contain the current User ID
  • The Read_by row should not contain the current User ID
  • Sort by date so the latest notifications are displayed on top.

I hope this will help! :slightly_smiling_face:

4 Likes

Perfect this is what I was trying to figure out myself. Thanks a lot

1 Like

Hello forum

Has anyone implemented this with multiple messages:

If we are talking about the messenger message area (telegram/signal), how to implement that unread messages are marked as read automatically?

I would be grateful for any advice and recommendations.