2019-10-10 06:53:08 +00:00
|
|
|
import {
|
|
|
|
Component,
|
|
|
|
OnInit,
|
|
|
|
OnDestroy,
|
|
|
|
AfterViewChecked,
|
|
|
|
ViewChild,
|
|
|
|
ElementRef
|
|
|
|
} from '@angular/core';
|
2019-09-23 05:23:24 +00:00
|
|
|
import { ucapAnimations } from '@ucap-webmessenger/ui';
|
2019-10-08 04:31:33 +00:00
|
|
|
import { Store, select } from '@ngrx/store';
|
|
|
|
import { NGXLogger } from 'ngx-logger';
|
2019-10-08 08:57:57 +00:00
|
|
|
import { Observable, Subscription } from 'rxjs';
|
2019-10-08 05:34:37 +00:00
|
|
|
import { Info, EventType } from '@ucap-webmessenger/protocol-event';
|
2019-10-08 04:31:33 +00:00
|
|
|
|
|
|
|
import * as AppStore from '@app/store';
|
2019-10-08 05:34:37 +00:00
|
|
|
import * as EventStore from '@app/store/messenger/event';
|
2019-10-11 09:03:01 +00:00
|
|
|
import * as ChatStore from '@app/store/messenger/chat';
|
2019-10-11 06:55:27 +00:00
|
|
|
import * as RoomStore from '@app/store/messenger/room';
|
2019-10-08 04:31:33 +00:00
|
|
|
import { LoginResponse } from '@ucap-webmessenger/protocol-authentication';
|
|
|
|
import { SessionStorageService } from '@ucap-webmessenger/web-storage';
|
|
|
|
import { LoginInfo, KEY_LOGIN_INFO } from '@app/types';
|
2019-10-11 02:40:35 +00:00
|
|
|
import { RoomInfo, UserInfo } from '@ucap-webmessenger/protocol-room';
|
2019-10-08 08:57:57 +00:00
|
|
|
import { tap } from 'rxjs/operators';
|
2019-10-14 04:53:22 +00:00
|
|
|
import { FileInfo } from '@ucap-webmessenger/ui-chat';
|
2019-09-23 05:23:24 +00:00
|
|
|
|
|
|
|
@Component({
|
2019-09-26 02:11:22 +00:00
|
|
|
selector: 'app-layout-messenger-messages',
|
2019-09-23 05:23:24 +00:00
|
|
|
templateUrl: './messages.component.html',
|
|
|
|
styleUrls: ['./messages.component.scss'],
|
|
|
|
animations: ucapAnimations
|
|
|
|
})
|
2019-10-10 06:53:08 +00:00
|
|
|
export class MessagesComponent implements OnInit, OnDestroy, AfterViewChecked {
|
|
|
|
@ViewChild('messageBoxContainer', { static: true })
|
|
|
|
private messageBoxContainer: ElementRef;
|
|
|
|
|
2019-10-08 05:59:22 +00:00
|
|
|
loginRes: LoginResponse;
|
|
|
|
loginResSubscription: Subscription;
|
2019-10-08 04:31:33 +00:00
|
|
|
eventList$: Observable<Info[]>;
|
2019-10-08 05:34:37 +00:00
|
|
|
roomInfo: RoomInfo;
|
|
|
|
roomInfoSubscription: Subscription;
|
2019-10-11 02:40:35 +00:00
|
|
|
userInfoList$: Observable<UserInfo[]>;
|
2019-10-08 06:25:00 +00:00
|
|
|
eventListProcessing$: Observable<boolean>;
|
2019-10-08 04:31:33 +00:00
|
|
|
|
|
|
|
constructor(
|
|
|
|
private store: Store<any>,
|
|
|
|
private sessionStorageService: SessionStorageService,
|
|
|
|
private logger: NGXLogger
|
|
|
|
) {}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
const loginInfo = this.sessionStorageService.get<LoginInfo>(KEY_LOGIN_INFO);
|
|
|
|
|
2019-10-08 05:59:22 +00:00
|
|
|
this.loginResSubscription = this.store
|
|
|
|
.pipe(
|
|
|
|
select(AppStore.AccountSelector.AuthenticationSelector.loginRes),
|
|
|
|
tap(loginRes => {
|
|
|
|
this.loginRes = loginRes;
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.subscribe();
|
2019-09-23 05:23:24 +00:00
|
|
|
|
2019-10-08 05:34:37 +00:00
|
|
|
this.roomInfoSubscription = this.store
|
|
|
|
.pipe(
|
|
|
|
select(AppStore.MessengerSelector.RoomSelector.roomInfo),
|
|
|
|
tap(roomInfo => {
|
|
|
|
this.roomInfo = roomInfo;
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.subscribe();
|
|
|
|
|
2019-10-11 02:40:35 +00:00
|
|
|
this.userInfoList$ = this.store.pipe(
|
|
|
|
select(AppStore.MessengerSelector.RoomSelector.userInfoList)
|
|
|
|
);
|
|
|
|
|
2019-10-08 06:25:00 +00:00
|
|
|
this.eventListProcessing$ = this.store.pipe(
|
|
|
|
select(AppStore.MessengerSelector.EventSelector.infoListProcessing)
|
|
|
|
);
|
|
|
|
|
2019-10-08 04:31:33 +00:00
|
|
|
this.eventList$ = this.store.pipe(
|
|
|
|
select(AppStore.MessengerSelector.EventSelector.infoList)
|
|
|
|
);
|
2019-10-10 06:53:08 +00:00
|
|
|
|
|
|
|
this.scrollToBottomForMessageBoxContainer();
|
2019-10-08 04:31:33 +00:00
|
|
|
}
|
2019-09-23 05:23:24 +00:00
|
|
|
|
2019-10-08 05:34:37 +00:00
|
|
|
ngOnDestroy(): void {
|
2019-10-08 05:59:22 +00:00
|
|
|
if (!!this.loginResSubscription) {
|
|
|
|
this.loginResSubscription.unsubscribe();
|
|
|
|
}
|
2019-10-08 05:34:37 +00:00
|
|
|
if (!!this.roomInfoSubscription) {
|
|
|
|
this.roomInfoSubscription.unsubscribe();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-10 06:53:08 +00:00
|
|
|
ngAfterViewChecked(): void {
|
|
|
|
this.scrollToBottomForMessageBoxContainer();
|
|
|
|
}
|
|
|
|
|
2019-09-23 05:23:24 +00:00
|
|
|
selectContact() {}
|
2019-10-08 05:34:37 +00:00
|
|
|
|
|
|
|
onSendMessage(message: string) {
|
|
|
|
this.store.dispatch(
|
|
|
|
EventStore.send({
|
2019-10-08 05:59:22 +00:00
|
|
|
senderSeq: this.loginRes.userSeq,
|
2019-10-08 05:34:37 +00:00
|
|
|
req: {
|
|
|
|
roomSeq: this.roomInfo.roomSeq,
|
|
|
|
eventType: EventType.Character,
|
|
|
|
sentMessage: message
|
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
2019-10-10 06:53:08 +00:00
|
|
|
|
2019-10-11 06:55:27 +00:00
|
|
|
onClickReceiveAlarm() {
|
|
|
|
this.store.dispatch(RoomStore.updateOnlyAlarm({ roomInfo: this.roomInfo }));
|
|
|
|
}
|
|
|
|
|
2019-10-10 06:53:08 +00:00
|
|
|
private scrollToBottomForMessageBoxContainer(): void {
|
|
|
|
try {
|
|
|
|
this.messageBoxContainer.nativeElement.scrollTop = this.messageBoxContainer.nativeElement.scrollHeight;
|
|
|
|
} catch (err) {}
|
|
|
|
}
|
2019-10-11 09:03:01 +00:00
|
|
|
|
|
|
|
/** MassText Detail View */
|
|
|
|
onMassDetail(value: number) {
|
|
|
|
this.store.dispatch(
|
|
|
|
ChatStore.selectedMassDetail({
|
|
|
|
massEventSeq: value
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
2019-10-14 04:53:22 +00:00
|
|
|
|
|
|
|
onImageViewer(value: FileInfo) {
|
|
|
|
this.logger.debug('imageViewer', value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** File Save, Save As */
|
|
|
|
onSave(value: { fileInfo: FileInfo; type: string }) {
|
|
|
|
this.logger.debug('fileSave', value);
|
|
|
|
}
|
2019-09-23 05:23:24 +00:00
|
|
|
}
|