Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit f820603

Browse files
committed
update tests to use new thread support method
1 parent 644cf0e commit f820603

File tree

6 files changed

+15
-40
lines changed

6 files changed

+15
-40
lines changed

src/components/structures/ThreadPanel.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ const ThreadPanel: React.FC<IProps> = ({
230230

231231
useEffect(() => {
232232
if (timelineSet && !Thread.hasServerSideSupport) {
233+
timelineSet.resetLiveTimeline();
233234
timelinePanel.current.refreshTimeline();
234235
}
235236
}, [timelineSet, timelinePanel]);

src/components/structures/ThreadView.tsx

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import { Room } from 'matrix-js-sdk/src/models/room';
2020
import { IEventRelation, MatrixEvent } from 'matrix-js-sdk/src/models/event';
2121
import { TimelineWindow } from 'matrix-js-sdk/src/timeline-window';
2222
import { Direction } from 'matrix-js-sdk/src/models/event-timeline';
23-
import { IRelationsRequestOpts } from 'matrix-js-sdk/src/@types/requests';
2423
import { logger } from 'matrix-js-sdk/src/logger';
2524
import classNames from 'classnames';
2625

@@ -195,9 +194,7 @@ export default class ThreadView extends React.Component<IProps, IState> {
195194
thread,
196195
}, async () => {
197196
thread.emit(ThreadEvent.ViewThread);
198-
await thread.fetchInitialEvents();
199-
this.nextBatch = thread.liveTimeline.getPaginationToken(Direction.Backward);
200-
this.timelinePanel.current?.refreshTimeline();
197+
this.timelinePanel.current?.refreshTimeline(this.props.initialEvent?.getId());
201198
});
202199
}
203200
};
@@ -242,35 +239,12 @@ export default class ThreadView extends React.Component<IProps, IState> {
242239
}
243240
};
244241

245-
private nextBatch: string;
246-
247242
private onPaginationRequest = async (
248243
timelineWindow: TimelineWindow | null,
249244
direction = Direction.Backward,
250245
limit = 20,
251246
): Promise<boolean> => {
252-
if (!Thread.hasServerSideSupport) {
253-
timelineWindow.extend(direction, limit);
254-
return true;
255-
}
256-
257-
const opts: IRelationsRequestOpts = {
258-
limit,
259-
};
260-
261-
if (this.nextBatch) {
262-
opts.from = this.nextBatch;
263-
}
264-
265-
const { nextBatch } = await this.state.thread.fetchEvents(opts);
266-
267-
this.nextBatch = nextBatch;
268-
269-
// Advances the marker on the TimelineWindow to define the correct
270-
// window of events to display on screen
271-
timelineWindow.extend(direction, limit);
272-
273-
return !!nextBatch;
247+
return timelineWindow.paginate(direction, limit);
274248
};
275249

276250
private onFileDrop = (dataTransfer: DataTransfer) => {

src/stores/widgets/StopGapWidgetDriver.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -443,12 +443,8 @@ export class StopGapWidgetDriver extends WidgetDriver {
443443
eventId,
444444
relationType ?? null,
445445
eventType ?? null,
446-
{
447-
from,
448-
to,
449-
limit,
450-
direction: dir,
451-
});
446+
{ from, to, limit, dir },
447+
);
452448

453449
return {
454450
originalEvent: originalEvent?.getEffectiveEvent(),

src/utils/EventUtils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,12 @@ export async function fetchInitialEvent(
238238
) {
239239
const threadId = initialEvent.threadRootId;
240240
const room = client.getRoom(roomId);
241+
const mapper = client.getEventMapper();
242+
const rootEvent = room.findEventById(threadId)
243+
?? mapper(await client.fetchRoomEvent(roomId, threadId));
241244
try {
242-
room.createThread(threadId, room.findEventById(threadId), [initialEvent], true);
245+
const thread = room.createThread(threadId, rootEvent, [initialEvent], true);
246+
initialEvent.setThread(thread);
243247
} catch (e) {
244248
logger.warn("Could not find root event: " + threadId);
245249
}

test/components/views/context_menus/MessageContextMenu-test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
EventType,
2828
} from 'matrix-js-sdk/src/matrix';
2929
import { ExtensibleEvent, MessageEvent, M_POLL_KIND_DISCLOSED, PollStartEvent } from 'matrix-events-sdk';
30-
import { Thread } from "matrix-js-sdk/src/models/thread";
30+
import { FeatureSupport, Thread } from "matrix-js-sdk/src/models/thread";
3131
import { mocked } from "jest-mock";
3232
import { act } from '@testing-library/react';
3333

@@ -469,7 +469,7 @@ describe('MessageContextMenu', () => {
469469
const eventContent = MessageEvent.from("hello");
470470
const mxEvent = new MatrixEvent(eventContent.serialize());
471471

472-
Thread.hasServerSideSupport = true;
472+
Thread.hasServerSideSupport = FeatureSupport.Experimental;
473473
const context = {
474474
canSendMessages: true,
475475
};

test/components/views/messages/MessageActionBar-test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
MsgType,
2626
Room,
2727
} from 'matrix-js-sdk/src/matrix';
28-
import { Thread } from 'matrix-js-sdk/src/models/thread';
28+
import { FeatureSupport, Thread } from 'matrix-js-sdk/src/models/thread';
2929

3030
import MessageActionBar from '../../../../src/components/views/messages/MessageActionBar';
3131
import {
@@ -388,13 +388,13 @@ describe('<MessageActionBar />', () => {
388388

389389
describe('thread button', () => {
390390
beforeEach(() => {
391-
Thread.setServerSideSupport(true, false);
391+
Thread.setServerSideSupport(FeatureSupport.Experimental);
392392
});
393393

394394
describe('when threads feature is not enabled', () => {
395395
it('does not render thread button when threads does not have server support', () => {
396396
jest.spyOn(SettingsStore, 'getValue').mockReturnValue(false);
397-
Thread.setServerSideSupport(false, false);
397+
Thread.setServerSideSupport(FeatureSupport.None);
398398
const { queryByLabelText } = getComponent({ mxEvent: alicesMessageEvent });
399399
expect(queryByLabelText('Reply in thread')).toBeFalsy();
400400
});

0 commit comments

Comments
 (0)