bug of chat room is fixed

This commit is contained in:
richard-loafle 2020-01-30 17:05:22 +09:00
parent 9069a58627
commit d71d13c676
4 changed files with 50 additions and 26 deletions

View File

@ -82,7 +82,9 @@
</virtual-scroller> </virtual-scroller>
<div <div
#chatMessagesBuffer #chatMessagesBufferContainer
fxFlexFill fxFlexFill
class="chat-messages-buffer disappear" class="chat-messages-buffer-container disappear"
></div> >
<div #chatMessagesBuffer fxFlexFill class="chat-messages-buffer"></div>
</div>

View File

@ -164,10 +164,12 @@ $tablet-l-width: 1024px;
display: none !important; display: none !important;
} }
.chat-messages-buffer { .chat-messages-buffer-container {
position: absolute; position: absolute;
top: 0px; top: 0px;
overflow-y: hidden !important; overflow-y: hidden !important;
padding: 30px 40px; padding: 2vh 2vw;
flex-direction: column; flex-direction: column;
.chat-messages-buffer {
}
} }

View File

@ -112,6 +112,9 @@ export class MessagesComponent implements OnInit, OnDestroy {
@ViewChild('chatMessagesBuffer', { static: false }) @ViewChild('chatMessagesBuffer', { static: false })
chatMessagesBuffer: ElementRef<HTMLElement>; chatMessagesBuffer: ElementRef<HTMLElement>;
@ViewChild('chatMessagesBufferContainer', { static: false })
chatMessagesBufferContainer: ElementRef<HTMLElement>;
@ViewChild(VirtualScrollerComponent, { static: false }) @ViewChild(VirtualScrollerComponent, { static: false })
private virtualScroller: VirtualScrollerComponent; private virtualScroller: VirtualScrollerComponent;
@ -148,6 +151,7 @@ export class MessagesComponent implements OnInit, OnDestroy {
readToHereEvent: Info<EventJson>; readToHereEvent: Info<EventJson>;
existReadToHereEvent = true; existReadToHereEvent = true;
hidden = false; hidden = false;
swapped = false;
constructor( constructor(
private logger: NGXLogger, private logger: NGXLogger,
@ -393,13 +397,14 @@ export class MessagesComponent implements OnInit, OnDestroy {
]; ];
} }
scrollTo( swapScrollTo(
to: Info<EventJson>, to: Info<EventJson>,
preCallback: () => void, preCallback: () => void,
postCallback: () => void, postCallback: () => void,
useHide: boolean useHide: boolean,
useSwap: boolean
) { ) {
this.preSwapScroll(useHide); this.preSwapScroll(useHide, useSwap);
if (!!preCallback) { if (!!preCallback) {
preCallback(); preCallback();
} }
@ -408,19 +413,35 @@ export class MessagesComponent implements OnInit, OnDestroy {
if (!!postCallback) { if (!!postCallback) {
postCallback(); postCallback();
} }
this.postSwapScroll(useHide); this.postSwapScroll(useHide, useSwap);
}); });
}); });
} }
preSwapScroll(useHide: boolean) { preSwapScroll(useHide: boolean, useSwap: boolean) {
if (useSwap && !this.swapped) {
this.chatMessagesBuffer.nativeElement.innerHTML = this.chatMessagesContainer.nativeElement.innerHTML;
this.chatMessagesBuffer.nativeElement.scrollTop = this.chatMessagesContainer.nativeElement.scrollTop;
this.chatMessagesBufferContainer.nativeElement.classList.remove(
'disappear'
);
this.swapped = true;
}
if (useHide && !this.hidden) { if (useHide && !this.hidden) {
this.chatMessagesContainer.nativeElement.classList.add('hide'); this.chatMessagesContainer.nativeElement.classList.add('hide');
this.hidden = true; this.hidden = true;
} }
} }
postSwapScroll(useHide: boolean) { postSwapScroll(useHide: boolean, useSwap: boolean) {
if (useSwap && this.swapped) {
this.chatMessagesBuffer.nativeElement.innerHTML = '';
this.chatMessagesBuffer.nativeElement.scrollTop = 0;
this.chatMessagesBufferContainer.nativeElement.classList.add('disappear');
this.swapped = false;
}
if (useHide && this.hidden) { if (useHide && this.hidden) {
this.chatMessagesContainer.nativeElement.classList.remove('hide'); this.chatMessagesContainer.nativeElement.classList.remove('hide');
this.hidden = false; this.hidden = false;
@ -434,12 +455,13 @@ export class MessagesComponent implements OnInit, OnDestroy {
scrollToBottom(): void { scrollToBottom(): void {
if (!!this.storedScrollItem) { if (!!this.storedScrollItem) {
if (!!this.readToHereEvent && this.firstCheckReadHere) { if (!!this.readToHereEvent && this.firstCheckReadHere) {
this.scrollTo( this.swapScrollTo(
this.readToHereEvent, this.readToHereEvent,
() => {}, () => {},
() => { () => {
this.firstCheckReadHere = false; this.firstCheckReadHere = false;
}, },
true,
true true
); );
} else { } else {
@ -447,13 +469,14 @@ export class MessagesComponent implements OnInit, OnDestroy {
i => i.seq === this.storedScrollItem.seq i => i.seq === this.storedScrollItem.seq
); );
this.scrollTo( this.swapScrollTo(
1 <= index ? this.eventList[index - 1] : this.eventList[0], 1 <= index ? this.eventList[index - 1] : this.eventList[0],
() => {}, () => {},
() => { () => {
this.storedScrollItem = undefined; this.storedScrollItem = undefined;
}, },
false true,
true
); );
} }
} else if (this.scrollUpInitalized) { } else if (this.scrollUpInitalized) {
@ -464,31 +487,34 @@ export class MessagesComponent implements OnInit, OnDestroy {
} }
} else { } else {
if (!!this.readToHereEvent && this.firstCheckReadHere) { if (!!this.readToHereEvent && this.firstCheckReadHere) {
this.scrollTo( this.swapScrollTo(
this.readToHereEvent, this.readToHereEvent,
() => {}, () => {},
() => { () => {
this.firstCheckReadHere = false; this.firstCheckReadHere = false;
}, },
true true,
false
); );
} else { } else {
if ( if (
this.virtualScroller.viewPortInfo.endIndex === this.virtualScroller.viewPortInfo.endIndex ===
this.eventList.length - 2 this.eventList.length - 2
) { ) {
this.scrollTo( this.swapScrollTo(
this.eventList[this.eventList.length - 1], this.eventList[this.eventList.length - 1],
() => {}, () => {},
() => {}, () => {},
true,
false false
); );
} else { } else {
this.scrollTo( this.swapScrollTo(
this.eventList[this.eventList.length - 1], this.eventList[this.eventList.length - 1],
() => {}, () => {},
() => {}, () => {},
true true,
false
); );
} }
} }
@ -534,7 +560,7 @@ export class MessagesComponent implements OnInit, OnDestroy {
if (this.scrollUpInitalized && this.eventRemained) { if (this.scrollUpInitalized && this.eventRemained) {
this.storeScrollPosition(); this.storeScrollPosition();
this.preSwapScroll(false); this.preSwapScroll(true, true);
this.moreEvent.emit(this.eventList[0].seq); this.moreEvent.emit(this.eventList[0].seq);

View File

@ -4,9 +4,6 @@ import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { FlexLayoutModule } from '@angular/flex-layout'; import { FlexLayoutModule } from '@angular/flex-layout';
import { ScrollingModule } from '@angular/cdk/scrolling';
import { ScrollingModule as ExperimentalScrollingModule } from '@angular/cdk-experimental/scrolling';
import { MatTooltipModule } from '@angular/material'; import { MatTooltipModule } from '@angular/material';
import { MatFormFieldModule } from '@angular/material/form-field'; import { MatFormFieldModule } from '@angular/material/form-field';
import { MatIconModule } from '@angular/material/icon'; import { MatIconModule } from '@angular/material/icon';
@ -78,9 +75,6 @@ const PROVIDERS = [DatePipe];
ReactiveFormsModule, ReactiveFormsModule,
FlexLayoutModule, FlexLayoutModule,
ScrollingModule,
ExperimentalScrollingModule,
MatFormFieldModule, MatFormFieldModule,
MatIconModule, MatIconModule,
MatInputModule, MatInputModule,