This commit is contained in:
leejinho 2020-01-20 17:36:12 +09:00
commit 5e8800cc3c
5 changed files with 130 additions and 77 deletions

View File

@ -7,7 +7,8 @@ import {
Output,
EventEmitter,
Inject,
ChangeDetectorRef
ChangeDetectorRef,
ChangeDetectionStrategy
} from '@angular/core';
import {
ucapAnimations,
@ -133,7 +134,8 @@ import { FileProtocolService } from '@ucap-webmessenger/protocol-file';
selector: 'app-layout-messenger-messages',
templateUrl: './messages.component.html',
styleUrls: ['./messages.component.scss'],
animations: ucapAnimations
animations: ucapAnimations,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class MessagesComponent implements OnInit, OnDestroy, AfterViewInit {
@Output()
@ -391,15 +393,15 @@ export class MessagesComponent implements OnInit, OnDestroy, AfterViewInit {
}
});
this.interval = setInterval(() => {
if (
!!this.roomInfoSubject.value &&
!!this.roomInfoSubject.value.isTimeRoom
) {
this.interval = setInterval(() => {
this.store.dispatch(EventStore.infoIntervalClear({}));
}
}, 1000);
}
}
ngOnDestroy(): void {
if (!!this.loginResSubscription) {
@ -424,8 +426,10 @@ export class MessagesComponent implements OnInit, OnDestroy, AfterViewInit {
this.searchEventListProcessingSubscription.unsubscribe();
}
if (!!this.interval) {
clearInterval(this.interval);
}
}
ngAfterViewInit(): void {
// this.readyToReply();
@ -1847,7 +1851,7 @@ export class MessagesComponent implements OnInit, OnDestroy, AfterViewInit {
this.eventRemainedSubject.value
) {
this.moreSearchProcessing = true;
this.chatMessages.storeScrollHeight();
this.chatMessages.storeScrollPosition();
// Case :: retrieve event infos step by step until include searchtext in event..
this.store.dispatch(

View File

@ -111,14 +111,14 @@ export class MessageBoxComponent implements OnInit, AfterViewInit {
}
ngAfterViewInit(): void {
this.logger.debug(
'offsetHeight' + this.message.seq,
this.mbContainer.nativeElement.offsetHeight
);
this.elementRef.nativeElement.style.height = `${this.mbContainer
.nativeElement.offsetHeight + 20}px`;
this.elementRef.nativeElement.style.maxHeight = `${this.mbContainer
.nativeElement.offsetHeight + 20}px`;
// this.logger.debug(
// 'offsetHeight' + this.message.seq,
// this.mbContainer.nativeElement.offsetHeight
// );
// this.elementRef.nativeElement.style.height = `${this.mbContainer
// .nativeElement.offsetHeight + 20}px`;
// this.elementRef.nativeElement.style.maxHeight = `${this.mbContainer
// .nativeElement.offsetHeight + 20}px`;
this.mbContainer.nativeElement.classList.remove('hide');
}

View File

@ -9,8 +9,14 @@
(psYReachStart)="onYReachStart($event)"
(psYReachEnd)="onYReachEnd($event)"
[enableUnequalChildrenSizes]="true"
[modifyOverflowStyleOfParentScroll]="false"
(vsChange)="onVsChange($event)"
>
<div
#chatMessagesContainer
class="chat-messages hide"
[style.opacity]="fixScreen ? 0 : 1"
>
<div class="chat-messages" [style.opacity]="fixScreen ? 0 : 1">
<div
*ngIf="eventRemained && eventList.length > 0"
class="message-row view-previous"
@ -51,17 +57,15 @@
<!-- MESSAGE -->
<div #container>
<ucap-chat-message-box
*ngFor="
let message of scroll.viewPortItems;
trackBy: trackByEvent;
let i = index
"
*ngFor="let message of scroll.viewPortItems; trackBy: trackByEvent"
[id]="message.seq"
[message]="message"
[mine]="message.senderSeq === loginRes.userSeq"
[highlight]="isHighlightedEvent(message.seq)"
[existReadToHere]="getReadHere(i) && existReadHere && !clearReadHere"
[dateChanged]="getDateSplitter(i)"
[existReadToHere]="
getReadHere(message) && existReadHere && !clearReadHere
"
[dateChanged]="getDateSplitter(message)"
[senderName]="getUserName(message.senderSeq)"
[profileImageRoot]="profileImageRoot"
[profileImage]="getUserProfile(message.senderSeq)"

View File

@ -185,3 +185,7 @@ $meBox-bg: #ffffff;
}
}
}
.hide {
opacity: 0 !important;
}

View File

@ -6,8 +6,9 @@ import {
Output,
ViewChild,
OnDestroy,
ChangeDetectionStrategy,
ElementRef,
Self
ChangeDetectorRef
} from '@angular/core';
import {
@ -28,12 +29,13 @@ import { FileDownloadItem } from '@ucap-webmessenger/api';
import { TranslateService } from '@ngx-translate/core';
import { PerfectScrollbarDirective } from 'ngx-perfect-scrollbar';
import { Observable, Subscription } from 'rxjs';
import { VirtualScrollerComponent } from 'ngx-virtual-scroller';
import { VirtualScrollerComponent, IPageInfo } from 'ngx-virtual-scroller';
@Component({
selector: 'ucap-chat-messages',
templateUrl: './messages.component.html',
styleUrls: ['./messages.component.scss']
styleUrls: ['./messages.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class MessagesComponent implements OnInit, OnDestroy {
@Input()
@ -103,13 +105,16 @@ export class MessagesComponent implements OnInit, OnDestroy {
@Output()
existNewMessage = new EventEmitter<Info<EventJson>>();
@ViewChild('chatMessagesContainer', { static: false })
chatMessagesContainer: ElementRef<HTMLElement>;
@ViewChild(PerfectScrollbarDirective, { static: false })
psChatContent: PerfectScrollbarDirective;
@ViewChild(VirtualScrollerComponent, { static: false })
private virtualScroller: VirtualScrollerComponent;
storedScrollHeight = 0; // 이전대화를 불러올 경우 현재 스크롤 포지션 유지를 위한 값. 0 이면 초기로딩.
storedScrollItem: Info<EventJson>; // 이전대화를 불러올 경우 현재 스크롤 포지션 유지를 위한 값. 0 이면 초기로딩.
scrollUpInitalized = false; // ps 에서 초기 로딩시 scroll reach start 이벤트 발생 버그를 우회하기 위한 init 값으로 scrollUp 에 의해 true 로 된다.
firstCheckReadHere = true;
initRoomLastEventSeq: number;
@ -142,6 +147,7 @@ export class MessagesComponent implements OnInit, OnDestroy {
constructor(
private logger: NGXLogger,
private datePipe: DatePipe,
private changeDetectorRef: ChangeDetectorRef,
private translateService: TranslateService
) {}
@ -153,12 +159,12 @@ export class MessagesComponent implements OnInit, OnDestroy {
this.loginRes = loginRes;
});
this.roomInfoSubscription = this.roomInfo$.subscribe(roomInfo => {
this.eventList = undefined;
this.newEventList = undefined;
this.searchedList = undefined;
this.eventInfoStatus = undefined;
this.eventRemained = undefined;
this.userInfos = undefined;
// this.eventList = undefined;
// this.newEventList = undefined;
// this.searchedList = undefined;
// this.eventInfoStatus = undefined;
// this.eventRemained = undefined;
// this.userInfos = undefined;
this.initEventMore();
this.roomInfo = roomInfo;
@ -175,6 +181,9 @@ export class MessagesComponent implements OnInit, OnDestroy {
this.firstCheckReadHere = false;
}
this.eventList = eventList;
this.changeDetectorRef.detectChanges();
if (this.searchingMode) {
const baseseq = this.baseEventSeq;
// setTimeout(() => {
@ -187,8 +196,6 @@ export class MessagesComponent implements OnInit, OnDestroy {
this.ready();
}
}
this.eventList = eventList;
});
this.newEventListSubscription = this.newEventList$.subscribe(
newEventList => {
@ -280,6 +287,9 @@ export class MessagesComponent implements OnInit, OnDestroy {
}
getUnreadCount(message: Info<EventJson>): string | number {
// if (!this.userInfos || 0 === this.userInfos.length) {
// return '';
// }
const unreadCnt = this.userInfos.filter(user => {
if (message.senderSeq === user.seq) {
// 본인 글은 unreadCount 에 포함하지 않는다.
@ -310,7 +320,9 @@ export class MessagesComponent implements OnInit, OnDestroy {
}
/** Date Splitter show check */
getDateSplitter(curIndex: number): boolean {
getDateSplitter(message: Info<EventJson>): boolean {
const curIndex = this.eventList.findIndex(v => v.seq === message.seq);
if (curIndex === 0) {
return true;
}
@ -318,21 +330,15 @@ export class MessagesComponent implements OnInit, OnDestroy {
if (!this.eventList[curIndex]) {
return false;
}
return (
this.datePipe.transform(
moment(this.eventList[curIndex].sendDate).toDate(),
'yyyyMMdd'
) !==
this.datePipe.transform(
moment(this.eventList[curIndex - 1].sendDate).toDate(),
'yyyyMMdd'
)
return !moment(this.eventList[curIndex].sendDate).isSame(
moment(this.eventList[curIndex - 1].sendDate),
'day'
);
}
return false;
}
getReadHere(messageIndex: number): boolean {
getReadHere(message: Info<EventJson>): boolean {
if (
!!this.roomInfo &&
!!this.roomInfo.lastReadEventSeq &&
@ -344,6 +350,10 @@ export class MessagesComponent implements OnInit, OnDestroy {
this.roomInfo.roomType === RoomType.Multi
) {
if (!this.roomInfo.isTimeRoom) {
const messageIndex = this.eventList.findIndex(
v => v.seq === message.seq
);
if (
this.eventList[messageIndex].seq ===
this.roomInfo.lastReadEventSeq + 1
@ -365,20 +375,36 @@ export class MessagesComponent implements OnInit, OnDestroy {
return rtnStr;
}
storeScrollHeight() {
this.storedScrollHeight = this.psChatContent.elementRef.nativeElement.scrollHeight;
storeScrollPosition() {
this.storedScrollItem = this.eventList[
this.virtualScroller.viewPortInfo.startIndex
];
}
scrollToStoredItem() {
if (!this.scrollUpInitalized) {
this.chatMessagesContainer.nativeElement.classList.remove('hide');
}
this.virtualScroller.scrollInto(this.storedScrollItem, true, 0, 0, () => {
this.storedScrollItem = undefined;
});
}
ready(): void {
if (!this.scrollUpInitalized) {
this.chatMessagesContainer.nativeElement.classList.add('hide');
}
setTimeout(() => {
this.scrollToBottom();
});
}
scrollToBottom(speed?: number): void {
if (this.storedScrollHeight > 0) {
if (this.psChatContent) {
this.psChatContent.update();
if (!!this.storedScrollItem) {
// if (this.psChatContent) {
// this.psChatContent.update();
const element = document.getElementById('message-box-readhere');
if (!!element && this.firstCheckReadHere) {
@ -388,17 +414,9 @@ export class MessagesComponent implements OnInit, OnDestroy {
this.firstCheckReadHere = false;
} else {
setTimeout(() => {
this.psChatContent.scrollToTop(
this.psChatContent.elementRef.nativeElement.scrollHeight -
this.storedScrollHeight,
speed
);
this.storedScrollHeight = 0;
});
}
this.scrollToStoredItem();
}
// }
} else if (this.scrollUpInitalized) {
if (!!this.newEventList && this.newEventList.length > 0) {
this.existNewMessage.emit(
@ -418,9 +436,15 @@ export class MessagesComponent implements OnInit, OnDestroy {
this.firstCheckReadHere = false;
} else {
setTimeout(() => {
this.psChatContent.scrollToBottom(0, speed);
});
this.virtualScroller.scrollToIndex(
this.eventList.length - 1,
true,
0,
0,
() => {
this.chatMessagesContainer.nativeElement.classList.remove('hide');
}
);
}
}
}
@ -429,7 +453,7 @@ export class MessagesComponent implements OnInit, OnDestroy {
initEventMore() {
// 방정보가 바뀌면 이전대화 보기 관련 값들을 초기화 한다.
this.scrollUpInitalized = false;
this.storedScrollHeight = 0;
this.storedScrollItem = undefined;
}
clear() {}
@ -464,9 +488,12 @@ export class MessagesComponent implements OnInit, OnDestroy {
event.stopPropagation();
if (this.scrollUpInitalized && this.eventRemained) {
this.storedScrollHeight = this.psChatContent.elementRef.nativeElement.scrollHeight;
// this.storedScrollItem = this.psChatContent.elementRef.nativeElement.scrollHeight;
this.storeScrollPosition();
this.moreEvent.emit(this.eventList[0].seq);
this.virtualScroller.invalidateCachedMeasurementAtIndex(0);
}
}
@ -506,6 +533,9 @@ export class MessagesComponent implements OnInit, OnDestroy {
}
onScrollup(event: any) {
if (!this.eventList || 0 === this.eventList.length) {
return;
}
this.scrollUpInitalized = true;
this.scrollUp.emit(event);
}
@ -516,6 +546,17 @@ export class MessagesComponent implements OnInit, OnDestroy {
this.yReachEnd.emit(event);
}
onVsChange(event: IPageInfo) {
if (
-1 === event.startIndex ||
-1 === event.endIndex ||
(0 === event.startIndex && 0 === event.endIndex)
) {
return;
}
this.logger.debug('onVsChange', event);
}
trackByEvent(index: number, info: Info<EventJson>): number {
return info.seq;
}