2019-11-13 06:42:30 +00:00
|
|
|
import {
|
|
|
|
Component,
|
|
|
|
OnInit,
|
|
|
|
OnDestroy,
|
|
|
|
Output,
|
2019-11-22 08:25:51 +00:00
|
|
|
EventEmitter,
|
|
|
|
ViewChild,
|
|
|
|
Input,
|
|
|
|
AfterViewChecked
|
2019-11-13 06:42:30 +00:00
|
|
|
} from '@angular/core';
|
|
|
|
import { Subscription, of } from 'rxjs';
|
|
|
|
import { Store, select } from '@ngrx/store';
|
|
|
|
import { tap, map, catchError } from 'rxjs/operators';
|
2019-11-26 08:54:37 +00:00
|
|
|
import { NGXLogger } from 'ngx-logger';
|
2019-11-13 06:42:30 +00:00
|
|
|
|
|
|
|
import * as AppStore from '@app/store';
|
|
|
|
|
|
|
|
import { UserInfo } from '@ucap-webmessenger/protocol-room';
|
|
|
|
import { VersionInfo2Response } from '@ucap-webmessenger/api-public';
|
|
|
|
import { SessionStorageService } from '@ucap-webmessenger/web-storage';
|
|
|
|
import { KEY_VER_INFO } from '@app/types/ver-info.type';
|
|
|
|
import { DialogService } from '@ucap-webmessenger/ui';
|
|
|
|
import { LoginResponse } from '@ucap-webmessenger/protocol-authentication';
|
|
|
|
import { KEY_LOGIN_RES_INFO } from '@app/types/login-res-info.type';
|
|
|
|
import {
|
|
|
|
MessageApiService,
|
2019-11-14 01:31:23 +00:00
|
|
|
MessageType,
|
2019-11-14 08:43:45 +00:00
|
|
|
RetrieveRequest,
|
2019-11-25 06:48:54 +00:00
|
|
|
MessageList,
|
|
|
|
RetrieveSearchRequest,
|
2019-11-26 08:54:37 +00:00
|
|
|
MessageSearchType,
|
2019-11-28 08:30:43 +00:00
|
|
|
DetailRequest,
|
|
|
|
MessageDetailInfo,
|
|
|
|
DelRequest,
|
|
|
|
CancelReservationRequest
|
2019-11-13 06:42:30 +00:00
|
|
|
} from '@ucap-webmessenger/api-message';
|
|
|
|
import { DeviceType } from '@ucap-webmessenger/core';
|
2019-11-14 08:43:45 +00:00
|
|
|
import { MessageStatusCode } from '@ucap-webmessenger/api';
|
|
|
|
import { ContentType } from '@ucap-webmessenger/api-message';
|
2019-11-15 01:49:41 +00:00
|
|
|
import { FormGroup, FormBuilder } from '@angular/forms';
|
2019-11-25 06:48:54 +00:00
|
|
|
import {
|
|
|
|
MatTabGroup,
|
|
|
|
MatSelectChange,
|
|
|
|
MatRadioChange
|
|
|
|
} from '@angular/material';
|
2019-11-26 08:54:37 +00:00
|
|
|
import {
|
|
|
|
MessageDetailDialogComponent,
|
|
|
|
MessageDetailDialogResult,
|
|
|
|
MessageDetailDialogData
|
|
|
|
} from '../../dialogs/message/message-detail.dialog.component';
|
2019-11-13 06:42:30 +00:00
|
|
|
|
|
|
|
@Component({
|
2019-11-22 08:25:51 +00:00
|
|
|
selector: 'app-layout-chat-left-sidenav-message',
|
|
|
|
templateUrl: './message.component.html',
|
|
|
|
styleUrls: ['./message.component.scss']
|
2019-11-13 06:42:30 +00:00
|
|
|
})
|
2019-11-22 08:25:51 +00:00
|
|
|
export class MessageBoxComponent
|
|
|
|
implements OnInit, OnDestroy, AfterViewChecked {
|
|
|
|
@Input()
|
|
|
|
isVisible = false;
|
|
|
|
|
2019-11-26 08:54:37 +00:00
|
|
|
@Output()
|
|
|
|
doRefreshUnReadCount = new EventEmitter();
|
|
|
|
|
2019-11-22 08:25:51 +00:00
|
|
|
@ViewChild('tabs', { static: false }) tabs: MatTabGroup;
|
|
|
|
isInitTabs = false;
|
|
|
|
|
2019-11-15 01:49:41 +00:00
|
|
|
fgSearch: FormGroup;
|
2019-11-25 06:48:54 +00:00
|
|
|
fgSearchType: FormGroup;
|
2019-11-13 06:42:30 +00:00
|
|
|
|
|
|
|
loginRes: LoginResponse;
|
|
|
|
sessionVerinfo: VersionInfo2Response;
|
|
|
|
|
2019-11-14 08:43:45 +00:00
|
|
|
messageList: MessageList[] = [];
|
|
|
|
|
|
|
|
messageRecieveListSubscription: Subscription;
|
2019-11-13 06:42:30 +00:00
|
|
|
messageSendListSubscription: Subscription;
|
2019-11-14 08:43:45 +00:00
|
|
|
messageReservationListSubscription: Subscription;
|
|
|
|
messageSearchListSubscription: Subscription;
|
|
|
|
|
2019-11-28 08:30:43 +00:00
|
|
|
currentTabIndex = 0;
|
|
|
|
defaultPageSize = 1000; // default
|
2019-11-14 08:43:45 +00:00
|
|
|
recieveCurrentPage = 0; // start index is 0.
|
|
|
|
sendCurrentPage = 0; // start index is 0.
|
|
|
|
reservationCurrentPage = 0; // start index is 0.
|
|
|
|
searchCurrentPage = 0; // start index is 0.
|
|
|
|
|
|
|
|
currentTotalCount = 0;
|
|
|
|
currentPage = 0;
|
2019-11-13 06:42:30 +00:00
|
|
|
|
2019-11-14 08:43:45 +00:00
|
|
|
ContentType = ContentType;
|
2019-11-22 08:25:51 +00:00
|
|
|
MessageType = MessageType;
|
2019-11-25 06:48:54 +00:00
|
|
|
MessageSearchType = MessageSearchType;
|
|
|
|
|
|
|
|
isSearch = false;
|
2019-11-13 06:42:30 +00:00
|
|
|
|
|
|
|
constructor(
|
|
|
|
private store: Store<any>,
|
2019-11-15 01:49:41 +00:00
|
|
|
private formBuilder: FormBuilder,
|
2019-11-13 06:42:30 +00:00
|
|
|
private sessionStorageService: SessionStorageService,
|
|
|
|
private dialogService: DialogService,
|
2019-11-26 08:54:37 +00:00
|
|
|
private messageApiService: MessageApiService,
|
|
|
|
private logger: NGXLogger
|
2019-11-13 06:42:30 +00:00
|
|
|
) {
|
|
|
|
this.loginRes = this.sessionStorageService.get<LoginResponse>(
|
|
|
|
KEY_LOGIN_RES_INFO
|
|
|
|
);
|
|
|
|
this.sessionVerinfo = this.sessionStorageService.get<VersionInfo2Response>(
|
|
|
|
KEY_VER_INFO
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
2019-11-15 01:49:41 +00:00
|
|
|
this.fgSearch = this.formBuilder.group({
|
|
|
|
searchInput: null
|
|
|
|
});
|
2019-11-25 06:48:54 +00:00
|
|
|
this.fgSearchType = this.formBuilder.group({
|
|
|
|
searchMessageType: [MessageType.All],
|
|
|
|
searchMessageSearchType: [MessageSearchType.Name]
|
|
|
|
});
|
2019-11-13 06:42:30 +00:00
|
|
|
|
2019-11-14 08:43:45 +00:00
|
|
|
// 초기 검색은 수신함.
|
|
|
|
this.getRetrieveMessage(MessageType.Receive, this.recieveCurrentPage);
|
2019-11-22 08:25:51 +00:00
|
|
|
|
|
|
|
if (!!this.tabs) {
|
|
|
|
this.tabs.realignInkBar();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ngAfterViewChecked(): void {
|
|
|
|
if (!!this.tabs && !this.isInitTabs && this.isVisible) {
|
|
|
|
this.isInitTabs = true;
|
|
|
|
this.tabs.realignInkBar();
|
|
|
|
}
|
2019-11-13 06:42:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy(): void {
|
2019-11-14 08:43:45 +00:00
|
|
|
if (!!this.messageRecieveListSubscription) {
|
|
|
|
this.messageRecieveListSubscription.unsubscribe();
|
|
|
|
}
|
2019-11-13 06:42:30 +00:00
|
|
|
if (!!this.messageSendListSubscription) {
|
|
|
|
this.messageSendListSubscription.unsubscribe();
|
|
|
|
}
|
2019-11-14 08:43:45 +00:00
|
|
|
if (!!this.messageReservationListSubscription) {
|
|
|
|
this.messageReservationListSubscription.unsubscribe();
|
|
|
|
}
|
|
|
|
if (!!this.messageSearchListSubscription) {
|
|
|
|
this.messageSearchListSubscription.unsubscribe();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onSelectedIndexChange(value: number) {
|
2019-11-28 08:30:43 +00:00
|
|
|
this.currentTabIndex = value;
|
|
|
|
let type: MessageType;
|
2019-11-14 08:43:45 +00:00
|
|
|
switch (value) {
|
|
|
|
case 0:
|
2019-11-28 08:30:43 +00:00
|
|
|
// Recieve
|
|
|
|
type = MessageType.Receive;
|
|
|
|
this.recieveCurrentPage = 0;
|
2019-11-14 08:43:45 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2019-11-28 08:30:43 +00:00
|
|
|
// Send
|
|
|
|
type = MessageType.Send;
|
|
|
|
this.sendCurrentPage = 0;
|
2019-11-14 08:43:45 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2019-11-28 08:30:43 +00:00
|
|
|
// Reservation
|
|
|
|
type = MessageType.Reservation;
|
|
|
|
this.reservationCurrentPage = 0;
|
2019-11-14 08:43:45 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-11-28 08:30:43 +00:00
|
|
|
|
|
|
|
this.getRetrieveMessage(type, 0);
|
2019-11-14 08:43:45 +00:00
|
|
|
}
|
|
|
|
|
2019-11-28 08:30:43 +00:00
|
|
|
/** 쪽지 검색 관련 */
|
2019-11-25 06:48:54 +00:00
|
|
|
onChangeSelection(event: MatSelectChange) {
|
|
|
|
this.searchCurrentPage = 0;
|
|
|
|
this.getSearchMessage(
|
|
|
|
event.value,
|
|
|
|
this.fgSearchType.get('searchMessageSearchType').value,
|
|
|
|
this.fgSearch.get('searchInput').value
|
|
|
|
);
|
|
|
|
}
|
|
|
|
onChangeSearchType(event: MatRadioChange) {
|
|
|
|
this.searchCurrentPage = 0;
|
|
|
|
this.getSearchMessage(
|
|
|
|
this.fgSearchType.get('searchMessageType').value,
|
|
|
|
event.value,
|
|
|
|
this.fgSearch.get('searchInput').value
|
|
|
|
);
|
|
|
|
}
|
2019-11-15 01:49:41 +00:00
|
|
|
onKeyDownEnter(event: KeyboardEvent, search: string) {
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
2019-11-25 06:48:54 +00:00
|
|
|
|
|
|
|
this.searchCurrentPage = 0;
|
|
|
|
|
|
|
|
this.getSearchMessage(
|
|
|
|
MessageType.All,
|
|
|
|
MessageSearchType.Name,
|
|
|
|
search.trim()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
getSearchMessage(
|
|
|
|
messageType: MessageType,
|
|
|
|
searchType: MessageSearchType,
|
|
|
|
searchStr: string
|
|
|
|
) {
|
|
|
|
this.isSearch = true;
|
|
|
|
this.messageSendListSubscription = this.messageApiService
|
|
|
|
.retrieveSearchMessage({
|
|
|
|
userSeq: this.loginRes.userSeq,
|
|
|
|
deviceType: DeviceType.PC,
|
|
|
|
tokenKey: this.loginRes.tokenString,
|
|
|
|
type: messageType,
|
|
|
|
pageSize: this.defaultPageSize,
|
|
|
|
pageCount: this.searchCurrentPage,
|
|
|
|
|
|
|
|
searchTitle: searchType === MessageSearchType.Title ? searchStr : '',
|
|
|
|
searchName: searchType === MessageSearchType.Name ? searchStr : '',
|
|
|
|
searchContent:
|
|
|
|
searchType === MessageSearchType.Contents ? searchStr : ''
|
|
|
|
} as RetrieveSearchRequest)
|
|
|
|
.pipe(
|
|
|
|
map(res => {
|
|
|
|
if (res.responseCode === MessageStatusCode.Success) {
|
|
|
|
this.currentTotalCount = res.totalCount;
|
|
|
|
this.currentPage = res.pageCount;
|
|
|
|
this.searchCurrentPage = res.pageCount;
|
|
|
|
this.messageList = res.messageList;
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
}),
|
2019-11-26 08:54:37 +00:00
|
|
|
catchError(error => of(this.logger.error(error)))
|
2019-11-25 06:48:54 +00:00
|
|
|
)
|
|
|
|
.subscribe();
|
2019-11-15 01:49:41 +00:00
|
|
|
}
|
2019-11-25 06:48:54 +00:00
|
|
|
onClickSearchCancel() {
|
|
|
|
this.isSearch = false;
|
|
|
|
this.getRetrieveMessage(MessageType.Receive, this.recieveCurrentPage);
|
|
|
|
}
|
2019-11-15 01:49:41 +00:00
|
|
|
|
2019-11-28 08:30:43 +00:00
|
|
|
/** 쪽지 타입별 조회 */
|
2019-11-14 08:43:45 +00:00
|
|
|
getRetrieveMessage(type: MessageType, trgtPageIndex: number) {
|
|
|
|
switch (type) {
|
|
|
|
case MessageType.Receive:
|
|
|
|
{
|
|
|
|
this.messageSendListSubscription = this.messageApiService
|
|
|
|
.retrieveReceiveMessage({
|
|
|
|
userSeq: this.loginRes.userSeq,
|
|
|
|
deviceType: DeviceType.PC,
|
|
|
|
tokenKey: this.loginRes.tokenString,
|
|
|
|
type: MessageType.Receive,
|
|
|
|
pageSize: this.defaultPageSize,
|
|
|
|
pageCount: this.recieveCurrentPage
|
|
|
|
} as RetrieveRequest)
|
|
|
|
.pipe(
|
|
|
|
map(res => {
|
|
|
|
if (res.responseCode === MessageStatusCode.Success) {
|
|
|
|
this.currentTotalCount = res.totalCount;
|
|
|
|
this.currentPage = res.pageCount;
|
|
|
|
this.recieveCurrentPage = res.pageCount;
|
|
|
|
this.messageList = res.messageList;
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
}),
|
2019-11-26 08:54:37 +00:00
|
|
|
catchError(error => of(this.logger.error(error)))
|
2019-11-14 08:43:45 +00:00
|
|
|
)
|
|
|
|
.subscribe();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MessageType.Send:
|
|
|
|
{
|
|
|
|
this.messageSendListSubscription = this.messageApiService
|
|
|
|
.retrieveSendMessage({
|
|
|
|
userSeq: this.loginRes.userSeq,
|
|
|
|
deviceType: DeviceType.PC,
|
|
|
|
tokenKey: this.loginRes.tokenString,
|
|
|
|
type: MessageType.Send,
|
|
|
|
pageSize: this.defaultPageSize,
|
|
|
|
pageCount: this.sendCurrentPage
|
|
|
|
} as RetrieveRequest)
|
|
|
|
.pipe(
|
|
|
|
map(res => {
|
|
|
|
if (res.responseCode === MessageStatusCode.Success) {
|
|
|
|
this.currentTotalCount = res.totalCount;
|
|
|
|
this.currentPage = res.pageCount;
|
|
|
|
this.sendCurrentPage = res.pageCount;
|
|
|
|
this.messageList = res.messageList;
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
}),
|
2019-11-26 08:54:37 +00:00
|
|
|
catchError(error => of(this.logger.error(error)))
|
2019-11-14 08:43:45 +00:00
|
|
|
)
|
|
|
|
.subscribe();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MessageType.Reservation:
|
|
|
|
{
|
|
|
|
this.messageSendListSubscription = this.messageApiService
|
|
|
|
.retrieveReservationMessage({
|
|
|
|
userSeq: this.loginRes.userSeq,
|
|
|
|
deviceType: DeviceType.PC,
|
|
|
|
tokenKey: this.loginRes.tokenString,
|
|
|
|
type: MessageType.Reservation,
|
|
|
|
pageSize: this.defaultPageSize,
|
|
|
|
pageCount: this.reservationCurrentPage
|
|
|
|
} as RetrieveRequest)
|
|
|
|
.pipe(
|
|
|
|
map(res => {
|
|
|
|
if (res.responseCode === MessageStatusCode.Success) {
|
|
|
|
this.currentTotalCount = res.totalCount;
|
|
|
|
this.currentPage = res.pageCount;
|
|
|
|
this.reservationCurrentPage = res.pageCount;
|
|
|
|
this.messageList = res.messageList;
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
}),
|
2019-11-26 08:54:37 +00:00
|
|
|
catchError(error => of(this.logger.error(error)))
|
2019-11-14 08:43:45 +00:00
|
|
|
)
|
|
|
|
.subscribe();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2019-11-13 06:42:30 +00:00
|
|
|
}
|
2019-11-26 08:54:37 +00:00
|
|
|
|
2019-11-28 08:30:43 +00:00
|
|
|
/** 쪽지 상세보기 */
|
2019-11-26 08:54:37 +00:00
|
|
|
onClickDetail(message: MessageList) {
|
|
|
|
this.messageApiService
|
|
|
|
.detailMessage({
|
|
|
|
userSeq: this.loginRes.userSeq,
|
|
|
|
deviceType: DeviceType.PC,
|
|
|
|
tokenKey: this.loginRes.tokenString,
|
|
|
|
type: message.type,
|
|
|
|
msgId: message.msgId
|
|
|
|
} as DetailRequest)
|
|
|
|
.pipe(
|
|
|
|
map(async res => {
|
|
|
|
if (res.responseCode === MessageStatusCode.Success) {
|
|
|
|
// Badge Refresh in case Receive Message..
|
|
|
|
if (res.msgInfo.type === MessageType.Receive) {
|
|
|
|
this.doRefreshUnReadCount.emit();
|
|
|
|
}
|
|
|
|
|
|
|
|
// detail view..
|
|
|
|
const result = await this.dialogService.open<
|
|
|
|
MessageDetailDialogComponent,
|
|
|
|
MessageDetailDialogData,
|
|
|
|
MessageDetailDialogResult
|
|
|
|
>(MessageDetailDialogComponent, {
|
|
|
|
width: '600px',
|
|
|
|
data: {
|
|
|
|
detail: res,
|
|
|
|
loginRes: this.loginRes
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-11-28 08:30:43 +00:00
|
|
|
if (!!result) {
|
|
|
|
switch (result.returnType) {
|
|
|
|
case 'DEL':
|
|
|
|
// 단건 삭제.
|
|
|
|
this.doMessageDelete([result.messageInfo]);
|
|
|
|
break;
|
|
|
|
case 'CANCEL_RESERVATION':
|
|
|
|
// 단건 발송취소(예약)
|
|
|
|
this.doMessageCancelReservation(result.messageInfo);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
catchError(error => of(this.logger.error(error)))
|
|
|
|
)
|
|
|
|
.subscribe();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** 쪽지(수신,발신) 삭제 */
|
|
|
|
doMessageDelete(messageInfo: MessageDetailInfo[]): void {
|
|
|
|
const msgList: { msgId: number }[] = [];
|
|
|
|
messageInfo.forEach(info => msgList.push({ msgId: info.msgId }));
|
|
|
|
this.messageApiService
|
|
|
|
.deleteMessage({
|
|
|
|
userSeq: this.loginRes.userSeq,
|
|
|
|
deviceType: DeviceType.PC,
|
|
|
|
tokenKey: this.loginRes.tokenString,
|
|
|
|
type: messageInfo[0].type,
|
|
|
|
msgList
|
|
|
|
} as DelRequest)
|
|
|
|
.pipe(
|
|
|
|
map(async res => {
|
|
|
|
if (res.responseCode === MessageStatusCode.Success) {
|
|
|
|
} else {
|
|
|
|
this.logger.error('message delete Error!');
|
|
|
|
}
|
|
|
|
// 현재탭 재조회.
|
|
|
|
this.onSelectedIndexChange(this.currentTabIndex);
|
|
|
|
}),
|
|
|
|
catchError(error => of(this.logger.error(error)))
|
|
|
|
)
|
|
|
|
.subscribe();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** 쪽지(예약) 삭제 */
|
|
|
|
doMessageCancelReservation(messageInfo: MessageDetailInfo): void {
|
|
|
|
this.messageApiService
|
|
|
|
.cancelReservationMessage({
|
|
|
|
userSeq: this.loginRes.userSeq,
|
|
|
|
deviceType: DeviceType.PC,
|
|
|
|
tokenKey: this.loginRes.tokenString,
|
|
|
|
type: messageInfo.type,
|
|
|
|
msgId: messageInfo.msgId
|
|
|
|
} as CancelReservationRequest)
|
|
|
|
.pipe(
|
|
|
|
map(async res => {
|
|
|
|
if (res.responseCode === MessageStatusCode.Success) {
|
2019-11-26 08:54:37 +00:00
|
|
|
} else {
|
2019-11-28 08:30:43 +00:00
|
|
|
this.logger.error('message(reservation) cancel Error!');
|
2019-11-26 08:54:37 +00:00
|
|
|
}
|
2019-11-28 08:30:43 +00:00
|
|
|
// 현재탭 재조회.
|
|
|
|
this.onSelectedIndexChange(this.currentTabIndex);
|
2019-11-26 08:54:37 +00:00
|
|
|
}),
|
|
|
|
catchError(error => of(this.logger.error(error)))
|
|
|
|
)
|
|
|
|
.subscribe();
|
|
|
|
}
|
2019-11-13 06:42:30 +00:00
|
|
|
}
|