Use updated createThread method (#7670)

This commit is contained in:
Germain 2022-02-01 08:58:45 +00:00 committed by GitHub
parent 3e1a5f7021
commit 0e36f91d76
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 10 deletions

View file

@ -88,7 +88,7 @@ async function getThreadTimelineSet(
const timelineSet = new EventTimelineSet(room, {});
Array.from(room.threads)
.sort(([, threadA], [, threadB]) => threadA.lastReply().getTs() - threadB.lastReply().getTs())
.sort(([, threadA], [, threadB]) => threadA.replyToEvent.getTs() - threadB.replyToEvent.getTs())
.forEach(([, thread]) => {
const isOwnEvent = thread.rootEvent.getSender() === client.getUserId();
if (filterType !== ThreadFilterType.My || isOwnEvent) {

View file

@ -15,9 +15,13 @@ limitations under the License.
*/
import React from 'react';
import { IEventRelation, MatrixEvent, Room } from 'matrix-js-sdk/src';
import { Thread, ThreadEvent } from 'matrix-js-sdk/src/models/thread';
import { RelationType } from 'matrix-js-sdk/src/@types/event';
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 classNames from "classnames";
import BaseCard from "../views/right_panel/BaseCard";
@ -141,7 +145,7 @@ export default class ThreadView extends React.Component<IProps, IState> {
private setupThread = (mxEv: MatrixEvent) => {
let thread = this.props.room.threads?.get(mxEv.getId());
if (!thread) {
thread = this.props.room.createThread([mxEv]);
thread = this.props.room.createThread(mxEv);
}
thread.on(ThreadEvent.Update, this.updateLastThreadReply);
thread.once(ThreadEvent.Ready, this.updateThread);
@ -167,10 +171,13 @@ export default class ThreadView extends React.Component<IProps, IState> {
this.setState({
thread,
lastThreadReply: thread.lastReply((ev: MatrixEvent) => {
return !ev.status;
return ev.isThreadRelation && !ev.status;
}),
}, () => {
}, async () => {
thread.emit(ThreadEvent.ViewThread);
if (!thread.initialEventsFetched) {
await thread.fetchInitialEvents();
}
this.timelinePanelRef.current?.refreshTimeline();
});
}
@ -180,7 +187,7 @@ export default class ThreadView extends React.Component<IProps, IState> {
if (this.state.thread) {
this.setState({
lastThreadReply: this.state.thread.lastReply((ev: MatrixEvent) => {
return !ev.status;
return ev.isThreadRelation && !ev.status;
}),
});
}
@ -207,6 +214,31 @@ export default class ThreadView extends React.Component<IProps, IState> {
</div>;
};
private onPaginationRequest = async (
timelineWindow: TimelineWindow | null,
direction = Direction.Backward,
limit = 20,
): Promise<boolean> => {
if (!this.state.thread.hasServerSideSupport) {
return false;
}
const timelineIndex = timelineWindow.getTimelineIndex(direction);
const paginationKey = direction === Direction.Backward ? "from" : "to";
const paginationToken = timelineIndex.timeline.getPaginationToken(direction);
const opts: IRelationsRequestOpts = {
limit,
[paginationKey]: paginationToken,
direction,
};
await this.state.thread.fetchEvents(opts);
return timelineWindow.paginate(direction, limit);
};
public render(): JSX.Element {
const highlightedEventId = this.props.isInitialEventHighlighted
? this.props.initialEvent?.getId()
@ -262,6 +294,7 @@ export default class ThreadView extends React.Component<IProps, IState> {
eventId={this.props.initialEvent?.getId()}
highlightedEventId={highlightedEventId}
onUserScroll={this.onScroll}
onPaginationRequest={this.onPaginationRequest}
/>
) }

View file

@ -407,7 +407,7 @@ export default class EventTile extends React.Component<IProps, IState> {
thread,
threadReplyCount: thread?.length,
threadLastReply: thread?.lastReply(),
threadLastReply: thread?.replyToEvent,
};
// don't do RR animations until we are mounted
@ -561,7 +561,7 @@ export default class EventTile extends React.Component<IProps, IState> {
}
this.setState({
threadLastReply: thread?.lastReply(),
threadLastReply: thread?.replyToEvent,
threadReplyCount: thread?.length,
thread,
});
@ -1290,7 +1290,7 @@ export default class EventTile extends React.Component<IProps, IState> {
// Thread panel shows the timestamp of the last reply in that thread
const ts = this.props.tileShape !== TileShape.ThreadPanel
? this.props.mxEvent.getTs()
: thread?.lastReply().getTs();
: thread?.replyToEvent.getTs();
const messageTimestamp = <MessageTimestamp
showRelative={this.props.tileShape === TileShape.ThreadPanel}

View file

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