Fix missing threads in thread list (#8011)

Co-authored-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Germain 2022-03-10 16:44:50 +00:00 committed by GitHub
parent 3f67a389c1
commit 246d6757ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 25 deletions

View file

@ -26,6 +26,7 @@ import {
UNSTABLE_FILTER_RELATED_BY_REL_TYPES, UNSTABLE_FILTER_RELATED_BY_REL_TYPES,
} from 'matrix-js-sdk/src/filter'; } from 'matrix-js-sdk/src/filter';
import { Thread, ThreadEvent } from 'matrix-js-sdk/src/models/thread'; import { Thread, ThreadEvent } from 'matrix-js-sdk/src/models/thread';
import { EventTimeline } from 'matrix-js-sdk/src/models/event-timeline';
import BaseCard from "../views/right_panel/BaseCard"; import BaseCard from "../views/right_panel/BaseCard";
import ResizeNotifier from '../../utils/ResizeNotifier'; import ResizeNotifier from '../../utils/ResizeNotifier';
@ -76,11 +77,10 @@ export async function getThreadTimelineSet(
}, },
); );
timelineSet.resetLiveTimeline(); // An empty pagination token allows to paginate from the very bottom of
await client.paginateEventTimeline( // the timeline set.
timelineSet.getLiveTimeline(), timelineSet.getLiveTimeline().setPaginationToken("", EventTimeline.BACKWARDS);
{ backwards: true, limit: 20 },
);
return timelineSet; return timelineSet;
} else { } else {
// Filter creation fails if HomeServer does not support the new relation // Filter creation fails if HomeServer does not support the new relation
@ -238,30 +238,15 @@ const ThreadPanel: React.FC<IProps> = ({ roomId, onClose, permalinkCreator }) =>
}, [mxClient, roomId]); }, [mxClient, roomId]);
useEffect(() => { useEffect(() => {
async function onNewThread(thread: Thread): Promise<void> { async function onNewThread(thread: Thread, toStartOfTimeline: boolean): Promise<void> {
setThreadCount(room.threads.size); setThreadCount(room.threads.size);
if (timelineSet) { if (timelineSet) {
const discoveredScrollingBack =
room.lastThread.rootEvent.localTimestamp < thread.rootEvent.localTimestamp;
// When the server support threads we're only interested in adding // When the server support threads we're only interested in adding
// the newly created threads to the list. // the newly created threads to the list.
// The ones discovered when scrolling back should be discarded as // The ones discovered when scrolling back should be discarded as
// they will be discovered by the `/messages` filter // they will be discovered by the `/messages` filter
if (Thread.hasServerSideSupport) { if (!Thread.hasServerSideSupport || !toStartOfTimeline) {
if (!discoveredScrollingBack) { timelineSet.addEventToTimeline(thread.rootEvent, timelineSet.getLiveTimeline(), toStartOfTimeline);
timelineSet.addEventToTimeline(
thread.rootEvent,
timelineSet.getLiveTimeline(),
false,
);
}
} else {
timelineSet.addEventToTimeline(
thread.rootEvent,
timelineSet.getLiveTimeline(),
!discoveredScrollingBack,
);
} }
} }
} }

View file

@ -157,7 +157,7 @@ export default class ThreadView extends React.Component<IProps, IState> {
private setupThread = (mxEv: MatrixEvent) => { private setupThread = (mxEv: MatrixEvent) => {
let thread = this.props.room.threads?.get(mxEv.getId()); let thread = this.props.room.threads?.get(mxEv.getId());
if (!thread) { if (!thread) {
thread = this.props.room.createThread(mxEv, [mxEv]); thread = this.props.room.createThread(mxEv, [mxEv], true);
} }
thread.on(ThreadEvent.Update, this.updateLastThreadReply); thread.on(ThreadEvent.Update, this.updateLastThreadReply);
this.updateThread(thread); this.updateThread(thread);

View file

@ -308,7 +308,7 @@ export async function fetchInitialEvent(
const rootEventData = await client.fetchRoomEvent(roomId, initialEvent.threadRootId); const rootEventData = await client.fetchRoomEvent(roomId, initialEvent.threadRootId);
const rootEvent = new MatrixEvent(rootEventData); const rootEvent = new MatrixEvent(rootEventData);
const room = client.getRoom(roomId); const room = client.getRoom(roomId);
room.createThread(rootEvent); room.createThread(rootEvent, [rootEvent], true);
} catch (e) { } catch (e) {
logger.warn("Could not find root event: " + initialEvent.threadRootId); logger.warn("Could not find root event: " + initialEvent.threadRootId);
} }