114 lines
3.4 KiB
TypeScript
114 lines
3.4 KiB
TypeScript
|
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 * as SyncStore from '@app/store/messenger/sync';
|
||
|
import * as RoomStore from '@app/store/messenger/room';
|
||
|
|
||
|
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 {
|
||
|
SelectGroupDialogComponent,
|
||
|
SelectGroupDialogResult,
|
||
|
SelectGroupDialogData
|
||
|
} from '../../dialogs/group/select-group.dialog.component';
|
||
|
import { GroupDetailData } from '@ucap-webmessenger/protocol-sync';
|
||
|
import {
|
||
|
CreateChatDialogComponent,
|
||
|
CreateChatDialogResult,
|
||
|
CreateChatDialogData
|
||
|
} from '../../dialogs/chat/create-chat.dialog.component';
|
||
|
import { UserSelectDialogType } from '@app/types';
|
||
|
import { LoginResponse } from '@ucap-webmessenger/protocol-authentication';
|
||
|
import { KEY_LOGIN_RES_INFO } from '@app/types/login-res-info.type';
|
||
|
import {
|
||
|
MessageApiService,
|
||
|
RetrieveRequest,
|
||
|
MessageType
|
||
|
} from '@ucap-webmessenger/api-message';
|
||
|
import { DeviceType } from '@ucap-webmessenger/core';
|
||
|
import { StatusCode } from '@ucap-webmessenger/api';
|
||
|
|
||
|
@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 {
|
||
|
userInfoList: UserInfo[];
|
||
|
userInfoListSubscription: Subscription;
|
||
|
|
||
|
loginRes: LoginResponse;
|
||
|
sessionVerinfo: VersionInfo2Response;
|
||
|
|
||
|
messageSendListSubscription: Subscription;
|
||
|
|
||
|
pageSize = 100; // default
|
||
|
currentPage = 0; // start index is 0.
|
||
|
|
||
|
constructor(
|
||
|
private store: Store<any>,
|
||
|
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() {
|
||
|
this.userInfoListSubscription = this.store
|
||
|
.pipe(
|
||
|
select(AppStore.MessengerSelector.RoomSelector.selectUserinfolist),
|
||
|
tap(userInfoList => {
|
||
|
this.userInfoList = userInfoList;
|
||
|
})
|
||
|
)
|
||
|
.subscribe();
|
||
|
|
||
|
this.messageSendListSubscription = this.messageApiService
|
||
|
.retrieveSendMessage({
|
||
|
userSeq: this.loginRes.userSeq,
|
||
|
deviceType: DeviceType.PC,
|
||
|
tokenKey: this.loginRes.tokenString,
|
||
|
type: MessageType.Send,
|
||
|
pageSize: this.pageSize,
|
||
|
pageCount: this.currentPage
|
||
|
} as RetrieveRequest)
|
||
|
.pipe(
|
||
|
map(res => {
|
||
|
console.log(res);
|
||
|
if (res.statusCode === StatusCode.Success) {
|
||
|
} else {
|
||
|
}
|
||
|
}),
|
||
|
catchError(error => of(console.log(error)))
|
||
|
)
|
||
|
.subscribe();
|
||
|
}
|
||
|
|
||
|
ngOnDestroy(): void {
|
||
|
if (!!this.userInfoListSubscription) {
|
||
|
this.userInfoListSubscription.unsubscribe();
|
||
|
}
|
||
|
if (!!this.messageSendListSubscription) {
|
||
|
this.messageSendListSubscription.unsubscribe();
|
||
|
}
|
||
|
}
|
||
|
}
|