forked from ng-book/angular2-rxjs-chat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChatThreads.ts
More file actions
75 lines (66 loc) · 1.73 KB
/
ChatThreads.ts
File metadata and controls
75 lines (66 loc) · 1.73 KB
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
import {
Component,
OnInit,
ChangeDetectionStrategy
} from '@angular/core';
import {ThreadsService} from '../services/services';
import {Observable} from 'rxjs';
import {Thread} from '../models';
@Component({
inputs: ['thread'],
selector: 'chat-thread',
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 *ngIf="selected">•</span>
</h5>
<small class="message-preview">{{thread.lastMessage.text}}</small>
</div>
<a (click)="clicked($event)" class="div-link">Select</a>
</div>
`
})
export class ChatThread implements OnInit {
thread: Thread;
selected: boolean = false;
constructor(public threadsService: ThreadsService) {
}
ngOnInit(): 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',
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<!-- conversations -->
<div class="row">
<div class="conversation-wrap">
<chat-thread
*ngFor="let thread of threads | async"
[thread]="thread">
</chat-thread>
</div>
</div>
`
})
export class ChatThreads {
threads: Observable<any>;
constructor(public threadsService: ThreadsService) {
this.threads = threadsService.orderedThreads;
}
}