next-ucap-messenger/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/right-drawer/message-box.component.ts

234 lines
7.2 KiB
TypeScript
Raw Normal View History

2019-11-13 06:42:30 +00:00
import {
Component,
OnInit,
OnDestroy,
Output,
EventEmitter
} from '@angular/core';
import { Subscription, of } from 'rxjs';
import { Store, select } from '@ngrx/store';
import { tap, map, catchError } from 'rxjs/operators';
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,
RetrieveRequest,
MessageList
2019-11-13 06:42:30 +00:00
} from '@ucap-webmessenger/api-message';
import { DeviceType } from '@ucap-webmessenger/core';
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-13 06:42:30 +00:00
@Component({
selector: 'app-layout-chat-right-drawer-message-box',
templateUrl: './message-box.component.html',
styleUrls: ['./message-box.component.scss']
})
export class MessageBoxComponent implements OnInit, OnDestroy {
2019-11-15 01:49:41 +00:00
fgSearch: FormGroup;
2019-11-13 06:42:30 +00:00
userInfoList: UserInfo[];
userInfoListSubscription: Subscription;
loginRes: LoginResponse;
sessionVerinfo: VersionInfo2Response;
messageList: MessageList[] = [];
messageRecieveListSubscription: Subscription;
2019-11-13 06:42:30 +00:00
messageSendListSubscription: Subscription;
messageReservationListSubscription: Subscription;
messageSearchListSubscription: Subscription;
defaultPageSize = 100; // default
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
ContentType = ContentType;
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,
private messageApiService: MessageApiService
) {
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-13 06:42:30 +00:00
this.userInfoListSubscription = this.store
.pipe(
select(AppStore.MessengerSelector.RoomSelector.selectUserinfolist),
tap(userInfoList => {
this.userInfoList = userInfoList;
})
)
.subscribe();
// 초기 검색은 수신함.
this.getRetrieveMessage(MessageType.Receive, this.recieveCurrentPage);
2019-11-13 06:42:30 +00:00
}
ngOnDestroy(): void {
if (!!this.userInfoListSubscription) {
this.userInfoListSubscription.unsubscribe();
}
if (!!this.messageRecieveListSubscription) {
this.messageRecieveListSubscription.unsubscribe();
}
2019-11-13 06:42:30 +00:00
if (!!this.messageSendListSubscription) {
this.messageSendListSubscription.unsubscribe();
}
if (!!this.messageReservationListSubscription) {
this.messageReservationListSubscription.unsubscribe();
}
if (!!this.messageSearchListSubscription) {
this.messageSearchListSubscription.unsubscribe();
}
}
onSelectedIndexChange(value: number) {
switch (value) {
case 0:
{
// Recieve
this.getRetrieveMessage(MessageType.Receive, this.recieveCurrentPage);
}
break;
case 1:
{
// Send
this.getRetrieveMessage(MessageType.Send, this.sendCurrentPage);
}
break;
case 2:
{
// Reservation
this.getRetrieveMessage(
MessageType.Reservation,
this.reservationCurrentPage
);
}
break;
}
}
2019-11-15 01:49:41 +00:00
onKeyDownEnter(event: KeyboardEvent, search: string) {
event.preventDefault();
event.stopPropagation();
}
onClickSearchCancel() {}
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 => {
console.log(res);
if (res.responseCode === MessageStatusCode.Success) {
this.currentTotalCount = res.totalCount;
this.currentPage = res.pageCount;
this.recieveCurrentPage = res.pageCount;
this.messageList = res.messageList;
} else {
}
}),
catchError(error => of(console.log(error)))
)
.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 => {
console.log(res);
if (res.responseCode === MessageStatusCode.Success) {
this.currentTotalCount = res.totalCount;
this.currentPage = res.pageCount;
this.sendCurrentPage = res.pageCount;
this.messageList = res.messageList;
} else {
}
}),
catchError(error => of(console.log(error)))
)
.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 => {
console.log(res);
if (res.responseCode === MessageStatusCode.Success) {
this.currentTotalCount = res.totalCount;
this.currentPage = res.pageCount;
this.reservationCurrentPage = res.pageCount;
this.messageList = res.messageList;
} else {
}
}),
catchError(error => of(console.log(error)))
)
.subscribe();
}
break;
}
2019-11-13 06:42:30 +00:00
}
}