refactoring of chat room

This commit is contained in:
richard-loafle 2020-01-31 13:12:21 +09:00
parent 6657461150
commit ae55cee3ab
4 changed files with 52 additions and 22 deletions

View File

@ -424,6 +424,9 @@ export class Effects {
break; break;
case SSVC_TYPE_EVENT_INFO_RES: case SSVC_TYPE_EVENT_INFO_RES:
{ {
if (!!infoList && 0 < infoList.length) {
infoList = infoList.sort((a, b) => a.seq - b.seq);
}
if ( if (
infoList.length > 0 && infoList.length > 0 &&
infoList.length >= req.requestCount && infoList.length >= req.requestCount &&

View File

@ -23,6 +23,7 @@
</ucap-chat-message-box-date-splitter> </ucap-chat-message-box-date-splitter>
<div <div
#mbChatRow
class="chat-row" class="chat-row"
[@shake]="{ [@shake]="{
value: shakeIt, value: shakeIt,

View File

@ -96,6 +96,9 @@ export class MessageBoxComponent implements OnInit, AfterViewInit {
@ViewChild('mbContainer', { static: true }) @ViewChild('mbContainer', { static: true })
mbContainer: ElementRef<HTMLElement>; mbContainer: ElementRef<HTMLElement>;
@ViewChild('mbChatRow', { static: true })
mbChatRow: ElementRef<HTMLElement>;
EventType = EventType; EventType = EventType;
moment = moment; moment = moment;
@ -104,13 +107,17 @@ export class MessageBoxComponent implements OnInit, AfterViewInit {
existReadHere = false; existReadHere = false;
shakeIt = false; shakeIt = false;
get offsetTop() {
return this.mbChatRow.nativeElement.offsetTop;
}
constructor( constructor(
private changeDetectorRef: ChangeDetectorRef, private changeDetectorRef: ChangeDetectorRef,
private logger: NGXLogger private logger: NGXLogger
) {} ) {}
ngOnInit() { ngOnInit() {
this.mbContainer.nativeElement.classList.add('hide'); // this.mbContainer.nativeElement.classList.add('hide');
} }
ngAfterViewInit(): void { ngAfterViewInit(): void {
@ -122,7 +129,7 @@ export class MessageBoxComponent implements OnInit, AfterViewInit {
// .nativeElement.offsetHeight + 20}px`; // .nativeElement.offsetHeight + 20}px`;
// this.elementRef.nativeElement.style.maxHeight = `${this.mbContainer // this.elementRef.nativeElement.style.maxHeight = `${this.mbContainer
// .nativeElement.offsetHeight + 20}px`; // .nativeElement.offsetHeight + 20}px`;
this.mbContainer.nativeElement.classList.remove('hide'); // this.mbContainer.nativeElement.classList.remove('hide');
} }
/** /**

View File

@ -122,6 +122,7 @@ export class MessagesComponent implements OnInit, OnDestroy {
chatMessageBoxList: QueryList<MessageBoxComponent>; chatMessageBoxList: QueryList<MessageBoxComponent>;
storedScrollItem: Info<EventJson>; // 이전대화를 불러올 경우 현재 스크롤 포지션 유지를 위한 값. 0 이면 초기로딩. storedScrollItem: Info<EventJson>; // 이전대화를 불러올 경우 현재 스크롤 포지션 유지를 위한 값. 0 이면 초기로딩.
storedScrollItemOffsetTop: number | undefined;
scrollUpInitalized = false; // ps 에서 초기 로딩시 scroll reach start 이벤트 발생 버그를 우회하기 위한 init 값으로 scrollUp 에 의해 true 로 된다. scrollUpInitalized = false; // ps 에서 초기 로딩시 scroll reach start 이벤트 발생 버그를 우회하기 위한 init 값으로 scrollUp 에 의해 true 로 된다.
firstCheckReadHere = true; firstCheckReadHere = true;
initRoomLastEventSeq: number; initRoomLastEventSeq: number;
@ -395,6 +396,17 @@ export class MessagesComponent implements OnInit, OnDestroy {
this.storedScrollItem = this.eventList[ this.storedScrollItem = this.eventList[
this.virtualScroller.viewPortInfo.startIndex this.virtualScroller.viewPortInfo.startIndex
]; ];
const chatMessageBox = this.chatMessageBoxList.find(
el =>
el.message.seq ===
this.eventList[this.virtualScroller.viewPortInfo.startIndex].seq
);
if (!!chatMessageBox) {
this.storedScrollItemOffsetTop = chatMessageBox.offsetTop;
} else {
this.storedScrollItemOffsetTop = 0;
}
} }
swapScrollTo( swapScrollTo(
@ -408,14 +420,23 @@ export class MessagesComponent implements OnInit, OnDestroy {
if (!!preCallback) { if (!!preCallback) {
preCallback(); preCallback();
} }
this.virtualScroller.scrollInto(to, true, 0, 0, () => {
setTimeout(() => { this.virtualScroller.scrollInto(
if (!!postCallback) { to,
postCallback(); true,
} undefined !== this.storedScrollItemOffsetTop
this.postSwapScroll(useHide, useSwap); ? -this.storedScrollItemOffsetTop
}); : 0,
}); 0,
() => {
setTimeout(() => {
if (!!postCallback) {
postCallback();
}
this.postSwapScroll(useHide, useSwap);
});
}
);
} }
preSwapScroll(useHide: boolean, useSwap: boolean) { preSwapScroll(useHide: boolean, useSwap: boolean) {
@ -465,15 +486,12 @@ export class MessagesComponent implements OnInit, OnDestroy {
true true
); );
} else { } else {
const index = this.eventList.findIndex(
i => i.seq === this.storedScrollItem.seq
);
this.swapScrollTo( this.swapScrollTo(
1 <= index ? this.eventList[index - 1] : this.eventList[0], this.storedScrollItem,
() => {}, () => {},
() => { () => {
this.storedScrollItem = undefined; this.storedScrollItem = undefined;
this.storedScrollItemOffsetTop = undefined;
}, },
true, true,
true true
@ -525,18 +543,17 @@ export class MessagesComponent implements OnInit, OnDestroy {
// 방정보가 바뀌면 이전대화 보기 관련 값들을 초기화 한다. // 방정보가 바뀌면 이전대화 보기 관련 값들을 초기화 한다.
this.scrollUpInitalized = false; this.scrollUpInitalized = false;
this.storedScrollItem = undefined; this.storedScrollItem = undefined;
this.storedScrollItemOffsetTop = undefined;
} }
clear() {} clear() {}
gotoPosition(eventSeq: number) { gotoPosition(eventSeq: number) {
if (!!this.virtualScroller) { if (!!this.virtualScroller) {
const index = this.eventList.findIndex(v => v.seq === eventSeq); const e = this.eventList.find(v => v.seq === eventSeq);
this.virtualScroller.scrollInto( this.swapScrollTo(
1 <= index ? this.eventList[index - 1] : this.eventList[0], e,
true, () => {},
0,
100,
() => { () => {
const chatMessageBox = this.chatMessageBoxList.find( const chatMessageBox = this.chatMessageBoxList.find(
el => el.message.seq === eventSeq el => el.message.seq === eventSeq
@ -544,7 +561,9 @@ export class MessagesComponent implements OnInit, OnDestroy {
if (!!chatMessageBox) { if (!!chatMessageBox) {
chatMessageBox.shake(); chatMessageBox.shake();
} }
} },
true,
true
); );
} }
} }