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

Commit 0e36f91

Browse files
author
Germain
authored
Use updated createThread method (#7670)
1 parent 3e1a5f7 commit 0e36f91

File tree

4 files changed

+43
-10
lines changed

4 files changed

+43
-10
lines changed

src/components/structures/ThreadPanel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ async function getThreadTimelineSet(
8888
const timelineSet = new EventTimelineSet(room, {});
8989

9090
Array.from(room.threads)
91-
.sort(([, threadA], [, threadB]) => threadA.lastReply().getTs() - threadB.lastReply().getTs())
91+
.sort(([, threadA], [, threadB]) => threadA.replyToEvent.getTs() - threadB.replyToEvent.getTs())
9292
.forEach(([, thread]) => {
9393
const isOwnEvent = thread.rootEvent.getSender() === client.getUserId();
9494
if (filterType !== ThreadFilterType.My || isOwnEvent) {

src/components/structures/ThreadView.tsx

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@ limitations under the License.
1515
*/
1616

1717
import React from 'react';
18-
import { IEventRelation, MatrixEvent, Room } from 'matrix-js-sdk/src';
1918
import { Thread, ThreadEvent } from 'matrix-js-sdk/src/models/thread';
2019
import { RelationType } from 'matrix-js-sdk/src/@types/event';
20+
import { Room } from 'matrix-js-sdk/src/models/room';
21+
import { IEventRelation, MatrixEvent } from 'matrix-js-sdk/src/models/event';
22+
import { TimelineWindow } from 'matrix-js-sdk/src/timeline-window';
23+
import { Direction } from 'matrix-js-sdk/src/models/event-timeline';
24+
import { IRelationsRequestOpts } from 'matrix-js-sdk/src/@types/requests';
2125
import classNames from "classnames";
2226

2327
import BaseCard from "../views/right_panel/BaseCard";
@@ -141,7 +145,7 @@ export default class ThreadView extends React.Component<IProps, IState> {
141145
private setupThread = (mxEv: MatrixEvent) => {
142146
let thread = this.props.room.threads?.get(mxEv.getId());
143147
if (!thread) {
144-
thread = this.props.room.createThread([mxEv]);
148+
thread = this.props.room.createThread(mxEv);
145149
}
146150
thread.on(ThreadEvent.Update, this.updateLastThreadReply);
147151
thread.once(ThreadEvent.Ready, this.updateThread);
@@ -167,10 +171,13 @@ export default class ThreadView extends React.Component<IProps, IState> {
167171
this.setState({
168172
thread,
169173
lastThreadReply: thread.lastReply((ev: MatrixEvent) => {
170-
return !ev.status;
174+
return ev.isThreadRelation && !ev.status;
171175
}),
172-
}, () => {
176+
}, async () => {
173177
thread.emit(ThreadEvent.ViewThread);
178+
if (!thread.initialEventsFetched) {
179+
await thread.fetchInitialEvents();
180+
}
174181
this.timelinePanelRef.current?.refreshTimeline();
175182
});
176183
}
@@ -180,7 +187,7 @@ export default class ThreadView extends React.Component<IProps, IState> {
180187
if (this.state.thread) {
181188
this.setState({
182189
lastThreadReply: this.state.thread.lastReply((ev: MatrixEvent) => {
183-
return !ev.status;
190+
return ev.isThreadRelation && !ev.status;
184191
}),
185192
});
186193
}
@@ -207,6 +214,31 @@ export default class ThreadView extends React.Component<IProps, IState> {
207214
</div>;
208215
};
209216

217+
private onPaginationRequest = async (
218+
timelineWindow: TimelineWindow | null,
219+
direction = Direction.Backward,
220+
limit = 20,
221+
): Promise<boolean> => {
222+
if (!this.state.thread.hasServerSideSupport) {
223+
return false;
224+
}
225+
226+
const timelineIndex = timelineWindow.getTimelineIndex(direction);
227+
228+
const paginationKey = direction === Direction.Backward ? "from" : "to";
229+
const paginationToken = timelineIndex.timeline.getPaginationToken(direction);
230+
231+
const opts: IRelationsRequestOpts = {
232+
limit,
233+
[paginationKey]: paginationToken,
234+
direction,
235+
};
236+
237+
await this.state.thread.fetchEvents(opts);
238+
239+
return timelineWindow.paginate(direction, limit);
240+
};
241+
210242
public render(): JSX.Element {
211243
const highlightedEventId = this.props.isInitialEventHighlighted
212244
? this.props.initialEvent?.getId()
@@ -262,6 +294,7 @@ export default class ThreadView extends React.Component<IProps, IState> {
262294
eventId={this.props.initialEvent?.getId()}
263295
highlightedEventId={highlightedEventId}
264296
onUserScroll={this.onScroll}
297+
onPaginationRequest={this.onPaginationRequest}
265298
/>
266299
) }
267300

src/components/views/rooms/EventTile.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ export default class EventTile extends React.Component<IProps, IState> {
407407

408408
thread,
409409
threadReplyCount: thread?.length,
410-
threadLastReply: thread?.lastReply(),
410+
threadLastReply: thread?.replyToEvent,
411411
};
412412

413413
// don't do RR animations until we are mounted
@@ -561,7 +561,7 @@ export default class EventTile extends React.Component<IProps, IState> {
561561
}
562562

563563
this.setState({
564-
threadLastReply: thread?.lastReply(),
564+
threadLastReply: thread?.replyToEvent,
565565
threadReplyCount: thread?.length,
566566
thread,
567567
});
@@ -1290,7 +1290,7 @@ export default class EventTile extends React.Component<IProps, IState> {
12901290
// Thread panel shows the timestamp of the last reply in that thread
12911291
const ts = this.props.tileShape !== TileShape.ThreadPanel
12921292
? this.props.mxEvent.getTs()
1293-
: thread?.lastReply().getTs();
1293+
: thread?.replyToEvent.getTs();
12941294

12951295
const messageTimestamp = <MessageTimestamp
12961296
showRelative={this.props.tileShape === TileShape.ThreadPanel}

src/utils/EventUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ export async function fetchInitialEvent(
290290
const rootEventData = await client.fetchRoomEvent(roomId, initialEvent.threadRootId);
291291
const rootEvent = new MatrixEvent(rootEventData);
292292
const room = client.getRoom(roomId);
293-
room.createThread([rootEvent]);
293+
room.createThread(rootEvent);
294294
} catch (e) {
295295
logger.warn("Could not find root event: " + initialEvent.threadRootId);
296296
}

0 commit comments

Comments
 (0)