diff --git a/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/profile/profile.dialog.component.html b/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/profile/profile.dialog.component.html index e906db4c..c8ab5d39 100644 --- a/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/profile/profile.dialog.component.html +++ b/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/profile/profile.dialog.component.html @@ -5,5 +5,7 @@ [isBuddy]="isBuddy" [isFavorit]="isFavorit" (openChat)="onClickChat($event)" + (toggleFavorit)="onClickToggleFavorit($event)" + (toggleBuddy)="onClickToggleBuddy($event)" > diff --git a/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/profile/profile.dialog.component.ts b/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/profile/profile.dialog.component.ts index a2e96594..e387083b 100644 --- a/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/profile/profile.dialog.component.ts +++ b/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/profile/profile.dialog.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit, Inject, ViewChild } from '@angular/core'; +import { Component, OnInit, Inject, ViewChild, OnDestroy } 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'; @@ -7,17 +7,20 @@ 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 * as SyncStore from '@app/store/messenger/sync'; -import { UserInfo } from '@ucap-webmessenger/protocol-sync'; +import { UserInfo, GroupDetailData } from '@ucap-webmessenger/protocol-sync'; import { UserInfoSS, UserInfoF, UserInfoDN } from '@ucap-webmessenger/protocol-query'; -import { DialogService } from '@ucap-webmessenger/ui'; +import { DialogService, ConfirmDialogComponent, ConfirmDialogData, ConfirmDialogResult } from '@ucap-webmessenger/ui'; import { VersionInfo2Response } from '@ucap-webmessenger/api-public'; import { LoginResponse } from '@ucap-webmessenger/protocol-authentication'; import { map } from 'rxjs/operators'; +import { Subscription } from 'rxjs'; +import { SelectGroupDialogComponent, SelectGroupDialogData, SelectGroupDialogResult } from '../group/select-group.dialog.component'; export interface ProfileDialogData { userInfo: UserInfo | UserInfoSS | UserInfoF | UserInfoDN; @@ -30,13 +33,15 @@ export interface ProfileDialogResult {} templateUrl: './profile.dialog.component.html', styleUrls: ['./profile.dialog.component.scss'] }) -export class ProfileDialogComponent implements OnInit { +export class ProfileDialogComponent implements OnInit, OnDestroy { loginRes: LoginResponse; sessionVerinfo: VersionInfo2Response; isMe: boolean; isBuddy: boolean; isFavorit: boolean; + selectAllBuddy2Subscription: Subscription; + constructor( public dialogRef: MatDialogRef, @Inject(MAT_DIALOG_DATA) public data: ProfileDialogData, @@ -55,18 +60,26 @@ export class ProfileDialogComponent implements OnInit { 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; - } - }) - ); + this.selectAllBuddy2Subscription = 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; + } + }) + ) + .subscribe(); + } + + ngOnDestroy(): void { + if (!!this.selectAllBuddy2Subscription) { + this.selectAllBuddy2Subscription.unsubscribe(); + } } onClickChat(userInfo: UserInfo | UserInfoSS | UserInfoF | UserInfoDN) { @@ -80,4 +93,71 @@ export class ProfileDialogComponent implements OnInit { this.dialogRef.close(); } + + onClickToggleFavorit(param: { + userInfo: UserInfo | UserInfoF; + isFavorit: boolean; + }) { + this.store.dispatch( + SyncStore.updateBuddy({ + seq: param.userInfo.seq, + isFavorit: param.isFavorit + }) + ); + } + + async onClickToggleBuddy(param: { + userInfo: UserInfo | UserInfoF; + isBuddy: boolean; + }) { + if (param.isBuddy) { + // 동료추가. + const result = await this.dialogService.open< + SelectGroupDialogComponent, + SelectGroupDialogData, + SelectGroupDialogResult + >(SelectGroupDialogComponent, { + width: '600px', + data: { + title: 'Group Select' + } + }); + + if (!!result && !!result.choice && result.choice) { + if (!!result.group) { + const oldGroup: GroupDetailData = result.group; + const trgtUserSeq: number[] = []; + result.group.userSeqs.map(seq => trgtUserSeq.push(seq)); + trgtUserSeq.push(param.userInfo.seq); + + this.store.dispatch( + SyncStore.updateGroupMember({ + oldGroup, + trgtUserSeq + }) + ); + } + } + } else { + // 동료삭제. + const result = await this.dialogService.open< + ConfirmDialogComponent, + ConfirmDialogData, + ConfirmDialogResult + >(ConfirmDialogComponent, { + width: '360px', + data: { + title: 'Delete Buddy', + html: `[${param.userInfo.name} ${param.userInfo.grade}]를 그룹에서 삭제하시겠습니까?
프로필에서 삭제하면 모든 그룹에서 삭제됩니다.` + } + }); + + if (!!result && !!result.choice && result.choice) { + this.store.dispatch( + SyncStore.delBuddyAndClear({ seq: param.userInfo.seq }) + ); + this.isBuddy = false + } + } + } } diff --git a/projects/ucap-webmessenger-app/src/app/store/messenger/sync/actions.ts b/projects/ucap-webmessenger-app/src/app/store/messenger/sync/actions.ts index 64dc4e1a..31d326b9 100644 --- a/projects/ucap-webmessenger-app/src/app/store/messenger/sync/actions.ts +++ b/projects/ucap-webmessenger-app/src/app/store/messenger/sync/actions.ts @@ -176,6 +176,19 @@ export const delBuddyFailure = createAction( '[Messenger::Sync] Buddy Del Failure', props<{ error: any }>() ); +/** 동료 삭제 및 그룹 클리어.(in profile) */ +export const delBuddyAndClear = createAction( + '[Messenger::Sync] Buddy Del and Group Clear', + props<{ seq: number }>() +); +export const delBuddyAndClearSuccess = createAction( + '[Messenger::Sync] Buddy Del and Group Clear Success', + props() +); +export const delBuddyAndClearFailure = createAction( + '[Messenger::Sync] Buddy Del and Group Clear Failure', + props<{ error: any }>() +); /** 동료 변경(즐겨찾기) */ export const updateBuddy = createAction( '[Messenger::Sync] Buddy Update', diff --git a/projects/ucap-webmessenger-app/src/app/store/messenger/sync/effects.ts b/projects/ucap-webmessenger-app/src/app/store/messenger/sync/effects.ts index a9938e06..a279bc19 100644 --- a/projects/ucap-webmessenger-app/src/app/store/messenger/sync/effects.ts +++ b/projects/ucap-webmessenger-app/src/app/store/messenger/sync/effects.ts @@ -1,4 +1,3 @@ -import { openTimer } from './../room/actions'; import { Injectable } from '@angular/core'; import { Actions, ofType, createEffect } from '@ngrx/effects'; @@ -48,7 +47,8 @@ import { updateGroupMember, delGroup, delGroupFailure, - delGroupSuccess + delGroupSuccess, + delBuddyAndClear } from './actions'; import { SessionStorageService } from '@ucap-webmessenger/web-storage'; import { LoginInfo, KEY_LOGIN_INFO } from '@app/types'; @@ -727,6 +727,54 @@ export class Effects { ) ); + delBuddyAndClear$ = createEffect( + () => { + return this.actions$.pipe( + ofType(delBuddyAndClear), + withLatestFrom( + this.store.pipe( + select( + (state: any) => + state.messenger.sync.group2.entities as Dictionary< + GroupDetailData + > + ) + ) + ), + tap(([req, groupList]) => { + // tslint:disable-next-line: forin + for (const key in groupList) { + const group: GroupDetailData = groupList[key]; + if (group.userSeqs.indexOf(req.seq) > -1) { + // Group Clear.. + this.store.dispatch( + updateGroup({ + groupSeq: group.seq, + groupName: group.name, + userSeqs: group.userSeqs.filter( + userSeq => userSeq !== req.seq + ) + }) + ); + } + } + + // Favorit Clear.. + this.store.dispatch( + updateBuddy({ + seq: req.seq, + isFavorit: false + }) + ); + + // Buddy Clear.. + this.store.dispatch(delBuddy({ userSeqs: [req.seq] })); + }) + ); + }, + { dispatch: false } + ); + updateBuddy$ = createEffect(() => this.actions$.pipe( ofType(updateBuddy), diff --git a/projects/ucap-webmessenger-ui-profile/src/lib/components/profile.component.html b/projects/ucap-webmessenger-ui-profile/src/lib/components/profile.component.html index 6c2f344c..240fca97 100644 --- a/projects/ucap-webmessenger-ui-profile/src/lib/components/profile.component.html +++ b/projects/ucap-webmessenger-ui-profile/src/lib/components/profile.component.html @@ -9,71 +9,147 @@
- +
- -
- - - + +
+ + - + points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2" + > - - - - - - - - - - - - - + + + + + + + + + + + + + + + +
  • - - - + + {{ userInfo.intro }}
  • - - - + + {{ userInfo.email }}
  • - - + - + d="M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7A2 2 0 0 1 22 16.92z" + > {{ userInfo.lineNumber }}
  • - - + @@ -84,47 +160,103 @@
    -
    - \ No newline at end of file + diff --git a/projects/ucap-webmessenger-ui-profile/src/lib/components/profile.component.ts b/projects/ucap-webmessenger-ui-profile/src/lib/components/profile.component.ts index 4d6ef844..a7612d97 100644 --- a/projects/ucap-webmessenger-ui-profile/src/lib/components/profile.component.ts +++ b/projects/ucap-webmessenger-ui-profile/src/lib/components/profile.component.ts @@ -22,10 +22,20 @@ export class ProfileComponent implements OnInit { @Input() isFavorit: boolean; @Input() - userInfo: UserInfo | UserInfoSS | UserInfoF | UserInfoDN; + userInfo: UserInfo | UserInfoF; @Output() - openChat = new EventEmitter(); + openChat = new EventEmitter(); + @Output() + toggleFavorit = new EventEmitter<{ + userInfo: UserInfo | UserInfoF; + isFavorit: boolean; + }>(); + @Output() + toggleBuddy = new EventEmitter<{ + userInfo: UserInfo | UserInfoF; + isBuddy: boolean; + }>(); constructor() {} @@ -40,4 +50,27 @@ export class ProfileComponent implements OnInit { onClickVideoConference() {} onClickMessage() {} + + onToggleFavorit() { + this.isFavorit = !this.isFavorit; + + this.toggleFavorit.emit({ + userInfo: this.userInfo, + isFavorit: this.isFavorit + }); + } + + onClickAddBuddy() { + this.toggleBuddy.emit({ + userInfo: this.userInfo, + isBuddy: true + }); + } + + onClickDelBuddy() { + this.toggleBuddy.emit({ + userInfo: this.userInfo, + isBuddy: false + }); + } }