2019-11-13 10:45:06 +09:00
|
|
|
import { map, tap } from 'rxjs/operators';
|
|
|
|
import { Component, OnInit, Inject, OnDestroy, ViewChild } from '@angular/core';
|
2019-09-27 12:53:21 +09:00
|
|
|
|
2019-11-13 10:45:06 +09:00
|
|
|
import { Store, select } from '@ngrx/store';
|
2019-09-27 12:53:21 +09:00
|
|
|
|
2019-11-13 10:45:06 +09:00
|
|
|
import * as AppSotre from '@app/store';
|
|
|
|
import * as ChatStore from '@app/store/messenger/chat';
|
|
|
|
import { Observable, Subscription } from 'rxjs';
|
2019-11-07 16:56:14 +09:00
|
|
|
import {
|
|
|
|
WindowIdle,
|
|
|
|
UCAP_NATIVE_SERVICE,
|
2019-11-21 10:29:19 +09:00
|
|
|
NativeService
|
2019-11-13 10:45:06 +09:00
|
|
|
} from '@ucap-webmessenger/native';
|
2019-11-08 13:35:39 +09:00
|
|
|
|
2019-11-13 10:45:06 +09:00
|
|
|
import { UserInfo } from '@ucap-webmessenger/protocol-sync';
|
2019-11-08 13:35:39 +09:00
|
|
|
import {
|
|
|
|
UserInfoSS,
|
|
|
|
UserInfoF,
|
2019-11-21 10:29:19 +09:00
|
|
|
UserInfoDN
|
2019-11-13 10:45:06 +09:00
|
|
|
} from '@ucap-webmessenger/protocol-query';
|
|
|
|
import { StatusProtocolService } from '@ucap-webmessenger/protocol-status';
|
|
|
|
import { StatusType, StatusCode } from '@ucap-webmessenger/core';
|
|
|
|
import { DialogService } from '@ucap-webmessenger/ui';
|
2019-11-08 13:35:39 +09:00
|
|
|
import {
|
|
|
|
ProfileDialogComponent,
|
|
|
|
ProfileDialogData,
|
2019-11-21 10:29:19 +09:00
|
|
|
ProfileDialogResult
|
2019-11-13 10:45:06 +09:00
|
|
|
} from '@app/layouts/messenger/dialogs/profile/profile.dialog.component';
|
|
|
|
import { MatSidenav, MatDrawer } from '@angular/material';
|
|
|
|
import { SplitAreaDirective } from 'angular-split';
|
2019-11-21 10:29:19 +09:00
|
|
|
import { NGXLogger } from 'ngx-logger';
|
2019-09-18 15:02:21 +09:00
|
|
|
|
|
|
|
@Component({
|
2019-11-13 10:45:06 +09:00
|
|
|
selector: 'app-page-messenger-main',
|
|
|
|
templateUrl: './main.page.component.html',
|
2019-11-21 10:29:19 +09:00
|
|
|
styleUrls: ['./main.page.component.scss']
|
2019-09-18 15:02:21 +09:00
|
|
|
})
|
2019-11-21 10:29:19 +09:00
|
|
|
export class MainPageComponent implements OnInit, OnDestroy {
|
2019-10-08 11:19:47 +09:00
|
|
|
selectedChat$: Observable<string | null>;
|
2019-11-11 14:31:26 +09:00
|
|
|
selectedRightDrawer$: Observable<string | null>;
|
2019-11-07 16:56:14 +09:00
|
|
|
idleStateChangedSubscription: Subscription;
|
2019-11-12 10:38:51 +09:00
|
|
|
chatOpenRoomSubscription: Subscription;
|
2019-09-23 14:23:24 +09:00
|
|
|
|
2019-11-13 10:45:06 +09:00
|
|
|
defaultLeftSideComponentWidth = 380;
|
|
|
|
leftSideComponentWidth = this.defaultLeftSideComponentWidth;
|
|
|
|
|
|
|
|
@ViewChild('rightDrawer', { static: true }) rightDrawer: MatDrawer;
|
2019-11-11 14:31:26 +09:00
|
|
|
|
2019-11-07 16:56:14 +09:00
|
|
|
constructor(
|
|
|
|
@Inject(UCAP_NATIVE_SERVICE) private nativeService: NativeService,
|
|
|
|
private store: Store<any>,
|
2019-11-08 13:35:39 +09:00
|
|
|
private statusProtocolService: StatusProtocolService,
|
2019-11-21 10:29:19 +09:00
|
|
|
private dialogService: DialogService,
|
|
|
|
private logger: NGXLogger
|
2019-11-07 16:56:14 +09:00
|
|
|
) {}
|
2019-09-19 14:15:43 +09:00
|
|
|
|
|
|
|
ngOnInit(): void {
|
2019-09-27 12:53:21 +09:00
|
|
|
this.selectedChat$ = this.store.pipe(
|
2019-11-11 14:31:26 +09:00
|
|
|
select(AppSotre.MessengerSelector.ChatSelector.selectedRoom),
|
|
|
|
tap(selectedRoom => {
|
|
|
|
if (!selectedRoom) {
|
|
|
|
this.rightDrawer.close();
|
|
|
|
}
|
|
|
|
return selectedRoom;
|
|
|
|
})
|
|
|
|
);
|
|
|
|
this.selectedRightDrawer$ = this.store.pipe(
|
|
|
|
select(AppSotre.MessengerSelector.ChatSelector.selectedRightDrawer),
|
|
|
|
tap(selectedRightDrawer => {
|
|
|
|
if (!!selectedRightDrawer) {
|
|
|
|
this.rightDrawer.open();
|
|
|
|
} else {
|
|
|
|
this.rightDrawer.close();
|
|
|
|
}
|
|
|
|
})
|
2019-09-27 12:53:21 +09:00
|
|
|
);
|
2019-11-07 16:56:14 +09:00
|
|
|
|
|
|
|
this.idleStateChangedSubscription = this.nativeService
|
|
|
|
.idleStateChanged()
|
|
|
|
.subscribe(action => {
|
|
|
|
console.log(action);
|
|
|
|
let statusType: StatusCode;
|
|
|
|
|
2019-11-13 10:45:06 +09:00
|
|
|
if (action === 'IDLE') {
|
2019-11-07 16:56:14 +09:00
|
|
|
// away
|
|
|
|
statusType = StatusCode.Away;
|
|
|
|
} else {
|
|
|
|
// online
|
|
|
|
statusType = StatusCode.OnLine;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.statusProtocolService.status({
|
|
|
|
statusDivisionType: StatusType.Messenger,
|
|
|
|
statusType,
|
2019-11-21 10:29:19 +09:00
|
|
|
statusMessage: ''
|
2019-11-07 16:56:14 +09:00
|
|
|
});
|
|
|
|
});
|
2019-11-12 10:38:51 +09:00
|
|
|
|
|
|
|
this.chatOpenRoomSubscription = this.nativeService
|
|
|
|
.chatOpenRoom()
|
|
|
|
.subscribe(roomSeq => {
|
|
|
|
this.store.dispatch(ChatStore.selectedRoom({ roomSeq }));
|
|
|
|
});
|
2019-11-07 16:56:14 +09:00
|
|
|
}
|
|
|
|
|
2019-11-21 10:29:19 +09:00
|
|
|
ngOnDestroy(): void {
|
2019-11-07 16:56:14 +09:00
|
|
|
if (!!this.idleStateChangedSubscription) {
|
|
|
|
this.idleStateChangedSubscription.unsubscribe();
|
|
|
|
}
|
2019-11-12 10:38:51 +09:00
|
|
|
|
|
|
|
if (!!this.chatOpenRoomSubscription) {
|
|
|
|
this.chatOpenRoomSubscription.unsubscribe();
|
|
|
|
}
|
2019-11-21 10:29:19 +09:00
|
|
|
|
|
|
|
this.logger.debug('-----------------------MainPageComponent ngOnDestroy');
|
2019-09-19 14:15:43 +09:00
|
|
|
}
|
2019-11-08 13:35:39 +09:00
|
|
|
|
2019-11-11 14:31:26 +09:00
|
|
|
onOpenedChange(event: boolean) {
|
|
|
|
if (!event) {
|
|
|
|
this.store.dispatch(
|
|
|
|
ChatStore.selectedRightDrawer({
|
2019-11-21 10:29:19 +09:00
|
|
|
req: null
|
2019-11-11 14:31:26 +09:00
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-13 10:45:06 +09:00
|
|
|
onGutterDragEnd(e: { gutterNum: number; sizes: Array<number> }) {
|
|
|
|
this.leftSideComponentWidth = e.sizes[0];
|
|
|
|
}
|
|
|
|
onGutterDblClick(e: { gutterNum: number; sizes: Array<number> }) {
|
|
|
|
this.leftSideComponentWidth = this.defaultLeftSideComponentWidth;
|
|
|
|
}
|
|
|
|
|
2019-11-08 13:35:39 +09:00
|
|
|
onClickOpenProfile(userInfo: UserInfo | UserInfoSS | UserInfoF | UserInfoDN) {
|
|
|
|
this.dialogService.open<
|
|
|
|
ProfileDialogComponent,
|
|
|
|
ProfileDialogData,
|
|
|
|
ProfileDialogResult
|
|
|
|
>(ProfileDialogComponent, {
|
|
|
|
data: {
|
2019-11-21 10:29:19 +09:00
|
|
|
userInfo
|
|
|
|
}
|
2019-11-08 13:35:39 +09:00
|
|
|
});
|
|
|
|
}
|
2019-11-13 11:06:13 +09:00
|
|
|
|
|
|
|
onCloseRightDrawer() {
|
|
|
|
this.rightDrawer.close();
|
|
|
|
}
|
2019-09-18 15:02:21 +09:00
|
|
|
}
|