2019-11-12 10:38:51 +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-12 10:38:51 +09:00
|
|
|
import { Store, select } from "@ngrx/store";
|
2019-09-27 12:53:21 +09:00
|
|
|
|
2019-11-12 10:38:51 +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,
|
|
|
|
NativeService
|
2019-11-12 10:38:51 +09:00
|
|
|
} from "@ucap-webmessenger/native";
|
2019-11-08 13:35:39 +09:00
|
|
|
|
2019-11-12 10:38:51 +09:00
|
|
|
import { UserInfo } from "@ucap-webmessenger/protocol-sync";
|
2019-11-08 13:35:39 +09:00
|
|
|
import {
|
|
|
|
UserInfoSS,
|
|
|
|
UserInfoF,
|
|
|
|
UserInfoDN
|
2019-11-12 10:38:51 +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,
|
|
|
|
ProfileDialogResult
|
2019-11-12 10:38:51 +09:00
|
|
|
} from "@app/layouts/messenger/dialogs/profile/profile.dialog.component";
|
|
|
|
import { MatSidenav, MatDrawer } from "@angular/material";
|
2019-09-18 15:02:21 +09:00
|
|
|
|
|
|
|
@Component({
|
2019-11-12 10:38:51 +09:00
|
|
|
selector: "app-page-messenger-main",
|
|
|
|
templateUrl: "./main.page.component.html",
|
|
|
|
styleUrls: ["./main.page.component.scss"]
|
2019-09-18 15:02:21 +09:00
|
|
|
})
|
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-11-12 10:38:51 +09:00
|
|
|
chatOpenRoomSubscription: Subscription;
|
2019-09-23 14:23:24 +09:00
|
|
|
|
2019-11-12 10:38:51 +09:00
|
|
|
@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,
|
|
|
|
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;
|
|
|
|
|
2019-11-12 10:38:51 +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-12 10:38:51 +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
|
|
|
}
|
|
|
|
|
|
|
|
OnDestroy(): void {
|
|
|
|
if (!!this.idleStateChangedSubscription) {
|
|
|
|
this.idleStateChangedSubscription.unsubscribe();
|
|
|
|
}
|
2019-11-12 10:38:51 +09:00
|
|
|
|
|
|
|
if (!!this.chatOpenRoomSubscription) {
|
|
|
|
this.chatOpenRoomSubscription.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
|
|
|
}
|