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

114 lines
3.4 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 * 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,
2019-11-14 01:31:23 +00:00
MessageType,
RetrieveRequest
2019-11-13 06:42:30 +00:00
} from '@ucap-webmessenger/api-message';
import { DeviceType } from '@ucap-webmessenger/core';
import { StatusCode, MessageStatusCode } from '@ucap-webmessenger/api';
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 {
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.responseCode === MessageStatusCode.Success) {
2019-11-13 06:42:30 +00:00
} else {
}
}),
catchError(error => of(console.log(error)))
)
.subscribe();
}
ngOnDestroy(): void {
if (!!this.userInfoListSubscription) {
this.userInfoListSubscription.unsubscribe();
}
if (!!this.messageSendListSubscription) {
this.messageSendListSubscription.unsubscribe();
}
}
}