2019-10-23 08:03:34 +00:00
|
|
|
import { exit } from './../../../../store/messenger/room/actions';
|
|
|
|
import { Component, OnInit, OnDestroy, ViewChild } 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-16 05:53:53 +00:00
|
|
|
import { Subscription, combineLatest, Observable } 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';
|
2019-10-23 08:03:34 +00:00
|
|
|
import * as RoomStore from '@app/store/messenger/room';
|
2019-10-29 03:23:40 +00:00
|
|
|
import { tap, debounceTime, delay } from 'rxjs/operators';
|
2019-10-11 02:58:03 +00:00
|
|
|
import {
|
|
|
|
RoomUserDetailData,
|
|
|
|
RoomUserData
|
|
|
|
} from '@ucap-webmessenger/protocol-sync';
|
2019-10-15 07:59:05 +00:00
|
|
|
import { VersionInfo2Response } from '@ucap-webmessenger/api-public';
|
|
|
|
import { SessionStorageService } from '@ucap-webmessenger/web-storage';
|
|
|
|
import { KEY_VER_INFO } from '@app/types/ver-info.type';
|
2019-10-16 05:53:53 +00:00
|
|
|
import { LoginResponse } from '@ucap-webmessenger/protocol-authentication';
|
2019-10-23 08:03:34 +00:00
|
|
|
import { MatMenuTrigger } from '@angular/material';
|
2019-10-29 02:07:03 +00:00
|
|
|
import { FormGroup, FormBuilder } from '@angular/forms';
|
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 {
|
2019-10-23 08:03:34 +00:00
|
|
|
@ViewChild('chatContextMenuTrigger', { static: true })
|
|
|
|
chatContextMenuTrigger: MatMenuTrigger;
|
|
|
|
chatContextMenuPosition = { x: '0px', y: '0px' };
|
|
|
|
|
2019-10-10 05:50:58 +00:00
|
|
|
roomList: RoomInfo[];
|
2019-10-11 02:58:03 +00:00
|
|
|
roomUserList: RoomUserDetailData[];
|
|
|
|
roomUserShortList: RoomUserData[];
|
2019-10-15 07:59:05 +00:00
|
|
|
sessionVerinfo: VersionInfo2Response;
|
2019-10-10 05:50:58 +00:00
|
|
|
|
2019-10-16 08:46:53 +00:00
|
|
|
loginRes: LoginResponse;
|
|
|
|
loginResSubscription: Subscription;
|
2019-10-10 05:50:58 +00:00
|
|
|
roomSubscription: Subscription;
|
2019-09-23 05:23:24 +00:00
|
|
|
|
2019-10-29 02:07:03 +00:00
|
|
|
isSearch = false;
|
2019-10-29 03:23:40 +00:00
|
|
|
searchRoomList: RoomInfo[] = [];
|
2019-10-29 02:07:03 +00:00
|
|
|
fgSearch: FormGroup;
|
|
|
|
recommendedWordList: string[];
|
|
|
|
filteredRecommendedWordList: string[];
|
|
|
|
|
2019-10-15 07:59:05 +00:00
|
|
|
constructor(
|
|
|
|
private store: Store<any>,
|
2019-10-29 02:07:03 +00:00
|
|
|
private formBuilder: FormBuilder,
|
2019-10-15 07:59:05 +00:00
|
|
|
private logger: NGXLogger,
|
|
|
|
private sessionStorageService: SessionStorageService
|
2019-10-16 06:01:16 +00:00
|
|
|
) {
|
|
|
|
this.sessionVerinfo = this.sessionStorageService.get<VersionInfo2Response>(
|
|
|
|
KEY_VER_INFO
|
|
|
|
);
|
2019-10-29 02:07:03 +00:00
|
|
|
this.recommendedWordList = [];
|
2019-10-16 06:01:16 +00:00
|
|
|
}
|
2019-10-02 09:09:39 +00:00
|
|
|
|
|
|
|
ngOnInit() {
|
2019-10-29 02:07:03 +00:00
|
|
|
this.fgSearch = this.formBuilder.group({
|
|
|
|
searchInput: null
|
|
|
|
});
|
|
|
|
|
|
|
|
this.fgSearch
|
|
|
|
.get('searchInput')
|
2019-10-29 03:23:40 +00:00
|
|
|
.valueChanges.pipe(debounceTime(100))
|
2019-10-29 02:07:03 +00:00
|
|
|
.subscribe(value => {
|
|
|
|
if (value !== null && value.length > 0) {
|
|
|
|
this.filteredRecommendedWordList = this.recommendedWordList.filter(
|
|
|
|
v => {
|
|
|
|
return v.includes(value);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
this.filteredRecommendedWordList = [];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-10-11 02:58:03 +00:00
|
|
|
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(
|
2019-10-11 02:58:03 +00:00
|
|
|
tap(([room, roomUser, roomUserShort]) => {
|
|
|
|
this.roomList = room;
|
2019-10-29 03:23:40 +00:00
|
|
|
this.searchRoomList = room;
|
2019-10-11 02:58:03 +00:00
|
|
|
this.roomUserList = roomUser;
|
|
|
|
this.roomUserShortList = roomUserShort;
|
2019-10-29 02:07:03 +00:00
|
|
|
|
|
|
|
const recommendedWordList = [];
|
|
|
|
for (const r of room) {
|
|
|
|
if (!!r.roomName && '' !== r.roomName.trim()) {
|
|
|
|
recommendedWordList.push(r.roomName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (const ru of roomUser) {
|
|
|
|
for (const u of ru.userInfos) {
|
|
|
|
if (u.seq !== this.loginRes.userSeq) {
|
|
|
|
if (!!u.name && '' !== u.name.trim()) {
|
|
|
|
recommendedWordList.push(u.name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (const ru of roomUserShort) {
|
|
|
|
for (const u of ru.userInfos) {
|
|
|
|
if (u.seq !== this.loginRes.userSeq) {
|
|
|
|
if (!!u.name && '' !== u.name.trim()) {
|
|
|
|
recommendedWordList.push(u.name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.recommendedWordList = [...recommendedWordList];
|
2019-10-10 05:50:58 +00:00
|
|
|
})
|
|
|
|
)
|
|
|
|
.subscribe();
|
2019-10-15 07:59:05 +00:00
|
|
|
|
2019-10-16 08:46:53 +00:00
|
|
|
this.loginResSubscription = this.store
|
|
|
|
.pipe(
|
|
|
|
select(AppStore.AccountSelector.AuthenticationSelector.loginRes),
|
|
|
|
tap(loginRes => {
|
|
|
|
this.loginRes = loginRes;
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.subscribe();
|
2019-10-10 05:50:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy(): void {
|
|
|
|
if (!!this.roomSubscription) {
|
|
|
|
this.roomSubscription.unsubscribe();
|
|
|
|
}
|
2019-10-16 08:46:53 +00:00
|
|
|
if (!!this.loginResSubscription) {
|
|
|
|
this.loginResSubscription.unsubscribe();
|
|
|
|
}
|
2019-10-02 09:09:39 +00:00
|
|
|
}
|
2019-10-08 02:19:47 +00:00
|
|
|
|
2019-10-29 03:23:40 +00:00
|
|
|
onClickSearchCancel() {
|
|
|
|
this.isSearch = false;
|
|
|
|
this.searchRoomList = [];
|
|
|
|
this.filteredRecommendedWordList = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
onKeyDownEnter(event: KeyboardEvent, search: string) {
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
|
2019-10-23 06:45:48 +00:00
|
|
|
if (search.trim().length > 1) {
|
|
|
|
this.isSearch = true;
|
2019-10-29 03:23:40 +00:00
|
|
|
this.searchRoomList = this.roomList.filter(room => {
|
|
|
|
if (room.roomName.indexOf(search) >= 0) {
|
|
|
|
return true;
|
|
|
|
} else if (
|
|
|
|
this.getRoomUserList(room).filter(user =>
|
|
|
|
user.seq !== this.loginRes.userSeq
|
|
|
|
? user.name.indexOf(search) >= 0
|
|
|
|
: false
|
|
|
|
).length > 0
|
|
|
|
) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.isSearch = false;
|
|
|
|
this.searchRoomList = [];
|
2019-10-23 06:45:48 +00:00
|
|
|
}
|
2019-10-29 03:23:40 +00:00
|
|
|
setTimeout(() => (this.filteredRecommendedWordList = []), 200);
|
2019-10-23 06:45:48 +00:00
|
|
|
}
|
|
|
|
|
2019-10-23 08:03:34 +00:00
|
|
|
onContextMenuChat(event: MouseEvent, roomInfo: RoomInfo) {
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
|
|
|
|
this.chatContextMenuPosition.x = event.clientX + 'px';
|
|
|
|
this.chatContextMenuPosition.y = event.clientY + 'px';
|
|
|
|
this.chatContextMenuTrigger.menu.focusFirstItem('mouse');
|
|
|
|
this.chatContextMenuTrigger.menuData = { roomInfo };
|
|
|
|
this.chatContextMenuTrigger.openMenu();
|
|
|
|
}
|
|
|
|
|
2019-10-08 02:19:47 +00:00
|
|
|
onSelectedRoom(roomInfo: RoomInfo) {
|
|
|
|
this.store.dispatch(ChatStore.selectedRoom({ roomSeq: roomInfo.roomSeq }));
|
|
|
|
}
|
2019-10-23 08:03:34 +00:00
|
|
|
onClickToggleAlarm(roomInfo: RoomInfo) {
|
|
|
|
this.store.dispatch(RoomStore.updateOnlyAlarm({ roomInfo }));
|
|
|
|
}
|
|
|
|
onClickExit(roomInfo: RoomInfo) {
|
|
|
|
this.store.dispatch(
|
|
|
|
RoomStore.exit({
|
|
|
|
roomSeq: roomInfo.roomSeq
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
2019-10-10 05:50:58 +00:00
|
|
|
|
2019-10-23 06:45:48 +00:00
|
|
|
getRoomUserList(roomInfo: RoomInfo): (RoomUserInfo | UserInfoShort)[] {
|
2019-10-11 02:58:03 +00:00
|
|
|
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
|
|
|
}
|
2019-10-11 02:58:03 +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
|
|
|
}
|
|
|
|
}
|
2019-09-23 05:23:24 +00:00
|
|
|
}
|