Skip to content

Commit

Permalink
Step 5.30: Determine message ownership based on sender id
Browse files Browse the repository at this point in the history
  • Loading branch information
dotansimha authored and DAB0mB committed Dec 24, 2016
1 parent 4eabd3e commit 9d567e8
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/pages/messages/messages.ts
Expand Up @@ -16,11 +16,14 @@ export class MessagesPage implements OnInit, OnDestroy {
messages: Observable<Message[]>;
message: string = "";
autoScroller: MutationObserver;
senderId: string;

constructor(navParams: NavParams, element: ElementRef) {
this.selectedChat = <Chat>navParams.get('chat');
this.title = this.selectedChat.title;
this.picture = this.selectedChat.picture;
this.senderId = Meteor.userId();

}

private get messagesPageContent(): Element {
Expand All @@ -44,15 +47,12 @@ export class MessagesPage implements OnInit, OnDestroy {
}

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;
message.ownership = this.senderId == message.senderId ? 'mine' : 'other';
});

return messages;
Expand Down

0 comments on commit 9d567e8

Please sign in to comment.