Show Message Status Like WhatsApp

1,370 views
Skip to first unread message

Vikas Ranjan

unread,
Dec 10, 2015, 10:46:05 AM12/10/15
to Firebase Google Group
I'm building a on-to-one chat application using Firebase.

I want to implement message-status feature (for ex. pending, sent, delivered, read) like WhatsApp or any other one-to-one Chat application.
How shall I structure message data in Firebase in order to implement this feature.
I also want to show unread message count to the users in each chat.

My current data structure for messages in Firebase looks like this, which is not adequate to implement this feature:




Any help will be deeply appreciated.

thurst0n

unread,
Dec 10, 2015, 4:16:59 PM12/10/15
to Firebase Google Group
I don't really have a full solution for you but maybe I can help you think through the problem. Since my strength is software development and not database architecture I always think about how I'm going to implement the code. (Translation: what makes my life easier programmer)

First let's define what the status' really mean *your definition may vary
pending - user has made client side request for their message to be sent
sent - server has received the message
delivered - recipient client has received the message
read - recipient user has opened the specific message on their device.



the server doesn't really need to know about pending, seems like that would just be the default status on client side until the client can confirm the server has received the message at which point we can update the client to show that the message is sent. Sent seems like it should be the default setting on the server side. By the nature of firebase data will be read as soon as it's changed through a callback. 

For example on the webside when we read data like in the example: 
"myFirebaseRef.child("location/city").on("value", function(snapshot) {
  alert(snapshot.val());  // Alerts "San Francisco"
});
the value event will fire once for the initial state of the data, and then again every time the value of that data changes. "

Value event listener on the android side.
It's essentially being delivered as soon as it's sent (assuming the client has network connection), so as soon as the callback or listener triggers put a call in your logic to update it to delivered. And finally, you'd need to decide which events the recipient can make that qualify as "Reading" (selecting message from conversation list, focusing on text entry box, (if mobile looking at the screen?)) And make the update here too.

So on the database side you can just have maybe a status variable that is initially "sent" and then update it as events are triggered by the recipient.

Seems like just another variable that you'll constantly update. 

Good luck!

Vikas Ranjan

unread,
Dec 15, 2015, 7:10:54 AM12/15/15
to Firebase Google Group
Thank you for this amazing explanation of the whole concept. This is really helpful.
Your answer definitely made us move forward but we are still brainstorming on how to structure our data to implement this.
Reply all
Reply to author
Forward
0 new messages