I'm wrapping up the development of a mobile app (ionic, but irrelevant), backed by a backend developed in Ruby on Rails 5, irrelevant again since this is more of a theoretical question/issue.
The thing here is, given the fact that users in the mobile application can log in or not (they've got a bunch of functionalities, and maybe half of those can be accessed by not logged in users), how should I handle the storage of the notification itself and the read state? Note: with notification I'm not referring to a push notification, but to the "message" that stays in a side menu inside the app (I've got push delivery covered).
The main issue here is: I want to be able to track the read notifications to prevent them from being marked as unread in case the user reinstalls the app (imagine 50 unread notifications just because you reinstalled).
I began with a model as follows for storing the notifications in the backend:
- id
- user_id
- push_notification_id (reference to the push notification id, irrelevant)
- read: Boolean
- content: Text
With this model, I'd insert a row for every user that needs to be notified, and track with a boolean column whether it was read or not. The issue is, only registered users could have notifications.
A second option is the removal of the user_id reference and the "read" attribute server-side, and assume I'm always gonna notify everyone, not some users. But now, I need a way to track which notifications were read. I could do that locally in the mobile app storing some ids in the local storage, but then again those would be deleted in case of reinstall.
A third option I've thought of, is to implement the second option with an "expiry" column server-side, which indicates when a notification should stop being "unread" by default in case of a new app install. This is the best I've got so far, but I'm not really convinced.
I know I'm asking for a lot of things here, but I am just looking for a good implementation model someone has made before, since I've been unable to find anything googling, and I'm sure this is a heavily repeated design pattern.
Thank you!