Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Step 6.6: Add basic messages component
- Loading branch information
1 parent
dffb2b5
commit 6996cda
Showing
1 changed file
with
21 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,21 +1,38 @@ | |||
import { Component, OnInit } from '@angular/core'; | import { Component, OnInit } from '@angular/core'; | ||
import { NavParams } from 'ionic-angular'; | 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({ | @Component({ | ||
selector: 'messages-page', | selector: 'messages-page', | ||
template: `Messages Page` | templateUrl: 'messages.html' | ||
}) | }) | ||
export class MessagesPage implements OnInit { | export class MessagesPage implements OnInit { | ||
selectedChat: Chat; | selectedChat: Chat; | ||
title: string; | |||
picture: string; | |||
messages: Observable<Message[]>; | |||
|
|
||
constructor(navParams: NavParams) { | constructor(navParams: NavParams) { | ||
this.selectedChat = <Chat>navParams.get('chat'); | this.selectedChat = <Chat>navParams.get('chat'); | ||
|
this.title = this.selectedChat.title; | ||
console.log('Selected chat is: ', this.selectedChat); | this.picture = this.selectedChat.picture; | ||
} | } | ||
|
|
||
ngOnInit() { | 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; | |||
}); | |||
} | } | ||
} | } |