Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle read notifications in mobile app backend

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!

like image 897
Martí Gascó Avatar asked Nov 09 '16 21:11

Martí Gascó


People also ask

Can apps read my notifications?

Built-in voice Notifications for Android phonesTalkback will read out loud notifications as they arrive along with everything on your screen (not just notifications). However, this changes the way you interact with your phone, which might be a drawback if you are looking for app to only read out loud notifications.

How do mobile app notifications work?

Push notifications look like SMS text messages and mobile alerts, but they only reach users who have installed your app. All the mobile platforms – iOS, Android, Fire OS, Windows and BlackBerry – have their own services for supporting push.

How do I handle background notifications on Android?

When your app is in the background, Android directs notification messages to the system tray. A user tap on the notification opens the app launcher by default. This includes messages that contain both notification and data payload (and all messages sent from the Notifications console).

What are the two types of notifications?

Android proposes several types of notifications to inform the user: notifications in the system bar. sound notifications.


1 Answers

Before you send a notification to user, generate a hash, place it into your Notification table and in the notification body. On mobile side, when user opens the push notification - you need to send a request to the server with that hash and notification-type (if you want). Server gets the hash and finds out which user and notes that the notification was read, and you can set your flag (isRead) to true,

like image 120
Yelnar Avatar answered Oct 11 '22 15:10

Yelnar