Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Step 4.6: Add basic messages component
  • Loading branch information
dotansimha authored and DAB0mB committed Feb 26, 2017
1 parent 4794e37 commit 4efc827
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions client/imports/pages/chat/messages-page.component.ts
@@ -1,21 +1,40 @@
import {Component, OnInit} from "@angular/core";
import {NavParams} from "ionic-angular";
import {Chat} from "../../../../both/models/chat.model";
import {Messages} from "../../../../both/collections/messages.collection";
import {Observable} from "rxjs";
import {Message} from "../../../../both/models/message.model";
import template from "./messages-page.component.html";

@Component({
selector: "messages-page",
template: `Messages Page`
template
})
export class MessagesPage implements OnInit {
private selectedChat: Chat;
private title: string;
private picture: string;
private messages: Observable<Message[]>;

constructor(navParams: NavParams) {
this.selectedChat = <Chat>navParams.get('chat');

console.log("Selected chat is: ", this.selectedChat);
this.title = this.selectedChat.title;
this.picture = this.selectedChat.picture;
}

ngOnInit() {
let isEven = false;

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

return messages;
});
}
}

0 comments on commit 4efc827

Please sign in to comment.