forked from ng-book/angular2-rxjs-chat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChatThreads.ts
81 lines (72 loc) · 1.87 KB
/
ChatThreads.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/// <reference path="../../typings/app.d.ts" />
import {Component, View, NgFor, NgIf,
LifecycleEvent} from "angular2/angular2";
import {ThreadsService} from "../services/services";
import {RxPipe} from "../util/RxPipe";
import * as Rx from "rx";
import {Thread} from "../models";
@Component({
lifecycle: [ LifecycleEvent.onInit ],
properties: ["thread"],
selector: "chat-thread"
})
@View({
directives: [NgIf],
template: `
<div class="media conversation">
<div class="pull-left">
<img class="media-object avatar"
src="{{thread.avatarSrc}}">
</div>
<div class="media-body">
<h5 class="media-heading contact-name">{{thread.name}}
<span *ng-if="selected">•</span>
</h5>
<small class="message-preview">{{thread.lastMessage.text}}</small>
</div>
<a (click)="clicked($event)" class="div-link">Select</a>
</div>
`
})
class ChatThread {
thread: Thread;
selected: boolean = false;
constructor(public threadsService: ThreadsService) {
}
onInit(): void {
this.threadsService.currentThread
.subscribe( (currentThread: Thread) => {
this.selected = currentThread &&
this.thread &&
(currentThread.id === this.thread.id);
});
}
clicked(event: any): void {
this.threadsService.setCurrentThread(this.thread);
event.preventDefault();
}
}
@Component({
selector: "chat-threads"
})
@View({
directives: [NgFor, ChatThread],
pipes: [RxPipe],
template: `
<!-- conversations -->
<div class="row">
<div class="conversation-wrap">
<chat-thread
*ng-for="#thread of threads | rx"
[thread]="thread">
</chat-thread>
</div>
</div>
`
})
export class ChatThreads {
threads: Rx.Observable<any>;
constructor(public threadsService: ThreadsService) {
this.threads = threadsService.orderedThreads;
}
}