next-ucap-messenger/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/left-sidenav/chat.component.ts

86 lines
2.4 KiB
TypeScript
Raw Normal View History

2019-10-10 05:50:58 +00:00
import { Component, OnInit, OnDestroy } from '@angular/core';
import { ucapAnimations } from '@ucap-webmessenger/ui';
2019-10-02 09:09:39 +00:00
import { NGXLogger } from 'ngx-logger';
import { Store, select } from '@ngrx/store';
import { Subscription, combineLatest } from 'rxjs';
2019-10-10 05:50:58 +00:00
import {
RoomInfo,
UserInfoShort,
UserInfo as RoomUserInfo
} from '@ucap-webmessenger/protocol-room';
2019-10-02 09:09:39 +00:00
import * as AppStore from '@app/store';
2019-10-08 02:19:47 +00:00
import * as ChatStore from '@app/store/messenger/chat';
import { tap, map } from 'rxjs/operators';
import {
RoomUserDetailData,
RoomUserData
} from '@ucap-webmessenger/protocol-sync';
@Component({
selector: 'app-layout-chat-left-sidenav-chat',
templateUrl: './chat.component.html',
styleUrls: ['./chat.component.scss'],
animations: ucapAnimations
})
2019-10-10 05:50:58 +00:00
export class ChatComponent implements OnInit, OnDestroy {
roomList: RoomInfo[];
roomUserList: RoomUserDetailData[];
roomUserShortList: RoomUserData[];
2019-10-10 05:50:58 +00:00
roomSubscription: Subscription;
2019-10-02 09:09:39 +00:00
constructor(private store: Store<any>, private logger: NGXLogger) {}
ngOnInit() {
this.roomSubscription = combineLatest([
this.store.pipe(
select(AppStore.MessengerSelector.SyncSelector.selectAllRoom)
),
this.store.pipe(
select(AppStore.MessengerSelector.SyncSelector.selectAllRoomUser)
),
this.store.pipe(
select(AppStore.MessengerSelector.SyncSelector.selectAllRoomUserShort)
)
])
2019-10-10 05:50:58 +00:00
.pipe(
tap(([room, roomUser, roomUserShort]) => {
this.roomList = room;
this.roomUserList = roomUser;
this.roomUserShortList = roomUserShort;
2019-10-10 05:50:58 +00:00
})
)
.subscribe();
}
ngOnDestroy(): void {
if (!!this.roomSubscription) {
this.roomSubscription.unsubscribe();
}
2019-10-02 09:09:39 +00:00
}
2019-10-08 02:19:47 +00:00
onSelectedRoom(roomInfo: RoomInfo) {
this.store.dispatch(ChatStore.selectedRoom({ roomSeq: roomInfo.roomSeq }));
}
2019-10-10 05:50:58 +00:00
getRoomUserList(roomInfo: RoomInfo): RoomUserInfo[] | UserInfoShort[] {
if (!!this.roomUserList && 0 < this.roomUserList.length) {
const i = this.roomUserList.findIndex(
value => roomInfo.roomSeq === value.roomSeq
);
if (-1 < i) {
return this.roomUserList[i].userInfos;
}
2019-10-10 05:50:58 +00:00
}
if (!!this.roomUserShortList && 0 < this.roomUserShortList.length) {
const i = this.roomUserShortList.findIndex(
value => roomInfo.roomSeq === value.roomSeq
);
if (-1 < i) {
return this.roomUserShortList[i].userInfos;
}
2019-10-10 05:50:58 +00:00
}
}
}