How to handle reading notifications in the backend of a mobile application

I am completing the development of a mobile application (ionic but non-essential) supported by a backend developed in Ruby on Rails 5 that is irrelevant, as this is more of a theoretical question / problem.

The point here is that users in the mobile application can log in or not (they have a bunch of functionality, and perhaps half of them can be accessed if you do not log in), how should I handle the storage of the notification itself and the status reading? Note: with a notification, I do not mean a push notification, but for a "message" that remains in the side menu inside the application (I have current delivery enabled).

The main problem is this: I want to be able to track read notifications so that they are not marked as unread if the user reinstalls the application (submit 50 unread notifications just because you reinstalled).

I started with the model as follows to store notifications in the backend:

  • ID
  • user_id
  • push_notification_id (link to the push notification identifier is not relevant)
  • : Boolean
  • content: Text

With this model, I would insert a row for each user that should be notified, and track with a boolean column whether it was read or not. The problem is that only registered users can receive notifications.

The second option is to delete the user_id link and the read attribute on the server, and suppose that I will always notify all, not some users. But now I need a way to keep track of which notifications have been read. I could do this locally in a mobile application, storing some identifiers in local storage, but then they will be deleted in case of reinstallation.

The third option that I was thinking about is to implement the second option with the "expiry" server server, which indicates when the notification ceases to be "unread" by default when a new application is installed. This is the best I've received so far, but I'm not sure.

I know that I ask a lot of things here, but I'm just looking for a good implementation model that someone has done before, since I could not find anything in the search engines, and I am sure that this is a very repetitive design.

Thanks!

+6
source share
2 answers

This example can be found with users at unow.com.

https://github.com/universitynow/message_center/tree/ce3ed6e17b4e650eae53e031ea764012ce6cbf4b/lib/concerns/models

The "item" model should give you some ideas on how to pass reading status to another recipient.

0
source

We used a similar approach like you, with some changes:

  • for a problem with a registered / unregistered user, you can change the user_id for some uid device so that the user does not need to register to track read
  • instead of accumulating reading information in one table, we had a table of unread notifications, and at the time of chnage we moved the reads to a new table β†’ the table will not become huge and operations on it (for example, counting) will be fast (depending on the number of users but think about the future!)
  • plus some functions like storing date_insert and running monthly work to clear records older than a year.
0
source

Source: https://habr.com/ru/post/1012189/


All Articles