bug of new message is fixed

This commit is contained in:
richard-loafle 2020-01-23 11:55:51 +09:00
parent 97499b0415
commit 0e536e5266

View File

@ -142,6 +142,7 @@ export class MessagesComponent implements OnInit, OnDestroy {
readToHereEvent: Info<EventJson>; readToHereEvent: Info<EventJson>;
swapped = false; swapped = false;
hidden = false;
constructor( constructor(
private logger: NGXLogger, private logger: NGXLogger,
@ -384,9 +385,10 @@ export class MessagesComponent implements OnInit, OnDestroy {
to: Info<EventJson>, to: Info<EventJson>,
preCallback: () => void, preCallback: () => void,
postCallback: () => void, postCallback: () => void,
useSwap: boolean = true useHide: boolean,
useSwap: boolean
) { ) {
this.preSwapScroll(useSwap); this.preSwapScroll(useHide, useSwap);
if (!!preCallback) { if (!!preCallback) {
preCallback(); preCallback();
} }
@ -395,12 +397,12 @@ export class MessagesComponent implements OnInit, OnDestroy {
if (!!postCallback) { if (!!postCallback) {
postCallback(); postCallback();
} }
this.postSwapScroll(useSwap); this.postSwapScroll(useHide, useSwap);
}, 100); }, 100);
}); });
} }
preSwapScroll(useSwap: boolean = true) { preSwapScroll(useHide: boolean, useSwap: boolean) {
if (useSwap && !this.swapped) { if (useSwap && !this.swapped) {
this.chatMessagesBuffer.nativeElement.innerHTML = this.chatMessagesContainer.nativeElement.innerHTML; this.chatMessagesBuffer.nativeElement.innerHTML = this.chatMessagesContainer.nativeElement.innerHTML;
this.chatMessagesBuffer.nativeElement.scrollTop = this.chatMessagesContainer.nativeElement.scrollTop; this.chatMessagesBuffer.nativeElement.scrollTop = this.chatMessagesContainer.nativeElement.scrollTop;
@ -408,10 +410,13 @@ export class MessagesComponent implements OnInit, OnDestroy {
this.swapped = true; this.swapped = true;
} }
this.chatMessagesContainer.nativeElement.classList.add('hide'); if (useHide && !this.hidden) {
this.chatMessagesContainer.nativeElement.classList.add('hide');
this.hidden = true;
}
} }
postSwapScroll(useSwap: boolean = true) { postSwapScroll(useHide: boolean, useSwap: boolean) {
if (useSwap && this.swapped) { if (useSwap && this.swapped) {
this.chatMessagesBuffer.nativeElement.innerHTML = ''; this.chatMessagesBuffer.nativeElement.innerHTML = '';
this.chatMessagesBuffer.nativeElement.scrollTop = 0; this.chatMessagesBuffer.nativeElement.scrollTop = 0;
@ -419,7 +424,10 @@ export class MessagesComponent implements OnInit, OnDestroy {
this.swapped = false; this.swapped = false;
} }
this.chatMessagesContainer.nativeElement.classList.remove('hide'); if (useHide && this.hidden) {
this.chatMessagesContainer.nativeElement.classList.remove('hide');
this.hidden = false;
}
} }
ready(): void { ready(): void {
@ -434,7 +442,9 @@ export class MessagesComponent implements OnInit, OnDestroy {
() => {}, () => {},
() => { () => {
this.firstCheckReadHere = false; this.firstCheckReadHere = false;
} },
true,
true
); );
} else { } else {
this.swapScroll( this.swapScroll(
@ -442,7 +452,9 @@ export class MessagesComponent implements OnInit, OnDestroy {
() => {}, () => {},
() => { () => {
this.storedScrollItem = undefined; this.storedScrollItem = undefined;
} },
true,
true
); );
} }
} else if (this.scrollUpInitalized) { } else if (this.scrollUpInitalized) {
@ -460,15 +472,31 @@ export class MessagesComponent implements OnInit, OnDestroy {
() => {}, () => {},
() => { () => {
this.firstCheckReadHere = false; this.firstCheckReadHere = false;
} },
true,
true
); );
} else { } else {
this.swapScroll( if (
this.eventList[this.eventList.length - 1], this.virtualScroller.viewPortInfo.endIndex ===
() => {}, this.eventList.length - 2
() => {}, ) {
false this.swapScroll(
); this.eventList[this.eventList.length - 1],
() => {},
() => {},
false,
false
);
} else {
this.swapScroll(
this.eventList[this.eventList.length - 1],
() => {},
() => {},
true,
false
);
}
} }
} }
} }
@ -499,7 +527,7 @@ export class MessagesComponent implements OnInit, OnDestroy {
if (this.scrollUpInitalized && this.eventRemained) { if (this.scrollUpInitalized && this.eventRemained) {
this.storeScrollPosition(); this.storeScrollPosition();
this.preSwapScroll(); this.preSwapScroll(true, true);
this.moreEvent.emit(this.eventList[0].seq); this.moreEvent.emit(this.eventList[0].seq);