mirror of
https://github.com/SableClient/Sable.git
synced 2026-12-03 07:12:34 -08:00
fix: ensure timeline continues fetching when hidden events are disabled
This commit is contained in:
1 parent
195732f099
commit
b1ac4a6fd5
3 files changed
+118
-13
No files matched your search
@@ -11,7 +11,7 @@ import {
|
|||||||
} from 'react';
|
} from 'react';
|
||||||
import type { Editor } from 'slate';
|
import type { Editor } from 'slate';
|
||||||
import { useAtomValue, useSetAtom, useStore } from 'jotai';
|
import { useAtomValue, useSetAtom, useStore } from 'jotai';
|
||||||
import type { Room } from '$types/matrix-sdk';
|
import type { Room, MatrixEvent, EventTimelineSet } from '$types/matrix-sdk';
|
||||||
import { Direction, EventType } from '$types/matrix-sdk';
|
import { Direction, EventType } from '$types/matrix-sdk';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import type { VListHandle } from 'virtua';
|
import type { VListHandle } from 'virtua';
|
||||||
@@ -35,7 +35,16 @@ import {
|
|||||||
factoryRenderLinkifyWithMention,
|
factoryRenderLinkifyWithMention,
|
||||||
} from '$plugins/react-custom-html-parser';
|
} from '$plugins/react-custom-html-parser';
|
||||||
import { today, yesterday, timeDayMonthYear } from '$utils/time';
|
import { today, yesterday, timeDayMonthYear } from '$utils/time';
|
||||||
import { unwrapRelationJumpTarget } from '$utils/room';
|
import {
|
||||||
|
unwrapRelationJumpTarget,
|
||||||
|
isEditEvent,
|
||||||
|
isReactionEvent,
|
||||||
|
isRedactableMessageType,
|
||||||
|
isMembershipChanged,
|
||||||
|
isThreadRelationEvent,
|
||||||
|
getRedactionTargetEvent,
|
||||||
|
shouldShowRedactionTimelineEvent,
|
||||||
|
} from '$utils/room';
|
||||||
import { useMemberEventParser } from '$hooks/useMemberEventParser';
|
import { useMemberEventParser } from '$hooks/useMemberEventParser';
|
||||||
import { usePowerLevelsContext } from '$hooks/usePowerLevels';
|
import { usePowerLevelsContext } from '$hooks/usePowerLevels';
|
||||||
import { useRoomCreators } from '$hooks/useRoomCreators';
|
import { useRoomCreators } from '$hooks/useRoomCreators';
|
||||||
@@ -72,6 +81,7 @@ import { useTimelineActions } from '$hooks/timeline/useTimelineActions';
|
|||||||
import {
|
import {
|
||||||
useProcessedTimeline,
|
useProcessedTimeline,
|
||||||
getProcessedRowIndexForRawTimelineIndex,
|
getProcessedRowIndexForRawTimelineIndex,
|
||||||
|
STANDARD_RENDERED_EVENT_TYPES,
|
||||||
type ProcessedEvent,
|
type ProcessedEvent,
|
||||||
} from '$hooks/timeline/useProcessedTimeline';
|
} from '$hooks/timeline/useProcessedTimeline';
|
||||||
import { useTimelineEventRenderer } from '$hooks/timeline/useTimelineEventRenderer';
|
import { useTimelineEventRenderer } from '$hooks/timeline/useTimelineEventRenderer';
|
||||||
@@ -512,6 +522,90 @@ export function RoomTimeline({
|
|||||||
setUnreadInfo,
|
setUnreadInfo,
|
||||||
hideReadsRef,
|
hideReadsRef,
|
||||||
readUptoEventIdRef,
|
readUptoEventIdRef,
|
||||||
|
isEventVisible: useCallback(
|
||||||
|
(mEvent: MatrixEvent, timelineSet: EventTimelineSet) => {
|
||||||
|
const type = mEvent.getType();
|
||||||
|
const isEdit = isEditEvent(mEvent);
|
||||||
|
const isReaction = isReactionEvent(mEvent);
|
||||||
|
const isRedactionEvt = mEvent.isRedaction();
|
||||||
|
|
||||||
|
if (hideMemberInReadOnly && isReadOnly) {
|
||||||
|
if (isReaction) return false;
|
||||||
|
if (
|
||||||
|
isRedactionEvt &&
|
||||||
|
getRedactionTargetEvent(timelineSet, mEvent)?.getType() ===
|
||||||
|
(EventType.Reaction as string)
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mEvent.isRedacted()) {
|
||||||
|
const showMessageTombstone =
|
||||||
|
hiddenEvents.showTombstoneEvents && isRedactableMessageType(type);
|
||||||
|
const showReactionTombstone = hiddenEvents.hiddenEventReactionTombstone && isReaction;
|
||||||
|
if (!showMessageTombstone && !showReactionTombstone) return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type === 'm.room.member') {
|
||||||
|
const membershipChanged = isMembershipChanged(mEvent);
|
||||||
|
if (hideMemberInReadOnly && isReadOnly) return false;
|
||||||
|
if (membershipChanged && hideMembershipEvents) return false;
|
||||||
|
if (!membershipChanged && hideNickAvatarEvents) return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const allowSpecificHiddenEvent =
|
||||||
|
(isEdit && hiddenEvents.hiddenEventEdits) ||
|
||||||
|
(isReaction && !mEvent.isRedacted() && hiddenEvents.hiddenEventReactions) ||
|
||||||
|
(isReaction && mEvent.isRedacted() && hiddenEvents.hiddenEventReactionTombstone) ||
|
||||||
|
(isRedactionEvt &&
|
||||||
|
shouldShowRedactionTimelineEvent(
|
||||||
|
mEvent,
|
||||||
|
timelineSet,
|
||||||
|
hiddenEvents.hiddenEventRedactionTimeline,
|
||||||
|
hiddenEvents.hiddenEventReactionRedactionTimeline
|
||||||
|
));
|
||||||
|
|
||||||
|
if (!(hiddenEvents.showHiddenEvents && hiddenEvents.hiddenEventOther)) {
|
||||||
|
const isStandardRendered = STANDARD_RENDERED_EVENT_TYPES.has(type);
|
||||||
|
if (!isStandardRendered && !allowSpecificHiddenEvent) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const threadRootId = mEvent.threadRootId;
|
||||||
|
if (
|
||||||
|
threadRootId !== undefined &&
|
||||||
|
threadRootId !== mEvent.getId() &&
|
||||||
|
isThreadRelationEvent(mEvent, threadRootId)
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isEdit && !hiddenEvents.hiddenEventEdits) return false;
|
||||||
|
if (isReaction) {
|
||||||
|
if (mEvent.isRedacted()) {
|
||||||
|
if (!hiddenEvents.hiddenEventReactionTombstone) return false;
|
||||||
|
} else if (!hiddenEvents.hiddenEventReactions) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
isRedactionEvt &&
|
||||||
|
!shouldShowRedactionTimelineEvent(
|
||||||
|
mEvent,
|
||||||
|
timelineSet,
|
||||||
|
hiddenEvents.hiddenEventRedactionTimeline,
|
||||||
|
hiddenEvents.hiddenEventReactionRedactionTimeline
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
[hiddenEvents, hideMemberInReadOnly, isReadOnly, hideMembershipEvents, hideNickAvatarEvents]
|
||||||
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
timelineSyncRef.current = timelineSync;
|
timelineSyncRef.current = timelineSync;
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ const MESSAGE_EVENT_TYPES = new Set([
|
|||||||
'm.room.encrypted',
|
'm.room.encrypted',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const STANDARD_RENDERED_EVENT_TYPES = new Set([
|
export const STANDARD_RENDERED_EVENT_TYPES = new Set([
|
||||||
'm.room.message',
|
'm.room.message',
|
||||||
'm.room.message.encrypted',
|
'm.room.message.encrypted',
|
||||||
'm.sticker',
|
'm.sticker',
|
||||||
@@ -453,12 +453,8 @@ const processTimelineItems = (
|
|||||||
|
|
||||||
if (!(showHiddenEvents && hiddenEventOther)) {
|
if (!(showHiddenEvents && hiddenEventOther)) {
|
||||||
const isStandardRendered = STANDARD_RENDERED_EVENT_TYPES.has(type);
|
const isStandardRendered = STANDARD_RENDERED_EVENT_TYPES.has(type);
|
||||||
if (!isStandardRendered) {
|
if (!isStandardRendered && !allowSpecificHiddenEvent) {
|
||||||
if (Object.keys(mEvent.getContent()).length === 0 && !allowSpecificHiddenEvent) continue;
|
continue;
|
||||||
if (!allowSpecificHiddenEvent) {
|
|
||||||
if (mEvent.getRelation()) continue;
|
|
||||||
if (mEvent.isRedaction()) continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import type {
|
|||||||
Room,
|
Room,
|
||||||
MatrixEvent,
|
MatrixEvent,
|
||||||
EventTimeline,
|
EventTimeline,
|
||||||
|
EventTimelineSet,
|
||||||
EventTimelineSetHandlerMap,
|
EventTimelineSetHandlerMap,
|
||||||
IRoomTimelineData,
|
IRoomTimelineData,
|
||||||
RoomEventHandlerMap,
|
RoomEventHandlerMap,
|
||||||
@@ -103,7 +104,8 @@ const useTimelinePagination = (
|
|||||||
mx: MatrixClient,
|
mx: MatrixClient,
|
||||||
timeline: TimelineState,
|
timeline: TimelineState,
|
||||||
setTimeline: Dispatch<SetStateAction<TimelineState>>,
|
setTimeline: Dispatch<SetStateAction<TimelineState>>,
|
||||||
limit: number
|
limit: number,
|
||||||
|
isEventVisible?: (mEvent: MatrixEvent, timelineSet: EventTimelineSet) => boolean
|
||||||
) => {
|
) => {
|
||||||
const timelineRef = useRef(timeline);
|
const timelineRef = useRef(timeline);
|
||||||
timelineRef.current = timeline;
|
timelineRef.current = timeline;
|
||||||
@@ -183,8 +185,19 @@ const useTimelinePagination = (
|
|||||||
const countAfter = getTimelinesEventsCount(getLinkedTimelines(firstTimeline));
|
const countAfter = getTimelinesEventsCount(getLinkedTimelines(firstTimeline));
|
||||||
const fetched = countAfter - countBefore;
|
const fetched = countAfter - countBefore;
|
||||||
|
|
||||||
|
let visibleFetched = fetched;
|
||||||
|
if (isEventVisible && fetched > 0) {
|
||||||
|
const afterEvents = getLinkedTimelines(firstTimeline).flatMap((t) =>
|
||||||
|
(t.getEvents() || []).map((ev) => ({ ev, ts: t.getTimelineSet() }))
|
||||||
|
);
|
||||||
|
const newEvents = backwards
|
||||||
|
? afterEvents.slice(0, fetched)
|
||||||
|
: afterEvents.slice(afterEvents.length - fetched);
|
||||||
|
visibleFetched = newEvents.filter(({ ev, ts }) => isEventVisible(ev, ts)).length;
|
||||||
|
}
|
||||||
|
|
||||||
let willContinue = false;
|
let willContinue = false;
|
||||||
if (fetched > 0 && fetched < 5) {
|
if (fetched > 0 && visibleFetched < 5) {
|
||||||
const checkTimeline = backwards
|
const checkTimeline = backwards
|
||||||
? freshLTimelines[0]
|
? freshLTimelines[0]
|
||||||
: freshLTimelines[freshLTimelines.length - 1];
|
: freshLTimelines[freshLTimelines.length - 1];
|
||||||
@@ -223,7 +236,7 @@ const useTimelinePagination = (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}, [mx, alive, setTimeline, limit, setBackwardStatus, setForwardStatus]);
|
}, [mx, alive, setTimeline, limit, setBackwardStatus, setForwardStatus, isEventVisible]);
|
||||||
|
|
||||||
return { paginate, backwardStatus, forwardStatus };
|
return { paginate, backwardStatus, forwardStatus };
|
||||||
};
|
};
|
||||||
@@ -357,6 +370,7 @@ export interface UseTimelineSyncOptions {
|
|||||||
setUnreadInfo: Dispatch<SetStateAction<ReturnType<typeof getRoomUnreadInfo>>>;
|
setUnreadInfo: Dispatch<SetStateAction<ReturnType<typeof getRoomUnreadInfo>>>;
|
||||||
hideReadsRef: React.MutableRefObject<boolean>;
|
hideReadsRef: React.MutableRefObject<boolean>;
|
||||||
readUptoEventIdRef: React.MutableRefObject<string | undefined>;
|
readUptoEventIdRef: React.MutableRefObject<string | undefined>;
|
||||||
|
isEventVisible?: (mEvent: MatrixEvent, timelineSet: EventTimelineSet) => boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useTimelineSync({
|
export function useTimelineSync({
|
||||||
@@ -370,6 +384,7 @@ export function useTimelineSync({
|
|||||||
setUnreadInfo,
|
setUnreadInfo,
|
||||||
hideReadsRef,
|
hideReadsRef,
|
||||||
readUptoEventIdRef,
|
readUptoEventIdRef,
|
||||||
|
isEventVisible,
|
||||||
}: UseTimelineSyncOptions) {
|
}: UseTimelineSyncOptions) {
|
||||||
const alive = useAlive();
|
const alive = useAlive();
|
||||||
|
|
||||||
@@ -402,7 +417,7 @@ export function useTimelineSync({
|
|||||||
paginate: handleTimelinePagination,
|
paginate: handleTimelinePagination,
|
||||||
backwardStatus,
|
backwardStatus,
|
||||||
forwardStatus,
|
forwardStatus,
|
||||||
} = useTimelinePagination(mx, timeline, setTimeline, PAGINATION_LIMIT);
|
} = useTimelinePagination(mx, timeline, setTimeline, PAGINATION_LIMIT, isEventVisible);
|
||||||
|
|
||||||
const prevEventsLengthRef = useRef(eventsLength);
|
const prevEventsLengthRef = useRef(eventsLength);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
Reference in new issue
Block a user