Building an app notification feature

Hi I am building a notifications system for my app - bit like the notifications about releases Bubble shows us when we log in.

So I have database tables as follows:

Notifications

  • Notification_ID
  • Notification_Msg
  • Users (List of users)

Users

  • Username

Notification-User-Mapping

  • Notification_ID
  • User_ID
  • Notification_Ack (yes/no)

I create a notification into the Notifications Table with multiple users:

  • Notification_ID =001
  • Notification_Msg = test this notification
  • Users = bob, sue, jim

I want each user to be able to acknowledge to say they have seen the notification hence I need the Notification-User-Mapping table so each user can Ack their notifications.

My problem is I am not sure how to Loop through the users and add a row for each into Notification-User-Mapping. What I should see in that table is:

Notification_ID =001
User_ID = Bob
Ack = True

Notification_ID =001
User_ID = Sue
Ack = False

Notification_ID =001
User_ID = Jim
Ack = True

I think I can do it as I add the notification into the Notifications table but can’t figure it out. Here is where I got to. Any ideas greatly received

SImon

To my knowledge - loops don’t exist in bubble at the moment. There are workarounds, but why not to go simplier?

Notification:

  • notification_msg
  • users (list of user)
  • ack (list of user)

Then simple search/filter on notification should work, eg. show notifications which are to current user (notification.users contains current user) but not acknowledged yet (notification.ack list doesn’t contain current user).
Then acknowledge of notification is just adding current user to ack list of given notification.

If you prefer to keep your data structure - forget adding ack with false. Add only read ones, the moment they’re acknowledged:
Notification_ID =001
User_ID = jim
Ack = True

Then these not acknowledged you can find doing search for notifications.users contains current user and search for user_notification_mapping for current user with specific notification id : count = 0

3 Likes

Didn’t think of that - will give it a try.

Thanks

Perfect that worked like a dream. Thanks so much for taking the time to reply.

Simon

I might be tempted to have the “unacknowledged” notifications stored on the user (you could do both) so that it is quicker to pull back their unread notifications.

In terms of “loops” this is what the “Schedule an API Workflow on a List” is for. Loop through a List of Users and do something to each user. Or indeed create a new thing for each one so you can have your Notification Table (you might want to store stuff, like date, for each ackknoeldegment).

1 Like