fix unread - wip

This commit is contained in:
Ajay Bura 2026-08-19 08:04:34 +05:30
commit b9342175a4
5 changed files with 49 additions and 30 deletions

View file

@ -202,6 +202,15 @@ export function RoomTimeline({ eventId, roomInputRef, editor, timeline }: RoomTi
console.log('mark as read.');
}, []);
const newDividerRef = useRef<HTMLDivElement>(null);
// if new divider exist always start form here.
useEffect(() => {
const newDividerEl = newDividerRef.current;
if (newDividerEl) {
scrollToElement(newDividerEl, { align: 'center', behavior: 'instant' });
}
}, [scrollToElement]);
const [atBottom, atBottomAnchorRef] = useAtBottomToggle(
getScrollElement,
messageBatch.next.end ?? false,
@ -259,12 +268,12 @@ export function RoomTimeline({ eventId, roomInputRef, editor, timeline }: RoomTi
const stickToBottom = useCallback(() => {
if (!atBottom) return;
// setTimeout(() => {
// const scrollEl = getScrollElement();
// if (scrollEl) {
// scrollToBottom(scrollEl, 'smooth');
// }
// }, 100);
setTimeout(() => {
const scrollEl = getScrollElement();
if (scrollEl) {
scrollToBottom(scrollEl, 'smooth');
}
}, 100);
}, [getScrollElement, atBottom]);
useObservableValueListener(timeline.outbox.senders, stickToBottom);
@ -489,6 +498,7 @@ export function RoomTimeline({ eventId, roomInputRef, editor, timeline }: RoomTi
messageSpacing={messageSpacing}
ts={dayDivider ? event.origin_server_ts : undefined}
unread={newDivider}
ref={newDivider ? newDividerRef : undefined}
/>
) : null;

View file

@ -1,4 +1,4 @@
import React, { ReactNode } from 'react';
import React, { forwardRef, ReactNode } from 'react';
import { as, Badge, Box, ContainerColor, Line, Text } from 'folds';
import classNames from 'classnames';
import { DividerTime, MessageBase } from '../../../components/message';
@ -30,9 +30,9 @@ type ComboDividerProps = {
replyCount?: number;
unread?: boolean;
};
export function ComboDivider({ messageSpacing, ts, replyCount, unread }: ComboDividerProps) {
return (
<MessageBase space={messageSpacing}>
export const ComboDivider = forwardRef<HTMLDivElement, ComboDividerProps>(
({ messageSpacing, ts, replyCount, unread }, ref) => (
<MessageBase space={messageSpacing} ref={ref}>
<TimelineDivider
variant={unread ? 'Critical' : 'Surface'}
before={
@ -75,5 +75,5 @@ export function ComboDivider({ messageSpacing, ts, replyCount, unread }: ComboDi
)}
</TimelineDivider>
</MessageBase>
);
}
)
);

View file

@ -15,7 +15,7 @@ import { Editor } from 'slate';
import { ReactEditor } from 'slate-react';
import { MessageEventWithoutRoomId } from 'neurone/lib/api/types';
import { scrollToBottom } from '../../../utils/dom';
import { MessageBatch } from '../../../../client/room/messages';
import { MessageBatch, RangeInfo } from '../../../../client/room/messages';
import { getResizeObserverEntry, useResizeObserver } from '../../../hooks/useResizeObserver';
import {
getIntersectionObserverEntry,
@ -50,18 +50,19 @@ export const useTimelineView = (): TimelineView => {
};
export const useTimelinePrefetch = (timeline: TimelineView, limit: number) => {
useEffect(
() =>
timeline.range.info.subscribe((info) => {
if (info.start <= limit) {
requestAnimationFrame(() => timeline.paginateBackward(limit));
}
if (info.end >= Math.max(timeline.batch.read.size - limit, 0)) {
requestAnimationFrame(() => timeline.paginateForward(limit));
}
}),
[timeline, limit]
);
useEffect(() => {
const handleInfo = (info: RangeInfo) => {
if (info.start <= limit) {
requestAnimationFrame(() => timeline.paginateBackward(limit));
}
if (info.end >= Math.max(timeline.batch.read.size - limit, 0)) {
requestAnimationFrame(() => timeline.paginateForward(limit));
}
};
handleInfo(timeline.range.info.read);
return timeline.range.info.subscribe(handleInfo);
}, [timeline, limit]);
};
export const useTimelinePaginate = (timeline: TimelineView, limit: number) =>

View file

@ -75,7 +75,7 @@ export function ThreadView({ threadTimeline, threadFocusRef, requestClose }: Thr
</Box>
</PageHeader>
<TimelineView threadTimeline={threadTimeline} />
<TimelineView threadTimeline={threadTimeline} threadInputRef={threadInputRef} />
<Box shrink="No" direction="Column">
<div style={{ padding: `0 ${config.space.S400}` }}>
<RoomInput

View file

@ -1,4 +1,12 @@
import React, { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
import React, {
RefObject,
useCallback,
useEffect,
useLayoutEffect,
useMemo,
useRef,
useState,
} from 'react';
import { ReactEditor } from 'slate-react';
import { Box, Scroll, Text, config } from 'folds';
import { MessageEventWithoutRoomId } from 'neurone/lib/api/types';
@ -67,16 +75,16 @@ import { MessageContent } from '../../../components/MessageContent';
type TimelineViewProps = {
threadTimeline: ThreadTimeline;
threadInputRef: RefObject<HTMLElement>;
};
const PAGINATION_LIMIT = 80;
export function TimelineView({ threadTimeline }: TimelineViewProps) {
export function TimelineView({ threadTimeline, threadInputRef }: TimelineViewProps) {
const ct = useClient();
const roomId = useRoom();
const encryptedRooms = useObservableValue(ct.encryptedRooms);
const editor = useEditor();
const roomInputRef = useRef<HTMLDivElement>(null);
const [hideActivity] = useSetting(settingsAtom, 'hideActivity');
const [messageLayout] = useSetting(settingsAtom, 'messageLayout');
@ -196,7 +204,7 @@ export function TimelineView({ threadTimeline }: TimelineViewProps) {
useEditorResizeStickBottom(
getScrollElement,
useCallback(() => roomInputRef?.current ?? null, [roomInputRef]),
useCallback(() => threadInputRef?.current ?? null, [threadInputRef]),
atBottom
);