rpaschoal / ng-chat

💬 A simple facebook/linkedin lookalike chat module for Angular applications.
MIT License
155 stars 92 forks source link

Double message when using getMessageHistory #208

Closed rcampion closed 2 years ago

rcampion commented 2 years ago

I managed to get a reference to the ngChatInstance from within the chat adapter.

I call triggerOpenChatWindow when I receive a message.

Now I have implemented getMessageHistory and getting the data from a web service.

When the first time a chat participant window is opened, I am getting two messages instead of one.

rcampion commented 2 years ago

This only happens when the chat window has not been opened yet.

rcampion commented 2 years ago

Fixed by saving state using onParticipantChatOpened and onParticipantChatClosed.

The problem was that I send a WebSocket message and save history to database within sendMessage and I call onMessageRecieved after I receive the WebSocket message.

Now I use a DataSharing service to maintain participant state and only call triggerOpenChatWindow when chat window is closed. Only call onMessageRecieved when chat window is open.

Seems to be working fine.

https://www.zdslogic.com