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

Commit

Permalink
update tests to use new thread support method
Browse files Browse the repository at this point in the history
  • Loading branch information
justjanne committed Oct 6, 2022
1 parent 644cf0e commit f820603
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 40 deletions.
1 change: 1 addition & 0 deletions src/components/structures/ThreadPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ const ThreadPanel: React.FC<IProps> = ({

useEffect(() => {
if (timelineSet && !Thread.hasServerSideSupport) {
timelineSet.resetLiveTimeline();
timelinePanel.current.refreshTimeline();
}
}, [timelineSet, timelinePanel]);
Expand Down
30 changes: 2 additions & 28 deletions src/components/structures/ThreadView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { Room } from 'matrix-js-sdk/src/models/room';
import { IEventRelation, MatrixEvent } from 'matrix-js-sdk/src/models/event';
import { TimelineWindow } from 'matrix-js-sdk/src/timeline-window';
import { Direction } from 'matrix-js-sdk/src/models/event-timeline';
import { IRelationsRequestOpts } from 'matrix-js-sdk/src/@types/requests';
import { logger } from 'matrix-js-sdk/src/logger';
import classNames from 'classnames';

Expand Down Expand Up @@ -195,9 +194,7 @@ export default class ThreadView extends React.Component<IProps, IState> {
thread,
}, async () => {
thread.emit(ThreadEvent.ViewThread);
await thread.fetchInitialEvents();
this.nextBatch = thread.liveTimeline.getPaginationToken(Direction.Backward);
this.timelinePanel.current?.refreshTimeline();
this.timelinePanel.current?.refreshTimeline(this.props.initialEvent?.getId());
});
}
};
Expand Down Expand Up @@ -242,35 +239,12 @@ export default class ThreadView extends React.Component<IProps, IState> {
}
};

private nextBatch: string;

private onPaginationRequest = async (
timelineWindow: TimelineWindow | null,
direction = Direction.Backward,
limit = 20,
): Promise<boolean> => {
if (!Thread.hasServerSideSupport) {
timelineWindow.extend(direction, limit);
return true;
}

const opts: IRelationsRequestOpts = {
limit,
};

if (this.nextBatch) {
opts.from = this.nextBatch;
}

const { nextBatch } = await this.state.thread.fetchEvents(opts);

this.nextBatch = nextBatch;

// Advances the marker on the TimelineWindow to define the correct
// window of events to display on screen
timelineWindow.extend(direction, limit);

return !!nextBatch;
return timelineWindow.paginate(direction, limit);
};

private onFileDrop = (dataTransfer: DataTransfer) => {
Expand Down
8 changes: 2 additions & 6 deletions src/stores/widgets/StopGapWidgetDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,12 +443,8 @@ export class StopGapWidgetDriver extends WidgetDriver {
eventId,
relationType ?? null,
eventType ?? null,
{
from,
to,
limit,
direction: dir,
});
{ from, to, limit, dir },
);

return {
originalEvent: originalEvent?.getEffectiveEvent(),
Expand Down
6 changes: 5 additions & 1 deletion src/utils/EventUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,12 @@ export async function fetchInitialEvent(
) {
const threadId = initialEvent.threadRootId;
const room = client.getRoom(roomId);
const mapper = client.getEventMapper();
const rootEvent = room.findEventById(threadId)
?? mapper(await client.fetchRoomEvent(roomId, threadId));
try {
room.createThread(threadId, room.findEventById(threadId), [initialEvent], true);
const thread = room.createThread(threadId, rootEvent, [initialEvent], true);
initialEvent.setThread(thread);
} catch (e) {
logger.warn("Could not find root event: " + threadId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
EventType,
} from 'matrix-js-sdk/src/matrix';
import { ExtensibleEvent, MessageEvent, M_POLL_KIND_DISCLOSED, PollStartEvent } from 'matrix-events-sdk';
import { Thread } from "matrix-js-sdk/src/models/thread";
import { FeatureSupport, Thread } from "matrix-js-sdk/src/models/thread";
import { mocked } from "jest-mock";
import { act } from '@testing-library/react';

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

Thread.hasServerSideSupport = true;
Thread.hasServerSideSupport = FeatureSupport.Experimental;
const context = {
canSendMessages: true,
};
Expand Down
6 changes: 3 additions & 3 deletions test/components/views/messages/MessageActionBar-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
MsgType,
Room,
} from 'matrix-js-sdk/src/matrix';
import { Thread } from 'matrix-js-sdk/src/models/thread';
import { FeatureSupport, Thread } from 'matrix-js-sdk/src/models/thread';

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

describe('thread button', () => {
beforeEach(() => {
Thread.setServerSideSupport(true, false);
Thread.setServerSideSupport(FeatureSupport.Experimental);
});

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

0 comments on commit f820603

Please sign in to comment.