rpaschoal / ng-chat

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

How to implement onMessagesSeen? #169

Closed glenelkins1984 closed 3 years ago

glenelkins1984 commented 3 years ago

Hi

I've got a custom history method to pull messages stored in a database from a php api, this all works fine as below:

getMessageHistory(userId: any): Observable<Message[]> {

    return this.api.post('user/messages/history/'+userId,{hideLoader:true}).pipe(
      map((response:ApiResponseInterface)=>{

        let messages =  <PrivateMessageInterface[]>response.data.messages;

        console.log("MESSAGE HISTORY",messages);

        return messages.map((message: PrivateMessageInterface)=>{

          let m = new Message();
          m.dateSent = new Date(message.sentOn);
          m.message = message.message;
          m.toId = message.sentTo.apiKey;
          m.fromId = message.sentFrom.apiKey;
          m.type = 1;
          m.dateSeen = null;

          return m;
        })
      })
    );
  }

As you can see, i set the dateSeen to null so i can get the number appearing and your document states an event is fired when a message is seen "onMessagesSeen" - but you don't explain how to implement this event? Just adding onMessagesSeen() to my adapter doesn't do anything when a chat is opened with unseen messages.