Implement MSC3869: Read event relations with the Widget API (#9210)
* Add an action to read relations according to MSC3869 Signed-off-by: Dominik Henneke <dominik.henneke@nordeck.net> * Apply review comments Signed-off-by: Dominik Henneke <dominik.henneke@nordeck.net> * Fix test Signed-off-by: Dominik Henneke <dominik.henneke@nordeck.net> * Update matrix-widget-api to 1.1.1 Signed-off-by: Dominik Henneke <dominik.henneke@nordeck.net> Signed-off-by: Dominik Henneke <dominik.henneke@nordeck.net>
This commit is contained in:
parent
f20d86b7b8
commit
0c22b15bba
4 changed files with 148 additions and 7 deletions
|
@ -21,6 +21,7 @@ import {
|
|||
IOpenIDUpdate,
|
||||
ISendEventDetails,
|
||||
ITurnServer,
|
||||
IReadEventRelationsResult,
|
||||
IRoomEvent,
|
||||
MatrixCapabilities,
|
||||
OpenIDRequestState,
|
||||
|
@ -37,6 +38,7 @@ import { IContent, IEvent, MatrixEvent } from "matrix-js-sdk/src/models/event";
|
|||
import { Room } from "matrix-js-sdk/src/models/room";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
import { THREAD_RELATION_TYPE } from "matrix-js-sdk/src/models/thread";
|
||||
import { Direction } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import { iterableDiff, iterableIntersection } from "../../utils/iterables";
|
||||
import { MatrixClientPeg } from "../../MatrixClientPeg";
|
||||
|
@ -366,4 +368,47 @@ export class StopGapWidgetDriver extends WidgetDriver {
|
|||
client.off(ClientEvent.TurnServersError, onTurnServersError);
|
||||
}
|
||||
}
|
||||
|
||||
public async readEventRelations(
|
||||
eventId: string,
|
||||
roomId?: string,
|
||||
relationType?: string,
|
||||
eventType?: string,
|
||||
from?: string,
|
||||
to?: string,
|
||||
limit?: number,
|
||||
direction?: 'f' | 'b',
|
||||
): Promise<IReadEventRelationsResult> {
|
||||
const client = MatrixClientPeg.get();
|
||||
const dir = direction as Direction;
|
||||
roomId = roomId ?? RoomViewStore.instance.getRoomId() ?? undefined;
|
||||
|
||||
if (typeof roomId !== "string") {
|
||||
throw new Error('Error while reading the current room');
|
||||
}
|
||||
|
||||
const {
|
||||
originalEvent,
|
||||
events,
|
||||
nextBatch,
|
||||
prevBatch,
|
||||
} = await client.relations(
|
||||
roomId,
|
||||
eventId,
|
||||
relationType ?? null,
|
||||
eventType ?? null,
|
||||
{
|
||||
from,
|
||||
to,
|
||||
limit,
|
||||
direction: dir,
|
||||
});
|
||||
|
||||
return {
|
||||
originalEvent: originalEvent?.getEffectiveEvent(),
|
||||
chunk: events.map(e => e.getEffectiveEvent()),
|
||||
nextBatch,
|
||||
prevBatch,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue