import { Component, OnInit, Inject, ViewChild } from '@angular/core'; import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material'; import { KEY_LOGIN_RES_INFO } from '@app/types/login-res-info.type'; import { KEY_VER_INFO } from '@app/types/ver-info.type'; import { SessionStorageService } from '@ucap-webmessenger/web-storage'; import { Store, select } from '@ngrx/store'; import * as AppStore from '@app/store'; import * as ChatStore from '@app/store/messenger/chat'; import { UserInfo } from '@ucap-webmessenger/protocol-sync'; import { UserInfoSS, UserInfoF, UserInfoDN } from '@ucap-webmessenger/protocol-query'; import { DialogService } from '@ucap-webmessenger/ui'; import { VersionInfo2Response } from '@ucap-webmessenger/api-public'; import { LoginResponse } from '@ucap-webmessenger/protocol-authentication'; import { map } from 'rxjs/operators'; export interface ProfileDialogData { userInfo: UserInfo | UserInfoSS | UserInfoF | UserInfoDN; } export interface ProfileDialogResult {} @Component({ selector: 'app-profile.dialog', templateUrl: './profile.dialog.component.html', styleUrls: ['./profile.dialog.component.scss'] }) export class ProfileDialogComponent implements OnInit { loginRes: LoginResponse; sessionVerinfo: VersionInfo2Response; isMe: boolean; isBuddy: boolean; isFavorit: boolean; constructor( public dialogRef: MatDialogRef, @Inject(MAT_DIALOG_DATA) public data: ProfileDialogData, private dialogService: DialogService, private sessionStorageService: SessionStorageService, private store: Store ) { this.sessionVerinfo = this.sessionStorageService.get( KEY_VER_INFO ); this.loginRes = this.sessionStorageService.get( KEY_LOGIN_RES_INFO ); } ngOnInit() { this.isMe = this.loginRes.userSeq === this.data.userInfo.seq; this.store.pipe( select(AppStore.MessengerSelector.SyncSelector.selectAllBuddy2), map(buddyList => { const users = buddyList.filter( buddy => buddy.seq === this.data.userInfo.seq ); this.isBuddy = users.length > 0; if (this.isBuddy) { this.isFavorit = users[0].isFavorit; } }) ); } onClickChat(userInfo: UserInfo | UserInfoSS | UserInfoF | UserInfoDN) { if (userInfo.seq === this.loginRes.userSeq) { this.store.dispatch( ChatStore.openRoom({ userSeqList: [this.loginRes.talkWithMeBotSeq] }) ); } else { this.store.dispatch(ChatStore.openRoom({ userSeqList: [userInfo.seq] })); } this.dialogRef.close(); } }