2019-10-18 00:48:38 +00:00
|
|
|
import { UserSelectDialogType } from './../../../../types/userselect.dialog.type';
|
2019-10-16 08:46:53 +00:00
|
|
|
import { Component, OnInit, OnDestroy, Inject } from '@angular/core';
|
2019-10-18 04:02:43 +00:00
|
|
|
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
|
2019-10-16 08:46:53 +00:00
|
|
|
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
|
|
|
|
import { NGXLogger } from 'ngx-logger';
|
2019-10-23 06:07:41 +00:00
|
|
|
import { Observable, combineLatest, Subscription, of } from 'rxjs';
|
|
|
|
import { map, tap, catchError } from 'rxjs/operators';
|
2019-10-16 08:46:53 +00:00
|
|
|
|
|
|
|
import { Store, select } from '@ngrx/store';
|
|
|
|
import * as AppStore from '@app/store';
|
|
|
|
import * as QueryStore from '@app/store/messenger/query';
|
2019-10-23 06:07:41 +00:00
|
|
|
import * as StatusStore from '@app/store/messenger/status';
|
2019-10-16 08:46:53 +00:00
|
|
|
|
|
|
|
import { SessionStorageService } from '@ucap-webmessenger/web-storage';
|
|
|
|
import { Company } from '@ucap-webmessenger/api-external';
|
|
|
|
import { VersionInfo2Response } from '@ucap-webmessenger/api-public';
|
|
|
|
import { LoginInfo, KEY_LOGIN_INFO } from '@app/types';
|
|
|
|
import { KEY_VER_INFO } from '@app/types/ver-info.type';
|
|
|
|
import { LoginResponse } from '@ucap-webmessenger/protocol-authentication';
|
|
|
|
import {
|
|
|
|
UserInfo,
|
|
|
|
GroupDetailData,
|
|
|
|
RoomUserDetailData,
|
|
|
|
RoomUserData
|
|
|
|
} from '@ucap-webmessenger/protocol-sync';
|
2019-10-17 02:49:41 +00:00
|
|
|
import {
|
|
|
|
DeptSearchType,
|
|
|
|
UserInfoSS,
|
|
|
|
UserInfoF,
|
2019-10-23 06:07:41 +00:00
|
|
|
UserInfoDN,
|
|
|
|
QueryProtocolService,
|
|
|
|
SSVC_TYPE_QUERY_DEPT_USER_DATA,
|
|
|
|
DeptUserData,
|
|
|
|
SSVC_TYPE_QUERY_DEPT_USER_RES
|
2019-10-17 02:49:41 +00:00
|
|
|
} from '@ucap-webmessenger/protocol-query';
|
2019-10-16 08:46:53 +00:00
|
|
|
import {
|
|
|
|
RoomInfo,
|
|
|
|
UserInfoShort,
|
|
|
|
UserInfo as RoomUserInfo
|
|
|
|
} from '@ucap-webmessenger/protocol-room';
|
|
|
|
|
|
|
|
export interface CreateChatDialogData {
|
2019-10-18 00:48:38 +00:00
|
|
|
type?: string;
|
2019-10-16 08:46:53 +00:00
|
|
|
title: string;
|
2019-10-21 04:10:19 +00:00
|
|
|
/** CASE :: EditMember */
|
|
|
|
group?: GroupDetailData;
|
2019-10-16 08:46:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface CreateChatDialogResult {
|
|
|
|
choice: boolean;
|
2019-10-17 09:05:44 +00:00
|
|
|
selectedUserList?: (UserInfo | UserInfoSS | UserInfoF | UserInfoDN)[];
|
2019-10-18 04:02:43 +00:00
|
|
|
groupName?: string;
|
2019-10-21 04:10:19 +00:00
|
|
|
oldGroup?: GroupDetailData;
|
2019-10-16 08:46:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-layout-messenger-create-chat',
|
|
|
|
templateUrl: './create-chat.dialog.component.html',
|
|
|
|
styleUrls: ['./create-chat.dialog.component.scss']
|
|
|
|
})
|
|
|
|
export class CreateChatDialogComponent implements OnInit, OnDestroy {
|
|
|
|
constructor(
|
|
|
|
public dialogRef: MatDialogRef<
|
|
|
|
CreateChatDialogData,
|
|
|
|
CreateChatDialogResult
|
|
|
|
>,
|
|
|
|
@Inject(MAT_DIALOG_DATA) public data: CreateChatDialogData,
|
|
|
|
private store: Store<any>,
|
|
|
|
private sessionStorageService: SessionStorageService,
|
2019-10-23 06:07:41 +00:00
|
|
|
private queryProtocolService: QueryProtocolService,
|
2019-10-18 04:02:43 +00:00
|
|
|
private formBuilder: FormBuilder,
|
2019-10-16 08:46:53 +00:00
|
|
|
private logger: NGXLogger
|
|
|
|
) {}
|
|
|
|
|
2019-10-18 00:48:38 +00:00
|
|
|
UserSelectDialogType = UserSelectDialogType;
|
|
|
|
|
2019-10-16 08:46:53 +00:00
|
|
|
loginRes: LoginResponse;
|
|
|
|
loginResSubscription: Subscription;
|
|
|
|
sessionVerinfo = this.sessionStorageService.get<VersionInfo2Response>(
|
|
|
|
KEY_VER_INFO
|
|
|
|
);
|
|
|
|
|
2019-10-23 06:07:41 +00:00
|
|
|
// 검색
|
|
|
|
isShowSearch = false;
|
|
|
|
searchProcessing = false;
|
|
|
|
searchUserInfos: UserInfoSS[] = [];
|
|
|
|
|
|
|
|
// 그룹
|
2019-10-16 08:46:53 +00:00
|
|
|
companyList$: Observable<Company[]>;
|
|
|
|
companyCode: string;
|
|
|
|
groupBuddyList$: Observable<
|
|
|
|
{ group: GroupDetailData; buddyList: UserInfo[] }[]
|
|
|
|
>;
|
|
|
|
favoritBuddyList$: Observable<UserInfo[]>;
|
|
|
|
|
2019-10-23 06:07:41 +00:00
|
|
|
// 대화방
|
2019-10-16 08:46:53 +00:00
|
|
|
roomList: RoomInfo[];
|
|
|
|
roomUserList: RoomUserDetailData[];
|
|
|
|
roomUserShortList: RoomUserData[];
|
|
|
|
roomSubscription: Subscription;
|
|
|
|
|
2019-10-17 02:49:41 +00:00
|
|
|
// 수집 데이터
|
|
|
|
selectedUserList: (UserInfo | UserInfoSS | UserInfoF | UserInfoDN)[] = [];
|
|
|
|
|
2019-10-18 04:02:43 +00:00
|
|
|
inputForm: FormGroup;
|
|
|
|
|
2019-10-16 08:46:53 +00:00
|
|
|
ngOnInit() {
|
|
|
|
const loginInfo = this.sessionStorageService.get<LoginInfo>(KEY_LOGIN_INFO);
|
|
|
|
this.companyCode = loginInfo.companyCode;
|
|
|
|
|
|
|
|
this.companyList$ = this.store.pipe(
|
|
|
|
select(AppStore.SettingSelector.CompanySelector.companyList)
|
|
|
|
);
|
|
|
|
|
|
|
|
this.loginResSubscription = this.store
|
|
|
|
.pipe(
|
|
|
|
select(AppStore.AccountSelector.AuthenticationSelector.loginRes),
|
|
|
|
tap(loginRes => {
|
|
|
|
this.loginRes = loginRes;
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.subscribe();
|
|
|
|
|
|
|
|
this.groupBuddyList$ = combineLatest([
|
|
|
|
this.store.pipe(
|
|
|
|
select(AppStore.MessengerSelector.SyncSelector.selectAllBuddy2)
|
|
|
|
),
|
|
|
|
this.store.pipe(
|
|
|
|
select(AppStore.MessengerSelector.SyncSelector.selectAllGroup2)
|
|
|
|
)
|
|
|
|
]).pipe(
|
|
|
|
map(([buddyList, groupList]) => {
|
|
|
|
const groupBuddyList: {
|
|
|
|
group: GroupDetailData;
|
|
|
|
buddyList: UserInfo[];
|
|
|
|
}[] = [];
|
|
|
|
for (const group of groupList) {
|
2019-10-21 04:10:19 +00:00
|
|
|
const data = {
|
2019-10-16 08:46:53 +00:00
|
|
|
group,
|
|
|
|
buddyList: buddyList.filter(buddy => {
|
|
|
|
return group.userSeqs.indexOf(buddy.seq) > -1;
|
|
|
|
})
|
2019-10-21 04:10:19 +00:00
|
|
|
};
|
|
|
|
groupBuddyList.push(data);
|
2019-10-16 08:46:53 +00:00
|
|
|
|
2019-10-21 04:10:19 +00:00
|
|
|
/** 그룹 멤버 변경일 경우 그룹원을 기본 셀렉트 한다. */
|
|
|
|
if (
|
|
|
|
this.data.type === UserSelectDialogType.EditMember &&
|
|
|
|
!!this.data.group &&
|
|
|
|
this.data.group.seq === group.seq
|
|
|
|
) {
|
|
|
|
this.selectedUserList = [...data.buddyList];
|
|
|
|
}
|
|
|
|
}
|
2019-10-16 08:46:53 +00:00
|
|
|
return groupBuddyList;
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
this.favoritBuddyList$ = this.store
|
|
|
|
.pipe(select(AppStore.MessengerSelector.SyncSelector.selectAllBuddy2))
|
|
|
|
.pipe(
|
|
|
|
map(buddyInfoList => {
|
|
|
|
return buddyInfoList
|
|
|
|
.filter(buddy => buddy.isFavorit)
|
|
|
|
.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
this.roomSubscription = combineLatest([
|
|
|
|
this.store.pipe(
|
|
|
|
select(AppStore.MessengerSelector.SyncSelector.selectAllRoom)
|
|
|
|
),
|
|
|
|
this.store.pipe(
|
|
|
|
select(AppStore.MessengerSelector.SyncSelector.selectAllRoomUser)
|
|
|
|
),
|
|
|
|
this.store.pipe(
|
|
|
|
select(AppStore.MessengerSelector.SyncSelector.selectAllRoomUserShort)
|
|
|
|
)
|
|
|
|
])
|
|
|
|
.pipe(
|
|
|
|
tap(([room, roomUser, roomUserShort]) => {
|
|
|
|
this.roomList = room;
|
|
|
|
this.roomUserList = roomUser;
|
|
|
|
this.roomUserShortList = roomUserShort;
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.subscribe();
|
2019-10-18 04:02:43 +00:00
|
|
|
|
|
|
|
this.inputForm = this.formBuilder.group({
|
|
|
|
groupName: ['', [Validators.required]]
|
|
|
|
});
|
2019-10-16 08:46:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy(): void {
|
|
|
|
if (!!this.roomSubscription) {
|
|
|
|
this.roomSubscription.unsubscribe();
|
|
|
|
}
|
|
|
|
if (!!this.loginResSubscription) {
|
|
|
|
this.loginResSubscription.unsubscribe();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
getRoomUserList(roomInfo: RoomInfo): RoomUserInfo[] | UserInfoShort[] {
|
|
|
|
if (!!this.roomUserList && 0 < this.roomUserList.length) {
|
|
|
|
const i = this.roomUserList.findIndex(
|
|
|
|
value => roomInfo.roomSeq === value.roomSeq
|
|
|
|
);
|
|
|
|
if (-1 < i) {
|
|
|
|
return this.roomUserList[i].userInfos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!!this.roomUserShortList && 0 < this.roomUserShortList.length) {
|
|
|
|
const i = this.roomUserShortList.findIndex(
|
|
|
|
value => roomInfo.roomSeq === value.roomSeq
|
|
|
|
);
|
|
|
|
if (-1 < i) {
|
|
|
|
return this.roomUserShortList[i].userInfos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-23 06:07:41 +00:00
|
|
|
/** 유저검색 */
|
2019-10-16 08:46:53 +00:00
|
|
|
onKeyDownEnterOrganizationTenantSearch(params: {
|
|
|
|
companyCode: string;
|
|
|
|
searchWord: string;
|
|
|
|
}) {
|
2019-10-23 06:07:41 +00:00
|
|
|
if (params.searchWord.trim().length > 1) {
|
|
|
|
this.isShowSearch = true;
|
|
|
|
this.searchProcessing = true;
|
|
|
|
|
|
|
|
const searchUserInfos: UserInfoSS[] = [];
|
|
|
|
this.queryProtocolService
|
|
|
|
.deptUser({
|
|
|
|
divCd: 'GRP',
|
|
|
|
companyCode: params.companyCode,
|
|
|
|
searchRange: DeptSearchType.All,
|
|
|
|
search: params.searchWord,
|
|
|
|
senderCompanyCode: params.companyCode,
|
|
|
|
senderEmployeeType: this.loginRes.userInfo.employeeType
|
|
|
|
})
|
|
|
|
.pipe(
|
|
|
|
map(res => {
|
|
|
|
switch (res.SSVC_TYPE) {
|
|
|
|
case SSVC_TYPE_QUERY_DEPT_USER_DATA:
|
|
|
|
searchUserInfos.push(...(res as DeptUserData).userInfos);
|
|
|
|
break;
|
|
|
|
case SSVC_TYPE_QUERY_DEPT_USER_RES:
|
|
|
|
{
|
|
|
|
// 검색 결과 처리.
|
|
|
|
this.searchUserInfos = searchUserInfos;
|
|
|
|
this.searchProcessing = false;
|
|
|
|
|
|
|
|
// 검색 결과에 따른 프레즌스 조회.
|
|
|
|
const userSeqList: number[] = [];
|
|
|
|
this.searchUserInfos.map(user => userSeqList.push(user.seq));
|
|
|
|
if (userSeqList.length > 0) {
|
|
|
|
this.store.dispatch(
|
|
|
|
StatusStore.bulkInfo({
|
|
|
|
divCd: 'groupSrch',
|
|
|
|
userSeqs: userSeqList
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
catchError(error => {
|
|
|
|
this.searchProcessing = false;
|
|
|
|
return of(this.logger.error(error));
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.subscribe();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/** 검색 취소 */
|
|
|
|
onClickCancel() {
|
|
|
|
this.isShowSearch = false;
|
|
|
|
this.searchUserInfos = [];
|
2019-10-16 08:46:53 +00:00
|
|
|
}
|
|
|
|
|
2019-10-17 09:05:44 +00:00
|
|
|
/** 동료그룹 :: 그룹의 checkbox 의 이벤트를 받아 선택된 유저리스트를 수집. */
|
2019-10-17 06:07:39 +00:00
|
|
|
onCheckGroup(params: {
|
|
|
|
isChecked: boolean;
|
|
|
|
groupBuddyList: { group: GroupDetailData; buddyList: UserInfo[] };
|
|
|
|
}) {
|
|
|
|
if (params.isChecked) {
|
|
|
|
params.groupBuddyList.buddyList.forEach(item => {
|
|
|
|
if (
|
|
|
|
this.selectedUserList.filter(user => user.seq === item.seq).length ===
|
|
|
|
0
|
|
|
|
) {
|
2019-10-17 08:02:20 +00:00
|
|
|
this.selectedUserList = [...this.selectedUserList, item];
|
2019-10-17 06:07:39 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.selectedUserList = this.selectedUserList.filter(
|
|
|
|
item =>
|
|
|
|
params.groupBuddyList.buddyList.filter(del => del.seq === item.seq)
|
|
|
|
.length === 0
|
|
|
|
);
|
|
|
|
}
|
2019-10-17 02:49:41 +00:00
|
|
|
}
|
2019-10-17 06:07:39 +00:00
|
|
|
|
2019-10-17 09:05:44 +00:00
|
|
|
/** 동료그룹>부서원, 조직도>부서원 :: 리스트의 checkbox 의 이벤트를 받아 선택된 유저리스트를 수집. */
|
2019-10-17 02:49:41 +00:00
|
|
|
onCheckUser(params: {
|
|
|
|
isChecked: boolean;
|
|
|
|
userInfo: UserInfo | UserInfoSS | UserInfoF | UserInfoDN;
|
|
|
|
}) {
|
|
|
|
if (params.isChecked) {
|
2019-10-17 06:07:39 +00:00
|
|
|
if (
|
|
|
|
this.selectedUserList.filter(user => user.seq === params.userInfo.seq)
|
2019-10-17 08:02:20 +00:00
|
|
|
.length === 0 &&
|
|
|
|
params.userInfo
|
2019-10-17 06:07:39 +00:00
|
|
|
) {
|
2019-10-17 08:02:20 +00:00
|
|
|
this.selectedUserList = [...this.selectedUserList, params.userInfo];
|
2019-10-17 06:07:39 +00:00
|
|
|
}
|
2019-10-17 02:49:41 +00:00
|
|
|
} else {
|
|
|
|
this.selectedUserList = this.selectedUserList.filter(
|
|
|
|
item => item.seq !== params.userInfo.seq
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-17 09:05:44 +00:00
|
|
|
/** 그룹>부서원 리스트의 ischecked 를 판단. */
|
2019-10-17 08:02:20 +00:00
|
|
|
getCheckedUser(userInfo: UserInfo | UserInfoSS | UserInfoF | UserInfoDN) {
|
|
|
|
if (!!this.selectedUserList && this.selectedUserList.length > 0) {
|
|
|
|
return (
|
|
|
|
this.selectedUserList.filter(item => item.seq === userInfo.seq).length >
|
|
|
|
0
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2019-10-17 09:05:44 +00:00
|
|
|
|
2019-10-18 00:48:38 +00:00
|
|
|
/** 선택된 사용자 취소 */
|
|
|
|
onClickDeleteUser(userInfo: UserInfo | UserInfoSS | UserInfoF | UserInfoDN) {
|
|
|
|
this.selectedUserList = this.selectedUserList.filter(
|
|
|
|
item => item.seq !== userInfo.seq
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-10-17 09:05:44 +00:00
|
|
|
/** 팝업의 선택 이벤트 전달. */
|
|
|
|
onClickChoice(choice: boolean): void {
|
|
|
|
this.dialogRef.close({
|
|
|
|
choice,
|
2019-10-18 04:02:43 +00:00
|
|
|
selectedUserList: this.selectedUserList,
|
|
|
|
groupName:
|
|
|
|
this.data.type === UserSelectDialogType.NewGroup
|
|
|
|
? this.inputForm.get('groupName').value
|
2019-10-21 04:10:19 +00:00
|
|
|
: '',
|
|
|
|
oldGroup:
|
|
|
|
this.data.type === UserSelectDialogType.EditMember
|
|
|
|
? this.data.group
|
|
|
|
: undefined
|
2019-10-17 09:05:44 +00:00
|
|
|
});
|
|
|
|
}
|
2019-10-16 08:46:53 +00:00
|
|
|
}
|