Implementing Stories feature in Android

Viewed 358

I want to implement something similar to the Stories feature in Facebook or WhatsApp.

Possible approaches :

  1. At first, I wanted to open a web socket so I could receive the latest Stories updates (new story from a friend, or if a story was removed).

  2. There'a another alternative - getting those updates using FCM pushes. A service which receives the pushes broadcasts the "new story"/"story removed" broadcast using a LocalBroadcastManager, and the suitable activity which is registered to this broadcast receives that update.

Using the push approach, it would mean that even if the app is killed, the push can still be triggered. It seems a bit of a waste.

But considering that there might slow connection, connection drops, etc., the websocket is also quite "vulnerable".

Also, what if 24 hours of a story expire, how do I make sure I always remove that story from the Stories list view and not keep displaying it ? With a socket, we may lose connection. if we reconnect after we were to supposed to be notified that the Story time expired, we would still display that Story.

1 Answers

Just store the stories in some sort of database, together with their creation dates. A client can then periodically fetch for new stories. Based on the creation date, the client can calculate the age of the story and decide to show it or not.

If a story has been seen by the client, he can store that information in local storage so watched stories can be displayed as old stories.

Now for the cleanup part, there are two options. Either you write a program that runs on a server 24/7, that like a client, periodically fetches the stories from the database, checks their age and deletes those which are too old. The other approach would use the same concept, but all normal clients delete old stories from the database.

The second option would be very insecure though, because the age calculation could be manipulated on the client side, either by mistake or by an attacker.

Related