Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Injectable } from '@angular/core';
- import { BehaviorSubject } from 'rxjs';
- import { UserRestService } from '../../services/user.rest.service';
- @Injectable()
- export class DirectoryService {
- users: any[] = [];
- users$: BehaviorSubject<Object[]>;
- constructor(
- private userRestService: UserRestService
- ) {
- this.users$ = new BehaviorSubject(this.users);
- this.__uploadUsers();
- }
- protected __uploadUsers():void {
- let uploader = () => {
- let recentDate = this.users.length ? new Date(this.users[this.users.length - 1].ModifiedTime) : new Date(0);
- this.userRestService.getUsersFrom(recentDate, 100)
- .subscribe(
- (value: Object[]) => {
- if (value && value.length) {
- this.__uploadAvatars(value);
- this.users = this.users.concat(value);
- this.users$.next(this.users);
- uploader();
- } else {
- this.users$.complete();
- }
- }
- );
- };
- uploader();
- }
- protected __uploadAvatars(users: Object[]):void {
- users.forEach((user: any) => {
- user.userImage = this.userRestService.getUserPhotoById(user.Id);
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement