Skip to content

Commit

Permalink
Step 7.18: Subscribe to 'messages'
Browse files Browse the repository at this point in the history
  • Loading branch information
dotansimha committed Nov 28, 2016
1 parent 9aace5d commit e3d16c4
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/pages/messages/messages.ts
Expand Up @@ -66,15 +66,19 @@ export class MessagesPage implements OnInit, OnDestroy {
}

ngOnInit() {
this.messages = Messages.find(
{chatId: this.selectedChat._id},
{sort: {createdAt: 1}}
).map((messages: Message[]) => {
messages.forEach((message: Message) => {
message.ownership = this.senderId == message.senderId ? 'mine' : 'other';
MeteorObservable.subscribe('messages', this.selectedChat._id).subscribe(() => {
MeteorObservable.autorun().subscribe(() => {
this.messages = Messages.find(
{chatId: this.selectedChat._id},
{sort: {createdAt: 1}}
).map((messages: Message[]) => {
messages.forEach((message: Message) => {
message.ownership = this.senderId == message.senderId ? 'mine' : 'other';
});

return messages;
});
});

return messages;
});

this.autoScroller = MeteorObservable.autorun().subscribe(() => {
Expand Down

0 comments on commit e3d16c4

Please sign in to comment.