Permalink
Browse files

Step 6.6: Add basic messages component

  • Loading branch information...
dotansimha authored and darkbasic committed Jan 24, 2017
1 parent dffb2b5 commit 6996cdad9d123b74933dc770fbaa30da447b1c59
Showing with 21 additions and 4 deletions.
  1. +21 −4 src/pages/messages/messages.ts
@@ -1,21 +1,38 @@
import { Component, OnInit } from '@angular/core';
import { NavParams } from 'ionic-angular';
import { Chat } from 'api/models';
import { Chat, Message } from 'api/models';
import { Observable } from 'rxjs';
import { Messages } from 'api/collections';
@Component({
selector: 'messages-page',
template: `Messages Page`
templateUrl: 'messages.html'
})
export class MessagesPage implements OnInit {
selectedChat: Chat;
title: string;
picture: string;
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 6996cda

Please sign in to comment.