ng-book / angular2-rxjs-chat

Example Chat Application using RxJS and Angular 2
1.67k stars 525 forks source link

How to know , particular Thread contains unread messages . #49

Open zahid49 opened 6 years ago

zahid49 commented 6 years ago

How can i get information that particular Thread contains unread messages. So , we can differentiate CSS of threads to look like unread.

vp93 commented 5 years ago

By using the action stream

markThreadAsRead: Subject<any> = new Subject<any>();

    // on the `updates` stream to mark the Messages as read
    this.markThreadAsRead
      .map( (thread: Thread) => {
        return (messages: Message[]) => {
          return messages.map( (message: Message) => {
            // note that we're manipulating `message` directly here. Mutability
            // can be confusing and there are lots of reasons why you might want
            // to, say, copy the Message object or some other 'immutable' here
            if (message.thread.id === thread.id) {
              message.isRead = true;
            }
            return message;
          });
        };
      })
      .subscribe(this.updates);
  }

now just use the isRead property on message to identify whether a message is read or not, and add the CSS accordingly.