121 lines
3.2 KiB
TypeScript
Raw Normal View History

import { map, tap } from 'rxjs/operators';
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';
import * as ChatStore from '@app/store/messenger/chat';
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';
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';
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>;
selectedRightDrawer$: Observable<string | null>;
idleStateChangedSubscription: Subscription;
@ViewChild('rightDrawer', { static: true }) rightDrawer: MatDrawer;
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-09-19 14:15:43 +09:00
ngOnInit(): void {
2019-09-27 12:53:21 +09:00
this.selectedChat$ = this.store.pipe(
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
);
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
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
}