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
|
@Injectable()
export class BoxService {
windows: Box[];
currentBox: Subject<Box> =
new BehaviorSubject<Box>(new Box());
currentBoxMessages: Observable<Message[]>;
constructor(public messagesService: MessagesService) {
this.windows = [
];
this.currentBoxMessages = this.currentBox
.combineLatest(messagesService.messages,
(currentBox: Box, messages: Message[]) => {
if (currentBox && messages.length > 0) {
return _.chain(messages)
.filter( (message: Message) =>
(message.thread.id === currentBox.id))
.map( (message: Message) => {
message.isRead = true;
return message; })
.value();
} else {
return [];
}
});
};
addChatWindow(id?: string, thread?: Thread): Box {
const newBox: Box = new Box(id, thread);
this.windows.push(newBox);
return newBox;
}
setCurrentBox(newBox?: Box): void {
this.currentBox.next(newBox);
}
}
export const boxsServiceInjectables: Array<any> = [
BoxService
]; |
Partager