2019-10-10 05:50:58 +00:00
|
|
|
import { Component, OnInit, OnDestroy } from '@angular/core';
|
2019-09-23 05:23:24 +00:00
|
|
|
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';
|
2019-10-10 05:50:58 +00:00
|
|
|
import { Subscription } from 'rxjs';
|
|
|
|
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';
|
2019-10-10 05:50:58 +00:00
|
|
|
import { tap } from 'rxjs/operators';
|
2019-09-23 05:23:24 +00:00
|
|
|
|
|
|
|
@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[];
|
|
|
|
roomUserInfoMap: {
|
|
|
|
[param: string]: {
|
|
|
|
userInfoShortList: UserInfoShort[];
|
|
|
|
userInfoList: RoomUserInfo[];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
roomSubscription: Subscription;
|
2019-09-23 05:23:24 +00:00
|
|
|
|
2019-10-02 09:09:39 +00:00
|
|
|
constructor(private store: Store<any>, private logger: NGXLogger) {}
|
|
|
|
|
|
|
|
ngOnInit() {
|
2019-10-10 05:50:58 +00:00
|
|
|
this.roomSubscription = this.store
|
|
|
|
.pipe(
|
|
|
|
select(AppStore.MessengerSelector.SyncSelector.room),
|
|
|
|
tap(room => {
|
|
|
|
this.roomList = room.roomList;
|
|
|
|
this.roomUserInfoMap = room.roomUserInfoMap;
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.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
|
|
|
|
2019-10-10 06:50:50 +00:00
|
|
|
getRoomUserList(roomInfo: RoomInfo): RoomUserInfo[] | UserInfoShort[] {
|
2019-10-10 05:50:58 +00:00
|
|
|
if (
|
|
|
|
!!this.roomUserInfoMap[roomInfo.roomSeq].userInfoList &&
|
|
|
|
0 < this.roomUserInfoMap[roomInfo.roomSeq].userInfoList.length
|
|
|
|
) {
|
2019-10-10 06:50:50 +00:00
|
|
|
return this.roomUserInfoMap[roomInfo.roomSeq].userInfoList;
|
2019-10-10 05:50:58 +00:00
|
|
|
}
|
|
|
|
if (
|
|
|
|
!!this.roomUserInfoMap[roomInfo.roomSeq].userInfoShortList &&
|
|
|
|
0 < this.roomUserInfoMap[roomInfo.roomSeq].userInfoShortList.length
|
|
|
|
) {
|
2019-10-10 06:50:50 +00:00
|
|
|
return this.roomUserInfoMap[roomInfo.roomSeq].userInfoShortList;
|
2019-10-10 05:50:58 +00:00
|
|
|
}
|
|
|
|
}
|
2019-09-23 05:23:24 +00:00
|
|
|
}
|