ChatWindow: stop unread notice disappearing

This commit is contained in:
Liam Fitzgerald 2021-03-25 16:38:27 +10:00
parent 48982706fe
commit 9db4217220
No known key found for this signature in database
GPG Key ID: D390E12C61D1CFFB

View File

@ -61,6 +61,7 @@ class ChatWindow extends Component<
private virtualList: VirtualScroller | null;
private unreadMarkerRef: React.RefObject<HTMLDivElement>;
private prevSize = 0;
private unreadSet = false;
INITIALIZATION_MAX_TIME = 100;
@ -116,7 +117,9 @@ class ChatWindow extends Component<
dismissedInitialUnread() {
const { unreadCount, graph } = this.props;
return this.state.unreadIndex.neq(graph.keys()?.[unreadCount]?.[0] ?? bigInt.zero)
return this.state.unreadIndex.neq(bigInt.zero) &&
this.state.unreadIndex.neq(graph.keys()?.[unreadCount]?.[0] ?? bigInt.zero);
}
handleWindowBlur() {
@ -132,16 +135,21 @@ class ChatWindow extends Component<
componentDidUpdate(prevProps: ChatWindowProps, prevState) {
const { history, graph, unreadCount, graphSize, station } = this.props;
if(unreadCount === 0 && prevProps.unreadCount !== unreadCount) {
this.unreadSet = true;
}
if(this.prevSize !== graphSize) {
this.prevSize = graphSize;
if(this.dismissedInitialUnread() &&
this.virtualList?.startOffset() < 5) {
this.dismissUnread();
}
if(this.state.unreadIndex.eq(bigInt.zero)) {
this.calculateUnreadIndex();
}
if(this.unreadSet &&
this.dismissedInitialUnread() &&
this.virtualList?.startOffset() < 5) {
this.dismissUnread();
}
}
if (unreadCount > prevProps.unreadCount) {
@ -318,7 +326,7 @@ class ChatWindow extends Component<
return (
<Col height='100%' overflow='hidden' position='relative'>
{ !this.dismissedInitialUnread() &&
{ this.dismissedInitialUnread() &&
(<UnreadNotice
unreadCount={unreadCount}
unreadMsg={