title: Chat message with Google Firebase Realtime Database architecture with Unread Message counter and Last Message
body: <p>I'm creating a chat section for android apps. By using Google <a href="https://firebase.google.com" rel="noreferrer">Firebase</a>.
  Following task already completed</p>
  
  <p>Create chat node 
  2. Separate particular chat thread using two users information. 
  3. Read all message for single chat thread.  </p>
  
  <p>Now my question is below.
  1. How to retrieve last message by single chat thread.
  2. How to create a database where i can get counter of unread message counter. </p>
  
  <p>Attachment of my chat database and objective below. </p>
  
  <p><strong>Current objective.</strong> 
  <a href="https://i.stack.imgur.com/cnN2R.png" rel="noreferrer"><img src="https://i.stack.imgur.com/cnN2R.png" alt="enter image description here"></a> </p>
  
  <p><strong>Already done.</strong></p>
  
  <p><a href="https://i.stack.imgur.com/VPAoc.png" rel="noreferrer"><img src="https://i.stack.imgur.com/VPAoc.png" alt="enter image description here"></a></p>
  
  <p><strong>Firebase database architecture.</strong></p>
  
  <p><a href="https://i.stack.imgur.com/BtmzD.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/BtmzD.jpg" alt="enter image description here"></a> </p>
  
  <p>Now how it will be easier for me to create database for make solution this problem.  </p>