Implement deep-linking for threads (matrix.to) (#7003)
This commit is contained in:
parent
bc32f05fcb
commit
e20ac7bf1e
8 changed files with 122 additions and 12 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue