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
kamilkisiela authored and dotansimha committed Nov 27, 2016
1 parent 5489fed commit b983ca4
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions client/imports/pages/chat/messages-page.component.ts
Expand Up @@ -37,15 +37,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 b983ca4

Please sign in to comment.