You've already forked matrix-react-sdk
mirror of
https://github.com/matrix-org/matrix-react-sdk.git
synced 2025-07-09 14:21:50 +03:00
Implement deep-linking for threads (matrix.to) (#7003)
This commit is contained in:
@ -21,6 +21,9 @@ import shouldHideEvent from "../shouldHideEvent";
|
||||
import { getHandlerTile, haveTileForEvent } from "../components/views/rooms/EventTile";
|
||||
import SettingsStore from "../settings/SettingsStore";
|
||||
import { EventType } from "matrix-js-sdk/src/@types/event";
|
||||
import { MatrixClient } from 'matrix-js-sdk/src/client';
|
||||
import { Thread } from 'matrix-js-sdk/src/models/thread';
|
||||
import { logger } from 'matrix-js-sdk/src/logger';
|
||||
|
||||
/**
|
||||
* Returns whether an event should allow actions like reply, reactions, edit, etc.
|
||||
@ -158,3 +161,37 @@ export function isVoiceMessage(mxEvent: MatrixEvent): boolean {
|
||||
!!content['org.matrix.msc3245.voice']
|
||||
);
|
||||
}
|
||||
|
||||
export async function fetchInitialEvent(
|
||||
client: MatrixClient,
|
||||
roomId: string,
|
||||
eventId: string): Promise<MatrixEvent | null> {
|
||||
let initialEvent: MatrixEvent;
|
||||
|
||||
try {
|
||||
const eventData = await client.fetchRoomEvent(roomId, eventId);
|
||||
initialEvent = new MatrixEvent(eventData);
|
||||
} catch (e) {
|
||||
logger.warn("Could not find initial event: " + initialEvent.threadRootId);
|
||||
initialEvent = null;
|
||||
}
|
||||
|
||||
if (initialEvent?.isThreadRelation) {
|
||||
try {
|
||||
const rootEventData = await client.fetchRoomEvent(roomId, initialEvent.threadRootId);
|
||||
const rootEvent = new MatrixEvent(rootEventData);
|
||||
const room = client.getRoom(roomId);
|
||||
const thread = new Thread(
|
||||
[rootEvent],
|
||||
room,
|
||||
client,
|
||||
);
|
||||
thread.addEvent(initialEvent);
|
||||
room.threads.set(thread.id, thread);
|
||||
} catch (e) {
|
||||
logger.warn("Could not find root event: " + initialEvent.threadRootId);
|
||||
}
|
||||
}
|
||||
|
||||
return initialEvent;
|
||||
}
|
||||
|
Reference in New Issue
Block a user