import { Component , OnInit } from '@angular/core' ; import { Location } from '@angular/common' ; import { Router } from '@angular/router' ; import { AddChat , GetUsers } from '../../../../graphql' ; import { ChatsService } from '../../../services/chats.service' ; @ Component ( { template : `
    <app-toolbar>
      <button class="navigation" mat-button (click)="goBack()">
        <mat-icon aria-label="Icon-button with an arrow back icon">arrow_back</mat-icon>
      </button>
      <div class="title">New chat</div>
    </app-toolbar>
    <div class="new-group" (click)="goToNewGroup()">
      <mat-icon color="secondary" aria-label="Icon-button with a group add icon">group_add</mat-icon>
      <div>New group</div>
    </div>
    <app-users-list [items]="users"
                    libSelectableList="single" (single)="addChat($event)">
    </app-users-list>
  ` , styleUrls : [ 'new-chat.component.scss' ] , } ) export class NewChatComponent implements OnInit { users : GetUsers . Users [ ] ; constructor ( private router , private location , private chatsService ) { } ngOnInit ( ) { this . chatsService . getUsers ( ) . users$ . subscribe ( users => this . users = users ) ; } goBack ( ) { this . location . back ( ) ; } goToNewGroup ( ) { this . router . navigate ( [ '/new-group' ] ) ; } addChat ( userId ) { const chatId = this . chatsService . getChatId ( userId ) ; if ( chatId ) { this . router . navigate ( [ '/chat' , chatId ] ) ; } else { const ouiId = ChatsService . getRandomId ( ) ; this . chatsService . addChat ( userId , this . users , ouiId ) . subscribe ( ) ; this . router . navigate ( [ '/chat' , ouiId ] , { queryParams : { oui : true } , skipLocationChange : true } ) ; } } }