How to count chat badge number

I have configured a chat in the Ionic/Angular 4 application using google firebase. But I am struggling to configure how to count the number of new/unread messages (the badge). Can anyone help?