2019-11-07 16:56:14 +09:00
|
|
|
import { map, tap } from 'rxjs/operators';
|
2019-11-11 14:31:26 +09:00
|
|
|
import { Component, OnInit, Inject, OnDestroy, ViewChild } from '@angular/core';
|
2019-09-27 12:53:21 +09:00
|
|
|
|
|
|
|
import { Store, select } from '@ngrx/store';
|
|
|
|
|
|
|
|
import * as AppSotre from '@app/store';
|
2019-11-11 14:31:26 +09:00
|
|
|
import * as ChatStore from '@app/store/messenger/chat';
|
2019-11-07 16:56:14 +09:00
|
|
|
import { Observable, Subscription } from 'rxjs';
|
|
|
|
import {
|
|
|
|
WindowIdle,
|
|
|
|
UCAP_NATIVE_SERVICE,
|
|
|
|
NativeService
|
|
|
|
} from '@ucap-webmessenger/native';
|
2019-11-08 13:35:39 +09:00
|
|
|
|
|
|
|
import { UserInfo } from '@ucap-webmessenger/protocol-sync';
|
|
|
|
import {
|
|
|
|
UserInfoSS,
|
|
|
|
UserInfoF,
|
|
|
|
UserInfoDN
|
|
|
|
} from '@ucap-webmessenger/protocol-query';
|
2019-11-07 16:56:14 +09:00
|
|
|
import { StatusProtocolService } from '@ucap-webmessenger/protocol-status';
|
|
|
|
import { StatusType, StatusCode } from '@ucap-webmessenger/core';
|
2019-11-08 13:35:39 +09:00
|
|
|
import { DialogService } from '@ucap-webmessenger/ui';
|
|
|
|
import {
|
|
|
|
ProfileDialogComponent,
|
|
|
|
ProfileDialogData,
|
|
|
|
ProfileDialogResult
|
|
|
|
} from '@app/layouts/messenger/dialogs/profile/profile.dialog.component';
|
2019-11-11 14:31:26 +09:00
|
|
|
import { MatSidenav, MatDrawer } from '@angular/material';
|
2019-09-18 15:02:21 +09:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-page-messenger-main',
|
|
|
|
templateUrl: './main.page.component.html',
|
|
|
|
styleUrls: ['./main.page.component.scss']
|
|
|
|
})
|
2019-09-19 14:15:43 +09:00
|
|
|
export class MainPageComponent implements OnInit {
|
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-09-23 14:23:24 +09:00
|
|
|
|
2019-11-11 14:31:26 +09:00
|
|
|
@ViewChild('rightDrawer', { static: true }) rightDrawer: MatDrawer;
|
|
|
|
|
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,
|
|
|
|
private dialogService: DialogService
|
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;
|
|
|
|
|
|
|
|
if (action === 'IDLE') {
|
|
|
|
// away
|
|
|
|
statusType = StatusCode.Away;
|
|
|
|
} else {
|
|
|
|
// online
|
|
|
|
statusType = StatusCode.OnLine;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.statusProtocolService.status({
|
|
|
|
statusDivisionType: StatusType.Messenger,
|
|
|
|
statusType,
|
|
|
|
statusMessage: ''
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
OnDestroy(): void {
|
|
|
|
if (!!this.idleStateChangedSubscription) {
|
|
|
|
this.idleStateChangedSubscription.unsubscribe();
|
|
|
|
}
|
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({
|
|
|
|
req: null
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-08 13:35:39 +09:00
|
|
|
onClickOpenProfile(userInfo: UserInfo | UserInfoSS | UserInfoF | UserInfoDN) {
|
|
|
|
this.dialogService.open<
|
|
|
|
ProfileDialogComponent,
|
|
|
|
ProfileDialogData,
|
|
|
|
ProfileDialogResult
|
|
|
|
>(ProfileDialogComponent, {
|
|
|
|
data: {
|
|
|
|
userInfo
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2019-09-18 15:02:21 +09:00
|
|
|
}
|