Skip to content

Commit

Permalink
Step 6.12: Add title and picture to chat
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilkisiela authored and DAB0mB committed Feb 26, 2017
1 parent 48cc20f commit 8eb7ebf
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion client/imports/pages/chats/chats.component.ts
@@ -1,6 +1,7 @@
import {Component, OnInit} from "@angular/core";
import template from "./chats.component.html"
import {Observable} from "rxjs";
import {Meteor} from 'meteor/meteor';
import {Chat} from "../../../../both/models/chat.model";
import * as moment from "moment";
import style from "./chats.component.scss";
Expand All @@ -21,6 +22,7 @@ import {NewChatComponent} from './new-chat.component';
})
export class ChatsComponent implements OnInit {
chats: Observable<Chat[]>;
senderId: string;

constructor(
private navCtrl: NavController,
Expand All @@ -29,6 +31,7 @@ export class ChatsComponent implements OnInit {
) {}

ngOnInit() {
this.senderId = Meteor.userId();
this.chats = Chats
.find({})
.mergeMap<Chat[]>(chats =>
Expand All @@ -44,7 +47,16 @@ export class ChatsComponent implements OnInit {

)
)
).zone();
).map(chats => {
chats.forEach(chat => {
const receiver = Meteor.users.findOne(chat.memberIds.find(memberId => memberId !== this.senderId))

chat.title = receiver.profile.name;
chat.picture = receiver.profile.picture;
});

return chats;
}).zone();
}

addChat(): void {
Expand Down

0 comments on commit 8eb7ebf

Please sign in to comment.